Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_1020_Regression / client.cpp
blob234ca120c13419ac5367d111d777fa420e94ce24
1 #include "Echo.h"
2 #include "ORB_Task.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");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[]);
14 class Crasher : public ACE_Event_Handler
16 public:
17 Crasher();
19 virtual int handle_timeout (ACE_Time_Value const & current_time,
20 void const * arg);
23 int
24 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
26 try
28 CORBA::ORB_var orb =
29 CORBA::ORB_init (argc, argv);
31 CORBA::Object_var poa_object =
32 orb->resolve_initial_references("RootPOA");
34 PortableServer::POA_var root_poa =
35 PortableServer::POA::_narrow (poa_object.in ());
37 if (CORBA::is_nil (root_poa.in ()))
38 ACE_ERROR_RETURN ((LM_ERROR,
39 " (%P|%t) Panic: nil RootPOA\n"),
40 1);
42 PortableServer::POAManager_var poa_manager =
43 root_poa->the_POAManager ();
45 CORBA::Object_var object =
46 orb->resolve_initial_references ("PolicyCurrent");
48 CORBA::PolicyCurrent_var policy_current =
49 CORBA::PolicyCurrent::_narrow (object.in ());
51 if (CORBA::is_nil (policy_current.in ()))
53 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
54 return 1;
56 CORBA::Any scope_as_any;
57 scope_as_any <<= Messaging::SYNC_WITH_TRANSPORT;
59 CORBA::PolicyList policies(1); policies.length (1);
60 policies[0] =
61 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
62 scope_as_any);
64 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
66 policies[0]->destroy ();
68 if (parse_args (argc, argv) != 0)
69 return 1;
71 PortableServer::Servant_var<Echo> impl;
73 Echo * tmp = 0;
74 // ACE_NEW_RETURN is the worst possible way to handle
75 // exceptions (think: what if the constructor allocates memory
76 // and fails?), but I'm not in the mood to fight for a more
77 // reasonable way to handle allocation errors in ACE.
78 ACE_NEW_RETURN (tmp,
79 Echo(orb.in()),
80 1);
81 impl = tmp;
84 PortableServer::ObjectId_var id =
85 root_poa->activate_object (impl.in ());
87 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
89 Test::Echo_var echo =
90 Test::Echo::_narrow (object_act.in ());
92 CORBA::Object_var tmp =
93 orb->string_to_object(ior);
95 Test::Server_var server =
96 Test::Server::_narrow(tmp.in ());
98 if (CORBA::is_nil (echo.in ()))
100 ACE_ERROR_RETURN ((LM_DEBUG,
101 "Nil Test::Server reference <%s>\n",
102 ior),
106 poa_manager->activate ();
108 Crasher crasher;
110 // Crash after 15 seconds
111 ACE_Time_Value interval(15, 0);
112 ACE_Reactor * reactor = orb->orb_core()->reactor();
113 reactor->schedule_timer(&crasher, 0, interval, interval);
115 ORB_Task task(orb.in());
116 task.activate(THR_NEW_LWP | THR_JOINABLE, 4, 1);
118 Test::Payload payload(16); payload.length(16);
119 for(int i = 0; i != 4; ++i)
121 server->start_task(echo.in());
124 task.wait();
126 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n"));
128 root_poa->destroy (true, true);
130 orb->destroy ();
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Exception caught:");
135 return 1;
138 return 0;
142 parse_args (int argc, ACE_TCHAR *argv[])
144 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
145 int c;
147 while ((c = get_opts ()) != -1)
148 switch (c)
150 case 'k':
151 ior = get_opts.opt_arg ();
152 break;
154 case '?':
155 default:
156 ACE_ERROR_RETURN ((LM_ERROR,
157 "usage: %s "
158 "-k <ior> "
159 "\n",
160 argv [0]),
161 -1);
163 // Indicates successful parsing of the command line
164 return 0;
167 Crasher::Crasher()
172 Crasher::handle_timeout (ACE_Time_Value const & ,
173 void const *)
175 ACE_OS::abort();
177 return 0;