Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Param_Test / options.cpp
blob52dc12bd4ba5e393df791cb2b4b1970e94a2982e
2 //=============================================================================
3 /**
4 * @file options.cpp
6 * Options for the Param_Test application
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
13 #include "options.h"
14 #include "tao/debug.h"
15 #include "ace/Read_Buffer.h"
16 #include "ace/Get_Opt.h"
17 #include "ace/OS_NS_string.h"
18 #include "ace/OS_NS_fcntl.h"
19 #include "ace/Log_Msg.h"
21 // Constructor.
22 Options::Options (void)
23 : ior_ (CORBA::string_dup ("file://test.ior")),
24 test_type_ (Options::NO_TEST),
25 invoke_type_ (Options::SII),
26 loop_count_ (1),
27 debug_ (0),
28 shutdown_ (0)
32 Options::~Options (void)
36 // Parses the command line arguments and returns an error status.
38 int
39 Options::parse_args (int argc, ACE_TCHAR **argv)
41 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xdn:f:i:t:k:"));
42 int c;
43 int result;
45 while ((c = get_opts ()) != -1)
46 switch (c)
48 case 'd': // debug flag
49 TAO_debug_level++;
50 this->debug_ = 1;
51 break;
53 case 'x':
54 this->shutdown_ = 1;
55 break;
57 case 'n': // loop count
58 this->loop_count_ = (CORBA::ULong) ACE_OS::atoi (get_opts.opt_arg ());
59 break;
61 case 'f':
62 result = this->read_ior (get_opts.opt_arg ());
64 if (result < 0)
65 ACE_ERROR_RETURN ((LM_ERROR,
66 "Unable to read ior from %s : %p\n",
67 get_opts.opt_arg ()),
68 -1);
70 break;
72 case 'k':
73 this->ior_ = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ()));
74 break;
76 case 'i': // invocation
77 if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("dii")))
78 this->invoke_type_ = Options::DII;
79 break;
81 case 't': // data type
82 if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("short")))
83 this->test_type_ = Options::TEST_SHORT;
84 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ulonglong")))
85 this->test_type_ = Options::TEST_ULONGLONG;
86 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ubstring")))
87 this->test_type_ = Options::TEST_UB_STRING;
88 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ubwstring")))
89 this->test_type_ = Options::TEST_UB_WSTRING;
90 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bdstring")))
91 this->test_type_ = Options::TEST_BD_STRING;
92 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bdwstring")))
93 this->test_type_ = Options::TEST_BD_WSTRING;
94 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("fixed_struct")))
95 this->test_type_ = Options::TEST_FIXED_STRUCT;
96 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_strseq")))
97 this->test_type_ = Options::TEST_UB_STRING_SEQUENCE;
98 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bd_strseq")))
99 this->test_type_ = Options::TEST_BD_STRING_SEQUENCE;
100 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_wstrseq")))
101 this->test_type_ = Options::TEST_UB_WSTRING_SEQUENCE;
102 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bd_wstrseq")))
103 this->test_type_ = Options::TEST_BD_WSTRING_SEQUENCE;
104 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("var_struct")))
105 this->test_type_ = Options::TEST_VAR_STRUCT;
106 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("nested_struct")))
107 this->test_type_ = Options::TEST_NESTED_STRUCT;
108 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("recursive_struct")))
109 this->test_type_ = Options::TEST_RECURSIVE_STRUCT;
110 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("objref_struct")))
111 this->test_type_ = Options::TEST_OBJREF_STRUCT;
112 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_struct_seq")))
113 this->test_type_ = Options::TEST_UB_STRUCT_SEQUENCE;
114 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bd_struct_seq")))
115 this->test_type_ = Options::TEST_BD_STRUCT_SEQUENCE;
116 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_array_seq")))
117 this->test_type_ = Options::TEST_UB_ARRAY_SEQUENCE;
118 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bd_array_seq")))
119 this->test_type_ = Options::TEST_BD_ARRAY_SEQUENCE;
120 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("objref")))
121 this->test_type_ = Options::TEST_OBJREF;
122 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("typecode")))
123 this->test_type_ = Options::TEST_TYPECODE;
124 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("any")))
125 this->test_type_ = Options::TEST_ANY;
126 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("objref_sequence")))
127 this->test_type_ = Options::TEST_OBJREF_SEQUENCE;
128 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("any_sequence")))
129 this->test_type_ = Options::TEST_ANYSEQ;
130 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_short_sequence")))
131 this->test_type_ = Options::TEST_UB_SHORTSEQ;
132 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bd_short_sequence")))
133 this->test_type_ = Options::TEST_BD_SHORTSEQ;
134 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("ub_long_sequence")))
135 this->test_type_ = Options::TEST_UB_LONGSEQ;
136 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("bd_long_sequence")))
137 this->test_type_ = Options::TEST_BD_LONGSEQ;
138 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("fixed_array")))
139 this->test_type_ = Options::TEST_FIXED_ARRAY;
140 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("var_array")))
141 this->test_type_ = Options::TEST_VAR_ARRAY;
142 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("multdim_array")))
143 this->test_type_ = Options::TEST_MULTDIM_ARRAY;
144 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("exception")))
145 this->test_type_ = Options::TEST_EXCEPTION;
146 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("big_union")))
147 this->test_type_ = Options::TEST_BIG_UNION;
148 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("small_union")))
149 this->test_type_ = Options::TEST_SMALL_UNION;
150 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("recursive_union")))
151 this->test_type_ = Options::TEST_RECURSIVE_UNION;
152 else if (!ACE_OS::strcmp (get_opts.opt_arg (), ACE_TEXT("complex_any")))
153 this->test_type_ = Options::TEST_COMPLEX_ANY;
154 break;
156 case '?':
157 default:
158 ACE_ERROR_RETURN ((LM_ERROR,
159 "usage: %s"
160 " [-d]"
161 " [-n loopcount]"
162 " [-f servant-IOR-file]"
163 " [-i invocation (sii/dii)]"
164 " [-t data type]"
165 "\n",
166 argv [0]),
167 -1);
170 // Indicates successful parsing of command line.
171 return 0;
174 // Get the factory IOR from the file created by the server.
176 Options::read_ior (ACE_TCHAR *filename)
178 // Open the file for reading.
179 ACE_HANDLE f_handle = ACE_OS::open (filename, 0);
181 if (f_handle == ACE_INVALID_HANDLE)
182 ACE_ERROR_RETURN ((LM_ERROR,
183 "Unable to open %s for writing: %p\n",
184 filename),
185 -1);
186 ACE_Read_Buffer ior_buffer (f_handle, true);
187 this->ior_ = ior_buffer.read ();
189 if (this->ior_.in () == 0)
190 ACE_ERROR_RETURN ((LM_ERROR,
191 "Unable to allocate memory to read ior: %p\n"),
192 -1);
193 return 0;
196 char const *
197 Options::param_test_ior (void) const
199 return this->ior_.in ();
202 Options::TEST_TYPE
203 Options::test_type (void)
205 return this->test_type_;
208 Options::INVOKE_TYPE
209 Options::invoke_type (void)
211 return this->invoke_type_;
214 CORBA::ULong
215 Options::loop_count (void)
217 return this->loop_count_;
220 CORBA::Boolean
221 Options::debug (void) const
223 return this->debug_;
226 CORBA::Boolean
227 Options::shutdown (void) const
229 return this->shutdown_;
232 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, Options, ACE_Recursive_Thread_Mutex);