3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
9 const ACE_TCHAR
* ior
= ACE_TEXT("file://ping.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("i:p:k:t:"));
17 while ((c
= get_opts ()) != -1)
21 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
25 period
= ACE_OS::atoi (get_opts
.opt_arg ());
29 ior
= get_opts
.opt_arg ();
33 kill_on
= ACE_OS::atoi (get_opts
.opt_arg ());
38 ACE_ERROR_RETURN ((LM_ERROR
,
41 "-p <period> (milliseconds) "
43 "-t <rate> (terminate server every n calls) "
48 // Indicates successful parsing of the command line
53 run_client (CORBA::ORB_ptr orb
,
54 PingObject_ptr server
,
55 PingObject_ptr callback
)
57 // Run the client requests in a separate routine to isolate the
60 for (int i
= 0; i
!= iterations
; ++i
)
62 ACE_Time_Value
tv (0, 1000 * period
);
63 const char* reason
= "";
66 reason
= "Exception during ping call";
67 server
->ping (callback
);
69 // Run for <period> milliseconds, to receive the reply
72 // Terminate the client if:
73 // - This is the last iteration
74 // - The iteration is 0 modulo <kill_on>
75 if (i
+ 1 == iterations
76 || (kill_on
!= 0 && i
> 0 && i
% kill_on
== 0))
78 ACE_DEBUG ((LM_DEBUG
, "Shutting down server\n"));
79 reason
= "Exception during server shutdown";
83 catch (const CORBA::TRANSIENT
&)
85 if (TAO_debug_level
> 0)
86 ACE_DEBUG ((LM_DEBUG
, "Ignoring transient exception\n"));
87 // ACE_PRINT_EXCEPTION (t, reason);
90 catch (const CORBA::COMM_FAILURE
&)
92 ACE_DEBUG ((LM_DEBUG
, "Ignoring comm failure exception\n"));
93 // ACE_PRINT_EXCEPTION (f, reason);
96 catch (const CORBA::Exception
& ex
)
98 ex
._tao_print_exception (reason
);
105 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
110 CORBA::ORB_init (argc
, argv
);
112 CORBA::Object_var poa_object
=
113 orb
->resolve_initial_references("RootPOA");
115 PortableServer::POA_var root_poa
=
116 PortableServer::POA::_narrow (poa_object
.in ());
118 PortableServer::POAManager_var poa_manager
=
119 root_poa
->the_POAManager ();
121 poa_manager
->activate ();
123 // create child poa with PERSISTENT policy
124 CORBA::PolicyList policies
;
127 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
129 root_poa
->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION
);
131 PortableServer::POA_var persistent_poa
=
132 root_poa
->create_POA("persistent",
135 policies
[0]->destroy ();
136 policies
[1]->destroy ();
138 poa_manager
->activate ();
140 if (parse_args (argc
, argv
) != 0)
143 CORBA::Object_var object
=
144 orb
->string_to_object (ior
);
146 PingObject_var server
=
147 PingObject::_narrow (object
.in ());
149 if (CORBA::is_nil (server
.in ()))
151 ACE_ERROR_RETURN ((LM_ERROR
,
152 "Object reference <%s> is nil.\n",
157 PingObject_i
callback_impl (orb
.in (),
158 persistent_poa
.in ());
160 PortableServer::ObjectId_var id
=
161 root_poa
->activate_object (&callback_impl
);
163 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
165 PingObject_var callback
=
166 PingObject::_narrow (object_act
.in ());
169 // If the ior_output_file exists, output the ior to it
170 run_client (orb
.in (),
174 persistent_poa
->destroy (1, 1);
176 root_poa
->destroy (1, 1);
178 catch (const CORBA::Exception
& ex
)
180 ex
._tao_print_exception ("Exception caught:");