Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Utils / ORB_Manager.cpp
blob0092a304741745ed37b64bd5423b522368282be4
1 // = AUTHOR
2 // Sumedh Mungee <sumedh@cs.wustl.edu>
4 #include "tao/Utils/ORB_Manager.h"
5 #include "tao/Utils/PolicyList_Destroyer.h"
7 #include "tao/PortableServer/POAManagerC.h"
8 #include "tao/PortableServer/IdAssignmentPolicyC.h"
9 #include "tao/PortableServer/LifespanPolicyC.h"
12 #include "tao/ORBInitializer_Registry.h"
14 #include "ace/Log_Msg.h"
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 // constructor
19 TAO_ORB_Manager::TAO_ORB_Manager (CORBA::ORB_ptr orb,
20 PortableServer::POA_ptr poa,
21 PortableServer::POAManager_ptr poa_manager)
22 : orb_ (CORBA::ORB::_duplicate(orb)),
23 poa_ (PortableServer::POA::_duplicate(poa)),
24 poa_manager_ (PortableServer::POAManager::_duplicate(poa_manager))
28 int
29 TAO_ORB_Manager::init (int &argc,
30 ACE_TCHAR *argv[],
31 const char *orb_name)
33 if (CORBA::is_nil (this->orb_.in ()))
35 this->orb_ = CORBA::ORB_init (argc, argv, orb_name);
38 if (CORBA::is_nil (this->poa_.in ()))
40 // Get the POA from the ORB.
41 CORBA::Object_var poa_object =
42 this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA);
44 if (CORBA::is_nil (poa_object.in ()))
45 TAOLIB_ERROR_RETURN ((LM_ERROR,
46 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
47 -1);
49 // Get the POA object.
50 this->poa_ = PortableServer::POA::_narrow (poa_object.in ());
53 if (CORBA::is_nil (this->poa_manager_.in ()))
55 // Get the POA_Manager.
56 this->poa_manager_ = this->poa_->the_POAManager ();
59 return 0;
62 #if !defined (CORBA_E_MICRO)
63 int
64 TAO_ORB_Manager::init_child_poa (int& argc,
65 ACE_TCHAR **argv,
66 const char *poa_name,
67 const char *orb_name)
69 // Check to see if root poa has to be created.
70 if (this->init (argc, argv, orb_name) == -1)
71 TAOLIB_ERROR_RETURN ((LM_ERROR,
72 ACE_TEXT (" (%P|%t) Error in init.\n")),
73 -1);
75 // Create the default policies - user-supplied ID, and persistent
76 // objects.
77 TAO::Utils::PolicyList_Destroyer policies (2);
78 policies.length (2);
80 // Id Assignment policy
81 policies[0] =
82 this->poa_->create_id_assignment_policy (PortableServer::USER_ID);
84 // Lifespan policy
85 policies[1] =
86 this->poa_->create_lifespan_policy (PortableServer::PERSISTENT);
88 // We use a different POA, otherwise the user would have to change
89 // the object key each time it invokes the server.
90 this->child_poa_ =
91 this->poa_->create_POA (poa_name, this->poa_manager_.in (), policies);
93 return 0;
95 #endif /* CORBA_E_MICRO */
97 // Activate POA manager.
99 int
100 TAO_ORB_Manager::activate_poa_manager ()
102 this->poa_manager_->activate ();
103 return 0;
106 // Activate servant in the POA.
108 char *
109 TAO_ORB_Manager::activate (PortableServer::Servant servant)
111 PortableServer::ObjectId_var id = this->poa_->activate_object (servant);
113 CORBA::Object_var obj = this->poa_->id_to_reference (id.in ());
115 CORBA::String_var str = this->orb_->object_to_string (obj.in ());
117 return str._retn ();
120 void
121 TAO_ORB_Manager::deactivate (const char *id)
123 CORBA::Object_var object = this->orb_->string_to_object (id);
125 PortableServer::ObjectId_var object_id =
126 this->poa_->reference_to_id (object.in ());
128 this->poa_->deactivate_object (object_id.in ());
131 #if !defined (CORBA_E_MICRO)
132 // Activate the object with the object_name under the child POA.
133 char *
134 TAO_ORB_Manager::activate_under_child_poa (const char *object_name,
135 PortableServer::Servant servant)
137 if (object_name == 0)
138 TAOLIB_ERROR_RETURN ((LM_ERROR,
139 ACE_TEXT ("\n(%P|%t) TAO_ORB_Manager::register: ")
140 ACE_TEXT ("object_name is null!")),
143 PortableServer::ObjectId_var id =
144 PortableServer::string_to_ObjectId (object_name);
146 this->child_poa_->activate_object_with_id (id.in (), servant);
148 CORBA::Object_var obj = this->child_poa_->id_to_reference (id.in ());
150 CORBA::String_var str = this->orb_->object_to_string (obj.in ());
152 return str._retn();
155 void
156 TAO_ORB_Manager::deactivate_under_child_poa (const char *id)
158 CORBA::Object_var object = this->orb_->string_to_object (id);
160 PortableServer::ObjectId_var object_id =
161 this->child_poa_->reference_to_id (object.in ());
163 this->child_poa_->deactivate_object (object_id.in ());
165 #endif /* CORBA_E_MICRO */
167 // Enter the ORB event loop.
170 TAO_ORB_Manager::run (ACE_Time_Value &tv)
172 this->poa_manager_->activate ();
174 this->orb_->run (tv);
176 return 0;
180 TAO_ORB_Manager::fini ()
182 this->poa_->destroy (1, 1);
184 this->child_poa_ = PortableServer::POA::_nil();
185 this->poa_ = PortableServer::POA::_nil();
186 this->poa_manager_ = PortableServer::POAManager::_nil();
188 this->orb_->destroy ();
190 this->orb_ = CORBA::ORB::_nil();
192 return 0;
196 TAO_ORB_Manager::run ()
198 this->poa_manager_->activate ();
200 this->orb_->run ();
202 return 0;
205 // Return the corba orb reference.
207 CORBA::ORB_ptr
208 TAO_ORB_Manager::orb ()
210 return CORBA::ORB::_duplicate (this->orb_.in ());
213 // Return the root POA reference
214 PortableServer::POA_ptr
215 TAO_ORB_Manager::root_poa ()
217 return PortableServer::POA::_duplicate (this->poa_.in ());
220 // Return the child POA reference
221 PortableServer::POA_ptr
222 TAO_ORB_Manager::child_poa ()
224 return PortableServer::POA::_duplicate (this->child_poa_.in ());
227 PortableServer::POAManager_ptr
228 TAO_ORB_Manager::poa_manager ()
230 return PortableServer::POAManager::_duplicate (this->poa_manager_.in ());
233 // Destructor.
235 TAO_ORB_Manager::~TAO_ORB_Manager ()
239 if (!CORBA::is_nil (this->poa_.in ()))
241 this->poa_->destroy (1,1);
243 if (!CORBA::is_nil (this->orb_.in ()))
245 this->orb_->destroy ();
248 catch (const ::CORBA::Exception&)
250 // ignore any exceptions..
254 TAO_END_VERSIONED_NAMESPACE_DECL