2 #include "ace/Get_Opt.h"
5 #include "Server_ORBInitializer.h"
6 #include "Server_Request_Interceptor.h"
8 #include "tao/ORBInitializer_Registry.h"
9 #include "tao/AnyTypeCode/AnyTypeCode_Adapter_Impl.h"
10 #include "ace/OS_NS_stdio.h"
12 const ACE_TCHAR
*ior1_file
= 0;
13 const ACE_TCHAR
*ior2_file
= 0;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 if (argc
!= 5) // foo -o IOR_1 -o IOR_2
19 ACE_ERROR_RETURN ((LM_ERROR
,
20 "Wrong number of arguments.\n"),
23 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
28 while ((c
= get_opts ()) != -1)
35 ior1_file
= get_opts
.opt_arg ();
38 else if (ior_count
== 2)
40 ior2_file
= get_opts
.opt_arg ();
46 ACE_ERROR_RETURN ((LM_ERROR
,
48 "-o IOR_1 -o IOR_2\n",
57 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
61 #if TAO_HAS_INTERCEPTORS == 1
62 Server_ORBInitializer
*temp_initializer
= 0;
63 ACE_NEW_RETURN (temp_initializer
,
64 Server_ORBInitializer
,
65 -1); // No exceptions yet!
66 PortableInterceptor::ORBInitializer_var orb_initializer
=
69 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
70 #endif /* TAO_HAS_INTERCEPTORS == 1 */
73 CORBA::ORB_init (argc
, argv
, "Server ORB");
75 CORBA::Object_var poa_object
=
76 orb
->resolve_initial_references ("RootPOA");
78 if (CORBA::is_nil (poa_object
.in ()))
79 ACE_ERROR_RETURN ((LM_ERROR
,
80 " (%P|%t) Unable to initialize the POA.\n"),
83 PortableServer::POA_var root_poa
=
84 PortableServer::POA::_narrow (poa_object
.in ());
86 PortableServer::POAManager_var poa_manager
=
87 root_poa
->the_POAManager ();
89 if (::parse_args (argc
, argv
) != 0)
92 CORBA::PolicyList policies
; // Empty policy list.
95 test_i
servant1 (1, orb
.in ());
97 PortableServer::POA_var first_poa
=
98 root_poa
->create_POA ("first POA",
102 PortableServer::ObjectId_var oid1
=
103 first_poa
->activate_object (&servant1
);
105 CORBA::Object_var obj1
=
106 first_poa
->servant_to_reference (&servant1
);
108 CORBA::String_var ior1
=
109 orb
->object_to_string (obj1
.in ());
111 ACE_DEBUG ((LM_DEBUG
,
112 "ForwardRequestTest::test servant 1: <%C>\n",
116 test_i
servant2 (2, orb
.in ());
118 PortableServer::POA_var second_poa
=
119 root_poa
->create_POA ("second POA",
123 PortableServer::ObjectId_var oid2
=
124 second_poa
->activate_object (&servant2
);
126 CORBA::Object_var obj2
=
127 second_poa
->servant_to_reference (&servant2
);
129 CORBA::String_var ior2
=
130 orb
->object_to_string (obj2
.in ());
132 ACE_DEBUG ((LM_DEBUG
,
133 "ForwardRequestTest::test servant 2: <%C>\n",
136 poa_manager
->activate ();
138 #if TAO_HAS_INTERCEPTORS == 1
139 // Set the forward references in the server request interceptor.
140 PortableInterceptor::ServerRequestInterceptor_var
141 server_interceptor
= temp_initializer
->server_interceptor ();
143 ForwardRequestTest::ServerRequestInterceptor_var interceptor
=
144 ForwardRequestTest::ServerRequestInterceptor::_narrow (
145 server_interceptor
.in ());
147 if (CORBA::is_nil (interceptor
.in ()))
148 ACE_ERROR_RETURN ((LM_ERROR
,
149 "(%P|%t) Could not obtain reference to "
150 "server request interceptor.\n"),
153 interceptor
->forward_references (obj1
.in (),
155 #endif /* TAO_HAS_INTERCEPTORS == 1 */
157 // Write each IOR to a file.
160 FILE *output_file
= ACE_OS::fopen (ior1_file
, "w");
161 if (output_file
== 0)
162 ACE_ERROR_RETURN ((LM_ERROR
,
163 "Cannot open output file <%s> for writing "
167 ACE_OS::fprintf (output_file
, "%s", ior1
.in ());
168 ACE_OS::fclose (output_file
);
171 output_file
= ACE_OS::fopen (ior2_file
, "w");
172 if (output_file
== 0)
173 ACE_ERROR_RETURN ((LM_ERROR
,
174 "Cannot open output file for writing IOR: %s",
177 ACE_OS::fprintf (output_file
, "%s", ior2
.in ());
178 ACE_OS::fclose (output_file
);
180 // Run the ORB event loop.
183 root_poa
->destroy (true, true);
187 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));
189 catch (const CORBA::Exception
& ex
)
191 ex
._tao_print_exception ("Caught exception:");