PG_Group_Factory.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file  PG_Group_Factory.cpp
00006  *
00007  * PG_Group_Factory.cpp,v 1.9 2006/03/14 06:14:34 jtc Exp
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            "PG_Group_Factory.cpp,v 1.9 2006/03/14 06:14:34 jtc Exp")
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   ACE_ENV_ARG_DECL)
00054 {
00055   ACE_ASSERT (CORBA::is_nil (this->orb_.in ()));
00056   ACE_ASSERT (CORBA::is_nil (this->poa_.in ()));
00057   ACE_ASSERT (CORBA::is_nil (this->factory_registry_.in ()));
00058 
00059   this->orb_ = CORBA::ORB::_duplicate(orb);
00060   this->poa_ = PortableServer::POA::_duplicate (poa);
00061   this->factory_registry_ = PortableGroup::FactoryRegistry::_duplicate (factory_registry);
00062 
00063 
00064   ACE_ASSERT (!CORBA::is_nil (this->orb_.in ()));
00065   ACE_ASSERT (!CORBA::is_nil (this->poa_.in ()));
00066   ACE_ASSERT (!CORBA::is_nil (this->factory_registry_.in ()));
00067 
00068   this->manipulator_.init (orb, poa ACE_ENV_ARG_PARAMETER);
00069 //  ACE_CHECK;
00070 }
00071 
00072 
00073 TAO::PG_Object_Group * TAO::PG_Group_Factory::create_group (
00074     const char * type_id,
00075     const PortableGroup::Criteria & the_criteria,
00076     TAO::PG_Property_Set * typeid_properties
00077     ACE_ENV_ARG_DECL)
00078   ACE_THROW_SPEC ((CORBA::SystemException,
00079                    PortableGroup::NoFactory,
00080                    PortableGroup::ObjectNotCreated,
00081                    PortableGroup::InvalidCriteria,
00082                    PortableGroup::InvalidProperty,
00083                    PortableGroup::CannotMeetCriteria))
00084 {
00085   ///////////////////////////////////
00086   // Create an empty group reference
00087 
00088   PortableGroup::ObjectGroupId group_id = 0;
00089   PortableGroup::ObjectGroup_var empty_group =
00090     this->manipulator_.create_object_group (
00091       type_id,
00092       this->domain_id_,
00093       group_id
00094       ACE_ENV_ARG_PARAMETER);
00095   ACE_CHECK_RETURN (0);
00096 
00097   // pick up the object group information as assigned by
00098   // ObjectGroupManager
00099 
00100   PortableGroup::TagGroupTaggedComponent tagged_component;
00101   if (! TAO::PG_Utils::get_tagged_component (empty_group, tagged_component))
00102   {
00103     ACE_THROW_RETURN (PortableGroup::ObjectNotCreated(), 0);
00104   }
00105 
00106   TAO::PG_Object_Group * objectGroup = 0;
00107 
00108   ACE_NEW_THROW_EX (
00109     objectGroup,
00110     TAO::PG_Object_Group (
00111       this->orb_.in (),
00112       this->factory_registry_.in (),
00113       this->manipulator_,
00114       empty_group.in (),
00115       tagged_component,
00116       type_id,
00117       the_criteria,
00118       typeid_properties
00119       ),
00120     CORBA::NO_MEMORY());
00121 
00122   if (this->group_map_.bind (group_id, objectGroup) != 0)
00123   {
00124     delete objectGroup;
00125     ACE_THROW_RETURN (PortableGroup::ObjectNotCreated(), 0);
00126   }
00127   return objectGroup;
00128 }
00129 
00130 void TAO::PG_Group_Factory::delete_group (PortableGroup::ObjectGroup_ptr object_group
00131     ACE_ENV_ARG_DECL)
00132   ACE_THROW_SPEC ((CORBA::SystemException,
00133                    PortableGroup::ObjectNotFound))
00134 {
00135   if (! destroy_group (object_group))
00136   {
00137     ACE_THROW (PortableGroup::ObjectNotFound ());
00138   }
00139 }
00140 
00141 
00142 void TAO::PG_Group_Factory::delete_group (PortableGroup::ObjectGroupId group_id
00143     ACE_ENV_ARG_DECL)
00144   ACE_THROW_SPEC ((CORBA::SystemException,
00145                    PortableGroup::ObjectNotFound))
00146 {
00147   if (! destroy_group (group_id))
00148   {
00149     ACE_THROW (PortableGroup::ObjectNotFound ());
00150   }
00151 }
00152 
00153     // insert group.  Take ownership
00154 int TAO::PG_Group_Factory::insert_group ( ::TAO::PG_Object_Group * group)
00155 {
00156   return insert_group (group->get_object_group_id(), group);
00157 }
00158 
00159 int TAO::PG_Group_Factory::insert_group (PortableGroup::ObjectGroupId group_id, ::TAO::PG_Object_Group * group)
00160 {
00161   return (this->group_map_.bind (group_id, group) == 0);
00162 }
00163 
00164 int TAO::PG_Group_Factory::find_group (PortableGroup::ObjectGroupId group_id, ::TAO::PG_Object_Group *& group) const
00165 {
00166   return (this->group_map_.find (group_id , group) == 0);
00167 }
00168 
00169 int TAO::PG_Group_Factory::find_group (PortableGroup::ObjectGroup_ptr object_group, ::TAO::PG_Object_Group *& group) const
00170 {
00171   int result = 0;
00172   PortableGroup::TagGroupTaggedComponent tc;
00173   if (TAO::PG_Utils::get_tagged_component (object_group, tc))
00174   {
00175     result = find_group (tc.object_group_id, group);
00176   }
00177   return result;
00178 }
00179 
00180 int TAO::PG_Group_Factory::destroy_group (PortableGroup::ObjectGroupId group_id)
00181 {
00182   ::TAO::PG_Object_Group * group = 0;
00183   int result = (this->group_map_.unbind (group_id, group) == 0);
00184   if (result)
00185   {
00186     delete group;
00187   }
00188   return result;
00189 }
00190 
00191 int TAO::PG_Group_Factory::destroy_group (PortableGroup::ObjectGroup_ptr object_group)
00192 {
00193   PortableGroup::TagGroupTaggedComponent tc;
00194   TAO::PG_Utils::get_tagged_component (object_group, tc);
00195   return destroy_group (tc.object_group_id);
00196 }
00197 
00198 
00199 
00200 PortableGroup::ObjectGroups *
00201 TAO::PG_Group_Factory::groups_at_location (
00202     const PortableGroup::Location & the_location
00203     ACE_ENV_ARG_DECL)
00204   ACE_THROW_SPEC ( (CORBA::SystemException))
00205 {
00206   size_t upper_limit = this->group_map_.current_size ();
00207   PortableGroup::ObjectGroups * result = 0;
00208   ACE_NEW_THROW_EX (
00209     result,
00210     PortableGroup::ObjectGroups (upper_limit),
00211     CORBA::NO_MEMORY());
00212   ACE_CHECK_RETURN (0);
00213 
00214   result->length(upper_limit);
00215 
00216   size_t group_count = 0;
00217   for (Group_Map_Iterator it = this->group_map_.begin ();
00218     it != this->group_map_.end ();
00219     ++it)
00220   {
00221     TAO::PG_Object_Group * group = (*it).int_id_;
00222     if (group->has_member_at (the_location))
00223     {
00224       (*result)[group_count] = group->reference ();
00225       ++group_count;
00226     }
00227   }
00228   result->length (group_count);
00229   return result;
00230 }
00231 
00232 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 14:03:33 2006 for TAO_PortableGroup by doxygen 1.3.6