2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_sys_time.h"
6 #include "ace/OS_NS_unistd.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
17 while ((c
= get_opts ()) != -1)
21 ior
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
40 * Use the ACE_Task_Base class to run server threads
42 class Worker
: public ACE_Task_Base
45 Worker (CORBA::ORB_ptr orb
);
48 virtual int svc (void);
49 // The thread entry point.
57 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
64 CORBA::ORB_init (argc
, argv
);
66 if (parse_args (argc
, argv
) != 0)
69 CORBA::Object_var tmp
=
70 orb
->string_to_object(ior
);
72 Test::Server_var test_server
=
73 Test::Server::_narrow(tmp
.in ());
75 if (CORBA::is_nil (test_server
.in ()))
76 ACE_ERROR_RETURN ((LM_DEBUG
,
77 "ERROR: Nil reference in Test::Server reference <%s>\n",
81 CORBA::Any scope_as_any
;
82 scope_as_any
<<= Messaging::SYNC_NONE
;
84 CORBA::PolicyList
policies(1); policies
.length (1);
86 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
89 tmp
= test_server
->_set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
91 policies
[0]->destroy ();
93 Test::Server_var test_server_no_sync
=
94 Test::Server::_narrow(tmp
.in ());
96 if (CORBA::is_nil (test_server_no_sync
.in ()))
97 ACE_ERROR_RETURN ((LM_DEBUG
,
98 "ERROR: Nil reference in Test::Server reference <%s>\n",
102 CORBA::Object_var poa_object
=
103 orb
->resolve_initial_references("RootPOA");
105 if (CORBA::is_nil (poa_object
.in ()))
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 " (%P|%t) Unable to initialize the POA.\n"),
110 PortableServer::POA_var root_poa
=
111 PortableServer::POA::_narrow (poa_object
.in ());
113 PortableServer::POAManager_var poa_manager
=
114 root_poa
->the_POAManager ();
116 poa_manager
->activate ();
118 Worker
worker (orb
.in ());
119 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
121 ACE_ERROR_RETURN ((LM_ERROR
,
122 "Cannot activate client server thread\n"),
125 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Test starting . . .\n"));
129 PortableServer::ObjectId_var id
=
130 root_poa
->activate_object (&client_impl
);
132 tmp
= root_poa
->id_to_reference (id
.in ());
134 Test::Client_var test_client
=
135 Test::Client::_narrow (tmp
.in ());
137 // setup client callback at server
138 test_server_no_sync
->setup (test_client
.in ());
140 // send oneway request to server
141 test_server_no_sync
->request (1);
143 // sleep 2 sec to give ample opportunity for oneway reply to be received by worker
146 // check if reply received
147 if (client_impl
.reply_count () > 0)
149 ACE_DEBUG ((LM_INFO
, "(%P|%t) Oneway reply correctly received\n"));
151 result
= 0; // test OK
155 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: Oneway reply not received\n"));
157 // send second request to trigger reception of first and second reply
158 test_server_no_sync
->request (2);
160 // sleep 2 sec to give ample opportunity for oneway reply to be received by worker
163 if (client_impl
.reply_count () > 1)
165 ACE_DEBUG ((LM_INFO
, "(%P|%t) Received both replies after second request\n"));
169 ACE_ERROR ((LM_ERROR
, "(%P|%t) FATAL ERROR: Still no replies received\n"));
173 // shutdown server (use original synchronous reference to be sure to deliver message)
174 test_server
->shutdown ();
179 worker
.thr_mgr ()->wait ();
183 catch (const CORBA::Exception
& ex
)
185 ex
._tao_print_exception ("Exception caught:");
192 // ****************************************************************
194 Worker::Worker (CORBA::ORB_ptr orb
)
195 : orb_ (CORBA::ORB::_duplicate (orb
))
206 catch (const CORBA::Exception
&)