3 #include "tao/ORB_Core.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/Reactor.h"
6 #include "ace/OS_NS_signal.h"
8 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[]);
14 class Client_Timer
: public ACE_Event_Handler
18 Client_Timer (ACE_Reactor
* reactor
)
19 : ACE_Event_Handler (reactor
)
21 this->reference_counting_policy ().value (
22 ACE_Event_Handler::Reference_Counting_Policy::ENABLED
);
27 ACE_Time_Value
tv (150, 0);
28 this->reactor()->schedule_timer (this, 0, tv
, tv
);
31 /// Thread entry point
32 int handle_timeout (ACE_Time_Value
const & , void const *)
34 this->reactor ()->cancel_timer (this);
35 // kill the application
36 ACE::terminate_process (ACE_OS::getpid ());
42 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
47 CORBA::ORB_init (argc
, argv
);
49 CORBA::Object_var poa_object
=
50 orb
->resolve_initial_references ("RootPOA");
52 PortableServer::POA_var root_poa
=
53 PortableServer::POA::_narrow (poa_object
.in ());
55 if (CORBA::is_nil (root_poa
.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR
,
57 " (%P|%t) Panic: nil RootPOA\n"),
60 PortableServer::POAManager_var poa_manager
=
61 root_poa
->the_POAManager ();
63 if (parse_args (argc
, argv
) != 0)
66 PortableServer::ServantBase_var impl
;
69 // ACE_NEW_RETURN is the worst possible way to handle
70 // exceptions (think: what if the constructor allocates memory
71 // and fails?), but I'm not in the mood to fight for a more
72 // reasonable way to handle allocation errors in ACE.
74 Echo(orb
.in(), 1000 / serverthreads
),
79 PortableServer::ObjectId_var id
=
80 root_poa
->activate_object (impl
.in ());
82 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
85 Test::Echo::_narrow (object_act
.in ());
87 CORBA::Object_var tmp
=
88 orb
->string_to_object(ior
);
90 Test::Echo_Caller_var server
=
91 Test::Echo_Caller::_narrow(tmp
.in ());
93 if (CORBA::is_nil (server
.in ()))
95 ACE_ERROR_RETURN ((LM_DEBUG
,
96 "Nil Test::Echo_Caller reference <%s>\n",
101 poa_manager
->activate ();
103 ORB_Task
worker (orb
.in());
104 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
109 for(int i
= serverthreads
; i
; --i
)
111 server
->start_task(echo
.in());
118 Client_Timer
* task
= new Client_Timer (orb
->orb_core()->reactor());
120 task
->remove_reference ();
126 ACE_DEBUG ((LM_DEBUG
,
127 "(%P|%t) client - event loop finished\n"));
129 // Actually the code here should never be reached.
130 root_poa
->destroy (true, true);
134 catch (const CORBA::Exception
& ex
)
136 ex
._tao_print_exception ("Exception caught:");
144 parse_args (int argc
, ACE_TCHAR
*argv
[])
146 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:t:"));
149 while ((c
= get_opts ()) != -1)
153 ior
= get_opts
.opt_arg ();
156 serverthreads
= ACE_OS::atoi(get_opts
.opt_arg ());
161 ACE_ERROR_RETURN ((LM_ERROR
,
169 // Indicates successful parsing of the command line