Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_1270_Regression / client.cpp
blob5a78c13b798cf91b7e19bc2da32d9328ca34d951
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"
6 #include "ace/Reactor.h"
8 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
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::ServantBase_var 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 (server.in ()))
90 ACE_ERROR_RETURN ((LM_DEBUG,
91 "Nil Test::Echo_Caller reference <%s>\n",
92 ior),
93 1);
96 poa_manager->activate ();
98 server->start_task(echo.in());
100 orb->run ();
102 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n"));
104 // Actually the code here should never be reached.
105 root_poa->destroy (true, true);
107 orb->destroy ();
109 catch (const CORBA::Exception& ex)
111 ex._tao_print_exception ("Exception caught in client:");
112 return 1;
115 return 0;
119 parse_args (int argc, ACE_TCHAR *argv[])
121 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
122 int c;
124 while ((c = get_opts ()) != -1)
125 switch (c)
127 case 'k':
128 ior = get_opts.opt_arg ();
129 break;
131 case '?':
132 default:
133 ACE_ERROR_RETURN ((LM_ERROR,
134 "usage: %s "
135 "-k <ior> "
136 "\n",
137 argv [0]),
138 -1);
140 // Indicates successful parsing of the command line
141 return 0;