2 //=============================================================================
6 * Options for the Param_Test application
8 * @author Aniruddha Gokhale
10 //=============================================================================
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"
22 Options::Options (void)
23 : ior_ (CORBA::string_dup ("file://test.ior")),
24 test_type_ (Options::NO_TEST
),
25 invoke_type_ (Options::SII
),
32 Options::~Options (void)
36 // Parses the command line arguments and returns an error status.
39 Options::parse_args (int argc
, ACE_TCHAR
**argv
)
41 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("xdn:f:i:t:k:"));
45 while ((c
= get_opts ()) != -1)
48 case 'd': // debug flag
57 case 'n': // loop count
58 this->loop_count_
= (CORBA::ULong
) ACE_OS::atoi (get_opts
.opt_arg ());
62 result
= this->read_ior (get_opts
.opt_arg ());
65 ACE_ERROR_RETURN ((LM_ERROR
,
66 "Unable to read ior from %s : %p\n",
73 this->ior_
= CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
76 case 'i': // invocation
77 if (!ACE_OS::strcmp (get_opts
.opt_arg (), ACE_TEXT("dii")))
78 this->invoke_type_
= Options::DII
;
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
;
158 ACE_ERROR_RETURN ((LM_ERROR
,
162 " [-f servant-IOR-file]"
163 " [-i invocation (sii/dii)]"
170 // Indicates successful parsing of command line.
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",
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"),
197 Options::param_test_ior (void) const
199 return this->ior_
.in ();
203 Options::test_type (void)
205 return this->test_type_
;
209 Options::invoke_type (void)
211 return this->invoke_type_
;
215 Options::loop_count (void)
217 return this->loop_count_
;
221 Options::debug (void) const
227 Options::shutdown (void) const
229 return this->shutdown_
;
232 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton
, Options
, ACE_Recursive_Thread_Mutex
);