Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "tao/Utils/ORB_Manager.h"
00014 #include "tao/Utils/PolicyList_Destroyer.h"
00015
00016 #include "tao/PortableServer/POAManagerC.h"
00017 #include "tao/PortableServer/IdAssignmentPolicyC.h"
00018 #include "tao/PortableServer/LifespanPolicyC.h"
00019
00020
00021 #include "tao/ORBInitializer_Registry.h"
00022
00023 #include "ace/Log_Msg.h"
00024
00025 ACE_RCSID (PortableServer,
00026 ORB_Manager,
00027 "$Id: ORB_Manager.cpp 82875 2008-09-29 14:17:15Z johnnyw $")
00028
00029
00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00031
00032
00033 TAO_ORB_Manager::TAO_ORB_Manager (CORBA::ORB_ptr orb,
00034 PortableServer::POA_ptr poa,
00035 PortableServer::POAManager_ptr poa_manager)
00036 : orb_ (CORBA::ORB::_duplicate(orb)),
00037 poa_ (PortableServer::POA::_duplicate(poa)),
00038 poa_manager_ (PortableServer::POAManager::_duplicate(poa_manager))
00039 {
00040 }
00041
00042 int
00043 TAO_ORB_Manager::init (int &argc,
00044 ACE_TCHAR *argv[],
00045 const char *orb_name)
00046 {
00047 if (CORBA::is_nil (this->orb_.in ()))
00048 {
00049 this->orb_ = CORBA::ORB_init (argc, argv, orb_name);
00050 }
00051
00052 if (CORBA::is_nil (this->poa_.in ()))
00053 {
00054
00055 CORBA::Object_var poa_object =
00056 this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA);
00057
00058 if (CORBA::is_nil (poa_object.in ()))
00059 ACE_ERROR_RETURN ((LM_ERROR,
00060 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
00061 -1);
00062
00063
00064 this->poa_ = PortableServer::POA::_narrow (poa_object.in ());
00065 }
00066
00067 if (CORBA::is_nil (this->poa_manager_.in ()))
00068 {
00069
00070 this->poa_manager_ = this->poa_->the_POAManager ();
00071 }
00072
00073 return 0;
00074 }
00075
00076 #if !defined (CORBA_E_MICRO)
00077 int
00078 TAO_ORB_Manager::init_child_poa (int& argc,
00079 ACE_TCHAR **argv,
00080 const char *poa_name,
00081 const char *orb_name)
00082 {
00083
00084 if (this->init (argc, argv, orb_name) == -1)
00085 ACE_ERROR_RETURN ((LM_ERROR,
00086 ACE_TEXT (" (%P|%t) Error in init.\n")),
00087 -1);
00088
00089
00090
00091 TAO::Utils::PolicyList_Destroyer policies (2);
00092 policies.length (2);
00093
00094
00095 policies[0] =
00096 this->poa_->create_id_assignment_policy (PortableServer::USER_ID);
00097
00098
00099 policies[1] =
00100 this->poa_->create_lifespan_policy (PortableServer::PERSISTENT);
00101
00102
00103
00104 this->child_poa_ =
00105 this->poa_->create_POA (poa_name, this->poa_manager_.in (), policies);
00106
00107 return 0;
00108 }
00109 #endif
00110
00111
00112
00113 int
00114 TAO_ORB_Manager::activate_poa_manager (void)
00115 {
00116 this->poa_manager_->activate ();
00117 return 0;
00118 }
00119
00120
00121
00122 char *
00123 TAO_ORB_Manager::activate (PortableServer::Servant servant)
00124 {
00125 PortableServer::ObjectId_var id = this->poa_->activate_object (servant);
00126
00127 CORBA::Object_var obj = this->poa_->id_to_reference (id.in ());
00128
00129 CORBA::String_var str = this->orb_->object_to_string (obj.in ());
00130
00131 return str._retn ();
00132 }
00133
00134 void
00135 TAO_ORB_Manager::deactivate (const char *id)
00136 {
00137 CORBA::Object_var object = this->orb_->string_to_object (id);
00138
00139 PortableServer::ObjectId_var object_id =
00140 this->poa_->reference_to_id (object.in ());
00141
00142 this->poa_->deactivate_object (object_id.in ());
00143 }
00144
00145 #if !defined (CORBA_E_MICRO)
00146
00147 char *
00148 TAO_ORB_Manager::activate_under_child_poa (const char *object_name,
00149 PortableServer::Servant servant)
00150 {
00151 if (object_name == 0)
00152 ACE_ERROR_RETURN ((LM_ERROR,
00153 ACE_TEXT ("\n(%P|%t) TAO_ORB_Manager::register: ")
00154 ACE_TEXT ("object_name is null!")),
00155 0);
00156
00157 PortableServer::ObjectId_var id =
00158 PortableServer::string_to_ObjectId (object_name);
00159
00160 this->child_poa_->activate_object_with_id (id.in (), servant);
00161
00162 CORBA::Object_var obj = this->child_poa_->id_to_reference (id.in ());
00163
00164 CORBA::String_var str = this->orb_->object_to_string (obj.in ());
00165
00166 return str._retn();
00167 }
00168
00169 void
00170 TAO_ORB_Manager::deactivate_under_child_poa (const char *id)
00171 {
00172 CORBA::Object_var object = this->orb_->string_to_object (id);
00173
00174 PortableServer::ObjectId_var object_id =
00175 this->child_poa_->reference_to_id (object.in ());
00176
00177 this->child_poa_->deactivate_object (object_id.in ());
00178 }
00179 #endif
00180
00181
00182
00183 int
00184 TAO_ORB_Manager::run (ACE_Time_Value &tv)
00185 {
00186 this->poa_manager_->activate ();
00187
00188 this->orb_->run (tv);
00189
00190 return 0;
00191 }
00192
00193 int
00194 TAO_ORB_Manager::fini (void)
00195 {
00196 this->poa_->destroy (1, 1);
00197
00198 this->child_poa_ = PortableServer::POA::_nil();
00199 this->poa_ = PortableServer::POA::_nil();
00200 this->poa_manager_ = PortableServer::POAManager::_nil();
00201
00202 this->orb_->destroy ();
00203
00204 this->orb_ = CORBA::ORB::_nil();
00205
00206 return 0;
00207 }
00208
00209 int
00210 TAO_ORB_Manager::run (void)
00211 {
00212 this->poa_manager_->activate ();
00213
00214 this->orb_->run ();
00215
00216 return 0;
00217 }
00218
00219
00220
00221 CORBA::ORB_ptr
00222 TAO_ORB_Manager::orb (void)
00223 {
00224 return CORBA::ORB::_duplicate (this->orb_.in ());
00225 }
00226
00227
00228 PortableServer::POA_ptr
00229 TAO_ORB_Manager::root_poa (void)
00230 {
00231 return PortableServer::POA::_duplicate (this->poa_.in ());
00232 }
00233
00234
00235 PortableServer::POA_ptr
00236 TAO_ORB_Manager::child_poa (void)
00237 {
00238 return PortableServer::POA::_duplicate (this->child_poa_.in ());
00239 }
00240
00241 PortableServer::POAManager_ptr
00242 TAO_ORB_Manager::poa_manager (void)
00243 {
00244 return PortableServer::POAManager::_duplicate (this->poa_manager_.in ());
00245 }
00246
00247
00248
00249 TAO_ORB_Manager::~TAO_ORB_Manager (void)
00250 {
00251 try
00252 {
00253 if (!CORBA::is_nil (this->poa_.in ()))
00254 {
00255 this->poa_->destroy (1,1);
00256 }
00257 if (!CORBA::is_nil (this->orb_.in ()))
00258 {
00259 this->orb_->destroy ();
00260 }
00261 }
00262 catch (const ::CORBA::Exception&)
00263 {
00264
00265 }
00266 }
00267
00268 TAO_END_VERSIONED_NAMESPACE_DECL