1 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
6 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
10 * Simpler Server Client implementation
12 * Implements the Simple_Server interface in test.idl
14 class Simple_Server_i
: public POA_Simple_Server
17 Simple_Server_i (CORBA::ORB_ptr orb
)
18 : orb_ (CORBA::ORB::_duplicate (orb
))
22 // = The Simple_Server methods.
23 char *test_method (Simple_Server_ptr objref
)
25 ACE_DEBUG ((LM_DEBUG
, "Client test_method() - sleeping\n"));
27 if (!CORBA::is_nil (objref
))
29 ACE_DEBUG ((LM_DEBUG
, "Client test_method() - signalling server\n"));
30 objref
->client_done ();
32 ACE_DEBUG ((LM_DEBUG
, "Client test_method() - returning\n"));
33 return CORBA::string_dup ("hello from client");
36 virtual void client_done ()
38 ACE_ERROR ((LM_ERROR
, "Unexpected call\n"));
52 parse_args (int argc
, ACE_TCHAR
*argv
[])
54 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("xk:s:"));
57 while ((c
= get_opts ()) != -1)
65 ior
= get_opts
.opt_arg ();
70 ACE_ERROR_RETURN ((LM_ERROR
,
78 // Indicates successful parsing of the command line
85 * Use the ACE_Task_Base class to run server threads
87 class Worker
: public ACE_Task_Base
90 Worker (CORBA::ORB_ptr orb
);
94 // The thread entry point.
102 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
106 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
108 CORBA::Object_var poa_object
=
109 orb
->resolve_initial_references("RootPOA");
111 if (CORBA::is_nil (poa_object
.in ()))
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 " (%P|%t) Unable to initialize the POA.\n"),
116 PortableServer::POA_var root_poa
=
117 PortableServer::POA::_narrow (poa_object
.in ());
119 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
121 if (parse_args (argc
, argv
) != 0)
124 Simple_Server_i
server_impl (orb
.in ());
126 PortableServer::ObjectId_var id
=
127 root_poa
->activate_object (&server_impl
);
129 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
131 Simple_Server_var server
= Simple_Server::_narrow (object
.in ());
133 CORBA::String_var local_ior
= orb
->object_to_string (server
.in ());
134 ACE_DEBUG ((LM_DEBUG
,
135 "Client interface started on <%C>\n",
137 CORBA::Object_var remote_object
= orb
->string_to_object (ior
);
139 Simple_Server_var remote_server
=
140 Simple_Server::_narrow (remote_object
.in ());
142 if (CORBA::is_nil (remote_server
.in ()))
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 "Object reference <%s> is nil\n",
151 remote_server
->shutdown ();
155 poa_manager
->activate ();
156 Worker
worker (orb
.in ());
157 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
159 ACE_ERROR_RETURN ((LM_ERROR
,
160 "Cannot activate client thread\n"),
162 ACE_DEBUG ((LM_DEBUG
, "ORB Thread started\n"));
163 CORBA::String_var str
= remote_server
->test_method (server
.in ());
164 ACE_DEBUG ((LM_DEBUG
, "Received \"%C\"\n", str
.in ()));
165 orb
->shutdown (true);
166 worker
.thr_mgr ()->wait ();
167 ACE_DEBUG ((LM_DEBUG
, "ORB Thread completed\n"));
171 catch (const CORBA::Exception
& ex
)
173 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("(%P|%t) Exception caught: \n%s\n"),
174 ACE_TEXT_CHAR_TO_TCHAR (ex
._info ().c_str ())));
181 // ****************************************************************
183 Worker::Worker (CORBA::ORB_ptr orb
)
184 : orb_ (CORBA::ORB::_duplicate (orb
))
195 catch (const CORBA::Exception
&)