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");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
15 while ((c
= get_opts ()) != -1)
19 ior
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
37 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
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"),
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 ()))
67 "ERROR: Nil policy current\n"));
70 CORBA::Any scope_as_any
;
71 scope_as_any
<<= Messaging::SYNC_WITH_TRANSPORT
;
73 CORBA::PolicyList
policies(1);
76 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
79 policy_current
->set_policy_overrides (policies
,
82 policies
[0]->destroy ();
84 if (parse_args (argc
, argv
) != 0)
87 PortableServer::Servant_var
<Echo
> impl
;
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.
95 Echo (orb
.in (), 100),
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",
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
,
132 ACE_ERROR ((LM_ERROR
,
133 "Error activating client task\n"));
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);
147 catch (const CORBA::Exception
& ex
)
149 ex
._tao_print_exception ("Exception caught:");