00001 #include "orbsvcs/PortableGroup/GOA.h"
00002
00003 ACE_RCSID (PortableGroup,
00004 GOA,
00005 "$Id: GOA.cpp 81416 2008-04-24 10:26:10Z johnnyw $")
00006
00007 #include "orbsvcs/PortableGroup/PortableGroup_Acceptor_Registry.h"
00008 #include "orbsvcs/PortableGroup/PortableGroup_Request_Dispatcher.h"
00009
00010 #include "tao/ORB_Core.h"
00011 #include "tao/ORB.h"
00012 #include "tao/Stub.h"
00013 #include "tao/Tagged_Components.h"
00014 #include "tao/Profile.h"
00015 #include "tao/CDR.h"
00016
00017 #include "ace/Auto_Ptr.h"
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 PortableServer::ObjectId *
00022 TAO_GOA::create_id_for_reference (CORBA::Object_ptr the_ref)
00023 {
00024
00025
00026 const char* repository_id = the_ref->_stubobj ()->type_id.in ();
00027
00028
00029
00030 CORBA::Object_var obj_ref = this->create_reference (repository_id);
00031
00032 PortableServer::ObjectId_var obj_id =
00033 this->reference_to_id (obj_ref.in ());
00034
00035
00036 this->associate_group_with_ref (the_ref,
00037 obj_ref.in ());
00038
00039 return obj_id._retn ();
00040 }
00041
00042 PortableGroup::IDs *
00043 TAO_GOA::reference_to_ids (CORBA::Object_ptr)
00044 {
00045 return 0;
00046 }
00047
00048 void
00049 TAO_GOA::associate_reference_with_id (CORBA::Object_ptr ref,
00050 const PortableServer::ObjectId & oid)
00051 {
00052
00053
00054
00055 CORBA::Object_var obj_ref = this->id_to_reference (oid);
00056
00057
00058 this->associate_group_with_ref (ref,
00059 obj_ref.in ());
00060 }
00061
00062 void
00063 TAO_GOA::disassociate_reference_with_id (CORBA::Object_ptr ref,
00064 const PortableServer::ObjectId & oid)
00065 {
00066 ACE_UNUSED_ARG (ref);
00067 ACE_UNUSED_ARG (oid);
00068 }
00069
00070
00071 TAO_GOA::TAO_GOA (const TAO_Root_POA::String &name,
00072 PortableServer::POAManager_ptr poa_manager,
00073 const TAO_POA_Policy_Set &policies,
00074 TAO_Root_POA *parent,
00075 ACE_Lock &lock,
00076 TAO_SYNCH_MUTEX &thread_lock,
00077 TAO_ORB_Core &orb_core,
00078 TAO_Object_Adapter *object_adapter)
00079 : TAO_Regular_POA (name,
00080 poa_manager,
00081 policies,
00082 parent,
00083 lock,
00084 thread_lock,
00085 orb_core,
00086 object_adapter)
00087 {
00088 }
00089
00090 TAO_GOA::~TAO_GOA (void)
00091 {
00092 }
00093
00094 TAO_Root_POA *
00095 TAO_GOA::new_POA (const String &name,
00096 PortableServer::POAManager_ptr poa_manager,
00097 const TAO_POA_Policy_Set &policies,
00098 TAO_Root_POA *parent,
00099 ACE_Lock &lock,
00100 TAO_SYNCH_MUTEX &thread_lock,
00101 TAO_ORB_Core &orb_core,
00102 TAO_Object_Adapter *object_adapter)
00103 {
00104 TAO_GOA *poa = 0;
00105
00106 ACE_NEW_THROW_EX (poa,
00107 TAO_GOA (name,
00108 poa_manager,
00109 policies,
00110 parent,
00111 lock,
00112 thread_lock,
00113 orb_core,
00114 object_adapter),
00115 CORBA::NO_MEMORY ());
00116
00117 return poa;
00118 }
00119
00120
00121 PortableServer::POA_ptr
00122 TAO_GOA::create_POA (const char *adapter_name,
00123 PortableServer::POAManager_ptr poa_manager,
00124 const CORBA::PolicyList &policies)
00125 {
00126 PortableServer::POA_ptr poa = this->TAO_Regular_POA::create_POA (adapter_name,
00127 poa_manager,
00128 policies);
00129 return poa;
00130 }
00131
00132 PortableServer::POA_ptr
00133 TAO_GOA::find_POA (const char *adapter_name,
00134 CORBA::Boolean activate_it)
00135 {
00136 PortableServer::POA_ptr poa = this->TAO_Regular_POA::find_POA (adapter_name,
00137 activate_it);
00138 return poa;
00139 }
00140
00141 void
00142 TAO_GOA::destroy (CORBA::Boolean etherealize_objects,
00143 CORBA::Boolean wait_for_completion)
00144 {
00145 this->TAO_Regular_POA::destroy (etherealize_objects,
00146 wait_for_completion);
00147 }
00148
00149
00150 #if (TAO_HAS_MINIMUM_POA == 0)
00151
00152 PortableServer::ThreadPolicy_ptr
00153 TAO_GOA::create_thread_policy (PortableServer::ThreadPolicyValue value)
00154 {
00155 PortableServer::ThreadPolicy_ptr policy =
00156 this->TAO_Regular_POA::create_thread_policy (value);
00157 return policy;
00158 }
00159
00160 #endif
00161
00162 PortableServer::LifespanPolicy_ptr
00163 TAO_GOA::create_lifespan_policy (PortableServer::LifespanPolicyValue value)
00164 {
00165 PortableServer::LifespanPolicy_ptr policy =
00166 this->TAO_Regular_POA::create_lifespan_policy (value);
00167 return policy;
00168 }
00169
00170 PortableServer::IdUniquenessPolicy_ptr
00171 TAO_GOA::create_id_uniqueness_policy (PortableServer::IdUniquenessPolicyValue value)
00172 {
00173 PortableServer::IdUniquenessPolicy_ptr policy =
00174 this->TAO_Regular_POA::create_id_uniqueness_policy (value);
00175 return policy;
00176 }
00177
00178
00179 PortableServer::IdAssignmentPolicy_ptr
00180 TAO_GOA::create_id_assignment_policy (PortableServer::IdAssignmentPolicyValue value)
00181 {
00182 PortableServer::IdAssignmentPolicy_ptr policy =
00183 this->TAO_Regular_POA::create_id_assignment_policy (value);
00184 return policy;
00185 }
00186
00187
00188 #if (TAO_HAS_MINIMUM_POA == 0)
00189
00190 PortableServer::ImplicitActivationPolicy_ptr
00191 TAO_GOA::create_implicit_activation_policy (PortableServer::ImplicitActivationPolicyValue value)
00192 {
00193 PortableServer::ImplicitActivationPolicy_ptr policy =
00194 this->TAO_Regular_POA::create_implicit_activation_policy (value);
00195 return policy;
00196 }
00197
00198 PortableServer::ServantRetentionPolicy_ptr
00199 TAO_GOA::create_servant_retention_policy (PortableServer::ServantRetentionPolicyValue value)
00200 {
00201 PortableServer::ServantRetentionPolicy_ptr policy =
00202 this->TAO_Regular_POA::create_servant_retention_policy (value);
00203 return policy;
00204 }
00205
00206
00207 PortableServer::RequestProcessingPolicy_ptr
00208 TAO_GOA::create_request_processing_policy (PortableServer::RequestProcessingPolicyValue value)
00209 {
00210 PortableServer::RequestProcessingPolicy_ptr policy =
00211 this->TAO_Regular_POA::create_request_processing_policy (value);
00212 return policy;
00213 }
00214
00215
00216 #endif
00217
00218 char *
00219 TAO_GOA::the_name (void)
00220 {
00221 char * name =
00222 this->TAO_Regular_POA::the_name ();
00223 return name;
00224 }
00225
00226 PortableServer::POA_ptr
00227 TAO_GOA::the_parent (void)
00228 {
00229 PortableServer::POA_ptr parent =
00230 this->TAO_Regular_POA::the_parent ();
00231 return parent;
00232 }
00233
00234 PortableServer::POAList *
00235 TAO_GOA::the_children (void)
00236 {
00237 PortableServer::POAList *children =
00238 this->TAO_Regular_POA::the_children ();
00239 return children;
00240 }
00241
00242 PortableServer::POAManager_ptr
00243 TAO_GOA::the_POAManager (void)
00244 {
00245 PortableServer::POAManager_ptr poa_manager =
00246 this->TAO_Regular_POA::the_POAManager ();
00247 return poa_manager;
00248 }
00249
00250
00251 #if (TAO_HAS_MINIMUM_POA == 0)
00252
00253 PortableServer::AdapterActivator_ptr
00254 TAO_GOA::the_activator (void)
00255 {
00256 PortableServer::AdapterActivator_ptr activator =
00257 this->TAO_Regular_POA::the_activator ();
00258 return activator;
00259 }
00260
00261 void
00262 TAO_GOA::the_activator (PortableServer::AdapterActivator_ptr adapter_activator)
00263 {
00264 this->TAO_Regular_POA::the_activator (adapter_activator);
00265 }
00266
00267 PortableServer::ServantManager_ptr
00268 TAO_GOA::get_servant_manager (void)
00269 {
00270 PortableServer::ServantManager_ptr servant_manager =
00271 this->TAO_Regular_POA::get_servant_manager ();
00272 return servant_manager;
00273 }
00274
00275 void
00276 TAO_GOA::set_servant_manager (PortableServer::ServantManager_ptr imgr)
00277 {
00278 this->TAO_Regular_POA::set_servant_manager (imgr);
00279 }
00280
00281 PortableServer::Servant
00282 TAO_GOA::get_servant (void)
00283 {
00284 PortableServer::Servant servant =
00285 this->TAO_Regular_POA::get_servant ();
00286 return servant;
00287 }
00288
00289 void
00290 TAO_GOA::set_servant (PortableServer::Servant servant)
00291 {
00292 this->TAO_Regular_POA::set_servant (servant);
00293 }
00294
00295 #endif
00296
00297 PortableServer::ObjectId *
00298 TAO_GOA::activate_object (PortableServer::Servant p_servant)
00299 {
00300 PortableServer::ObjectId *object_id =
00301 this->TAO_Regular_POA::activate_object (p_servant);
00302 return object_id;
00303 }
00304
00305 void
00306 TAO_GOA::activate_object_with_id (const PortableServer::ObjectId &id,
00307 PortableServer::Servant p_servant)
00308 {
00309 this->TAO_Regular_POA::activate_object_with_id (id, p_servant);
00310 }
00311
00312 void
00313 TAO_GOA::deactivate_object (const PortableServer::ObjectId &oid)
00314 {
00315 this->TAO_Regular_POA::deactivate_object (oid);
00316 }
00317
00318 CORBA::Object_ptr
00319 TAO_GOA::create_reference (const char *intf)
00320 {
00321 CORBA::Object_ptr obj =
00322 this->TAO_Regular_POA::create_reference (intf);
00323 return obj;
00324 }
00325
00326 CORBA::Object_ptr
00327 TAO_GOA::create_reference_with_id (const PortableServer::ObjectId &oid,
00328 const char *intf)
00329 {
00330 CORBA::Object_ptr obj =
00331 this->TAO_Regular_POA::create_reference_with_id (oid,
00332 intf);
00333 return obj;
00334 }
00335
00336 PortableServer::ObjectId *
00337 TAO_GOA::servant_to_id (PortableServer::Servant p_servant)
00338 {
00339 PortableServer::ObjectId *object_id =
00340 this->TAO_Regular_POA::servant_to_id (p_servant);
00341 return object_id;
00342 }
00343
00344 CORBA::Object_ptr
00345 TAO_GOA::servant_to_reference (PortableServer::Servant p_servant)
00346 {
00347 CORBA::Object_ptr obj =
00348 this->TAO_Regular_POA::servant_to_reference (p_servant);
00349 return obj;
00350 }
00351
00352
00353 PortableServer::Servant
00354 TAO_GOA::reference_to_servant (CORBA::Object_ptr reference)
00355 {
00356 PortableServer::Servant servant =
00357 this->TAO_Regular_POA::reference_to_servant (reference);
00358 return servant;
00359 }
00360
00361 PortableServer::ObjectId *
00362 TAO_GOA::reference_to_id (CORBA::Object_ptr reference)
00363 {
00364 PortableServer::ObjectId *object_id =
00365 this->TAO_Regular_POA::reference_to_id (reference);
00366 return object_id;
00367 }
00368
00369 PortableServer::Servant
00370 TAO_GOA::id_to_servant (const PortableServer::ObjectId &oid)
00371 {
00372 PortableServer::Servant servant =
00373 this->TAO_Regular_POA::id_to_servant (oid);
00374 return servant;
00375 }
00376
00377 CORBA::Object_ptr
00378 TAO_GOA::id_to_reference (const PortableServer::ObjectId &oid)
00379 {
00380 CORBA::Object_ptr obj =
00381 this->TAO_Regular_POA::id_to_reference (oid);
00382 return obj;
00383 }
00384
00385 CORBA::OctetSeq *
00386 TAO_GOA::id (void)
00387 {
00388 return this->TAO_Regular_POA::id ();
00389 }
00390
00391 int
00392 TAO_GOA::find_group_component (const CORBA::Object_ptr the_ref,
00393 PortableGroup::TagGroupTaggedComponent &group)
00394 {
00395 const TAO_MProfile& profiles = the_ref->_stubobj ()->base_profiles ();
00396 const TAO_Profile* profile;
00397 CORBA::ULong slot;
00398
00399
00400
00401 slot = 0;
00402 while (0 != (profile = profiles.get_profile (slot)))
00403 {
00404 if (this->find_group_component_in_profile (profile, group) == 0)
00405 return 0;
00406
00407 ++slot;
00408 }
00409
00410
00411 return -1;
00412 }
00413
00414 int
00415 TAO_GOA::find_group_component_in_profile (const TAO_Profile* profile,
00416 PortableGroup::TagGroupTaggedComponent &group)
00417 {
00418
00419
00420 const TAO_Tagged_Components& components = profile->tagged_components ();
00421
00422 IOP::TaggedComponent tagged_component;
00423 tagged_component.tag = IOP::TAG_GROUP;
00424
00425
00426 if (components.get_component (tagged_component) == 0)
00427 return -1;
00428
00429
00430 const CORBA::Octet *buf =
00431 tagged_component.component_data.get_buffer ();
00432
00433 TAO_InputCDR in_cdr (reinterpret_cast <const char*> (buf),
00434 tagged_component.component_data.length ());
00435
00436
00437 CORBA::Boolean byte_order;
00438 if ((in_cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
00439 return -1;
00440 in_cdr.reset_byte_order (static_cast <int> (byte_order));
00441
00442 if ((in_cdr >> group) == 0)
00443 return -1;
00444
00445 return 0;
00446 }
00447
00448 int
00449 TAO_GOA::create_group_acceptors (CORBA::Object_ptr the_ref,
00450 TAO_PortableGroup_Acceptor_Registry &acceptor_registry,
00451 TAO_ORB_Core &orb_core)
00452 {
00453 const TAO_MProfile& profiles = the_ref->_stubobj ()->base_profiles ();
00454 const TAO_Profile* profile;
00455 CORBA::ULong slot;
00456 int num = 0;
00457
00458
00459
00460 slot = 0;
00461 while (0 != (profile = profiles.get_profile (slot)))
00462 {
00463 if (profile->supports_multicast ())
00464 {
00465 acceptor_registry.open (profile,
00466 orb_core);
00467 ++num;
00468 }
00469
00470 ++slot;
00471 }
00472
00473
00474 return num;
00475 }
00476
00477 void
00478 TAO_GOA::associate_group_with_ref (
00479 CORBA::Object_ptr group_ref,
00480 CORBA::Object_ptr obj_ref)
00481 {
00482
00483 PortableGroup::TagGroupTaggedComponent *tmp_group_id;
00484 ACE_NEW_THROW_EX (tmp_group_id,
00485 PortableGroup::TagGroupTaggedComponent,
00486 CORBA::NO_MEMORY (
00487 CORBA::SystemException::_tao_minor_code (
00488 TAO::VMCID,
00489 ENOMEM),
00490 CORBA::COMPLETED_NO));
00491
00492 PortableGroup::TagGroupTaggedComponent_var group_id = tmp_group_id;
00493
00494 if (this->find_group_component (group_ref, group_id.inout ()) != 0)
00495 {
00496
00497
00498 throw PortableGroup::NotAGroupObject ();
00499 }
00500
00501 PortableGroup_Request_Dispatcher *rd =
00502 dynamic_cast <PortableGroup_Request_Dispatcher*>(
00503 this->orb_core_.request_dispatcher());
00504
00505
00506
00507 this->create_group_acceptors (group_ref,
00508 rd->acceptor_registry_,
00509 this->orb_core_);
00510
00511
00512 const TAO::ObjectKey &key =
00513 obj_ref->_stubobj ()->profile_in_use ()->object_key ();
00514 rd->group_map_.add_groupid_objectkey_pair (group_id._retn (), key);
00515 }
00516
00517 TAO_END_VERSIONED_NAMESPACE_DECL