Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Faults / pong.cpp
blob207d54190ee4903f36c4109647bfdc59c0452d78
1 #include "ping_i.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
6 int iterations = 60;
7 int period = 10;
8 int kill_on = 30;
9 const ACE_TCHAR* ior = ACE_TEXT("file://ping.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:p:k:t:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'i':
21 iterations = ACE_OS::atoi (get_opts.opt_arg ());
22 break;
24 case 'p':
25 period = ACE_OS::atoi (get_opts.opt_arg ());
26 break;
28 case 'k':
29 ior = get_opts.opt_arg ();
30 break;
32 case 't':
33 kill_on = ACE_OS::atoi (get_opts.opt_arg ());
34 break;
36 case '?':
37 default:
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "usage: %s "
40 "-i <iterations> "
41 "-p <period> (milliseconds) "
42 "-k ior "
43 "-t <rate> (terminate server every n calls) "
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 void
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
58 // exceptions...
60 for (int i = 0; i != iterations; ++i)
62 ACE_Time_Value tv (0, 1000 * period);
63 const char* reason = "";
64 try
66 reason = "Exception during ping call";
67 server->ping (callback);
69 // Run for <period> milliseconds, to receive the reply
70 orb->run (tv);
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";
80 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);
88 ACE_OS::sleep (tv);
90 catch (const CORBA::COMM_FAILURE&)
92 ACE_DEBUG ((LM_DEBUG, "Ignoring comm failure exception\n"));
93 // ACE_PRINT_EXCEPTION (f, reason);
94 ACE_OS::sleep (tv);
96 catch (const CORBA::Exception& ex)
98 ex._tao_print_exception (reason);
99 ACE_OS::sleep (tv);
105 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
109 CORBA::ORB_var orb =
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;
125 policies.length (2);
126 policies[0] =
127 root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
128 policies[1] =
129 root_poa->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION);
131 PortableServer::POA_var persistent_poa =
132 root_poa->create_POA("persistent",
133 poa_manager.in (),
134 policies);
135 policies[0]->destroy ();
136 policies[1]->destroy ();
138 poa_manager->activate ();
140 if (parse_args (argc, argv) != 0)
141 return 1;
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",
153 ior),
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 (),
171 server.in (),
172 callback.in ());
174 persistent_poa->destroy (true, true);
176 root_poa->destroy (true, true);
178 catch (const CORBA::Exception& ex)
180 ex._tao_print_exception ("Exception caught:");
181 return 1;
184 return 0;