PG_Object_Group_Manipulator.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file PG_Object_Group_Manipulator.cpp
00006  *
00007  * $Id: PG_Object_Group_Manipulator.cpp 76589 2007-01-25 18:04:11Z elliott_c $
00008  *
00009  * @author Dale Wilson <wilson_d@ociweb.com>
00010  */
00011 //=============================================================================
00012 
00013 #include "orbsvcs/PortableGroup/PG_Object_Group_Manipulator.h"
00014 #include "orbsvcs/PortableGroup/PG_Utils.h"
00015 
00016 #include "tao/debug.h"
00017 #include <ace/OS_NS_stdio.h>
00018 
00019 ACE_RCSID (PortableGroup,
00020            PG_Object_Group_Manipulator,
00021            "$Id: PG_Object_Group_Manipulator.cpp 76589 2007-01-25 18:04:11Z elliott_c $")
00022 
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 TAO::PG_Object_Group_Manipulator::PG_Object_Group_Manipulator ()
00027   : orb_ (CORBA::ORB::_nil ())
00028   , poa_ (PortableServer::POA::_nil ())
00029   , iorm_ ()
00030   , lock_ogid_ ()
00031   , next_ogid_ (1)   // don't use ogid 0
00032 {
00033 }
00034 
00035 TAO::PG_Object_Group_Manipulator::~PG_Object_Group_Manipulator ()
00036 {
00037 }
00038 
00039 void TAO::PG_Object_Group_Manipulator::allocate_ogid (PortableGroup::ObjectGroupId & ogid)
00040 {
00041   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_ogid_);
00042 
00043   // The numerical value used for the ObjectId increases
00044   // monotonically.
00045 
00046   ogid = this->next_ogid_;
00047   this->next_ogid_ += 1;
00048 }
00049 
00050 PortableServer::ObjectId * TAO::PG_Object_Group_Manipulator::convert_ogid_to_oid (PortableGroup::ObjectGroupId ogid) const
00051 {
00052   // 4294967295 -- Largest 32 bit unsigned integer
00053   char oid_str[11];
00054   ACE_OS::snprintf (oid_str, sizeof(oid_str),
00055                    "%lu",
00056                    static_cast<ACE_UINT32> (ogid));
00057   oid_str[sizeof(oid_str) - 1] = '\0';
00058 
00059   return PortableServer::string_to_ObjectId (oid_str);
00060 }
00061 
00062 PortableGroup::ObjectGroup_ptr
00063 TAO::PG_Object_Group_Manipulator::create_object_group (
00064   const char * type_id,
00065   const char * domain_id,
00066   PortableGroup::ObjectGroupId & group_id)
00067 {
00068    allocate_ogid(group_id);
00069    PortableServer::ObjectId_var oid = convert_ogid_to_oid (group_id);
00070 
00071   // Create a reference for the ObjectGroup
00072   CORBA::Object_var object_group =
00073     this->poa_->create_reference_with_id (oid.in(),
00074                                           type_id);
00075 
00076   PortableGroup::TagGroupTaggedComponent tag_component;
00077 
00078   tag_component.component_version.major = (CORBA::Octet) 1;
00079   tag_component.component_version.minor = (CORBA::Octet) 0;
00080   tag_component.group_domain_id = domain_id;
00081   tag_component.object_group_id = group_id;
00082   tag_component.object_group_ref_version = 0;
00083 
00084   // Set the property
00085   TAO::PG_Utils::set_tagged_component (object_group,
00086                                        tag_component);
00087 
00088   return object_group._retn ();
00089 }
00090 
00091 void
00092 TAO::PG_Object_Group_Manipulator::init (CORBA::ORB_ptr orb,
00093                                         PortableServer::POA_ptr poa)
00094 {
00095   ACE_ASSERT (CORBA::is_nil (this->orb_.in ()) && !CORBA::is_nil (orb));
00096   this->orb_ = CORBA::ORB::_duplicate (orb);
00097 
00098   ACE_ASSERT (CORBA::is_nil (this->poa_.in ()) && !CORBA::is_nil (poa));
00099   this->poa_ = PortableServer::POA::_duplicate (poa);
00100 
00101   // Get an object reference for the ORBs IORManipulation object!
00102   CORBA::Object_var IORM = this->orb_->resolve_initial_references (
00103     TAO_OBJID_IORMANIPULATION, 0);
00104 
00105   this->iorm_ = TAO_IOP::TAO_IOR_Manipulation::_narrow (
00106     IORM.in ());
00107 }
00108 
00109 int TAO::PG_Object_Group_Manipulator::set_primary (
00110       TAO_IOP::TAO_IOR_Property * prop,
00111       PortableGroup::ObjectGroup_ptr group,
00112       CORBA::Object_ptr new_primary) const
00113 {
00114   int sts = this->iorm_->is_primary_set (prop, group);
00115   if (sts)
00116   {
00117     (void)this->iorm_->remove_primary_tag (prop, group);
00118   }
00119   /////note: iorm takes it's parameters in the "wrong" order for this call
00120   return this->iorm_->set_primary (prop, new_primary, group);
00121 }
00122 
00123 PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group_Manipulator::merge_iors(
00124   TAO_IOP::TAO_IOR_Manipulation::IORList & list) const
00125 {
00126   return this->iorm_->merge_iors (list);
00127 }
00128 
00129 PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group_Manipulator::remove_profiles(
00130       PortableGroup::ObjectGroup_ptr group,
00131       PortableGroup::ObjectGroup_ptr profile) const
00132 {
00133   return this->iorm_->remove_profiles(group, profile);
00134 }
00135 
00136 void dump_membership (const char * label, PortableGroup::ObjectGroup_ptr member)
00137 {
00138   ACE_UNUSED_ARG (label);
00139   ACE_UNUSED_ARG (member);
00140 #if 0
00141   PortableGroup::TagFTGroupTaggedComponent ft_tag_component;
00142   TAO_FT_IOGR_Property prop (ft_tag_component);
00143   if (this->iorm_->is_primary_set (&prop, member))
00144   {
00145     ACE_DEBUG ( (LM_DEBUG,
00146       ACE_TEXT ("%T %n (%P|%t) - %s: PRIMARY member.\n"),
00147       label
00148       ));
00149   }
00150   else
00151   {
00152     ACE_DEBUG ( (LM_DEBUG,
00153       ACE_TEXT ("%T %n (%P|%t) - %s: backup member.\n"),
00154       label
00155       ));
00156   }
00157 
00158   PortableGroup::TagGroupTaggedComponent tag_component;
00159   if (TAO::PG_Utils::get_tagged_component (member, tag_component))
00160   {
00161     ACE_DEBUG ( (LM_DEBUG,
00162       ACE_TEXT ("%T %n (%P|%t) - %s: Group: .")
00163       ACE_TEXT (" version: %u\n"),
00164 
00165       label,
00166       tag_component.object_group_ref_version
00167       ));
00168   }
00169   else
00170   {
00171     ACE_DEBUG ( (LM_DEBUG,
00172       ACE_TEXT ("%T %n (%P|%t) - %s: No group information found.\n"),
00173       label
00174       ));
00175   }
00176 #endif
00177 }
00178 
00179 TAO_END_VERSIONED_NAMESPACE_DECL

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