Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_1269_Regression / client.cpp
blobe87829affdbedea70f4e0c2634bac2b07afadea6
1 #include "Echo.h"
2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "tao/ORB_Core.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
8 bool do_shutdown = false;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[]);
13 int
14 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
16 try
18 CORBA::ORB_var orb =
19 CORBA::ORB_init (argc, argv);
21 CORBA::Object_var poa_object =
22 orb->resolve_initial_references("RootPOA");
24 PortableServer::POA_var root_poa =
25 PortableServer::POA::_narrow (poa_object.in ());
27 if (CORBA::is_nil (root_poa.in ()))
28 ACE_ERROR_RETURN ((LM_ERROR,
29 " (%P|%t) Panic: nil RootPOA\n"),
30 1);
32 PortableServer::POAManager_var poa_manager =
33 root_poa->the_POAManager ();
35 CORBA::Object_var object =
36 orb->resolve_initial_references ("PolicyCurrent");
38 CORBA::PolicyCurrent_var policy_current =
39 CORBA::PolicyCurrent::_narrow (object.in ());
41 if (CORBA::is_nil (policy_current.in ()))
43 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
44 return 1;
46 CORBA::Any scope_as_any;
47 scope_as_any <<= Messaging::SYNC_WITH_TRANSPORT;
49 CORBA::PolicyList policies(1); policies.length (1);
50 policies[0] =
51 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
52 scope_as_any);
54 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
56 policies[0]->destroy ();
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 PortableServer::Servant_var<Echo> impl;
63 Echo * tmp;
64 // ACE_NEW_RETURN is the worst possible way to handle
65 // exceptions (think: what if the constructor allocates memory
66 // and fails?), but I'm not in the mood to fight for a more
67 // reasonable way to handle allocation errors in ACE.
68 ACE_NEW_RETURN (tmp,
69 Echo(orb.in(), 100),
70 1);
71 impl = tmp;
74 PortableServer::ObjectId_var id =
75 root_poa->activate_object (impl.in ());
77 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
79 Test::Echo_var echo =
80 Test::Echo::_narrow (object_act.in ());
82 CORBA::Object_var tmp =
83 orb->string_to_object(ior);
85 Test::Echo_Caller_var server =
86 Test::Echo_Caller::_narrow(tmp.in ());
88 if (CORBA::is_nil (echo.in ()))
90 ACE_ERROR_RETURN ((LM_DEBUG,
91 "Nil Test::Echo_Caller reference <%s>\n",
92 ior),
93 1);
96 if (do_shutdown)
98 server->shutdown ();
99 return 0;
102 poa_manager->activate ();
104 server->start_task(echo.in());
106 orb->run ();
108 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n"));
110 // Actually the code here should never be reached.
111 root_poa->destroy (true, true);
113 orb->destroy ();
115 catch (const CORBA::Exception& ex)
117 ex._tao_print_exception ("Exception caught:");
118 return 1;
121 return 0;
125 parse_args (int argc, ACE_TCHAR *argv[])
127 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
128 int c;
130 while ((c = get_opts ()) != -1)
131 switch (c)
133 case 'k':
134 ior = get_opts.opt_arg ();
135 break;
137 case 'x':
138 do_shutdown = true;
139 break;
141 case '?':
142 default:
143 ACE_ERROR_RETURN ((LM_ERROR,
144 "usage: %s "
145 "-k <ior> "
146 "\n",
147 argv [0]),
148 -1);
150 // Indicates successful parsing of the command line
151 return 0;