Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3000_Regression / client.cpp
blobf584cc96ec3415bf9e83a1918b6ddc590e2ba3ce
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");
8 bool shutdown_server = false;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:s"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
22 case 's':
23 shutdown_server = true;
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-k <ior>"
30 "-s "
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
42 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 CORBA::Object_var poa_object =
48 orb->resolve_initial_references("RootPOA");
50 PortableServer::POA_var root_poa =
51 PortableServer::POA::_narrow (poa_object.in ());
53 if (CORBA::is_nil (root_poa.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR,
55 " (%P|%t) Panic: nil RootPOA\n"),
56 1);
58 PortableServer::POAManager_var poa_manager =
59 root_poa->the_POAManager ();
61 // Make all oneways "reliable."
63 CORBA::Object_var manager_object =
64 orb->resolve_initial_references("ORBPolicyManager");
65 CORBA::PolicyManager_var policy_manager =
66 CORBA::PolicyManager::_narrow(manager_object.in());
68 if (CORBA::is_nil (policy_manager.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR,
70 " (%P|%t) Panic: nil PolicyManager\n"),
71 1);
72 CORBA::Any policy_value;
73 policy_value <<= Messaging::SYNC_WITH_SERVER;
74 CORBA::PolicyList policies(1); policies.length(1);
75 policies[0] =
76 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
77 policy_value);
79 policy_manager->set_policy_overrides (policies,
80 CORBA::ADD_OVERRIDE);
82 policies[0]->destroy ();
85 if (parse_args (argc, argv) != 0)
86 return 1;
88 CORBA::Object_var tmp =
89 orb->string_to_object(ior);
91 Test::Service_var service =
92 Test::Service::_narrow(tmp.in ());
94 if (CORBA::is_nil (service.in ()))
96 ACE_ERROR_RETURN ((LM_DEBUG,
97 "Nil service reference <%s>\n",
98 ior),
99 1);
102 Callback *callback_impl;
103 ACE_NEW_RETURN (callback_impl,
104 Callback (),
106 PortableServer::ServantBase_var owner_transfer(callback_impl);
108 PortableServer::ObjectId_var id =
109 root_poa->activate_object (callback_impl);
111 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
113 Test::Callback_var callback =
114 Test::Callback::_narrow (object.in ());
116 poa_manager->activate ();
118 ACE_DEBUG ((LM_DEBUG,
119 "(%P|%t) client - starting test\n"));
121 service->run_test (callback.in ());
123 ACE_DEBUG ((LM_DEBUG,
124 "(%P|%t) client - running ORB\n"));
126 while (!callback_impl->received_callback ())
128 orb->perform_work ();
130 if (shutdown_server) {
131 service->shutdown ();
134 root_poa->destroy (true, true);
136 orb->destroy ();
138 catch (const CORBA::Exception& ex)
140 ex._tao_print_exception ("Exception caught:");
141 return 1;
144 return 0;