diff options
Diffstat (limited to 'TAO/tao/IIOP_Profile.cpp')
-rw-r--r-- | TAO/tao/IIOP_Profile.cpp | 251 |
1 files changed, 167 insertions, 84 deletions
diff --git a/TAO/tao/IIOP_Profile.cpp b/TAO/tao/IIOP_Profile.cpp index cfbd467ac38..434ecd1c937 100644 --- a/TAO/tao/IIOP_Profile.cpp +++ b/TAO/tao/IIOP_Profile.cpp @@ -6,9 +6,9 @@ #include "tao/CDR.h" #include "tao/Environment.h" #include "tao/ORB.h" +#include "tao/MProfile.h" #include "tao/ORB_Core.h" #include "tao/POA.h" -#include "tao/Connect.h" #include "tao/debug.h" ACE_RCSID(tao, IIOP_Profile, "$Id$") @@ -19,18 +19,19 @@ ACE_RCSID(tao, IIOP_Profile, "$Id$") static const char *prefix_ = "iiop:"; -const char TAO_IIOP_Profile::object_key_delimiter = '/'; - TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, const char *object_key) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (), object_addr_ (addr), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { this->set(addr); int l = ACE_OS::strlen (object_key); @@ -44,14 +45,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (object_key), object_addr_ (addr), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { this->set(addr); this->create_body (); @@ -60,14 +64,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, const TAO_IOP_Version& version, const char *object_key) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (version), object_key_ (), object_addr_ (addr), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { this->set(addr); int l = ACE_OS::strlen (object_key); @@ -82,14 +89,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, const TAO_IOP_Version& version, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (version), object_key_ (object_key), object_addr_ (addr), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { this->set(addr); this->create_body (); @@ -98,14 +108,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const ACE_INET_Addr& addr, TAO_IIOP_Profile::TAO_IIOP_Profile (const char* host, CORBA::UShort port, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (port), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (object_key), object_addr_ (port, host), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { if (host) @@ -121,15 +134,18 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const char* host, TAO_IIOP_Profile::TAO_IIOP_Profile (const char* host, CORBA::UShort port, const TAO_ObjectKey& object_key, - const ACE_INET_Addr& addr) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + const ACE_INET_Addr& addr) + : host_ (0), port_ (port), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (object_key), object_addr_ (addr), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { if (host) @@ -146,14 +162,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const char* host, CORBA::UShort port, const TAO_IOP_Version& version, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (port), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (object_key), object_addr_ (port, host), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { ACE_UNUSED_ARG (version); @@ -165,14 +184,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const char* host, } TAO_IIOP_Profile::TAO_IIOP_Profile (const TAO_IIOP_Profile *pfile) - : TAO_Profile (pfile->tag ()), - host_(0), + : host_(0), port_(pfile->port_), + tag_(pfile->tag_), body_(pfile->body_), version_(pfile->version_), object_key_(pfile->object_key_), object_addr_(pfile->object_addr_), - hint_(0) + hint_(0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { ACE_NEW (this->host_, @@ -183,14 +205,17 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const TAO_IIOP_Profile *pfile) } TAO_IIOP_Profile::TAO_IIOP_Profile (const TAO_IIOP_Profile &pfile) - : TAO_Profile (pfile.tag ()), - host_(0), + : host_(0), port_(pfile.port_), + tag_(pfile.tag_), body_(pfile.body_), version_(pfile.version_), object_key_(pfile.object_key_), object_addr_(pfile.object_addr_), - hint_(0) + hint_(0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { ACE_NEW (this->host_, @@ -201,40 +226,48 @@ TAO_IIOP_Profile::TAO_IIOP_Profile (const TAO_IIOP_Profile &pfile) } TAO_IIOP_Profile::TAO_IIOP_Profile (const TAO_IOP_Version &version) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (version), object_key_ (), object_addr_ (), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { } -TAO_IIOP_Profile::TAO_IIOP_Profile (const char *string, - CORBA::Environment &env) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), +TAO_IIOP_Profile::TAO_IIOP_Profile (const char *string, CORBA::Environment &env) + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (), object_addr_ (), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { parse_string (string, env); } TAO_IIOP_Profile::TAO_IIOP_Profile (void) - : TAO_Profile (TAO_IOP_TAG_INTERNET_IOP), - host_ (0), + : host_ (0), port_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_IIOP_MAJOR, DEF_IIOP_MINOR), object_key_ (), object_addr_ (), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { } @@ -246,8 +279,6 @@ TAO_IIOP_Profile::set (const ACE_INET_Addr& addr) this->port_ = addr.get_port_number(); - // @@ We really should be passing in TAO_ORB_Core as a parameter, - // instead of using the ORB_Core singleton. if (TAO_ORB_Core_instance ()->orb_params ()->use_dotted_decimal_addresses ()) { temphost2 = addr.get_host_addr (); @@ -274,8 +305,16 @@ TAO_IIOP_Profile::set (const ACE_INET_Addr& addr) TAO_IIOP_Profile::~TAO_IIOP_Profile (void) { + assert (this->refcount_ == 0); + delete [] this->host_; this->host_ = 0; + + if (forward_to_) + { + delete forward_to_; + } + } // return codes: @@ -283,7 +322,9 @@ TAO_IIOP_Profile::~TAO_IIOP_Profile (void) // 0 -> can't understand this version // 1 -> success. int -TAO_IIOP_Profile::decode (TAO_InputCDR& cdr) +TAO_IIOP_Profile::parse (TAO_InputCDR& cdr, + CORBA::Boolean &continue_decoding, + CORBA::Environment &env) { CORBA::ULong encap_len = cdr.length (); @@ -300,13 +341,11 @@ TAO_IIOP_Profile::decode (TAO_InputCDR& cdr) && cdr.read_octet (this->version_.minor) && this->version_.minor <= TAO_IIOP_Profile::DEF_IIOP_MINOR)) { - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) IIOP_Profile::decode - v%d.%d\n", - this->version_.major, - this->version_.minor)); - } + ACE_DEBUG ((LM_DEBUG, + "detected new v%d.%d IIOP profile", + this->version_.major, + this->version_.minor)); + return 0; } if (this->host_) @@ -319,12 +358,7 @@ TAO_IIOP_Profile::decode (TAO_InputCDR& cdr) if (cdr.read_string (this->host_) == 0 || cdr.read_ushort (this->port_) == 0) { - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) IIOP_Profile::decode - " - "error while decoding host/port")); - } + ACE_DEBUG ((LM_DEBUG, "error decoding IIOP host/port")); return -1; } @@ -357,25 +391,26 @@ TAO_IIOP_Profile::parse_string (const char *string, if (!string || !*string) return 0; - // Remove the "N.n@" version prefix, if it exists, and verify the - // version is one that we accept. + // Remove the "N.N//" prefix, and verify the version's one + // that we accept - // Check for version - if (isdigit (string [0]) && - string[1] == '.' && - isdigit (string [2]) && - string[3] == '@') + if (isdigit (string [0]) + && isdigit (string [2]) + && string [1] == '.' + && string [3] == '/' + && string [4] == '/') { // @@ This may fail for non-ascii character sets [but take that // with a grain of salt] this->version_.set_version ((char) (string [0] - '0'), (char) (string [2] - '0')); - string += 4; - // Skip over the "N.n@" + string += 5; } + else + ACE_THROW_RETURN (CORBA::MARSHAL (), 0); - if (this->version_.major != TAO_IIOP_Profile::DEF_IIOP_MAJOR || - this->version_.minor > TAO_IIOP_Profile::DEF_IIOP_MINOR) + if (this->version_.major != TAO_IIOP_Profile::DEF_IIOP_MAJOR + || this->version_.minor > TAO_IIOP_Profile::DEF_IIOP_MINOR) { ACE_THROW_RETURN (CORBA::MARSHAL (), -1); } @@ -413,7 +448,7 @@ TAO_IIOP_Profile::parse_string (const char *string, *cp = 0; start++; // increment past : - cp = ACE_OS::strchr (start, this->object_key_delimiter); + cp = ACE_OS::strchr (start, '/'); if (cp == 0) { @@ -422,11 +457,6 @@ TAO_IIOP_Profile::parse_string (const char *string, } this->port_ = (CORBA::UShort) ACE_OS::atoi (start); - // @@ This call to atoi appears to pass in a string that - // still has the object key appended to it. - // Shouldn't we actually parse the port from the string - // rather than pass a `port/object_key' combined string? - // -Ossama this->object_addr_.set (this->port_, this->host_); @@ -583,6 +613,60 @@ TAO_IIOP_Profile::operator= (const TAO_IIOP_Profile &src) return *this; } +// Memory managment + +CORBA::ULong +TAO_IIOP_Profile::_incr_refcnt (void) +{ + // OK, think I got it. When this object is created (guard) the + // lock is automatically acquired (refcount_lock_). Then when + // we leave this method the destructir for guard is called which + // releases the lock! + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->refcount_lock_, 0); + + return this->refcount_++; +} + +CORBA::ULong +TAO_IIOP_Profile::_decr_refcnt (void) +{ + { + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->refcount_lock_, 0); + this->refcount_--; + if (this->refcount_ != 0) + return this->refcount_; + } + + // refcount is 0, so delete us! + // delete will call our ~ destructor which in turn deletes stuff. + delete this; + return 0; +} + + +void +TAO_IIOP_Profile::forward_to (TAO_MProfile *mprofiles) +{ + // we assume ownership of the profile list!! + if (forward_to_) + delete this->forward_to_; + + ACE_NEW (this->forward_to_, + TAO_MProfile (mprofiles)); + +} + +TAO_MProfile * +TAO_IIOP_Profile::forward_to (void) +{ + TAO_MProfile *temp; + + ACE_NEW_RETURN (temp, + TAO_MProfile (this->forward_to_), + 0); + return temp; +} + CORBA::String TAO_IIOP_Profile::to_string (CORBA::Environment &env) { @@ -593,15 +677,12 @@ TAO_IIOP_Profile::to_string (CORBA::Environment &env) this->object_key ()); u_int buflen = (ACE_OS::strlen (::prefix_) + + 1 /* major # */ + 1 /* minor # */ + 2 /* double-slash separator */ + - 1 /* major version */ + - 1 /* decimal point */ + - 1 /* minor version */ + - 1 /* `@' character */ + ACE_OS::strlen (this->host_) + 1 /* colon separator */ + 5 /* port number */ + - 1 /* object key separator */ + + 1 /* slash separator */ + ACE_OS::strlen (key) + 1 /* zero terminator */); @@ -610,13 +691,12 @@ TAO_IIOP_Profile::to_string (CORBA::Environment &env) static const char digits [] = "0123456789"; ACE_OS::sprintf (buf, - "%s//%c.%c@%s:%d%c%s", + "%s%c.%c//%s:%d/%s", ::prefix_, digits [this->version_.major], digits [this->version_.minor], this->host_, this->port_, - this->object_key_delimiter, key.in ()); return buf; } @@ -630,8 +710,11 @@ TAO_IIOP_Profile::prefix (void) int TAO_IIOP_Profile::encode (TAO_OutputCDR &stream) const { - // UNSIGNED LONG, protocol tag - stream.write_ulong (this->tag ()); + // UNSIGNED LONG, tag for this protocol profile; + // @@ it seems like this is not a good separation of concerns, why + // do we write the TAG here? That's generic code and should be + // handled by the object reference writer (IMHO). + stream.write_ulong (TAO_IOP_TAG_INTERNET_IOP); // UNSIGNED LONG, number of succeeding bytes in the // encapsulation. We don't actually need to make the |