3 #include "tao/IORManipulation/IORManip_Loader.h"
5 #include "ace/SString.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_stdio.h"
9 const ACE_TCHAR
*first_ior
= 0;
10 const ACE_TCHAR
*second_ior
= 0;
11 const ACE_TCHAR
*third_ior
= 0;
12 const ACE_TCHAR
*ior_output_file
= 0;
15 parse_args (int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:b:c:d:"));
20 while ((c
= get_opts ()) != -1)
24 first_ior
= get_opts
.opt_arg ();
27 second_ior
= get_opts
.opt_arg ();
30 third_ior
= get_opts
.opt_arg ();
33 ior_output_file
= get_opts
.opt_arg ();
37 ACE_ERROR_RETURN ((LM_ERROR
,
46 // Indicates successful parsing of the command line
51 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
57 // Initilaize the ORB, POA etc.
58 manager
.init (argc
, argv
);
60 if (parse_args (argc
, argv
) == -1)
63 manager
.activate_servant ();
65 manager
.make_iors_register ();
69 catch (const CORBA::Exception
& ex
)
71 ex
._tao_print_exception ("Caught");
86 Manager::init (int argc
, ACE_TCHAR
*argv
[])
88 this->orb_
= CORBA::ORB_init (argc
, argv
);
90 // Obtain the RootPOA.
91 CORBA::Object_var obj_var
=
92 this->orb_
->resolve_initial_references ("RootPOA");
94 // Get the POA_var object from Object_var.
95 PortableServer::POA_var root_poa_var
=
96 PortableServer::POA::_narrow (obj_var
.in ());
98 // Get the POAManager of the RootPOA.
99 PortableServer::POAManager_var poa_manager_var
=
100 root_poa_var
->the_POAManager ();
102 poa_manager_var
->activate ();
104 // Policies for the childPOA to be created.
105 CORBA::PolicyList
policies (4);
108 // The next two policies are common to both
109 // Id Assignment Policy
111 root_poa_var
->create_id_assignment_policy (PortableServer::USER_ID
);
115 root_poa_var
->create_lifespan_policy (PortableServer::PERSISTENT
);
117 // Tell the POA to use a servant manager
119 root_poa_var
->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
);
121 // Servant Retention Policy -> Use a locator
123 root_poa_var
->create_servant_retention_policy (PortableServer::NON_RETAIN
);
125 ACE_CString name
= "newPOA";
128 root_poa_var
->create_POA (name
.c_str (),
129 poa_manager_var
.in (),
132 // Creation of childPOAs is over. Destroy the Policy objects.
133 for (CORBA::ULong i
= 0;
134 i
< policies
.length ();
137 CORBA::Policy_ptr policy
= policies
[i
];
145 Manager::activate_servant ()
147 ACE_NEW_THROW_EX (this->servant_locator_
,
148 Servant_Locator (this->orb_
.in ()),
149 CORBA::NO_MEMORY ());
151 this->servant_locator_var_
= this->servant_locator_
;
153 // Set ServantLocator object as the servant Manager of
155 this->new_poa_var_
->set_servant_manager (this->servant_locator_
);
157 // Try to create a reference with user created ID in new_poa
158 // which uses ServantLocator.
160 PortableServer::ObjectId_var second_foo_oid_var
=
161 PortableServer::string_to_ObjectId ("Simple_Server");
163 this->new_manager_ior_
=
164 new_poa_var_
->create_reference_with_id (second_foo_oid_var
.in (),
165 "IDL:Simple_Server:1.0");
171 Manager::make_iors_register ()
174 CORBA::Object_var object_primary
=
175 this->orb_
->string_to_object (first_ior
);
178 CORBA::Object_var object_secondary
=
179 this->orb_
->string_to_object (second_ior
);
182 ACE_DEBUG ((LM_DEBUG
,
183 "Here is the culprit\n"));
185 CORBA::Object_var object_tertiary
=
186 this->orb_
->string_to_object (third_ior
);
188 // Get an object reference for the ORBs IORManipultion object!
189 CORBA::Object_ptr IORM
=
190 this->orb_
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
193 TAO_IOP::TAO_IOR_Manipulation_ptr iorm
=
194 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
);
198 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (3);
200 iors
[0] = CORBA::Object::_duplicate (object_primary
.in ());
201 iors
[1] = CORBA::Object::_duplicate (object_secondary
.in ());
202 iors
[2] = CORBA::Object::_duplicate (this->new_manager_ior_
.in ());
204 // Create a merged set 1;
205 CORBA::Object_var merged_set1
=
206 iorm
->merge_iors (iors
);
208 if (object_secondary
.in () == 0)
209 ACE_DEBUG ((LM_DEBUG
,
210 " There is a problem 1 "));
212 if (object_tertiary
.in () == 0)
213 ACE_DEBUG ((LM_DEBUG
,
214 " There is a problem\n"));
216 TAO_IOP::TAO_IOR_Manipulation::IORList
iors_again (3);
217 iors_again
.length(3);
218 iors_again
[0] = CORBA::Object::_duplicate (object_secondary
.in ());
219 iors_again
[1] = CORBA::Object::_duplicate (object_tertiary
.in ());
220 iors_again
[2] = CORBA::Object::_duplicate (this->new_manager_ior_
.in ());
222 // Create merged set 2
223 CORBA::Object_var merged_set2
=
224 iorm
->merge_iors (iors_again
);
226 CORBA::String_var iorref1
=
227 this->orb_
->object_to_string (merged_set1
.in ());
229 if (ior_output_file
!= 0)
231 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
232 if (output_file
== 0)
233 ACE_ERROR_RETURN ((LM_ERROR
,
234 "Cannot open output file for writing IOR: %s",
237 ACE_OS::fprintf (output_file
, "%s", iorref1
.in ());
238 ACE_OS::fclose (output_file
);
241 this->servant_locator_
->set (merged_set2
);