2 #include "ace/Get_Opt.h"
3 #include "tao/RTCORBA/RTCORBA.h"
4 #include "tao/RTCORBA/RT_Policy_i.h"
5 #include "tao/RTPortableServer/RTPortableServer.h"
6 #include "tao/Strategies/advanced_resource.h"
8 class Test_i
: public POA_Test
11 // An implementation for the Test interface in test.idl
14 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::test_method ()
37 "Test method invoked on the sever\n"));
44 "(%P|%t) Shutting down\n"));
45 this->orb_
->shutdown (false);
48 //*************************************************************************
50 const ACE_TCHAR
*ior_output_file1
= ACE_TEXT("test1.ior");
51 const ACE_TCHAR
*ior_output_file2
= ACE_TEXT("test2.ior");
52 CORBA::ULong protocol_type
= 0;
54 // Parse command-line arguments.
56 parse_args (int argc
, ACE_TCHAR
*argv
[])
58 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:c:p:"));
61 while ((c
= get_opts ()) != -1)
65 ior_output_file1
= get_opts
.opt_arg ();
69 ior_output_file2
= get_opts
.opt_arg ();
73 result
= ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ()),
76 if (result
== 0 || result
== EOF
)
77 ACE_ERROR_RETURN ((LM_ERROR
,
78 "Unable to process <-p> option"),
84 ACE_ERROR_RETURN ((LM_ERROR
,
98 check_for_nil (CORBA::Object_ptr obj
, const char *msg
)
100 if (CORBA::is_nil (obj
))
101 ACE_ERROR_RETURN ((LM_ERROR
,
102 "ERROR: Object reference <%C> is nil\n",
110 create_object (PortableServer::POA_ptr poa
,
113 const ACE_TCHAR
*filename
)
115 // Register with poa.
116 PortableServer::ObjectId_var id
=
117 poa
->activate_object (server_impl
);
119 CORBA::Object_var server
=
120 poa
->id_to_reference (id
.in ());
122 // Print out the IOR.
123 CORBA::String_var ior
=
124 orb
->object_to_string (server
.in ());
126 ACE_DEBUG ((LM_DEBUG
, "<%C>\n\n", ior
.in ()));
128 // Print ior to the file.
131 FILE *output_file
= ACE_OS::fopen (filename
, "w");
132 if (output_file
== 0)
133 ACE_ERROR_RETURN ((LM_ERROR
,
134 "Cannot open output file for writing IOR: %s",
137 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
138 ACE_OS::fclose (output_file
);
145 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
151 CORBA::ORB_init (argc
, argv
);
154 if (parse_args (argc
, argv
) != 0)
158 CORBA::Object_var object
=
159 orb
->resolve_initial_references ("RTORB");
160 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
161 if (check_for_nil (rt_orb
.in (), "RTORB") == -1)
166 orb
->resolve_initial_references("RootPOA");
167 PortableServer::POA_var root_poa
=
168 PortableServer::POA::_narrow (object
.in ());
169 if (check_for_nil (root_poa
.in (), "RootPOA") == -1)
173 PortableServer::POAManager_var poa_manager
=
174 root_poa
->the_POAManager ();
176 // Create child POA with RTCORBA::ClientProtocolPolicy set.
177 RTCORBA::ProtocolList protocols
;
178 protocols
.length (1);
179 protocols
[0].protocol_type
= protocol_type
;
180 protocols
[0].orb_protocol_properties
=
181 TAO_Protocol_Properties_Factory::create_orb_protocol_property
183 protocols
[0].transport_protocol_properties
=
184 TAO_Protocol_Properties_Factory::create_transport_protocol_property
185 (protocol_type
, orb
->orb_core ());
187 CORBA::PolicyList poa_policy_list
;
188 poa_policy_list
.length (1);
190 rt_orb
->create_client_protocol_policy (protocols
);
192 PortableServer::POA_var poa
=
193 root_poa
->create_POA ("Child_POA",
198 Test_i
server_impl (orb
.in ());
202 ACE_DEBUG ((LM_DEBUG
, "\nActivated object one as "));
203 result
= create_object (poa
.in (), orb
.in (), &server_impl
,
209 ACE_DEBUG ((LM_DEBUG
, "\nActivated object two as "));
210 result
= create_object (root_poa
.in (), orb
.in (), &server_impl
,
215 // Run ORB Event loop.
216 poa_manager
->activate ();
220 ACE_DEBUG ((LM_DEBUG
, "Server ORB event loop finished\n\n"));
222 catch (const CORBA::Exception
& ex
)
224 ex
._tao_print_exception (
225 "Unexpected exception caught in ClientProtocolPolicy: test server");