2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
6 #include "ServerORBInitializer.h"
8 #include "tao/ORBInitializer_Registry.h"
10 #include "ace/OS_NS_stdio.h"
11 #include "ace/OS_NS_strings.h"
13 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
15 extern PortableInterceptor::SlotId slot_id
;
18 parse_args (int argc
, ACE_TCHAR
*argv
[])
21 for(int i
= 1; i
< argc
; i
++)
23 if (ACE_OS::strncasecmp(argv
[i
], ACE_TEXT("-ORB"), 4) != 0)
30 ior_output_file
= argv
[i
];
36 #if defined (ACE_HAS_THREADS)
37 argv
[i
] = const_cast<ACE_TCHAR
*> (ACE_TEXT("-ORBSvcConfDirective"));
38 #endif /* ACE_HAS_THREADS */
41 #if defined (ACE_HAS_THREADS)
42 argv
[i
] = const_cast<ACE_TCHAR
*> (ACE_TEXT("static Server_Strategy_Factory \"-ORBConcurrency thread-per-connection\""));
44 ACE_DEBUG ((LM_DEBUG
, "NOTE: Non-threaded build. "
45 "Defaulting to single threaded.\n"));
46 #endif /* ACE_HAS_THREADS */
58 ACE_ERROR_RETURN ((LM_ERROR
,
66 // Indicates successful parsing of the command line
71 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
75 PortableInterceptor::ORBInitializer_ptr temp_initializer
=
76 PortableInterceptor::ORBInitializer::_nil ();
78 ACE_NEW_RETURN (temp_initializer
,
80 -1); // No CORBA exceptions yet!
81 PortableInterceptor::ORBInitializer_var orb_initializer
=
84 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
86 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
90 if (parse_args (argc
, argv
) != 0)
93 CORBA::Object_var obj
=
94 orb
->resolve_initial_references ("RootPOA");
96 PortableServer::POA_var root_poa
=
97 PortableServer::POA::_narrow (obj
.in ());
99 if (CORBA::is_nil (root_poa
.in ()))
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "Unable to obtain RootPOA reference.\n"),
104 PortableServer::POAManager_var poa_manager
=
105 root_poa
->the_POAManager ();
107 poa_manager
->activate ();
109 obj
= orb
->resolve_initial_references ("PICurrent");
111 PortableInterceptor::Current_var pi_current
=
112 PortableInterceptor::Current::_narrow (obj
.in ());
114 if (CORBA::is_nil (pi_current
.in ()))
115 ACE_ERROR_RETURN ((LM_ERROR
,
116 "Unable to obtain PICurrent reference.\n"),
119 test_i
server_impl (pi_current
.in (),
123 obj
= server_impl
._this ();
125 PICurrentTest::test_var server
=
126 PICurrentTest::test::_narrow (obj
.in ());
128 if (CORBA::is_nil (server
.in ()))
129 ACE_ERROR_RETURN ((LM_ERROR
,
130 "Unable to obtain reference to "
131 "PICurrentTest::test object.\n"),
134 CORBA::String_var ior
=
135 orb
->object_to_string (server
.in ());
137 ACE_DEBUG ((LM_INFO
, "PICurrentTest::test: <%C>\n", ior
.in ()));
139 // If the ior_output_file exists, output the IOR to it.
140 if (ior_output_file
!= 0)
142 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
143 if (output_file
== 0)
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 "Cannot open output file for writing "
149 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
150 ACE_OS::fclose (output_file
);
158 ACE_DEBUG ((LM_INFO
, "Event loop finished.\n"));
160 catch (const CORBA::Exception
& ex
)
162 ex
._tao_print_exception ("PICurrent test (server-side):");