1 #include "Client_Peer.h"
2 #include "Clock_Ticks.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "tao/ORB_Core.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Reactor.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[]);
14 class Timer
: public ACE_Event_Handler
17 Timer(Test::Peer_ptr local_peer
,
18 Test::Peer_ptr remote_peer
);
20 virtual int handle_timeout (ACE_Time_Value
const & current_time
,
24 Test::Peer_var local_peer_
;
25 Test::Peer_var remote_peer_
;
29 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
34 CORBA::ORB_init (argc
, argv
);
36 CORBA::Object_var poa_object
=
37 orb
->resolve_initial_references("RootPOA");
39 PortableServer::POA_var root_poa
=
40 PortableServer::POA::_narrow (poa_object
.in ());
42 if (CORBA::is_nil (root_poa
.in ()))
43 ACE_ERROR_RETURN ((LM_ERROR
,
44 " (%P|%t) Panic: nil RootPOA\n"),
47 PortableServer::POAManager_var poa_manager
=
48 root_poa
->the_POAManager ();
50 CORBA::Object_var object
=
51 orb
->resolve_initial_references ("PolicyCurrent");
53 CORBA::PolicyCurrent_var policy_current
=
54 CORBA::PolicyCurrent::_narrow (object
.in ());
56 if (CORBA::is_nil (policy_current
.in ()))
58 ACE_ERROR ((LM_ERROR
, "ERROR: Nil policy current\n"));
61 CORBA::Any scope_as_any
;
62 scope_as_any
<<= Messaging::SYNC_WITH_SERVER
;
64 CORBA::PolicyList
policies(1); policies
.length (1);
66 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
69 policy_current
->set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
71 policies
[0]->destroy ();
73 if (parse_args (argc
, argv
) != 0)
78 Client_Peer (orb
.in ()),
80 PortableServer::ServantBase_var
owner_transfer(impl
);
82 PortableServer::ObjectId_var id
=
83 root_poa
->activate_object (impl
);
85 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
87 Test::Peer_var local_peer
=
88 Test::Peer::_narrow (object_act
.in ());
90 CORBA::Object_var tmp
=
91 orb
->string_to_object(ior
);
94 Test::Peer::_narrow(tmp
.in ());
96 if (CORBA::is_nil (peer
.in ()))
98 ACE_ERROR_RETURN ((LM_DEBUG
,
99 "Nil Test::Peer reference <%s>\n",
104 poa_manager
->activate ();
106 Timer
timer(local_peer
.in (), peer
.in ());
108 ACE_Time_Value
interval(0, 50 * Clock_Ticks::get_usecs_per_tick ());
109 ACE_Reactor
* reactor
= orb
->orb_core()->reactor();
110 reactor
->schedule_timer(&timer
, 0, interval
, interval
);
112 ACE_Time_Value
run_time(120, 0);
115 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - event loop finished\n"));
117 root_poa
->destroy (1, 1);
121 catch (const CORBA::Exception
& ex
)
123 ex
._tao_print_exception ("Exception caught:");
131 parse_args (int argc
, ACE_TCHAR
*argv
[])
133 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
136 while ((c
= get_opts ()) != -1)
140 ior
= get_opts
.opt_arg ();
145 ACE_ERROR_RETURN ((LM_ERROR
,
152 // Indicates successful parsing of the command line
156 Timer::Timer(Test::Peer_ptr local_peer
,
157 Test::Peer_ptr remote_peer
)
158 : local_peer_ (Test::Peer::_duplicate (local_peer
))
159 , remote_peer_ (Test::Peer::_duplicate (remote_peer
))
164 Timer::handle_timeout (ACE_Time_Value
const & ,
168 this->remote_peer_
->callme (this->local_peer_
.in(), 32, data
);