1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
4 #include "Server_ORBInitializer.h"
5 #include "tao/ORBInitializer_Registry.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
23 ACE_ERROR_RETURN ((LM_ERROR
,
30 // Indicates successful parsing of the command line
35 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
39 Server_ORBInitializer
* temp_initializer
= 0;
41 ACE_NEW_RETURN (temp_initializer
,
42 Server_ORBInitializer
,
43 -1); // No exceptions yet!
44 PortableInterceptor::ORBInitializer_var initializer
=
47 PortableInterceptor::register_orb_initializer (initializer
.in ());
49 // Now we can create the ORB
51 CORBA::ORB_init (argc
, argv
);
53 CORBA::Object_var poa_object
=
54 orb
->resolve_initial_references ("RootPOA");
56 if (CORBA::is_nil (poa_object
.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 " (%P|%t) Unable to initialize the POA.\n"),
61 PortableServer::POA_var root_poa
=
62 PortableServer::POA::_narrow (poa_object
.in ());
64 PortableServer::POAManager_var poa_manager
=
65 root_poa
->the_POAManager ();
67 poa_manager
->activate ();
69 if (parse_args (argc
, argv
) != 0)
72 Visual_i
server_impl (orb
.in ());
74 PortableServer::ObjectId_var id
=
75 root_poa
->activate_object (&server_impl
);
77 // Create a second object to receive forwarded requests
78 Visual_i
forward_server_impl (orb
.in ());
80 PortableServer::ObjectId_var forward_id
=
81 root_poa
->activate_object (&forward_server_impl
);
83 CORBA::Object_var forward_test_obj
=
84 root_poa
->id_to_reference (forward_id
.in ());
86 Echo_Server_Request_Interceptor
* server_interceptor
=
87 temp_initializer
->server_interceptor ();
89 if (server_interceptor
== 0)
90 ACE_ERROR_RETURN ((LM_ERROR
,
91 "(%P|%t) Could not obtain reference to "
92 "server request interceptor.\n"),
95 server_interceptor
->forward_reference (forward_test_obj
.in ());
97 CORBA::Object_var test_obj
=
98 root_poa
->id_to_reference (id
.in ());
100 Test_Interceptors::Visual_var server
=
101 Test_Interceptors::Visual::_narrow (test_obj
.in ());
103 CORBA::String_var ior
=
104 orb
->object_to_string (server
.in ());
106 ACE_DEBUG ((LM_DEBUG
,
107 "Test_Interceptors::Visual: <%C>\n",
110 // If the ior_output_file exists, output the ior to it
111 if (ior_output_file
!= 0)
113 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
114 if (output_file
== 0)
115 ACE_ERROR_RETURN ((LM_ERROR
,
116 "Cannot open output file for writing IOR: %s",
119 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
120 ACE_OS::fclose (output_file
);
125 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
127 root_poa
->destroy (1, 1);
131 catch (const CORBA::Exception
& ex
)
133 ex
._tao_print_exception ("Caught exception in server:");