1 #include "ORT_test_i.h"
2 #include "ServerORBInitializer.h"
4 #include "tao/ORBInitializer_Registry.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_stdio.h"
9 const ACE_TCHAR
*ior_output_file
= 0;
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
22 ACE_DEBUG ((LM_DEBUG
, "FILE ==== %s\n", ior_output_file
));
25 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
37 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
41 PortableInterceptor::ORBInitializer_ptr tmp
;
45 -1); // No CORBA exceptions yet!
47 PortableInterceptor::ORBInitializer_var orb_initializer
= tmp
;
49 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
51 // Initialize the ORB.
52 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
, "ORT Test ORB");
54 if (parse_args (argc
, argv
) != 0)
57 CORBA::Object_var obj
=
58 orb
->resolve_initial_references ("RootPOA");
61 PortableServer::POA_var root_poa
=
62 PortableServer::POA::_narrow (obj
.in ());
64 // Check for nil references
65 if (CORBA::is_nil (root_poa
.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR
,
67 "Unable to obtain RootPOA reference.\n"),
70 // Get poa_manager reference
71 PortableServer::POAManager_var poa_manager
=
72 root_poa
->the_POAManager ();
75 poa_manager
->activate ();
77 CORBA::PolicyList
policies (0);
80 // Lets create some POA's
81 PortableServer::POA_var first_poa
=
82 root_poa
->create_POA ("FIRST_POA",
86 PortableServer::POA_var second_poa
=
87 first_poa
->create_POA ("SECOND_POA",
91 PortableServer::POA_var third_poa
=
92 second_poa
->create_POA ("THIRD_POA",
96 PortableServer::POA_var fourth_poa
=
97 third_poa
->create_POA ("FOURTH_POA",
101 ORT_test_i
ort_test_impl (orb
.in ());
103 PortableServer::ObjectId_var oid
=
104 fourth_poa
->activate_object (&ort_test_impl
);
106 obj
= fourth_poa
->servant_to_reference (&ort_test_impl
);
108 // Convert the object reference to a string format.
109 CORBA::String_var ior
=
110 orb
->object_to_string (obj
.in ());
112 // Dump it to a file.
113 if (ior_output_file
!= 0)
115 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
116 if (output_file
== 0)
117 ACE_ERROR_RETURN ((LM_ERROR
,
118 "Cannot open output file %s for writing "
123 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
124 ACE_OS::fclose (output_file
);
131 catch (const CORBA::Exception
& ex
)
133 ex
._tao_print_exception ("ORT test server:");