diff options
Diffstat (limited to 'TAO/tao/UIOP_Profile.cpp')
-rw-r--r-- | TAO/tao/UIOP_Profile.cpp | 435 |
1 files changed, 270 insertions, 165 deletions
diff --git a/TAO/tao/UIOP_Profile.cpp b/TAO/tao/UIOP_Profile.cpp index 787cebb5089..99807b48ef0 100644 --- a/TAO/tao/UIOP_Profile.cpp +++ b/TAO/tao/UIOP_Profile.cpp @@ -8,6 +8,7 @@ #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/debug.h" @@ -18,20 +19,20 @@ ACE_RCSID(tao, UIOP_Profile, "$Id$") # include "tao/UIOP_Profile.i" #endif /* __ACE_INLINE__ */ - static const char *prefix_ = "uiop:"; -const char TAO_UIOP_Profile::object_key_delimiter = '|'; - TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, const char *object_key) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_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); @@ -45,13 +46,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_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,13 +64,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, const TAO_IOP_Version& version, const char *object_key) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (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); @@ -81,13 +88,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, const TAO_IOP_Version& version, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (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 (); @@ -95,13 +105,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const ACE_UNIX_Addr& addr, TAO_UIOP_Profile::TAO_UIOP_Profile (const char* rendezvous_point, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_MINOR), object_key_ (object_key), object_addr_ (rendezvous_point), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { if (rendezvous_point) @@ -117,13 +130,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const char* rendezvous_point, TAO_UIOP_Profile::TAO_UIOP_Profile (const char* rendezvous_point, const TAO_ObjectKey& object_key, const ACE_UNIX_Addr& addr) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_MINOR), object_key_ (object_key), object_addr_ (addr), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { if (rendezvous_point) @@ -139,13 +155,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const char* rendezvous_point, TAO_UIOP_Profile::TAO_UIOP_Profile (const char* rendezvous_point, const TAO_IOP_Version& version, const TAO_ObjectKey& object_key) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_MINOR), object_key_ (object_key), object_addr_ (rendezvous_point), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { ACE_UNUSED_ARG (version); @@ -157,13 +176,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const char* rendezvous_point, } TAO_UIOP_Profile::TAO_UIOP_Profile (const TAO_UIOP_Profile *pfile) - : TAO_Profile (pfile->tag ()), - rendezvous_point_(0), + : rendezvous_point_(0), + 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->rendezvous_point_, @@ -174,13 +196,16 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const TAO_UIOP_Profile *pfile) } TAO_UIOP_Profile::TAO_UIOP_Profile (const TAO_UIOP_Profile &pfile) - : TAO_Profile (pfile.tag ()), - rendezvous_point_(0), + : rendezvous_point_(0), + 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->rendezvous_point_, @@ -191,37 +216,46 @@ TAO_UIOP_Profile::TAO_UIOP_Profile (const TAO_UIOP_Profile &pfile) } TAO_UIOP_Profile::TAO_UIOP_Profile (const TAO_IOP_Version &version) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (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_UIOP_Profile::TAO_UIOP_Profile (const char *string, CORBA::Environment &env) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_MINOR), object_key_ (), object_addr_ (), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { parse_string (string, env); } TAO_UIOP_Profile::TAO_UIOP_Profile (void) - : TAO_Profile (TAO_IOP_TAG_UNIX_IOP), - rendezvous_point_ (0), + : rendezvous_point_ (0), + tag_ (TAO_IOP_TAG_INTERNET_IOP), body_ (), version_ (DEF_UIOP_MAJOR, DEF_UIOP_MINOR), object_key_ (), object_addr_ (), - hint_ (0) + hint_ (0), + // what about refcount_lock_ (), + refcount_ (1), + forward_to_ (0) { } @@ -229,29 +263,107 @@ int TAO_UIOP_Profile::set (const ACE_UNIX_Addr& addr) { char temp_rendezvous_point[MAXPATHLEN + 1]; - - addr.addr_to_string (temp_rendezvous_point, sizeof (temp_rendezvous_point)); + const char *temp_rendezvous_point2 = 0; + +// if (TAO_ORB_Core_instance ()->orb_params ()->use_dotted_decimal_addresses ()) +// { +// temp_rendezvous_point2 = addr.get_rendezvous_point_addr (); +// if (temp_rendezvous_point2 == 0) +// return -1; +// } +// else +// { + if (addr.get_rendezvous_point_name (temprendezvous_point, + sizeof (temp_rendezvous_point)) != 0) + return -1; + + temp_rendezvous_point2 = temp_rendezvous_point; +// } ACE_NEW_RETURN (this->rendezvous_point_, - char[ACE_OS::strlen (temp_rendezvous_point) + 1], + char[ACE_OS::strlen (temp_rendezvous_point2) + 1], -1); + ACE_OS::strcpy (this->rendezvous_point_, temp_rendezvous_point2); - ACE_OS::strcpy (this->rendezvous_point_, temp_rendezvous_point); + return 0; -// ACE_DEBUG ((LM_DEBUG, -// "UIOP_Profile::set -- \n" -// " temp_rendezvous_point: <%s>\n" -// " rendezvous_point: <%s>\n", -// temp_rendezvous_point, -// this->rendezvous_point_)); - - return 0; // Success } TAO_UIOP_Profile::~TAO_UIOP_Profile (void) { + assert (this->refcount_ == 0); + delete [] this->rendezvous_point_; this->rendezvous_point_ = 0; + + if (forward_to_) + { + delete forward_to_; + } + +} + +// return codes: +// -1 -> error +// 0 -> can't understand this version +// 1 -> success. +int +TAO_UIOP_Profile::parse (TAO_InputCDR& cdr, + CORBA::Boolean &continue_decoding, + CORBA::Environment &env) +{ + CORBA::ULong encap_len = cdr.length (); + + // Read and verify major, minor versions, ignoring UIOP + // profiles whose versions we don't understand. + // FIXME: Version question again, what do we do about them for this + // protocol? + + if (!(cdr.read_octet (this->version_.major) + && this->version_.major == TAO_UIOP_Profile::DEF_UIOP_MAJOR + && cdr.read_octet (this->version_.minor) + && this->version_.minor <= TAO_UIOP_Profile::DEF_UIOP_MINOR)) + { + ACE_DEBUG ((LM_DEBUG, + "detected new v%d.%d UIOP profile", + this->version_.major, + this->version_.minor)); + return 0; + } + + if (this->rendezvous_point_) + { + delete [] this->rendezvous_point_; + this->rendezvous_point_ = 0; + } + + // Get rendezvous_point + if (cdr.read_string (this->rendezvous_point_) == 0) + { + ACE_DEBUG ((LM_DEBUG, "error decoding UIOP rendezvous_point")); + return -1; + } + + this->object_addr_.set (this->rendezvous_point_); + + // ... and object key. + + if ((cdr >> this->object_key_) == 0) + return -1; + + if (cdr.length () != 0 && TAO_debug_level) + { + // If there is extra data in the profile we are supposed to + // ignore it, but print a warning just in case... + ACE_DEBUG ((LM_DEBUG, + "%d bytes out of %d left after UIOP profile data\n", + cdr.length (), + encap_len)); + } + if (cdr.good_bit ()) + return 1; + + return -1; } int @@ -261,58 +373,74 @@ TAO_UIOP_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_UIOP_Profile::DEF_UIOP_MAJOR || - this->version_.minor > TAO_UIOP_Profile::DEF_UIOP_MINOR) + if (this->version_.major != TAO_UIOP_Profile::DEF_UIOP_MAJOR + || this->version_.minor > TAO_UIOP_Profile::DEF_UIOP_MINOR) { ACE_THROW_RETURN (CORBA::MARSHAL (), -1); } - // Pull off the "rendezvous point" part of the objref + // Pull off the "rendezvous_pointname:" part of the objref // Copy the string because we are going to modify it... CORBA::String_var copy = CORBA::string_dup (string); char *start = copy.inout (); - char *cp = ACE_OS::strchr (start, this->object_key_delimiter); + char *cp = ACE_OS::strchr (start, ':'); if (cp == 0) { ACE_THROW_RETURN (CORBA::MARSHAL (), -1); - // No rendezvous point specified } if (this->rendezvous_point_) { + // @@ You are setting this->rendezvous_point_ using CORBA::string_alloc() a + // couple of lines below, you should then use CORBA::string_free() + // to release it! In general use a single form of memory + // allocation for a field/variable to avoid new/free() and + // malloc/delete() mismatches. + // Ohh, and if you are going to use CORBA::string_alloc() & + // friends you may consider using CORBA::String_var to manage + // the memory automatically (though there may be forces that + // suggest otherwise). delete [] this->rendezvous_point_; this->rendezvous_point_ = 0; } - ACE_NEW_RETURN (this->rendezvous_point_, - char[1 + cp - start], - -1); + this->rendezvous_point_ = CORBA::string_alloc (1 + cp - start); + for (cp = this->rendezvous_point_; *start != ':'; *cp++ = *start++) + continue; + + *cp = 0; start++; // increment past : - ACE_OS::strncpy (this->rendezvous_point_, start, cp - start); - this->rendezvous_point_[cp - start] = '\0'; + cp = ACE_OS::strchr (start, '/'); + + if (cp == 0) + { + CORBA::string_free (this->rendezvous_point_); + ACE_THROW_RETURN (CORBA::MARSHAL (), -1); + } this->object_addr_.set (this->rendezvous_point_); - start = ++cp; // increment past the object key separator + start = ++cp; // increment past the / TAO_POA::decode_string_to_sequence (this->object_key_, start); @@ -358,7 +486,7 @@ TAO_UIOP_Profile::is_equivalent (TAO_Profile *other_profile, { env.clear (); - if (other_profile->tag () != TAO_IOP_TAG_UNIX_IOP) + if (other_profile->tag () != TAO_IOP_TAG_INTERNET_IOP) return 0; TAO_UIOP_Profile *op = @@ -398,9 +526,9 @@ TAO_UIOP_Profile::hash (CORBA::ULong max, } char * -TAO_UIOP_Profile::addr_to_string (void) +TAO_UIOP_Profile::addr_to_string(void) { - static char s[MAXPATHLEN + 1]; + static char s[MAXPATHLEN + MAXPATHLEN]; ACE_OS::sprintf (s, "%s", this->rendezvous_point_); return s; @@ -415,7 +543,7 @@ TAO_UIOP_Profile::rendezvous_point (const char *r) this->rendezvous_point_ = 0; } - if (r) + if (h) { ACE_NEW_RETURN (this->rendezvous_point_, char[ACE_OS::strlen (r) + 1], @@ -462,21 +590,76 @@ TAO_UIOP_Profile::operator= (const TAO_UIOP_Profile &src) return *this; } +// Memory managment + +CORBA::ULong +TAO_UIOP_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_UIOP_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_UIOP_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_UIOP_Profile::forward_to (void) +{ + TAO_MProfile *temp; + + ACE_NEW_RETURN (temp, + TAO_MProfile (this->forward_to_), + 0); + return temp; +} + CORBA::String -TAO_UIOP_Profile::to_string (CORBA::Environment &) +TAO_UIOP_Profile::to_string (CORBA::Environment &env) { + ACE_UNUSED_ARG (env); + CORBA::String_var key; TAO_POA::encode_sequence_to_string (key.inout(), 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->rendezvous_point_) + - 1 /* object key separator */ + + 1 /* colon separator */ + + 5 /* port number */ + + 1 /* slash separator */ + ACE_OS::strlen (key) + 1 /* zero terminator */); @@ -485,12 +668,11 @@ TAO_UIOP_Profile::to_string (CORBA::Environment &) static const char digits [] = "0123456789"; ACE_OS::sprintf (buf, - "%s//%c.%c@%s%c%s", + "%s%c.%c//%s/%s", ::prefix_, digits [this->version_.major], digits [this->version_.minor], this->rendezvous_point_, - this->object_key_delimiter, key.in ()); return buf; } @@ -501,81 +683,6 @@ TAO_UIOP_Profile::prefix (void) return ::prefix_; } -// return codes: -// -1 -> error -// 0 -> can't understand this version -// 1 -> success. -int -TAO_UIOP_Profile::decode (TAO_InputCDR& cdr) -{ - CORBA::ULong encap_len = cdr.length (); - - if (TAO_debug_level > 0) - { - char *buf = (char *) cdr.rd_ptr (); // ptr to first buffer - ACE_HEX_DUMP ((LM_DEBUG, - (const char*)buf, - encap_len, - "\n")); - } - - // Read and verify major, minor versions, ignoring UIOP - // profiles whose versions we don't understand. - // FIXME: Version question again, what do we do about them for this - // protocol? - - if (!(cdr.read_octet (this->version_.major) - && this->version_.major == TAO_UIOP_Profile::DEF_UIOP_MAJOR - && cdr.read_octet (this->version_.minor) - && this->version_.minor <= TAO_UIOP_Profile::DEF_UIOP_MINOR)) - { - ACE_DEBUG ((LM_DEBUG, - "detected new v%d.%d UIOP profile", - this->version_.major, - this->version_.minor)); - return 0; - } - - if (this->rendezvous_point_) - { - delete [] this->rendezvous_point_; - this->rendezvous_point_ = 0; - } - - // Get rendezvous_point - if (cdr.read_string (this->rendezvous_point_) == 0) - { - ACE_DEBUG ((LM_DEBUG, "error decoding UIOP rendezvous_point")); - return -1; - } - - this->object_addr_.set (this->rendezvous_point_); - - // ... and object key. - - if ((cdr >> this->object_key_) == 0) - return -1; - - if (cdr.length () != 0 && TAO_debug_level) - { - // If there is extra data in the profile we are supposed to - // ignore it, but print a warning just in case... - ACE_DEBUG ((LM_DEBUG, - "%d bytes out of %d left after UIOP profile data\n", - cdr.length (), - encap_len)); - } - -// ACE_DEBUG ((LM_DEBUG, -// "UIOP_Profile --- r point: <%s>\n", -// this->rendezvous_point_)); - - if (cdr.good_bit ()) - return 1; - - return -1; -} - int TAO_UIOP_Profile::encode (TAO_OutputCDR &stream) const { @@ -583,7 +690,7 @@ TAO_UIOP_Profile::encode (TAO_OutputCDR &stream) const // @@ 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_UNIX_IOP); + 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 @@ -597,8 +704,10 @@ TAO_UIOP_Profile::encode (TAO_OutputCDR &stream) const + 1 // version minor + 1 // pad byte + 4 // sizeof (strlen) - + rendezvous_pointlen + 1 // strlen + null - + (~rendezvous_pointlen & 0x3) // optional pad short + + rendezvous_pointlen + 1 // strlen + null + + (~rendezvous_pointlen & 01) // optional pad byte + + 2 // port + + ( rendezvous_pointlen & 02) // optional pad short + 4 // sizeof (key length) + this->object_key_.length (); // key length. stream.write_ulong (encap_len); @@ -613,10 +722,6 @@ TAO_UIOP_Profile::encode (TAO_OutputCDR &stream) const // STRING rendezvous_pointname from profile stream.write_string (this->rendezvous_point_); -// ACE_DEBUG ((LM_DEBUG, -// "UIOP_Profile::encode -- rendezvous point: <%s>\n", -// this->rendezvous_point_)); - // OCTET SEQUENCE for object key stream << this->object_key_; |