Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / CSD_Strategy / ThreadPool5 / ClientTask.cpp
blobb2fb6013b67157e91c4f9dfb2317fa69e2df1127
1 //=============================================================================
2 /**
3 * @file ClientTask.cpp
5 * @author Tim Bradley <bradley_t@ociweb.com>
6 */
7 //=============================================================================
9 #include "ClientTask.h"
10 #include "ace/SString.h"
11 #include "ace/OS_NS_unistd.h"
13 ClientTask::ClientTask(CORBA::ORB_ptr orb,
14 Foo_ptr foo,
15 Callback_ptr callback,
16 bool collocated)
17 : orb_ (CORBA::ORB::_duplicate (orb)),
18 foo_(Foo::_duplicate(foo)),
19 callback_(Callback::_duplicate(callback)),
20 collocated_ (collocated)
24 ClientTask::~ClientTask()
28 int
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"),
38 -1);
41 return 0;
45 int
46 ClientTask::svc()
48 ACE_DEBUG((LM_DEBUG,
49 "(%P|%t) ClientTask::svc start\n"));
51 try
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"));
59 return -1;
62 for (CORBA::Long i = 1; i <= 100; i++)
64 // Simple Two-way calls.
65 this->foo_->op1();
67 this->foo_->op2(i);
69 CORBA::Long value = this->foo_->op3();
71 ACE_DEBUG((LM_DEBUG,
72 "(%P|%t) ===> Value retrieved from op3() == %d\n",
73 value));
75 for (CORBA::ULong j = 1; j <= 5; j++)
77 this->foo_->op4(495 + (i * 5) + j);
80 try
82 ACE_DEBUG((LM_DEBUG, "(%P|%t) ===> Invoke op5()\n"));
83 this->foo_->op5();
84 ACE_DEBUG((LM_DEBUG, "(%P|%t) ===> No exception raised from op5(). :-(\n"));
86 catch (const FooException& )
88 ACE_DEBUG((LM_DEBUG,
89 "(%P|%t) ===> Caught FooException - as expected.\n"));
92 // Two-Way calls with inout parameters.
93 CORBA::String_var message = CORBA::string_dup( "Hello! " );
94 CORBA::Boolean result
95 = this->foo_->op6( "TAO User", message.inout());
97 if (result)
99 ACE_DEBUG((LM_DEBUG,
100 "(%P|%t) ===> Message from op6() == %s\n",
101 message.in ()));
103 else
105 ACE_DEBUG((LM_DEBUG,
106 "(%P|%t) ===> op6() returned false.\n"));
109 // Callback test.
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);
130 Var_Array var_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,
139 buffer1,
140 true);
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,
147 buffer2,
148 true);
149 this->foo_->test_unbounded_var_size_arg (ub_var_size_string.in ());
151 TimeOfDay t;
152 t.hour = 12;
153 t.minute = 30;
154 t.second = 10;
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 ());
165 ACE_DEBUG((LM_DEBUG,
166 "(%P|%t) ClientTask::svc - Invoke foo->done()\n"));
168 this->foo_->done ();
170 ACE_DEBUG((LM_DEBUG,
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:");
177 catch (...)
179 ACE_ERROR((LM_ERROR,
180 "(%P|%t) Unknown (...) exception caught in ClientTask::svc()\n"));
183 if (! collocated_)
185 ACE_OS::sleep (2);
186 this->orb_->shutdown(0);
189 ACE_DEBUG((LM_DEBUG,
190 "(%P|%t) ClientTask::svc end\n"));
192 return 0;
197 ClientTask::close(u_long)
199 ACE_DEBUG((LM_DEBUG,
200 "(%P|%t) ClientTask::close() - enter/exit\n"));
201 return 0;
205 bool
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);
215 #else
216 this->foo_->_is_a ("Not_An_IDL_Type");
217 #endif /* TAO_HAS_MESSAGING == 1 */
218 return true;
220 catch (const CORBA::Exception&)
225 return false;