00001
00002
00003
00004
00005
00006
00007
00008
00009
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 "PG_Object_Group_Manipulator.cpp,v 1.10 2006/03/14 06:14:34 jtc Exp")
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)
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
00044
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
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 ACE_ENV_ARG_DECL)
00068 {
00069 allocate_ogid(group_id);
00070 PortableServer::ObjectId_var oid = convert_ogid_to_oid (group_id);
00071
00072
00073 CORBA::Object_var object_group =
00074 this->poa_->create_reference_with_id (oid.in(),
00075 type_id
00076 ACE_ENV_ARG_PARAMETER);
00077 ACE_CHECK_RETURN (CORBA::Object::_nil ());
00078
00079 PortableGroup::TagGroupTaggedComponent tag_component;
00080
00081 tag_component.component_version.major = (CORBA::Octet) 1;
00082 tag_component.component_version.minor = (CORBA::Octet) 0;
00083 tag_component.group_domain_id = domain_id;
00084 tag_component.object_group_id = group_id;
00085 tag_component.object_group_ref_version = 0;
00086
00087
00088 TAO::PG_Utils::set_tagged_component (object_group,
00089 tag_component);
00090 ACE_CHECK_RETURN (CORBA::Object::_nil ());
00091
00092 return object_group._retn ();
00093 }
00094
00095 void
00096 TAO::PG_Object_Group_Manipulator::init (CORBA::ORB_ptr orb,
00097 PortableServer::POA_ptr poa
00098 ACE_ENV_ARG_DECL)
00099 {
00100 ACE_ASSERT (CORBA::is_nil (this->orb_.in ()) && !CORBA::is_nil (orb));
00101 this->orb_ = CORBA::ORB::_duplicate (orb);
00102
00103 ACE_ASSERT (CORBA::is_nil (this->poa_.in ()) && !CORBA::is_nil (poa));
00104 this->poa_ = PortableServer::POA::_duplicate (poa);
00105
00106
00107 CORBA::Object_var IORM = this->orb_->resolve_initial_references (
00108 TAO_OBJID_IORMANIPULATION, 0 ACE_ENV_ARG_PARAMETER);
00109 ACE_CHECK;
00110
00111 this->iorm_ = TAO_IOP::TAO_IOR_Manipulation::_narrow (
00112 IORM.in () ACE_ENV_ARG_PARAMETER);
00113
00114 }
00115
00116 int TAO::PG_Object_Group_Manipulator::set_primary (
00117 TAO_IOP::TAO_IOR_Property * prop,
00118 PortableGroup::ObjectGroup_ptr group,
00119 CORBA::Object_ptr new_primary
00120 ACE_ENV_ARG_DECL) const
00121 {
00122 int sts = this->iorm_->is_primary_set (prop, group ACE_ENV_ARG_PARAMETER);
00123 ACE_CHECK_RETURN (0);
00124 if (sts)
00125 {
00126 (void)this->iorm_->remove_primary_tag (prop, group ACE_ENV_ARG_PARAMETER);
00127 ACE_CHECK_RETURN (0);
00128 }
00129
00130 return this->iorm_->set_primary (prop, new_primary, group ACE_ENV_ARG_PARAMETER);
00131 }
00132
00133 PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group_Manipulator::merge_iors(
00134 TAO_IOP::TAO_IOR_Manipulation::IORList & list ACE_ENV_ARG_DECL) const
00135 {
00136 return this->iorm_->merge_iors (list ACE_ENV_ARG_PARAMETER);
00137 }
00138
00139 PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group_Manipulator::remove_profiles(
00140 PortableGroup::ObjectGroup_ptr group,
00141 PortableGroup::ObjectGroup_ptr profile
00142 ACE_ENV_ARG_DECL) const
00143 {
00144 return this->iorm_->remove_profiles(group, profile ACE_ENV_ARG_PARAMETER);
00145 }
00146
00147 void dump_membership (const char * label, PortableGroup::ObjectGroup_ptr member)
00148 {
00149 ACE_UNUSED_ARG (label);
00150 ACE_UNUSED_ARG (member);
00151 #if 0
00152 PortableGroup::TagFTGroupTaggedComponent ft_tag_component;
00153 TAO_FT_IOGR_Property prop (ft_tag_component);
00154 if (this->iorm_->is_primary_set (&prop, member))
00155 {
00156 ACE_DEBUG ( (LM_DEBUG,
00157 ACE_TEXT ("%T %n (%P|%t) - %s: PRIMARY member.\n"),
00158 label
00159 ));
00160 }
00161 else
00162 {
00163 ACE_DEBUG ( (LM_DEBUG,
00164 ACE_TEXT ("%T %n (%P|%t) - %s: backup member.\n"),
00165 label
00166 ));
00167 }
00168
00169 PortableGroup::TagGroupTaggedComponent tag_component;
00170 if (TAO::PG_Utils::get_tagged_component (member, tag_component))
00171 {
00172 ACE_DEBUG ( (LM_DEBUG,
00173 ACE_TEXT ("%T %n (%P|%t) - %s: Group: .")
00174 ACE_TEXT (" version: %u\n"),
00175
00176 label,
00177 tag_component.object_group_ref_version
00178 ));
00179 }
00180 else
00181 {
00182 ACE_DEBUG ( (LM_DEBUG,
00183 ACE_TEXT ("%T %n (%P|%t) - %s: No group information found.\n"),
00184 label
00185 ));
00186 }
00187 #endif
00188 }
00189
00190 TAO_END_VERSIONED_NAMESPACE_DECL