📄 uipmc_profile.cpp
字号:
// This may look like C, but it's really -*- C++ -*-
//
// UIPMC_Profile.cpp,v 1.14 2003/12/22 01:44:38 wilson_d Exp
#include "UIPMC_Profile.h"
#include "miopconf.h"
#include "tao/CDR.h"
#include "tao/Environment.h"
#include "tao/ORB.h"
#include "tao/ORB_Core.h"
#include "tao/debug.h"
#include "tao/target_specification.h"
#include "orbsvcs/miopC.h"
#include "orbsvcs/PortableGroupC.h"
ACE_RCSID(tao, UIPMC_Profile, "UIPMC_Profile.cpp,v 1.14 2003/12/22 01:44:38 wilson_d Exp")
#if !defined (__ACE_INLINE__)
# include "UIPMC_Profile.i"
#endif /* __ACE_INLINE__ */
static const char prefix_[] = "uipmc";
// UIPMC doesn't support object keys, so send profiles by default in the GIOP 1.2 target
// specification.
static const CORBA::Short default_addressing_mode_ = TAO_Target_Specification::Profile_Addr;
const char TAO_UIPMC_Profile::object_key_delimiter_ = '/';
char
TAO_UIPMC_Profile::object_key_delimiter (void) const
{
return TAO_UIPMC_Profile::object_key_delimiter_;
}
TAO_UIPMC_Profile::TAO_UIPMC_Profile (TAO_ORB_Core *orb_core)
: TAO_Profile (TAO_TAG_UIPMC_PROFILE,
orb_core,
TAO_GIOP_Message_Version (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR)),
endpoint_ (),
count_ (1),
tagged_profile_ ()
{
addressing_mode_ = default_addressing_mode_;
}
TAO_UIPMC_Profile::TAO_UIPMC_Profile (const ACE_INET_Addr &addr,
TAO_ORB_Core *orb_core)
: TAO_Profile (TAO_TAG_UIPMC_PROFILE,
orb_core,
TAO_GIOP_Message_Version (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR)),
endpoint_ (addr),
count_ (1),
tagged_profile_ ()
{
addressing_mode_ = default_addressing_mode_;
}
TAO_UIPMC_Profile::TAO_UIPMC_Profile (const CORBA::Octet class_d_address[4],
CORBA::UShort port,
TAO_ORB_Core *orb_core)
: TAO_Profile (TAO_TAG_UIPMC_PROFILE,
orb_core,
TAO_GIOP_Message_Version (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR)),
endpoint_ (class_d_address, port),
count_ (1),
tagged_profile_ ()
{
addressing_mode_ = default_addressing_mode_;
}
/*
TAO_UIPMC_Profile::TAO_UIPMC_Profile (const char *string,
TAO_ORB_Core *orb_core
ACE_ENV_ARG_DECL)
: TAO_Profile (TAO_TAG_UIPMC_PROFILE,
orb_core,
TAO_GIOP_Message_Version (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR)),
endpoint_ (),
count_ (1),
tagged_profile_ ()
{
this->add_group_component ();
this->parse_string (string ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
addressing_mode_ = default_addressing_mode_;
}
TAO_UIPMC_Profile::TAO_UIPMC_Profile (TAO_ORB_Core *orb_core)
: TAO_Profile (TAO_TAG_UIPMC_PROFILE,
orb_core,
TAO_GIOP_Message_Version (TAO_DEF_GIOP_MAJOR, TAO_DEF_GIOP_MINOR)),
endpoint_ (),
count_ (1),
tagged_profile_ ()
{
addressing_mode_ = default_addressing_mode_;
}
*/
TAO_UIPMC_Profile::~TAO_UIPMC_Profile (void)
{
}
int
TAO_UIPMC_Profile::decode_endpoints (void)
{
ACE_NOTSUP_RETURN (-1);
}
int
TAO_UIPMC_Profile::decode_profile (TAO_InputCDR& cdr)
{
CORBA::UShort port = 0;
ACE_CString address;
if (!(cdr.read_string (address)
&& cdr.read_ushort (port)))
{
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("TAO (%P|%t) UIPMC_Profile::decode - ")
ACE_TEXT ("Couldn't unmarshal address and port!\n")));
return -1;
}
if (cdr.good_bit ())
{
// If everything was successful, update the endpoint's address
// and port with the new data.
ACE_INET_Addr addr (port, address.c_str ());
this->endpoint_.object_addr (addr);
return 1;
}
return -1;
}
void
TAO_UIPMC_Profile::parse_string (const char *string
ACE_ENV_ARG_DECL)
{
this->parse_string_i (string
ACE_ENV_ARG_PARAMETER);
}
void
TAO_UIPMC_Profile::parse_string_i (const char *string
ACE_ENV_ARG_DECL)
{
// Remove the "N.n@" version prefix, if it exists, and verify the
// version is one that we accept.
// Check for MIOP version
if (isdigit (string [0]) &&
string[1] == '.' &&
isdigit (string [2]) &&
string[3] == '@')
{
if (string[0] != '1' ||
string[2] != '0')
{
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
string += 4;
// Skip over the "N.n@"
}
// UIPMC profiles always use GIOP 1.2
this->version_.set_version (1, 2);
//
// Parse the group_id.
//
// Parse the group component version.
if (isdigit (string [0]) &&
string[1] == '.' &&
isdigit (string [2]) &&
string[3] == '-')
{
CORBA::Char major;
CORBA::Char minor;
major = (char) (string [0] - '0');
minor = (char) (string [2] - '0');
// Verify that a supported version of MIOP is specified.
if (major != TAO_DEF_MIOP_MAJOR ||
minor > TAO_DEF_MIOP_MINOR)
{
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
// Skip over "N.n-"
string += 4;
}
else
{
// The group component version is mandatory.
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
// Parse the group_domain_id.
// The Domain ID is terminated with a '-'.
// Wrap the string in a ACE_CString
ACE_CString ace_str (string, 0, 0);
// Look for the group domain delimitor.
int pos = ace_str.find ('-');
if (pos == ACE_CString::npos)
{
// The group_domain_id is mandatory, so throw an
// exception if it isn't found.
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
// Save the group_domain_id.
ACE_CString group_domain_id = ace_str.substring (0, pos);
// Parse the group_id.
// The group_id is terminated with a '-' or a '/'.
// Skip past the last '-'.
pos++;
int end_pos = ace_str.find ('-',pos);
CORBA::Boolean parse_group_ref_version_flag = 0;
if (end_pos != ACE_CString::npos)
{
// String was terminated by a '-', so there's a group
// reference version to be parsed.
parse_group_ref_version_flag = 1;
}
else
{
// Look for a slash as the separator.
end_pos = ace_str.find ('/', pos);
if (end_pos == ACE_CString::npos)
{
// The Group ID is mandatory, so throw an exception.
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
}
// Get the domain_id.
ACE_CString str_domain_id = ace_str.substring (pos, end_pos - pos);
// Convert the domain_id into numerical form.
// @@ group_id is actually 64 bits, but strtoul only can parse 32 bits.
// @@ Need a 64 bit strtoul...
PortableGroup::ObjectGroupId group_id =
ACE_OS::strtoul (str_domain_id.c_str (), 0, 10);
PortableGroup::ObjectGroupRefVersion ref_version = 0;
if (parse_group_ref_version_flag)
{
// Try to find the group version. It is terminated by a '/'.
pos = end_pos + 1;
end_pos = ace_str.find ('/', pos);
if (end_pos == ACE_CString::npos)
{
// The group version was expected but not found,
// so throw an exception.
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
ACE_CString str_group_ref_ver = ace_str.substring (pos, end_pos - pos);
ref_version =
ACE_OS::strtoul (str_group_ref_ver.c_str (), 0, 10);
}
// Parse the group multicast address.
// The multicast address is terminated by a ':'.
pos = end_pos + 1;
end_pos = ace_str.find (':', pos);
if (end_pos == ACE_CString::npos)
{
// The multicast address is mandatory, so throw an exception,
// since it wasn't found.
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
ACE_CString mcast_addr = ace_str.substring (pos, end_pos - pos);
// Parse the multicast port number.
// First check that there's something left in the string.
pos = end_pos + 1;
if (ace_str[pos] == '\0')
{
// The multicast port is mandatory, so throw an exception,
// since it wasn't found.
ACE_THROW (CORBA::INV_OBJREF (
CORBA::SystemException::_tao_minor_code (
TAO_DEFAULT_MINOR_CODE,
EINVAL),
CORBA::COMPLETED_NO));
}
CORBA::UShort mcast_port =
ACE_static_cast (CORBA::UShort,
ACE_OS::strtoul (ace_str.c_str () + pos, 0, 10));
//
// Finally, set all of the fields of the profile.
//
ACE_INET_Addr addr (mcast_port, mcast_addr.c_str ());
this->endpoint_.object_addr (addr);
this->set_group_info (group_domain_id.c_str (),
group_id,
ref_version);
}
CORBA::Boolean
TAO_UIPMC_Profile::do_is_equivalent (const TAO_Profile *other_profile)
{
const TAO_UIPMC_Profile *op =
ACE_dynamic_cast (const TAO_UIPMC_Profile *, other_profile);
if (op == 0)
return 0;
return this->endpoint_.is_equivalent (&op->endpoint_);
}
CORBA::ULong
TAO_UIPMC_Profile::hash (CORBA::ULong max
ACE_ENV_ARG_DECL_NOT_USED)
{
// Get the hashvalue for all endpoints.
CORBA::ULong hashval = this->endpoint_.hash ();
hashval += this->version_.minor;
hashval += this->tag ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -