2 #include "tao/RTCORBA/RT_Policy_i.h"
3 #include "tao/RTPortableServer/RTPortableServer.h"
4 #include "tao/Strategies/advanced_resource.h"
5 #include "tao/ORB_Core.h"
6 #include "tao/Policy_Set.h"
7 #include "ace/Get_Opt.h"
8 #include "tao/PortableServer/Root_POA.h"
10 class Test_i
: public POA_Test
13 // An implementation for the Test interface in test.idl
16 Test_i (CORBA::ORB_ptr orb
);
19 //FUZZ: disable check_for_lack_ACE_OS
21 //FUZZ: enable check_for_lack_ACE_OS
28 Test_i::Test_i (CORBA::ORB_ptr orb
)
29 : orb_ (CORBA::ORB::_duplicate (orb
))
34 Test_i::shutdown (void)
37 "Received request to shut down the ORB\n"));
38 this->orb_
->shutdown (0);
41 //*************************************************************************
43 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
44 int protocol_chosen
= 0;
45 CORBA::ULong protocol_type
= 0;
47 // Parse command-line arguments.
49 parse_args (int argc
, ACE_TCHAR
*argv
[])
51 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:p:"));
54 while ((c
= get_opts ()) != -1)
58 ior_output_file
= get_opts
.opt_arg ();
62 result
= ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ()),
65 if (result
== 0 || result
== EOF
)
66 ACE_ERROR_RETURN ((LM_ERROR
,
67 "Unable to process <-p> option"),
75 ACE_ERROR_RETURN ((LM_ERROR
,
87 check_server_protocol_at_root_poa (CORBA::ORB_ptr
/*orb*/,
88 PortableServer::POA_ptr poa
)
90 // Users should never write code like below.
91 // It is for testing purposes only! (Unfortunately, there
92 // is no standard way to access POA policies).
93 TAO_Root_POA
&tao_poa
=
94 dynamic_cast<TAO_Root_POA
&> (*poa
);
96 TAO_POA_Policy_Set
&policies
=
99 CORBA::Policy_var server_protocol
=
100 policies
.get_cached_policy (TAO_CACHED_POLICY_RT_SERVER_PROTOCOL
);
102 RTCORBA::ServerProtocolPolicy_var policy
=
103 RTCORBA::ServerProtocolPolicy::_narrow (server_protocol
.in ());
105 if (CORBA::is_nil (policy
.in ()))
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "\nERROR: ORB default for ServerProtocolPolicy "
111 RTCORBA::ProtocolList_var protocols
= policy
->protocols ();
113 ACE_DEBUG ((LM_DEBUG
,
114 "\nRoot POA ServerProtocolPolicy "
115 "contains %u protocols:\n", protocols
->length ()));
117 for (CORBA::ULong i
= 0; i
< protocols
->length (); ++i
)
119 CORBA::ULong
const protocol_type
= protocols
[i
].protocol_type
;
120 ACE_DEBUG ((LM_DEBUG
,
121 " Protocol %u: IOP::ProfileId = %u\n",
123 RTCORBA::ProtocolProperties_var properties
=
124 protocols
[i
].transport_protocol_properties
;
127 if (protocol_type
== IOP::TAG_INTERNET_IOP
)
129 RTCORBA::TCPProtocolProperties_var tcp_properties
=
130 RTCORBA::TCPProtocolProperties::_narrow (properties
.in ());
132 if (!CORBA::is_nil (tcp_properties
.in ()))
133 ACE_DEBUG ((LM_DEBUG
,
135 " send_buffer_size = %d\n"
136 " receive_buffer_size = %d\n"
140 " enable_network_priority = %d\n",
141 tcp_properties
->send_buffer_size (),
142 tcp_properties
->recv_buffer_size (),
143 tcp_properties
->keep_alive (),
144 tcp_properties
->dont_route (),
145 tcp_properties
->no_delay (),
146 tcp_properties
->enable_network_priority ()));
148 else if (protocol_type
== TAO_TAG_UIOP_PROFILE
)
150 RTCORBA::UnixDomainProtocolProperties_var uiop_properties
=
151 RTCORBA::UnixDomainProtocolProperties::_narrow (properties
.in ());
153 if (!CORBA::is_nil (uiop_properties
.in ()))
154 ACE_DEBUG ((LM_DEBUG
,
156 " send_buffer_size = %d\n"
157 " receive_buffer_size = %d\n",
158 uiop_properties
->send_buffer_size (),
159 uiop_properties
->recv_buffer_size ()));
161 else if (protocol_type
== TAO_TAG_SHMEM_PROFILE
)
163 RTCORBA::SharedMemoryProtocolProperties_var shmem_properties
=
164 RTCORBA::SharedMemoryProtocolProperties::_narrow (properties
.in ());
166 if (!CORBA::is_nil (shmem_properties
.in ()))
167 ACE_DEBUG ((LM_DEBUG
,
169 " send_buffer_size = %d\n"
170 " receive_buffer_size = %d\n"
174 " preallocate_buffer_size = %d\n"
175 " mmap_filename = %s\n"
176 " mmap_lockname = %s\n",
177 shmem_properties
->send_buffer_size (),
178 shmem_properties
->recv_buffer_size (),
179 shmem_properties
->keep_alive (),
180 shmem_properties
->dont_route (),
181 shmem_properties
->no_delay (),
182 shmem_properties
->preallocate_buffer_size (),
183 shmem_properties
->mmap_filename (),
184 shmem_properties
->mmap_lockname ()));
186 else if (protocol_type
== TAO_TAG_DIOP_PROFILE
)
188 RTCORBA::UserDatagramProtocolProperties_var diop_properties
=
189 RTCORBA::UserDatagramProtocolProperties::_narrow (properties
.in ());
191 if (!CORBA::is_nil (diop_properties
.in ()))
192 ACE_DEBUG ((LM_DEBUG
,
194 " enable_network_priority = %d\n",
195 diop_properties
->enable_network_priority ()));
197 else if (protocol_type
== TAO_TAG_SCIOP_PROFILE
)
199 RTCORBA::StreamControlProtocolProperties_var sciop_properties
=
200 RTCORBA::StreamControlProtocolProperties::_narrow (properties
.in ());
202 if (!CORBA::is_nil (sciop_properties
.in ()))
203 ACE_DEBUG ((LM_DEBUG
,
205 " send_buffer_size = %d\n"
206 " receive_buffer_size = %d\n"
210 " enable_network_priority = %d\n",
211 sciop_properties
->send_buffer_size (),
212 sciop_properties
->recv_buffer_size (),
213 sciop_properties
->keep_alive (),
214 sciop_properties
->dont_route (),
215 sciop_properties
->no_delay (),
216 sciop_properties
->enable_network_priority ()));
225 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
230 CORBA::ORB_init (argc
, argv
);
232 if (parse_args (argc
, argv
) != 0)
235 CORBA::Object_var object
=
236 orb
->resolve_initial_references("RootPOA");
238 PortableServer::POA_var root_poa
=
239 PortableServer::POA::_narrow (object
.in ());
241 if (CORBA::is_nil (root_poa
.in ()))
242 ACE_ERROR_RETURN ((LM_ERROR
,
243 "ERROR: Panic <RootPOA> is nil\n"),
246 PortableServer::POAManager_var poa_manager
=
247 root_poa
->the_POAManager ();
249 object
= orb
->resolve_initial_references ("RTORB");
250 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
252 // Check ServerProtocol configurations.
253 int result
= check_server_protocol_at_root_poa (orb
.in (),
258 // If a protocol type was indicated using command line option,
259 // create a child POA with ServerProtocolPolicy containing
260 // that protocol and register Test object with child POA.
261 // Otherwise, register Test object with the root POA (ORB
262 // default ServerProtocolPolicy will get used).
263 RTCORBA::ProtocolList protocols
;
264 protocols
.length (1);
265 protocols
[0].protocol_type
= protocol_type
;
266 protocols
[0].transport_protocol_properties
=
267 RTCORBA::ProtocolProperties::_nil ();
268 protocols
[0].orb_protocol_properties
=
269 RTCORBA::ProtocolProperties::_nil ();
271 CORBA::PolicyList poa_policy_list
;
272 poa_policy_list
.length (1);
274 rt_orb
->create_server_protocol_policy (protocols
);
276 PortableServer::POA_var poa
;
281 root_poa
->create_POA ("Child_POA",
288 poa
= PortableServer::POA::_duplicate (root_poa
.in ());
291 Test_i
server_impl (orb
.in ());
293 PortableServer::ObjectId_var id
=
294 poa
->activate_object (&server_impl
);
296 CORBA::Object_var server
=
297 poa
->id_to_reference (id
.in ());
300 CORBA::String_var ior
=
301 orb
->object_to_string (server
.in ());
303 ACE_DEBUG ((LM_DEBUG
, "\nActivated as <%C>\n\n", ior
.in ()));
305 if (ior_output_file
!= 0)
307 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
308 if (output_file
== 0)
309 ACE_ERROR_RETURN ((LM_ERROR
,
310 "Cannot open output file for writing IOR: %s",
313 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
314 ACE_OS::fclose (output_file
);
317 // Run ORB Event loop.
318 poa_manager
->activate ();
322 ACE_DEBUG ((LM_DEBUG
, "Server ORB event loop finished\n\n"));
324 catch (const CORBA::Exception
& ex
)
326 ex
._tao_print_exception ("Exception caught:");