1 #include "Object_Factory_i.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR
*ior_output_file
= 0;
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
.optarg
;
22 ACE_ERROR_RETURN ((LM_ERROR
,
30 // Indicates successful parsing of the command line
35 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
39 /// Initialize the ORB.
40 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
42 "gateway_server_orb");
44 if (parse_args (argc
, argv
) != 0)
47 /// Resolve reference to RootPOA
48 CORBA::Object_var obj
=
49 orb
->resolve_initial_references ("RootPOA");
51 /// Narrow it down correctly.
52 PortableServer::POA_var root_poa
=
53 PortableServer::POA::_narrow (obj
.in ());
55 /// Check for nil references
56 if (CORBA::is_nil (root_poa
.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 "Unable to obtain RootPOA reference.\n"),
61 /// Get poa_manager reference
62 PortableServer::POAManager_var poa_manager
=
63 root_poa
->the_POAManager ();
66 poa_manager
->activate ();
70 CORBA::PolicyList
policies (3);
74 root_poa
->create_servant_retention_policy (PortableServer::RETAIN
);
77 root_poa
->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT
);
81 root_poa
->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID
);
83 PortableServer::POA_var gateway_poa
=
84 root_poa
->create_POA ("Gateway_POA",
88 for (CORBA::ULong i
= 0; i
!= policies
.length (); ++i
) {
89 policies
[i
]->destroy ();
92 // Get the POA Current object reference
94 orb
->resolve_initial_references ("POACurrent");
96 // Narrow the object reference to a POA Current reference
97 PortableServer::Current_var poa_current
=
98 PortableServer::Current::_narrow (obj
.in ());
102 ACE_NEW_THROW_EX (gateway
,
103 Gateway_i (orb
.in (),
105 CORBA::NO_MEMORY ());
107 gateway_poa
->set_servant (gateway
);
110 PortableServer::ObjectId_var oid
=
111 PortableServer::string_to_ObjectId ("Object_Factory");
113 /// This class is used to create a object reference.
114 Object_Factory_i
*object_factory
;
116 ACE_NEW_THROW_EX (object_factory
,
117 Object_Factory_i (orb
.in (),
119 CORBA::NO_MEMORY ());
121 /// Activate the Object_Factory_i Object
122 gateway_poa
->activate_object_with_id (oid
.in (),
125 // Get the object reference.
126 CORBA::Object_var gateway_object_factory
=
127 gateway_poa
->id_to_reference (oid
.in ());
129 /// Convert the object reference to a string format.
130 CORBA::String_var ior
=
131 orb
->object_to_string (gateway_object_factory
.in ());
133 /// If the ior_output_file exists, output the IOR to it.
134 if (ior_output_file
!= 0)
136 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
137 if (output_file
== 0)
138 ACE_ERROR_RETURN ((LM_ERROR
,
139 "Cannot open output file for writing "
143 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
144 ACE_OS::fclose (output_file
);
149 catch (const CORBA::Exception
& ex
)
151 ex
._tao_print_exception ("ORT test (gateway_server):");