4 #include "Hello_Impl.h"
5 #include "orbsvcs/PortableGroup/GOA.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Manual_Event.h"
8 #include "tao/Policy_Manager.h"
10 #define CLIENT_SLEEP_TIME 1000 /* in microseconds */
11 #define CLIENT_THREAD_NUMBER 32
12 #define HELLO_CALL_NUMBER 100
14 const ACE_TCHAR
*uipmc_url
= 0;
15 const ACE_TCHAR
*client_uipmc_url
= 0;
18 test_sleep (int microsec
)
20 ACE_Time_Value
tv (microsec
/ 1000000, microsec
% 1000000);
22 ACE_OS::sleep ((const ACE_Time_Value
&) tv
);
26 parse_args (int argc
, ACE_TCHAR
*argv
[])
28 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("u:c:"));
29 const unsigned char full_success
= 0x03;
30 unsigned char success
= 0;
35 if (success
== full_success
&& c
== -1)
39 ACE_ERROR_RETURN ((LM_ERROR
,
50 uipmc_url
= get_opts
.opt_arg ();
54 client_uipmc_url
= get_opts
.opt_arg ();
61 // Indicates successful parsing of the command line
67 : public ACE_Task_Base
70 ORBThread (CORBA::ORB_ptr orb
, ACE_Manual_Event
& me
, ACE_Thread_Manager
*thr_mgr
)
71 : ACE_Task_Base (thr_mgr
)
72 , orb_ (CORBA::ORB::_duplicate (orb
))
85 catch (const CORBA::Exception
& ex
)
87 ex
._tao_print_exception ("Exception caught in ORBThread:");
96 ACE_Manual_Event
& me_
;
101 : public ACE_Task_Base
104 ClientThread (Test::Hello_ptr hello
, MessageLog
*log
, int calls
)
105 : hello_ (Test::Hello::_duplicate (hello
))
107 , call_count_ (calls
)
121 ACE_GUARD_RETURN (ACE_Mutex
, ace_mon
, this->mutex_
, 0);
125 if (c
>= this->call_count_
)
128 this->hello_
->say_hello (c
);
130 this->logger_
->register_message_send (c
);
132 test_sleep (CLIENT_SLEEP_TIME
);
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Exception caught in ClientThread:");
146 Test::Hello_var hello_
;
154 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
156 MessageLog
logger (HELLO_CALL_NUMBER
);
161 CORBA::ORB_init (argc
, argv
);
163 CORBA::Object_var poa_object
=
164 orb
->resolve_initial_references("RootPOA");
166 PortableGroup::GOA_var root_poa
=
167 PortableGroup::GOA::_narrow (poa_object
.in ());
169 if (CORBA::is_nil (root_poa
.in ()))
170 ACE_ERROR_RETURN ((LM_ERROR
,
171 " (%P|%t) Panic: nil RootPOA\n"),
174 PortableServer::POAManager_var poa_manager
=
175 root_poa
->the_POAManager ();
177 Hello_Impl
* hello_impl
;
178 ACE_NEW_RETURN (hello_impl
,
179 Hello_Impl (orb
.in (), &logger
),
181 PortableServer::ServantBase_var
owner_transfer (hello_impl
);
183 if (parse_args (argc
, argv
) != 0)
186 // create UIPMC reference
187 CORBA::String_var multicast_url
=
188 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(uipmc_url
));
189 CORBA::Object_var miop_ref
=
190 orb
->string_to_object (multicast_url
.in ());
192 // create UIPMC reference for client access
193 CORBA::String_var client_multicast_url
=
194 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(client_uipmc_url
));
195 CORBA::Object_var client_miop_ref
=
196 orb
->string_to_object (client_multicast_url
.in ());
199 PortableServer::ObjectId_var id
=
200 root_poa
->create_id_for_reference (miop_ref
.in ());
201 PortableServer::ObjectId_var client_id
=
202 root_poa
->create_id_for_reference (client_miop_ref
.in ());
204 // activate Hello Object
205 root_poa
->activate_object_with_id (id
.in (),
208 // create Hello reference
209 Test::Hello_var hello
=
210 Test::Hello::_unchecked_narrow (client_miop_ref
.in ());
212 poa_manager
->activate ();
217 ORBThread
orb_thr (orb
.in (), me
, ACE_Thread_Manager::instance ());
218 orb_thr
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1, 1);
222 ClientThread
cln_thr (hello
.in (), &logger
, HELLO_CALL_NUMBER
);
223 cln_thr
.activate (THR_NEW_LWP
| THR_JOINABLE
, CLIENT_THREAD_NUMBER
);
226 // shutdown the server, after 10 invocations of shutdown() we can be
227 // more or less sure that server actually received that call
228 for (int i
= 0; i
< 10; i
++)
233 if (logger
.report_statistics () == HELLO_CALL_NUMBER
)
234 ACE_ERROR_RETURN ((LM_ERROR
,
235 "\n (%P|%t) No single call got through to the server\n"),
238 root_poa
->destroy (true, true);
242 catch (const CORBA::Exception
& ex
)
244 ex
._tao_print_exception ("Exception caught in main ():");
248 ACE_DEBUG ((LM_DEBUG
,
249 "\n (%P|%t) uipmc_test is successful..\n"));