2 #include "ace/Get_Opt.h"
4 #include "Server_ORBInitializer.h"
5 #include "Server_Request_Interceptor.h"
6 #include "tao/ORBInitializer_Registry.h"
7 #include "ace/OS_NS_stdio.h"
8 #include "CrashPoint.h"
10 const ACE_TCHAR
*ior_file
= 0;
12 int server_number
= 0;
15 parse_args (int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:c:n:s:"));
20 while ((c
= get_opts ()) != -1)
24 ior_file
= get_opts
.opt_arg ();
27 crash_point
= ACE_OS::atoi (get_opts
.opt_arg ());
30 number
= ACE_OS::atoi (get_opts
.opt_arg ());
33 server_number
= ACE_OS::atoi (get_opts
.opt_arg ());
36 ACE_ERROR_RETURN ((LM_ERROR
,
40 "-n <server number>\n",
49 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
53 #if TAO_HAS_INTERCEPTORS == 1
54 Server_ORBInitializer
*temp_initializer
= 0;
55 ACE_NEW_RETURN (temp_initializer
,
56 Server_ORBInitializer
,
57 -1); // No exceptions yet!
58 PortableInterceptor::ORBInitializer_var orb_initializer
=
61 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
62 #endif /* TAO_HAS_INTERCEPTORS == 1 */
65 CORBA::ORB_init (argc
, argv
, "Server ORB");
67 CORBA::Object_var poa_object
=
68 orb
->resolve_initial_references ("RootPOA");
70 if (CORBA::is_nil (poa_object
.in ()))
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 " (%P|%t) Unable to initialize the POA.\n"),
75 PortableServer::POA_var root_poa
=
76 PortableServer::POA::_narrow (poa_object
.in ());
78 PortableServer::POAManager_var poa_manager
=
79 root_poa
->the_POAManager ();
81 if (::parse_args (argc
, argv
) != 0)
85 ACE_NEW_RETURN (test_impl
, test_i (number
, orb
.in ()), 1);
86 PortableServer::ServantBase_var
owner_transfer (test_impl
);
88 PortableServer::ObjectId_var id
=
89 root_poa
->activate_object (test_impl
);
91 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
93 RedirectionTest::test_var test
=
94 RedirectionTest::test::_narrow (object
.in ());
96 CORBA::String_var ior
=
97 orb
->object_to_string (test
.in ());
99 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
100 if (output_file
== 0)
101 ACE_ERROR_RETURN ((LM_ERROR
,
102 "Cannot open output file <%s> for writing "
104 ior_file
, ior
.in ()),
106 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
107 ACE_OS::fclose (output_file
);
109 if (server_number
== 2)
112 poa_manager
->activate ();
114 // Run the ORB event loop.
117 root_poa
->destroy (true, true);
121 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));
123 catch (const CORBA::Exception
& ex
)
125 ex
._tao_print_exception ("Caught exception:");