1 //=============================================================================
5 * @author Tim Bradley <bradley_t@ociweb.com>
7 //=============================================================================
9 #include "ClientTask.h"
10 #include "ace/SString.h"
11 #include "ace/OS_NS_unistd.h"
13 ClientTask::ClientTask(CORBA::ORB_ptr orb
,
15 Callback_ptr callback
,
17 : orb_ (CORBA::ORB::_duplicate (orb
)),
18 foo_(Foo::_duplicate(foo
)),
19 callback_(Callback::_duplicate(callback
)),
20 collocated_ (collocated
)
24 ClientTask::~ClientTask()
29 ClientTask::open(void*)
31 if (this->activate(THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
33 // Assumes that when activate returns non-zero return code that
34 // no threads were activated.
35 ACE_ERROR_RETURN((LM_ERROR
,
36 "(%P|%t) ClientTask failed to activate "
37 "the client thread.\n"),
49 "(%P|%t) ClientTask::svc start\n"));
53 // Make sure the connection is established before making
54 // remote invocations.
55 if (this->validate_connection () == false)
57 ACE_ERROR((LM_ERROR
, "(%P|%t)ClientTask::svc " \
58 "client connect failed.\n"));
62 for (CORBA::Long i
= 1; i
<= 100; i
++)
64 // Simple Two-way calls.
69 CORBA::Long value
= this->foo_
->op3();
72 "(%P|%t) ===> Value retrieved from op3() == %d\n",
75 for (CORBA::ULong j
= 1; j
<= 5; j
++)
77 this->foo_
->op4(495 + (i
* 5) + j
);
82 ACE_DEBUG((LM_DEBUG
, "(%P|%t) ===> Invoke op5()\n"));
84 ACE_DEBUG((LM_DEBUG
, "(%P|%t) ===> No exception raised from op5(). :-(\n"));
86 catch (const FooException
& )
89 "(%P|%t) ===> Caught FooException - as expected.\n"));
92 // Two-Way calls with inout parameters.
93 CORBA::String_var message
= CORBA::string_dup( "Hello! " );
95 = this->foo_
->op6( "TAO User", message
.inout());
100 "(%P|%t) ===> Message from op6() == %s\n",
106 "(%P|%t) ===> op6() returned false.\n"));
110 this->foo_
->callback_object (this->callback_
.in ());
112 this->foo_
->test_callback ();
114 // One-Way calls with various arguments.
115 CORBA::String_var ub_string
= CORBA::string_dup( "UNBOUNDED STRING" );
116 this->foo_
->test_unbounded_string_arg (ub_string
.in ());
118 CORBA::String_var bd_string
= CORBA::string_dup( "BOUNDED STRING" );
119 this->foo_
->test_bounded_string_arg (bd_string
.in ());
121 Fixed_Array fixed_array
;
123 for (CORBA::ULong m
= 0; m
< 20; m
++)
125 fixed_array
[m
] = i
+ m
;
128 this->foo_
->test_fixed_array_arg (fixed_array
);
131 var_array
[0] = CORBA::string_dup( "STRING 1" );
132 var_array
[1] = CORBA::string_dup( "STRING 2" );
133 var_array
[2] = CORBA::string_dup( "STRING 3" );
134 this->foo_
->test_var_array_arg (var_array
);
136 Bounded_Var_Size_var bd_var_size_string
= new Bounded_Var_Size();
137 char* buffer1
= CORBA::string_dup ("BOUNDED VAR SIZE CHAR");
138 bd_var_size_string
->replace (ACE_OS::strlen (buffer1
) + 1,
141 this->foo_
->test_bounded_var_size_arg (bd_var_size_string
.in ());
143 char* buffer2
= CORBA::string_dup ("UNBOUNDED VAR SIZE CHAR");
144 Unbounded_Var_Size_var ub_var_size_string
= new Unbounded_Var_Size(100);
145 ub_var_size_string
->replace (ub_var_size_string
->maximum (),
146 ACE_OS::strlen (buffer2
) + 1,
149 this->foo_
->test_unbounded_var_size_arg (ub_var_size_string
.in ());
155 this->foo_
->test_fixed_size_arg (t
);
157 this->foo_
->test_fixed_size_arg_two_way (t
);
159 CORBA::Boolean special_value
= 1;
160 this->foo_
->test_special_basic_arg (special_value
);
162 this->foo_
->test_objref_arg (this->callback_
.in ());
166 "(%P|%t) ClientTask::svc - Invoke foo->done()\n"));
171 "(%P|%t) ClientTask::svc - Back from foo->done()\n"));
173 catch (const CORBA::Exception
& ex
)
175 ex
._tao_print_exception ("Caught exception in ClientTask::svc:");
180 "(%P|%t) Unknown (...) exception caught in ClientTask::svc()\n"));
186 this->orb_
->shutdown(0);
190 "(%P|%t) ClientTask::svc end\n"));
197 ClientTask::close(u_long
)
200 "(%P|%t) ClientTask::close() - enter/exit\n"));
206 ClientTask::validate_connection ()
208 for (CORBA::ULong j
= 0; j
!= 1000; ++j
)
212 #if (TAO_HAS_CORBA_MESSAGING == 1)
213 CORBA::PolicyList_var unused
;
214 this->foo_
->_validate_connection (unused
);
216 this->foo_
->_is_a ("Not_An_IDL_Type");
217 #endif /* TAO_HAS_MESSAGING == 1 */
220 catch (const CORBA::Exception
&)