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
[])
58 // Initilaize the ORB, POA etc.
59 manager
.init (argc
, argv
);
61 if (parse_args (argc
, argv
) == -1)
64 manager
.activate_servant ();
66 manager
.make_iors_register ();
70 catch (const CORBA::Exception
& ex
)
72 ex
._tao_print_exception ("Caught");
79 Manager::Manager (void)
87 Manager::init (int argc
, ACE_TCHAR
*argv
[])
89 this->orb_
= CORBA::ORB_init (argc
, argv
);
91 // Obtain the RootPOA.
92 CORBA::Object_var obj_var
=
93 this->orb_
->resolve_initial_references ("RootPOA");
95 // Get the POA_var object from Object_var.
96 PortableServer::POA_var root_poa_var
=
97 PortableServer::POA::_narrow (obj_var
.in ());
99 // Get the POAManager of the RootPOA.
100 PortableServer::POAManager_var poa_manager_var
=
101 root_poa_var
->the_POAManager ();
103 poa_manager_var
->activate ();
105 // Policies for the childPOA to be created.
106 CORBA::PolicyList
policies (4);
109 // The next two policies are common to both
110 // Id Assignment Policy
112 root_poa_var
->create_id_assignment_policy (PortableServer::USER_ID
);
116 root_poa_var
->create_lifespan_policy (PortableServer::PERSISTENT
);
118 // Tell the POA to use a servant manager
120 root_poa_var
->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
);
122 // Servant Retention Policy -> Use a locator
124 root_poa_var
->create_servant_retention_policy (PortableServer::NON_RETAIN
);
126 ACE_CString name
= "newPOA";
129 root_poa_var
->create_POA (name
.c_str (),
130 poa_manager_var
.in (),
133 // Creation of childPOAs is over. Destroy the Policy objects.
134 for (CORBA::ULong i
= 0;
135 i
< policies
.length ();
138 CORBA::Policy_ptr policy
= policies
[i
];
146 Manager::activate_servant (void)
149 ACE_NEW_THROW_EX (this->servant_locator_
,
150 Servant_Locator (this->orb_
.in ()),
151 CORBA::NO_MEMORY ());
153 this->servant_locator_var_
= this->servant_locator_
;
155 // Set ServantLocator object as the servant Manager of
157 this->new_poa_var_
->set_servant_manager (this->servant_locator_
);
159 // Try to create a reference with user created ID in new_poa
160 // which uses ServantLocator.
162 PortableServer::ObjectId_var second_foo_oid_var
=
163 PortableServer::string_to_ObjectId ("Simple_Server");
165 this->new_manager_ior_
=
166 new_poa_var_
->create_reference_with_id (second_foo_oid_var
.in (),
167 "IDL:Simple_Server:1.0");
173 Manager::make_iors_register (void)
176 CORBA::Object_var object_primary
=
177 this->orb_
->string_to_object (first_ior
);
180 CORBA::Object_var object_secondary
=
181 this->orb_
->string_to_object (second_ior
);
184 ACE_DEBUG ((LM_DEBUG
,
185 "Here is the culprit\n"));
187 CORBA::Object_var object_tertiary
=
188 this->orb_
->string_to_object (third_ior
);
190 // Get an object reference for the ORBs IORManipultion object!
191 CORBA::Object_ptr IORM
=
192 this->orb_
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
195 TAO_IOP::TAO_IOR_Manipulation_ptr iorm
=
196 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
);
200 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (3);
202 iors
[0] = CORBA::Object::_duplicate (object_primary
.in ());
203 iors
[1] = CORBA::Object::_duplicate (object_secondary
.in ());
204 iors
[2] = CORBA::Object::_duplicate (this->new_manager_ior_
.in ());
206 // Create a merged set 1;
207 CORBA::Object_var merged_set1
=
208 iorm
->merge_iors (iors
);
210 if (object_secondary
.in () == 0)
211 ACE_DEBUG ((LM_DEBUG
,
212 " There is a problem 1 "));
214 if (object_tertiary
.in () == 0)
215 ACE_DEBUG ((LM_DEBUG
,
216 " There is a problem\n"));
218 TAO_IOP::TAO_IOR_Manipulation::IORList
iors_again (3);
219 iors_again
.length(3);
220 iors_again
[0] = CORBA::Object::_duplicate (object_secondary
.in ());
221 iors_again
[1] = CORBA::Object::_duplicate (object_tertiary
.in ());
222 iors_again
[2] = CORBA::Object::_duplicate (this->new_manager_ior_
.in ());
224 // Create merged set 2
225 CORBA::Object_var merged_set2
=
226 iorm
->merge_iors (iors_again
);
228 CORBA::String_var iorref1
=
229 this->orb_
->object_to_string (merged_set1
.in ());
231 if (ior_output_file
!= 0)
233 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
234 if (output_file
== 0)
235 ACE_ERROR_RETURN ((LM_ERROR
,
236 "Cannot open output file for writing IOR: %s",
239 ACE_OS::fprintf (output_file
, "%s", iorref1
.in ());
240 ACE_OS::fclose (output_file
);
243 this->servant_locator_
->set (merged_set2
);