GOA.cpp

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

Generated on Sun Jan 27 16:22:30 2008 for TAO_PortableGroup by doxygen 1.3.6