2 #include "tao/DynamicInterface/Request.h" /* This must come first for
4 #include "Client_Task.h"
6 #include "tao/Object.h"
8 char TEST_STR
[] = "This is a DII collocation test.";
10 CORBA::Long TEST_BASIC_VALUE
= 12345;
11 CORBA::Char TEST_SPECIAL_VALUE
= 'x';
12 CORBA::Short TEST_HOUR
= 12;
13 CORBA::Short TEST_MINUTE
= 59;
14 CORBA::Short TEST_SECOND
= 59;
16 Client_Task::Client_Task (const ACE_TCHAR
*ior
,
17 const ACE_TCHAR
*simple_test_ior
,
19 ACE_Thread_Manager
*thr_mgr
)
20 : ACE_Task_Base (thr_mgr
)
22 , simple_test_input_ (simple_test_ior
)
23 , corb_ (CORBA::ORB::_duplicate (corb
))
29 Client_Task::svc (void)
33 CORBA::Object_var obj
=
34 this->corb_
->string_to_object (input_
);
36 if (CORBA::is_nil (obj
.in ()))
38 ACE_ERROR_RETURN ((LM_DEBUG
,
39 "Nil Test::Hello reference <%s>\n",
44 CORBA::Object_var simple_test_obj
=
45 this->corb_
->string_to_object (simple_test_input_
);
47 if (CORBA::is_nil (simple_test_obj
.in ()))
49 ACE_ERROR_RETURN ((LM_ERROR
,
50 "Nil Test::Simple_Test reference <%s>\n",
55 Test::Simple_Test_var simple_test
56 = Test::Simple_Test::_narrow (simple_test_obj
.in ());
58 CORBA::Request_var
req (obj
->_request ("test_basic_arg"));
59 req
->add_in_arg ("basic") <<= TEST_BASIC_VALUE
;
60 req
->add_out_arg ("x") <<= l
;
62 if (req
->response_received ())
64 for (CORBA::ULong count
=0; count
<req
->arguments ()->count () ;++count
)
66 CORBA::NamedValue_ptr arg
= req
->arguments ()->item (count
);
67 if (ACE_OS::strcmp (arg
->name (), "x") == 0)
70 if (*(arg
->value()) >>= y
)
75 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid out value, received %d\n", y
), 1);
81 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid typed value\n"), 1);
89 ACE_ERROR_RETURN ((LM_ERROR
, "Response received not true\n"), 1);
92 req
= obj
->_request ("test_unbounded_string_arg");
94 req
->add_in_arg ("ub_string") <<= TEST_STR
;
96 if (req
->response_received ())
102 ACE_ERROR_RETURN ((LM_ERROR
, "Response received not true\n"), 1);
105 req
= obj
->_request ("test_unbounded_string_arg_out");
107 req
->add_in_arg ("ub_string") <<= TEST_STR
;
108 req
->add_out_arg ("x") <<= NULL_STR
;
110 if (req
->response_received ())
112 for (CORBA::ULong count
=0; count
<req
->arguments ()->count () ;++count
)
114 CORBA::NamedValue_ptr arg
= req
->arguments ()->item (count
);
115 if (ACE_OS::strcmp (arg
->name (), "x") == 0)
117 const char * ystring
= 0;
118 if (*(arg
->value()) >>= ystring
)
120 if (ACE_OS::strcmp(ystring
, TEST_STR
) != 0)
123 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid out value, received %s\n", ystring
), 1);
129 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid typed value\n"), 1);
137 ACE_ERROR_RETURN ((LM_ERROR
, "Response received not true\n"), 1);
140 req
= obj
->_request ("test_bounded_string_arg");
142 ACE_CString
bs (TEST_STR
);
143 bs
= bs
.substr (0, ::Test::BOUNDED_STRING_SIZE
);
145 req
->add_in_arg ("bd_string")
146 <<= CORBA::Any::from_string (bs
.c_str (), ::Test::BOUNDED_STRING_SIZE
);
150 req
= obj
->_request ("test_fixed_array_arg");
152 ::Test::Fixed_Array fixed_array
;
154 for (CORBA::ULong m
= 0 ; m
< ::Test::FIX_ARRAY_SIZE
; m
++)
156 fixed_array
[m
] = m
+ 999;
159 req
->add_in_arg ("fixed_array") <<= ::Test::Fixed_Array_forany (fixed_array
);
163 req
= obj
->_request ("test_var_array_arg");
165 ::Test::Var_Array var_array
;
167 for (CORBA::ULong i
= 0; i
< ::Test::VAR_ARRAY_SIZE
; ++i
)
169 var_array
[i
] = CORBA::string_dup(TEST_STR
);
172 req
->add_in_arg ("var_array") <<= var_array
;
176 req
= obj
->_request ("test_bounded_var_size_arg");
178 ACE_CString
bvs (TEST_STR
);
179 bvs
= bvs
.substr (0, ::Test::BOUNDED_VAR_SIZE
);
181 ::Test::Bounded_Var_Size_Arg
* bd_var_size
182 = new ::Test::Bounded_Var_Size_Arg();
184 bd_var_size
->replace (::Test::BOUNDED_VAR_SIZE
,
185 const_cast <CORBA::Char
*> (bvs
.c_str ()));
187 req
->add_in_arg ("bd_var_size") <<= bd_var_size
;
191 req
= obj
->_request ("test_unbounded_var_size_arg");
193 ::Test::Unbounded_Var_Size_Arg
* ub_var_size
194 = new ::Test::Unbounded_Var_Size_Arg();
195 ub_var_size
->replace (ub_var_size
->maximum (),
196 ACE_OS::strlen (TEST_STR
),
199 req
->add_in_arg ("ub_var_size") <<= ub_var_size
;
203 req
= obj
->_request ("test_fixed_size_arg");
207 t
.minute
= TEST_MINUTE
;
208 t
.second
= TEST_SECOND
;
210 req
->add_in_arg ("fixed_size") <<= t
;
214 req
= obj
->_request ("test_special_basic_arg");
216 req
->add_in_arg ("special") <<= CORBA::Any::from_char (TEST_SPECIAL_VALUE
);
220 req
= obj
->_request ("test_object_arg");
222 req
->add_in_arg ("object") <<= simple_test_obj
.in ();
226 req
= obj
->_request ("test_objref_arg");
228 req
->add_in_arg ("objref") <<= simple_test
.in ();
232 req
= obj
->_request ("test_args_1");
234 req
->add_in_arg ("arg1") <<= simple_test_obj
.in ();
235 req
->add_in_arg ("arg2") <<= CORBA::Any::from_char (TEST_SPECIAL_VALUE
);
236 req
->add_in_arg ("arg3") <<= simple_test
.in ();
240 req
= obj
->_request ("test_args_2");
242 req
->add_in_arg ("arg1") <<= TEST_STR
;
243 req
->add_in_arg ("arg2") <<= ::Test::Fixed_Array_forany (fixed_array
);
244 req
->add_in_arg ("arg3") <<= t
;
248 req
= obj
->_request ("test_args_3");
251 = new ::Test::Bounded_Var_Size_Arg();
252 bd_var_size
->replace (::Test::BOUNDED_VAR_SIZE
,
253 const_cast <CORBA::Char
*> (bvs
.c_str ()));
256 = new ::Test::Unbounded_Var_Size_Arg();
257 ub_var_size
->replace (ub_var_size
->maximum (),
258 ACE_OS::strlen (TEST_STR
),
261 for (CORBA::ULong j
= 0; j
< ::Test::VAR_ARRAY_SIZE
; ++j
)
263 var_array
[j
] = CORBA::string_dup(TEST_STR
);
266 req
->add_in_arg ("arg1")
267 <<= CORBA::Any::from_string (bs
.c_str (), ::Test::BOUNDED_STRING_SIZE
);
269 req
->add_in_arg ("arg2") <<= bd_var_size
;
270 req
->add_in_arg ("arg3") <<= ub_var_size
;
271 req
->add_in_arg ("arg4") <<= var_array
;
275 req
= obj
->_request ("shutdown");
281 catch (const CORBA::Exception
& ex
)
284 ex
._tao_print_exception ("Exception caught:");
290 ACE_ERROR ((LM_ERROR
, "(%P|%t)Client_Task::svc - caught unknown exception\n"));
299 Client_Task::error_count () const