Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_1020_Basic_Regression / client.cpp
blob1ff260e8f3cbbf68df311d2e3dd6079a577e3b53
1 #include "Echo.h"
2 #include "Client_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "tao/Messaging/Messaging.h"
5 #include "tao/AnyTypeCode/Any.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;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-k <ior> "
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 CORBA::ORB_var orb =
42 CORBA::ORB_init (argc, argv);
44 CORBA::Object_var poa_object =
45 orb->resolve_initial_references("RootPOA");
47 PortableServer::POA_var root_poa =
48 PortableServer::POA::_narrow (poa_object.in ());
50 if (CORBA::is_nil (root_poa.in ()))
51 ACE_ERROR_RETURN ((LM_ERROR,
52 " (%P|%t) Panic: nil RootPOA\n"),
53 1);
55 PortableServer::POAManager_var poa_manager =
56 root_poa->the_POAManager ();
58 CORBA::Object_var object =
59 orb->resolve_initial_references ("PolicyCurrent");
61 CORBA::PolicyCurrent_var policy_current =
62 CORBA::PolicyCurrent::_narrow (object.in ());
64 if (CORBA::is_nil (policy_current.in ()))
66 ACE_ERROR ((LM_ERROR,
67 "ERROR: Nil policy current\n"));
68 return 1;
70 CORBA::Any scope_as_any;
71 scope_as_any <<= Messaging::SYNC_WITH_TRANSPORT;
73 CORBA::PolicyList policies(1);
74 policies.length (1);
75 policies[0] =
76 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
77 scope_as_any);
79 policy_current->set_policy_overrides (policies,
80 CORBA::ADD_OVERRIDE);
82 policies[0]->destroy ();
84 if (parse_args (argc, argv) != 0)
85 return 1;
87 PortableServer::Servant_var<Echo> impl;
89 Echo * tmp;
90 // ACE_NEW_RETURN is the worst possible way to handle
91 // exceptions (think: what if the constructor allocates memory
92 // and fails?), but I'm not in the mood to fight for a more
93 // reasonable way to handle allocation errors in ACE.
94 ACE_NEW_RETURN (tmp,
95 Echo (orb.in (), 100),
96 1);
97 impl = tmp;
100 PortableServer::ObjectId_var id =
101 root_poa->activate_object (impl.in ());
103 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
105 Test::Echo_var echo =
106 Test::Echo::_narrow (object_act.in ());
108 CORBA::Object_var tmp =
109 orb->string_to_object(ior);
111 Test::Echo_Caller_var server =
112 Test::Echo_Caller::_narrow(tmp.in ());
114 if (CORBA::is_nil (echo.in ()))
116 ACE_ERROR_RETURN ((LM_DEBUG,
117 "Nil Test::Echo_Caller reference <%s>\n",
118 ior),
122 poa_manager->activate ();
124 Client_Task ctask (orb.in ());
126 server->start_task (echo.in());
128 if (ctask.activate (THR_NEW_LWP | THR_JOINABLE,
130 1) == -1)
132 ACE_ERROR ((LM_ERROR,
133 "Error activating client task\n"));
135 return 1;
138 ACE_Thread_Manager::instance ()->wait ();
140 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n"));
142 // Actually the code here should never be reached.
143 root_poa->destroy (true, true);
145 orb->destroy ();
147 catch (const CORBA::Exception& ex)
149 ex._tao_print_exception ("Exception caught:");
150 return 1;
153 return 0;