📄 pg_object_group.cpp
字号:
// -*- C++ -*-
//
// PG_Object_Group.cpp,v 1.6 2003/12/28 23:31:26 bala Exp
#include "PG_Object_Group.h"
#include "PG_conf.h"
#include <ace/Get_Opt.h>
#include <ace/Vector_T.h>
#include <tao/debug.h>
#include <tao/PortableServer/ORB_Manager.h>
#include <orbsvcs/PortableGroup/PG_Operators.h> // Borrow operator == on CosNaming::Name
#include <orbsvcs/PortableGroup/PG_Utils.h>
#define TODO int todo;
//#define TODO
TAO::PG_Object_Group::MemberInfo::MemberInfo (
CORBA::Object_ptr member,
const PortableGroup::Location & location)
: member_ (CORBA::Object::_duplicate (member))
, factory_(PortableGroup::GenericFactory::_nil())
, location_ (location)
, is_primary_ (0)
{
}
TAO::PG_Object_Group::MemberInfo::MemberInfo (
CORBA::Object_ptr member,
const PortableGroup::Location & location,
PortableGroup::GenericFactory_ptr factory,
PortableGroup::GenericFactory::FactoryCreationId factory_id)
: member_ (CORBA::Object::_duplicate (member))
, factory_ (PortableGroup::GenericFactory::_duplicate (factory))
, factory_id_ (factory_id)
, location_ (location)
, is_primary_ (0)
{
}
TAO::PG_Object_Group::MemberInfo::~MemberInfo (void)
{
if( ! CORBA::is_nil (this->factory_.in()))
{
this->factory_->delete_object (this->factory_id_);
}
}
TAO::PG_Object_Group::PG_Object_Group (
CORBA::ORB_ptr orb,
PortableGroup::FactoryRegistry_ptr factory_registry,
TAO::PG_Object_Group_Manipulator & manipulator,
CORBA::Object_ptr empty_group,
const PortableGroup::TagGroupTaggedComponent & tagged_component,
const char * type_id,
const PortableGroup::Criteria & the_criteria,
TAO::PG_Property_Set * type_properties)
: internals_()
, orb_ (CORBA::ORB::_duplicate (orb))
, factory_registry_ (PortableGroup::FactoryRegistry::_duplicate (factory_registry))
, manipulator_ (manipulator)
, empty_ (1)
, role_ (type_id)
, type_id_ (CORBA::string_dup (type_id))
, tagged_component_ (tagged_component)
, reference_ (CORBA::Object::_duplicate(empty_group))
, members_ ()
, primary_location_(0)
, properties_ (the_criteria, type_properties)
, initial_number_members_ (0)
, minimum_number_members_ (0)
, group_specific_factories_ ()
{
}
TAO::PG_Object_Group::~PG_Object_Group ()
{
for (MemberMap_Iterator it = this->members_.begin();
it != this->members_.end();
++it)
{
MemberInfo * member = (*it).int_id_;
delete member;
}
this->members_.unbind_all ();
}
#if 0 // may want this again someday
/////////////////////
// q&d debug function
static void dump_ior (const char * base, const char * ext, unsigned long version, const char * iogr)
{
char filename[1000];
ACE_OS::sprintf(filename, "%s_%lu.%s", base, version, ext );
FILE * iorfile = ACE_OS::fopen(filename, "w");
ACE_OS::fwrite (iogr, 1, ACE_OS::strlen(iogr), iorfile);
ACE_OS::fclose (iorfile);
}
#endif // may want this again someday
PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group::reference()const
{
// const cast to simulate mutable
InternalGuard guard(ACE_const_cast (TAO::PG_Object_Group *, this)->internals_);
return PortableGroup::ObjectGroup::_duplicate (this->reference_);
}
void TAO::PG_Object_Group::get_group_specific_factories (PortableGroup::FactoryInfos & result) const
{
// const cast to simulate mutable
InternalGuard guard(ACE_const_cast (TAO::PG_Object_Group *, this)->internals_);
// copy is needed to have some semblance of thread safeness.
// if performance is an issue avoid this method.
result = this->group_specific_factories_;
}
const PortableGroup::Location & TAO::PG_Object_Group::get_primary_location() const
{
// const cast to simulate mutable
InternalGuard guard(ACE_const_cast (TAO::PG_Object_Group *, this)->internals_);
return this->primary_location_;
}
PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group::add_member_to_iogr(
CORBA::Object_ptr member
ACE_ENV_ARG_DECL)
{
// assume internals is locked
PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil();
////////////////////////////
// @@ HACK ALERT
// The PortableGroup::ObjectGroupManager creates an object reference containing
// a dummy entry so it will have a place to store the tagged group component.
// If this is the first entry, we need to remove that entry once we have a *real* member.
// This can be avoided when we get support for TAG_MULTIPLE_COMPONENTS
// For now, we already have a copy of the tagGroupTagged component and we're going to use
// it below wen we increment the group version so we can clean out the dummy entry.
PortableGroup::ObjectGroup_var cleaned = PortableGroup::ObjectGroup::_duplicate (this->reference_.in ());
if (this->empty_)
{
// remove the original profile. It's a dummy entry supplied by create_object.
cleaned =
this->manipulator_.remove_profiles (cleaned.in (), this->reference_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil());
this->empty_ = 0;
}
// create a list of references to be merged
TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
iors.length (2);
iors [0] = CORBA::Object::_duplicate (cleaned.in());
iors [1] = CORBA::Object::_duplicate (member);
// Now merge the list into one new IOGR
result =
this->manipulator_.merge_iors (iors ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (PortableGroup::ObjectGroup::_nil ());
return result._retn ();
}
void TAO::PG_Object_Group::add_member (
const PortableGroup::Location & the_location,
CORBA::Object_ptr member
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,
PortableGroup::ObjectNotAdded))
{
InternalGuard guard(this->internals_);
/////////////////////////////////////////
// Convert the new member to a string IOR
// This keeps a clean IOR (not and IOGR!)
// while we add it to a group. We need a
// IORs, not IOGRs to send new IOGRs out
// to replicas.
CORBA::String_var member_ior_string =
orb_->object_to_string (member
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
PortableGroup::ObjectGroup_var new_reference =
add_member_to_iogr (member
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// Convert new member back to a (non group) ior.
CORBA::Object_var member_ior =
this->orb_->string_to_object (member_ior_string.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
MemberInfo * info = 0;
ACE_NEW_THROW_EX (info,
MemberInfo(member_ior.in(),
the_location),
CORBA::NO_MEMORY());
if (this->members_.bind (the_location, info) != 0)
{
// @@ Dale why this is a NO MEMORY exception?
ACE_THROW(CORBA::NO_MEMORY());
}
this->reference_ = new_reference; // note var-to-var assignment does a duplicate
if (this->increment_version ())
{
this->distribute_iogr (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
else
{
ACE_THROW (PortableGroup::ObjectNotAdded ());
}
if (TAO_debug_level > 6)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("PG (%P|%t) exit Object_Group add_member \n")));
}
}
int TAO::PG_Object_Group::set_primary_member (
TAO_IOP::TAO_IOR_Property * prop,
const PortableGroup::Location & the_location
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
, PortableGroup::MemberNotFound
))
{
InternalGuard guard(this->internals_);
int result = 1;
MemberInfo * info;
if (this->members_.find (the_location, info) == 0)
{
int cleared = 0;
this->primary_location_ = the_location;
for (MemberMap_Iterator it = this->members_.begin();
!cleared && it != this->members_.end();
++it)
{
cleared = (*it).int_id_->is_primary_;
(*it).int_id_->is_primary_ = 0;
}
info->is_primary_ = 1;
int set_ok = this->manipulator_.set_primary (prop, this->reference_.in (), info->member_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (! set_ok)
{
if (TAO_debug_level > 3)
{
ACE_ERROR ( (LM_ERROR,
ACE_TEXT ("%T %n (%P|%t) - Can't set primary in IOGR .\n")
));
}
//@@: ACE_THROW (FT::PrimaryNotSet());
result = 0;
}
if (result && this->increment_version())
{
this->distribute_iogr (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
}
else
{
if (TAO_debug_level > 3)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("TAO-PG (%P|%t) - set_primary_location throwing PrimaryNotSet because increment version failed.\n")
));
}
//@@: ACE_THROW (FT::PrimaryNotSet());
result = 0;
}
}
else
{
if (TAO_debug_level > 3)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("TAO-PG (%P|%t) - set_primary_location ")
ACE_TEXT ("throwing MemberNotFound.\n")));
}
ACE_THROW_RETURN (PortableGroup::MemberNotFound(),
-1);
}
return result;
}
void TAO::PG_Object_Group::remove_member (
const PortableGroup::Location & the_location
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ( (CORBA::SystemException,
PortableGroup::MemberNotFound))
{
InternalGuard guard(this->internals_);
MemberInfo * info;
if (this->members_.unbind (the_location, info) == 0)
{
if (this->members_.current_size() > 0)
{
this->reference_ =
this->manipulator_.remove_profiles (this->reference_.in (), info->member_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
else
{
empty_ = 1;
}
delete info;
if (the_location == this->primary_location_)
{
this->primary_location_.length(0);
}
if (this->increment_version ())
{
this->distribute_iogr (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
}
else
{
if (TAO_debug_level > 6)
{
ACE_DEBUG ((LM_DEBUG,
"TAO-PG (%P|%t) - remove_member throwing MemberNotFound.\n"
));
}
ACE_THROW (PortableGroup::MemberNotFound() );
}
}
PortableGroup::ObjectGroupId TAO::PG_Object_Group::get_object_group_id () const
{
// const cast to simulate mutable
InternalGuard guard(ACE_const_cast (TAO::PG_Object_Group *, this)->internals_);
return this->tagged_component_.object_group_id;
}
void TAO::PG_Object_Group::set_properties_dynamically (
const PortableGroup::Properties & overrides
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,
PortableGroup::InvalidProperty,
PortableGroup::UnsupportedProperty))
{
InternalGuard guard (this->internals_);
this->properties_.decode (overrides ACE_ENV_ARG_PARAMETER);
//@@ int todo_override_rather_than_replace?
}
void TAO::PG_Object_Group::get_properties (PortableGroup::Properties_var & result) const
ACE_THROW_SPEC ((CORBA::SystemException))
{
// const cast to simulate mutable
InternalGuard guard (ACE_const_cast (TAO::PG_Object_Group *, this)->internals_);
this->properties_.export_properties(*result);
}
PortableGroup::TypeId TAO::PG_Object_Group::get_type_id () const
{
// const cast to simulate mutable
InternalGuard guard(ACE_const_cast (TAO::PG_Object_Group *, this)->internals_);
return CORBA::string_dup(this->type_id_);
}
///////////////////
// Internal method
int TAO::PG_Object_Group::increment_version ()
{
// assume internals is locked
int result = 0;
this->tagged_component_.object_group_ref_version += 1;
if (TAO_debug_level > 3)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%T %n (%P|%t) - Setting IOGR version to %u\n"),
ACE_static_cast(unsigned, this->tagged_component_.object_group_ref_version)
));
}
// Set the version
if ( TAO::PG_Utils::set_tagged_component (this->reference_, this->tagged_component_) )
{
result = 1;
}
return result;
}
//////////////////
// Internal method
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -