Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / CallbackTest / client.cpp
blob0a7c35f171233fc4e17686bb65191ad295634ccb
1 #include "Callback.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'k':
19 ior = get_opts.opt_arg ();
20 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-k <ior>"
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 CORBA::ORB_var orb =
40 CORBA::ORB_init (argc, argv);
42 CORBA::Object_var poa_object =
43 orb->resolve_initial_references("RootPOA");
45 PortableServer::POA_var root_poa =
46 PortableServer::POA::_narrow (poa_object.in ());
48 if (CORBA::is_nil (root_poa.in ()))
49 ACE_ERROR_RETURN ((LM_ERROR,
50 " (%P|%t) Panic: nil RootPOA\n"),
51 1);
53 PortableServer::POAManager_var poa_manager =
54 root_poa->the_POAManager ();
56 // Make all oneways "reliable."
58 CORBA::Object_var manager_object =
59 orb->resolve_initial_references("ORBPolicyManager");
60 CORBA::PolicyManager_var policy_manager =
61 CORBA::PolicyManager::_narrow(manager_object.in());
63 if (CORBA::is_nil (policy_manager.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR,
65 " (%P|%t) Panic: nil PolicyManager\n"),
66 1);
67 CORBA::Any policy_value;
68 policy_value <<= Messaging::SYNC_WITH_SERVER;
69 CORBA::PolicyList policies(1); policies.length(1);
70 policies[0] =
71 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
72 policy_value);
74 policy_manager->set_policy_overrides (policies,
75 CORBA::ADD_OVERRIDE);
77 policies[0]->destroy ();
80 if (parse_args (argc, argv) != 0)
81 return 1;
83 CORBA::Object_var tmp =
84 orb->string_to_object(ior);
86 Test::Service_var service =
87 Test::Service::_narrow(tmp.in ());
89 if (CORBA::is_nil (service.in ()))
91 ACE_ERROR_RETURN ((LM_DEBUG,
92 "Nil service reference <%s>\n",
93 ior),
94 1);
97 Callback *callback_impl;
98 ACE_NEW_RETURN (callback_impl,
99 Callback(orb.in ()),
101 PortableServer::ServantBase_var owner_transfer(callback_impl);
103 PortableServer::ObjectId_var id =
104 root_poa->activate_object (callback_impl);
106 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
108 Test::Callback_var callback =
109 Test::Callback::_narrow (object.in ());
111 poa_manager->activate ();
113 ACE_DEBUG ((LM_DEBUG,
114 "(%P|%t) client - starting test\n"));
116 service->run_test (callback.in ());
118 ACE_DEBUG ((LM_DEBUG,
119 "(%P|%t) client - running ORB\n"));
121 orb->run ();
123 root_poa->destroy (true, true);
125 orb->destroy ();
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Exception caught:");
130 return 1;
133 return 0;