PG_Group_Factory.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file  PG_Group_Factory.cpp
00006  *
00007  * $Id: PG_Group_Factory.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00008  *
00009  * @author Dale Wilson <wilson_d@ociweb.com>
00010  */
00011 //=============================================================================
00012 
00013 #include "orbsvcs/PortableGroup/PG_Group_Factory.h"
00014 #include "orbsvcs/PortableGroup/PG_Property_Utils.h"
00015 #include "orbsvcs/PortableGroup/PG_conf.h"
00016 #include "orbsvcs/PortableGroupC.h"
00017 #include "orbsvcs/PortableGroup/PG_Object_Group.h"
00018 #include <orbsvcs/PortableGroup/PG_Utils.h>
00019 
00020 ACE_RCSID (PortableGroup,
00021            PG_Group_Factory,
00022            "$Id: PG_Group_Factory.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00023 
00024 
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026 
00027 TAO::PG_Group_Factory::PG_Group_Factory ()
00028   : orb_ (CORBA::ORB::_nil())
00029   , poa_ (PortableServer::POA::_nil())
00030   , manipulator_ ()
00031   , domain_id_ ("default-domain")
00032 
00033 {
00034 }
00035 
00036 TAO::PG_Group_Factory::~PG_Group_Factory (void)
00037 {
00038   for (Group_Map_Iterator it = this->group_map_.begin ();
00039     it != this->group_map_.end ();
00040     ++it)
00041   {
00042     TAO::PG_Object_Group * group = (*it).int_id_;
00043     delete group;
00044   }
00045   this->group_map_.unbind_all ();
00046 }
00047 
00048 
00049 void TAO::PG_Group_Factory::init (
00050   CORBA::ORB_ptr orb,
00051   PortableServer::POA_ptr poa,
00052   PortableGroup::FactoryRegistry_ptr factory_registry)
00053 {
00054   ACE_ASSERT (CORBA::is_nil (this->orb_.in ()));
00055   ACE_ASSERT (CORBA::is_nil (this->poa_.in ()));
00056   ACE_ASSERT (CORBA::is_nil (this->factory_registry_.in ()));
00057 
00058   this->orb_ = CORBA::ORB::_duplicate(orb);
00059   this->poa_ = PortableServer::POA::_duplicate (poa);
00060   this->factory_registry_ = PortableGroup::FactoryRegistry::_duplicate (factory_registry);
00061 
00062 
00063   ACE_ASSERT (!CORBA::is_nil (this->orb_.in ()));
00064   ACE_ASSERT (!CORBA::is_nil (this->poa_.in ()));
00065   ACE_ASSERT (!CORBA::is_nil (this->factory_registry_.in ()));
00066 
00067   this->manipulator_.init (orb, poa);
00068 }
00069 
00070 
00071 TAO::PG_Object_Group * TAO::PG_Group_Factory::create_group (
00072     const char * type_id,
00073     const PortableGroup::Criteria & the_criteria,
00074     TAO::PG_Property_Set * typeid_properties)
00075 {
00076   ///////////////////////////////////
00077   // Create an empty group reference
00078 
00079   PortableGroup::ObjectGroupId group_id = 0;
00080   PortableGroup::ObjectGroup_var empty_group =
00081     this->manipulator_.create_object_group (
00082       type_id,
00083       this->domain_id_,
00084       group_id);
00085 
00086   // pick up the object group information as assigned by
00087   // ObjectGroupManager
00088 
00089   PortableGroup::TagGroupTaggedComponent tagged_component;
00090   if (! TAO::PG_Utils::get_tagged_component (empty_group, tagged_component))
00091   {
00092     throw PortableGroup::ObjectNotCreated();
00093   }
00094 
00095   TAO::PG_Object_Group * objectGroup = 0;
00096 
00097   ACE_NEW_THROW_EX (
00098     objectGroup,
00099     TAO::PG_Object_Group (
00100       this->orb_.in (),
00101       this->factory_registry_.in (),
00102       this->manipulator_,
00103       empty_group.in (),
00104       tagged_component,
00105       type_id,
00106       the_criteria,
00107       typeid_properties
00108       ),
00109     CORBA::NO_MEMORY());
00110 
00111   if (this->group_map_.bind (group_id, objectGroup) != 0)
00112   {
00113     delete objectGroup;
00114     throw PortableGroup::ObjectNotCreated();
00115   }
00116   return objectGroup;
00117 }
00118 
00119 void TAO::PG_Group_Factory::delete_group (PortableGroup::ObjectGroup_ptr object_group)
00120 {
00121   if (! destroy_group (object_group))
00122   {
00123     throw PortableGroup::ObjectNotFound ();
00124   }
00125 }
00126 
00127 
00128 void TAO::PG_Group_Factory::delete_group (PortableGroup::ObjectGroupId group_id)
00129 {
00130   if (! destroy_group (group_id))
00131   {
00132     throw PortableGroup::ObjectNotFound ();
00133   }
00134 }
00135 
00136     // insert group.  Take ownership
00137 int TAO::PG_Group_Factory::insert_group ( ::TAO::PG_Object_Group * group)
00138 {
00139   return insert_group (group->get_object_group_id(), group);
00140 }
00141 
00142 int TAO::PG_Group_Factory::insert_group (PortableGroup::ObjectGroupId group_id, ::TAO::PG_Object_Group * group)
00143 {
00144   return (this->group_map_.bind (group_id, group) == 0);
00145 }
00146 
00147 int TAO::PG_Group_Factory::find_group (PortableGroup::ObjectGroupId group_id, ::TAO::PG_Object_Group *& group) const
00148 {
00149   return (this->group_map_.find (group_id , group) == 0);
00150 }
00151 
00152 int TAO::PG_Group_Factory::find_group (PortableGroup::ObjectGroup_ptr object_group, ::TAO::PG_Object_Group *& group) const
00153 {
00154   int result = 0;
00155   PortableGroup::TagGroupTaggedComponent tc;
00156   if (TAO::PG_Utils::get_tagged_component (object_group, tc))
00157   {
00158     result = find_group (tc.object_group_id, group);
00159   }
00160   return result;
00161 }
00162 
00163 int TAO::PG_Group_Factory::destroy_group (PortableGroup::ObjectGroupId group_id)
00164 {
00165   ::TAO::PG_Object_Group * group = 0;
00166   int result = (this->group_map_.unbind (group_id, group) == 0);
00167   if (result)
00168   {
00169     delete group;
00170   }
00171   return result;
00172 }
00173 
00174 int TAO::PG_Group_Factory::destroy_group (PortableGroup::ObjectGroup_ptr object_group)
00175 {
00176   PortableGroup::TagGroupTaggedComponent tc;
00177   TAO::PG_Utils::get_tagged_component (object_group, tc);
00178   return destroy_group (tc.object_group_id);
00179 }
00180 
00181 
00182 
00183 PortableGroup::ObjectGroups *
00184 TAO::PG_Group_Factory::groups_at_location (
00185     const PortableGroup::Location & the_location)
00186 {
00187   size_t upper_limit = this->group_map_.current_size ();
00188   PortableGroup::ObjectGroups * result = 0;
00189   ACE_NEW_THROW_EX (
00190     result,
00191     PortableGroup::ObjectGroups (upper_limit),
00192     CORBA::NO_MEMORY());
00193 
00194   result->length(upper_limit);
00195 
00196   size_t group_count = 0;
00197   for (Group_Map_Iterator it = this->group_map_.begin ();
00198     it != this->group_map_.end ();
00199     ++it)
00200   {
00201     TAO::PG_Object_Group * group = (*it).int_id_;
00202     if (group->has_member_at (the_location))
00203     {
00204       (*result)[group_count] = group->reference ();
00205       ++group_count;
00206     }
00207   }
00208   result->length (group_count);
00209   return result;
00210 }
00211 
00212 TAO_END_VERSIONED_NAMESPACE_DECL

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