3 #include "tao/PortableServer/Object_Adapter.h"
4 #include "tao/PortableServer/POA_Current.h"
5 #include "tao/PortableServer/POA_Current_Impl.h"
12 test_i (CORBA::ORB_ptr orb
,
13 PortableServer::POA_ptr poa
);
15 void set_other (test_ptr test
);
19 PortableServer::POA_ptr
_default_POA (void);
23 PortableServer::POA_var poa_
;
27 PortableServer::Current_var poa_current_
;
30 test_i::test_i (CORBA::ORB_ptr orb
,
31 PortableServer::POA_ptr poa
)
32 : orb_ (CORBA::ORB::_duplicate (orb
)),
33 poa_ (PortableServer::POA::_duplicate (poa
))
35 CORBA::Object_var object
;
38 this->orb_
->resolve_initial_references ("POACurrent");
41 PortableServer::Current::_narrow (object
.in ());
45 test_i::set_other (test_ptr test
)
47 this->other_
= test::_duplicate (test
);
53 if (this->other_
.in () != test::_nil ())
55 this->other_
->method ();
59 TAO::Portable_Server::POA_Current
&tao_poa_current
=
60 dynamic_cast <TAO::Portable_Server::POA_Current
&>
61 (*(this->poa_current_
.in ()));
63 TAO::Portable_Server::POA_Current_Impl
&tao_poa_current_implementation
=
64 *tao_poa_current
.implementation ();
66 const char *upcall
= 0;
67 if (tao_poa_current_implementation
.previous ())
68 upcall
= "collocated";
72 PortableServer::ObjectId_var id
=
73 this->poa_current_
->get_object_id ();
75 CORBA::String_var id_string
=
76 PortableServer::ObjectId_to_string (id
.in ());
79 "%C method() invoked for <%C> servant in thread %t\n",
85 PortableServer::POA_ptr
86 test_i::_default_POA (void)
88 return PortableServer::POA::_duplicate (this->poa_
.in ());
91 class Task
: public ACE_Task_Base
95 Task (CORBA::ORB_ptr orb
);
103 Task::Task (CORBA::ORB_ptr orb
)
104 : orb_ (CORBA::ORB::_duplicate (orb
))
115 catch (const CORBA::Exception
&)
123 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
128 CORBA::ORB_init (argc
, argv
);
130 CORBA::Object_var object
=
131 orb
->resolve_initial_references ("RootPOA");
133 PortableServer::POA_var root_poa
=
134 PortableServer::POA::_narrow (object
.in ());
136 PortableServer::POAManager_var poa_manager
=
137 root_poa
->the_POAManager ();
139 poa_manager
->activate ();
141 Task
task (orb
.in ());
145 ACE_ASSERT (result
!= -1);
146 ACE_UNUSED_ARG (result
);
148 CORBA::PolicyList
policies (1);
152 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
154 PortableServer::POA_var child_poa
=
155 root_poa
->create_POA ("child_poa",
159 test_i
*base_servant
=
160 new test_i (orb
.in (),
163 PortableServer::ServantBase_var
safe_base_servant (base_servant
);
165 PortableServer::ObjectId_var base_oid
=
166 PortableServer::string_to_ObjectId ("base");
168 child_poa
->activate_object_with_id (base_oid
.in (),
171 PortableServer::ObjectId_var id_act
=
172 root_poa
->activate_object (base_servant
);
174 CORBA::Object_var object_act
= root_poa
->id_to_reference (id_act
.in ());
177 test::_narrow (object_act
.in ());
179 test_i
*first_servant
=
180 new test_i (orb
.in (),
183 PortableServer::ServantBase_var
safe_first_servant (first_servant
);
185 PortableServer::ObjectId_var first_oid
=
186 PortableServer::string_to_ObjectId ("first");
188 child_poa
->activate_object_with_id (first_oid
.in (),
191 PortableServer::ObjectId_var id_actu
=
192 root_poa
->activate_object (first_servant
);
194 object_act
= root_poa
->id_to_reference (id_actu
.in ());
196 test_var first_test
=
197 test::_narrow (object_act
.in ());
199 base_servant
->set_other (first_test
.in ());
201 base_test
->method ();
203 PortableServer::ObjectId_var second_oid
=
204 PortableServer::string_to_ObjectId ("second");
207 child_poa
->create_reference_with_id (second_oid
.in (),
210 test_var second_test
=
211 test::_narrow (object
.in ());
213 test_i
*second_servant
=
214 new test_i (orb
.in (),
217 PortableServer::ServantBase_var
safe_second_servant (second_servant
);
219 child_poa
->activate_object_with_id (second_oid
.in (),
222 base_servant
->set_other (second_test
.in ());
224 base_test
->method ();
226 PortableServer::ObjectId_var third_oid
=
227 PortableServer::string_to_ObjectId ("third");
230 child_poa
->create_reference_with_id (third_oid
.in (),
233 CORBA::String_var third_ior
=
234 orb
->object_to_string (object
.in ());
237 orb
->string_to_object (third_ior
.in ());
239 test_var third_test
=
240 test::_narrow (object
.in ());
242 test_i
*third_servant
=
243 new test_i (orb
.in (),
246 PortableServer::ServantBase_var
safe_third_servant (third_servant
);
248 child_poa
->activate_object_with_id (third_oid
.in (),
251 base_servant
->set_other (third_test
.in ());
253 base_test
->method ();
257 result
= task
.wait ();
258 ACE_ASSERT (result
!= -1);
259 ACE_UNUSED_ARG (result
);
261 catch (const CORBA::Exception
& ex
)
263 ex
._tao_print_exception ("Caught exception:");