1 /*
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
105 public:
106 enum {
107 name_length_max = 16, // maximum length of name
108 arg_length_max = 1024, // maximum length of argument
109 arg_count_max = 3 // maximum number of arguments
110 };
111
112 // name of special operation that can be enqueued when all
113 // clients detach
114 static char* detachall_operation_name() { return (char*)"detachall"; }
115
116 private:
117 char _name[name_length_max+1];
118 char _arg[arg_count_max][arg_length_max+1];
119
120 public:
121 const char* name() const { return _name; }
122
123 // set the operation name
124 void set_name(char* name) {
125 size_t len = strlen(name);
126 assert(len <= name_length_max, "exceeds maximum name length");
127 memcpy(_name, name, MIN2(len + 1, (size_t)name_length_max));
128 }
129
130 // get an argument value
131 const char* arg(int i) const {
132 assert(i>=0 && i<arg_count_max, "invalid argument index");
133 return _arg[i];
134 }
135
136 // set an argument value
137 void set_arg(int i, char* arg) {
138 assert(i>=0 && i<arg_count_max, "invalid argument index");
139 if (arg == NULL) {
140 _arg[i][0] = '\0';
141 } else {
142 size_t len = strlen(arg);
143 assert(len <= arg_length_max, "exceeds maximum argument length");
144 memcpy(_arg[i], arg, MIN2(len + 1, (size_t)arg_length_max));
145 }
146 }
147
148 // create an operation of a given name
149 AttachOperation(char* name) {
150 set_name(name);
151 for (int i=0; i<arg_count_max; i++) {
152 set_arg(i, NULL);
153 }
154 }
155
156 // complete operation by sending result code and any result data to the client
157 virtual void complete(jint result, bufferedStream* result_stream) = 0;
158 };
159 #endif // INCLUDE_SERVICES
160
161 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP
|
1 /*
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
105 public:
106 enum {
107 name_length_max = 16, // maximum length of name
108 arg_length_max = 1024, // maximum length of argument
109 arg_count_max = 3 // maximum number of arguments
110 };
111
112 // name of special operation that can be enqueued when all
113 // clients detach
114 static char* detachall_operation_name() { return (char*)"detachall"; }
115
116 private:
117 char _name[name_length_max+1];
118 char _arg[arg_count_max][arg_length_max+1];
119
120 public:
121 const char* name() const { return _name; }
122
123 // set the operation name
124 void set_name(char* name) {
125 assert(strlen(name) <= name_length_max, "exceeds maximum name length");
126 size_t len = MIN2(strlen(name), (size_t)name_length_max);
127 memcpy(_name, name, len);
128 _name[len] = '\0';
129 }
130
131 // get an argument value
132 const char* arg(int i) const {
133 assert(i>=0 && i<arg_count_max, "invalid argument index");
134 return _arg[i];
135 }
136
137 // set an argument value
138 void set_arg(int i, char* arg) {
139 assert(i>=0 && i<arg_count_max, "invalid argument index");
140 if (arg == NULL) {
141 _arg[i][0] = '\0';
142 } else {
143 assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
144 size_t len = MIN2(strlen(arg), (size_t)arg_length_max);
145 memcpy(_arg[i], arg, len);
146 _arg[i][len] = '\0';
147 }
148 }
149
150 // create an operation of a given name
151 AttachOperation(char* name) {
152 set_name(name);
153 for (int i=0; i<arg_count_max; i++) {
154 set_arg(i, NULL);
155 }
156 }
157
158 // complete operation by sending result code and any result data to the client
159 virtual void complete(jint result, bufferedStream* result_stream) = 0;
160 };
161 #endif // INCLUDE_SERVICES
162
163 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP
|