4133
|
1 /*
|
|
2 * Copyright (c) 2011, 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 *
|
|
23 */
|
|
24
|
|
25 #ifndef SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP
|
|
26 #define SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP
|
|
27
|
|
28 #include "classfile/vmSymbols.hpp"
|
|
29 #include "memory/allocation.hpp"
|
|
30 #include "runtime/os.hpp"
|
|
31 #include "runtime/thread.hpp"
|
|
32 #include "utilities/exceptions.hpp"
|
|
33
|
|
34 class GenDCmdArgument : public ResourceObj {
|
|
35 protected:
|
|
36 GenDCmdArgument* _next;
|
|
37 const char* _name;
|
|
38 const char* _description;
|
|
39 const char* _type;
|
|
40 const char* _default_string;
|
|
41 bool _is_set;
|
|
42 bool _is_mandatory;
|
|
43 GenDCmdArgument(const char* name, const char* description, const char* type,
|
|
44 const char* default_string, bool mandatory) {
|
|
45 _name = name;
|
|
46 _description = description;
|
|
47 _type = type;
|
|
48 _default_string = default_string;
|
|
49 _is_mandatory = mandatory;
|
|
50 _is_set = false;
|
|
51 };
|
|
52 public:
|
|
53 const char* name() { return _name; }
|
|
54 const char* description() { return _description; }
|
|
55 const char* type() { return _type; }
|
|
56 const char* default_string() { return _default_string; }
|
|
57 bool is_set() { return _is_set; }
|
|
58 void set_is_set(bool b) { _is_set = b; }
|
|
59 bool is_mandatory() { return _is_mandatory; }
|
|
60 bool has_value() { return _is_set || _default_string != NULL; }
|
|
61 bool has_default() { return _default_string != NULL; }
|
|
62 void read_value(const char* str, size_t len, TRAPS);
|
|
63 virtual void parse_value(const char* str, size_t len, TRAPS) = 0;
|
|
64 virtual void init_value(TRAPS) = 0;
|
|
65 virtual void reset(TRAPS) = 0;
|
|
66 virtual void cleanup() = 0;
|
|
67 void set_next(GenDCmdArgument* arg) {
|
|
68 _next = arg;
|
|
69 }
|
|
70 GenDCmdArgument* next() {
|
|
71 return _next;
|
|
72 }
|
|
73 };
|
|
74
|
|
75 template <class ArgType> class DCmdArgument: public GenDCmdArgument {
|
|
76 private:
|
|
77 ArgType _value;
|
|
78 public:
|
|
79 DCmdArgument(const char* name, const char* description, const char* type,
|
|
80 bool mandatory) :
|
|
81 GenDCmdArgument(name, description, type, NULL, mandatory) { }
|
|
82 DCmdArgument(const char* name, const char* description, const char* type,
|
|
83 bool mandatory, const char* defaultvalue) :
|
|
84 GenDCmdArgument(name, description, type, defaultvalue, mandatory)
|
|
85 { }
|
|
86 ~DCmdArgument() { destroy_value(); }
|
|
87 ArgType value() { return _value;}
|
|
88 void set_value(ArgType v) { _value = v; }
|
|
89 void reset(TRAPS) {
|
|
90 destroy_value();
|
|
91 init_value(CHECK);
|
|
92 _is_set = false;
|
|
93 }
|
|
94 void cleanup() {
|
|
95 destroy_value();
|
|
96 }
|
|
97 void parse_value(const char* str, size_t len, TRAPS);
|
|
98 void init_value(TRAPS);
|
|
99 void destroy_value();
|
|
100 };
|
|
101
|
|
102 #endif /* SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP */
|