1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
4 #include "server_interceptor.h"
5 #include "Server_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
9 const ACE_TCHAR
*ior_input_file
= ACE_TEXT("file://thr_server.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("i:o:"));
18 while ((c
= get_opts ()) != -1)
22 ior_input_file
= get_opts
.opt_arg ();
25 ior_output_file
= get_opts
.opt_arg ();
29 ACE_ERROR_RETURN ((LM_ERROR
,
37 // Indicates successful parsing of the command line
42 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
46 // Create the ORB initializer.
47 Server_ORBInitializer
*temp_initializer
= 0;
48 ACE_NEW_RETURN (temp_initializer
,
49 Server_ORBInitializer
,
52 PortableInterceptor::ORBInitializer_var initializer
=
55 PortableInterceptor::register_orb_initializer (initializer
.in ());
57 // Now initialize the ORB.
58 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
,
61 CORBA::Object_var poa_object
=
62 orb
->resolve_initial_references ("RootPOA");
64 if (CORBA::is_nil (poa_object
.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR
,
67 " (%P|%t) Unable to initialize the POA.\n" ),
71 PortableServer::POA_var root_poa
=
72 PortableServer::POA::_narrow (poa_object
.in ());
74 PortableServer::POAManager_var poa_manager
=
75 root_poa
->the_POAManager ();
77 poa_manager
->activate ();
79 if (parse_args (argc
, argv
) != 0)
84 // Create the interceptor.
85 Echo_Server_Request_Interceptor
* server_interceptor
=
86 temp_initializer
->server_interceptor();
88 if (server_interceptor
== 0)
90 ACE_ERROR_RETURN ((LM_ERROR
,
91 "(%P|%t) Could not obtain reference to "
92 "server request interceptor.\n"),
96 // Pull in the ior from the remote server to use as the forward location.
97 CORBA::Object_var forward_location
= orb
->string_to_object (ior_input_file
);
99 if (CORBA::is_nil (forward_location
.in ()))
101 ACE_ERROR_RETURN ((LM_ERROR
,
102 "Object reference <%s> is nil\n",
107 server_interceptor
->forward_reference (forward_location
.in ());
109 Bug1495_i
server_impl (orb
.in ());
111 PortableServer::ObjectId_var id
=
112 root_poa
->activate_object (&server_impl
);
114 CORBA::Object_var test_obj
=
115 root_poa
->id_to_reference (id
.in ());
117 Bug1495_Regression::Bug1495_var server
=
118 Bug1495_Regression::Bug1495::_narrow (test_obj
.in ());
120 CORBA::String_var ior
=
121 orb
->object_to_string (server
.in ());
123 // Output the server IOR to a file
124 if (ior_output_file
!= 0)
126 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
128 if (output_file
== 0)
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "Cannot open output file for writing the "
132 "server IOR: %s", ior_output_file
),
136 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
137 ACE_OS::fclose (output_file
);
140 ACE_Time_Value
tv (15, 0);
144 if (server_interceptor
->forward_location_done() == false)
146 ACE_ERROR ((LM_ERROR
, "ERROR: Forward location has not occurred!\n"));
149 ACE_DEBUG ((LM_DEBUG
, "Threaded Server event loop finished\n"));
150 root_poa
->destroy (1, 1);
154 catch (const CORBA::Exception
& ex
)
156 ex
._tao_print_exception ("Caught an exception in server:");
160 ACE_DEBUG ((LM_DEBUG
, "Threaded Server ready\n"));