1 #include "Server_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"
8 #include "ace/OS_NS_time.h"
10 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
15 parse_args (int argc
, ACE_TCHAR
*argv
[]);
17 class Sleeper
: public ACE_Event_Handler
20 Sleeper(CORBA::ORB_ptr orb
);
22 virtual int handle_timeout (ACE_Time_Value
const & current_time
,
30 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
35 CORBA::ORB_init (argc
, argv
);
37 CORBA::Object_var poa_object
=
38 orb
->resolve_initial_references("RootPOA");
40 PortableServer::POA_var root_poa
=
41 PortableServer::POA::_narrow (poa_object
.in ());
43 if (CORBA::is_nil (root_poa
.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR
,
45 " (%P|%t) Panic: nil RootPOA\n"),
48 PortableServer::POAManager_var poa_manager
=
49 root_poa
->the_POAManager ();
51 CORBA::Object_var object
=
52 orb
->resolve_initial_references ("PolicyCurrent");
54 CORBA::PolicyCurrent_var policy_current
=
55 CORBA::PolicyCurrent::_narrow (object
.in ());
57 if (CORBA::is_nil (policy_current
.in ()))
59 ACE_ERROR ((LM_ERROR
, "ERROR: Nil policy current\n"));
62 CORBA::Any scope_as_any
;
63 scope_as_any
<<= Messaging::SYNC_WITH_SERVER
;
65 CORBA::PolicyList
policies(1); policies
.length (1);
67 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
70 policy_current
->set_policy_overrides (policies
,
73 policies
[0]->destroy ();
75 seed
= (unsigned int) ACE_OS::gethrtime ();
77 if (parse_args (argc
, argv
) != 0)
80 ACE_DEBUG ((LM_DEBUG
, "SEED = %u\n", seed
));
84 Server_Peer (seed
, orb
.in (), payload_size
),
86 PortableServer::ServantBase_var
owner_transfer(impl
);
88 PortableServer::ObjectId_var id
=
89 root_poa
->activate_object (impl
);
91 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
94 Test::Peer::_narrow (object_act
.in ());
96 CORBA::String_var ior
=
97 orb
->object_to_string (peer
.in ());
99 // If the ior_output_file exists, output the ior to it
100 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
101 if (output_file
== 0)
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 "Cannot open output file for writing IOR: %s",
106 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
107 ACE_OS::fclose (output_file
);
109 poa_manager
->activate ();
111 Sleeper
sleeper (orb
.in ());
113 ACE_Time_Value
interval(0, 500000);
114 ACE_Reactor
* reactor
= orb
->orb_core()->reactor();
115 reactor
->schedule_timer(&sleeper
, 0, interval
, interval
);
117 // ACE_Time_Value run_time(600, 0);
118 // orb->run (run_time);
121 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
123 root_poa
->destroy (1, 1);
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Exception caught:");
137 parse_args (int argc
, ACE_TCHAR
*argv
[])
139 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:s:b:"));
142 while ((c
= get_opts ()) != -1)
146 ior_output_file
= get_opts
.opt_arg ();
150 seed
= ACE_OS::atoi(get_opts
.opt_arg ());
154 payload_size
= ACE_OS::atoi(get_opts
.opt_arg ());
159 ACE_ERROR_RETURN ((LM_ERROR
,
168 // Indicates successful parsing of the command line
172 Sleeper::Sleeper(CORBA::ORB_ptr orb
)
173 : orb_ (CORBA::ORB::_duplicate (orb
))
178 Sleeper::handle_timeout (ACE_Time_Value
const & ,
181 // ACE_DEBUG((LM_DEBUG, "(%P|%t) - Sleeper::handle_timeout()\n"));
182 ACE_Time_Value
clk_tck (0, Clock_Ticks::get_usecs_per_tick ());
183 this->orb_
->perform_work(clk_tck
);