diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 13 | ||||
-rw-r--r-- | cpp/src/Ice/Endpoint.cpp | 106 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 31 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.cpp | 140 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.h | 9 |
6 files changed, 237 insertions, 64 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 4973f7506c7..113376032fa 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -606,6 +606,16 @@ IceInternal::BasicStream::read(vector<Double>& v) void IceInternal::BasicStream::write(const string& v) { + // + // TODO: Revise reading/writing of strings and wstrings. Strings + // shouldn't be null-terminated on the wire. Instead, the string + // size should be transmitted first, and strings should be allowed + // to have 0 bytes. Only one initial Int parameter is sufficient, + // with negative values indicating redirection, and positive + // values for string lengths. Strings with length 0 should never + // be redirected. + // + map<string, Int>::const_iterator p = _encapsStack.back().stringsWritten.find(v); if (p != _encapsStack.back().stringsWritten.end()) { @@ -643,6 +653,7 @@ IceInternal::BasicStream::write(const vector<string>& v) void IceInternal::BasicStream::read(string& v) { + // TODO: Needs to be revised. See comments in write(const string&). Int idx; read(idx); @@ -695,6 +706,7 @@ IceInternal::BasicStream::read(vector<string>& v) void IceInternal::BasicStream::write(const wstring& v) { + // TODO: Needs to be revised. See comments in write(const string&). map<wstring, Int>::const_iterator p = _encapsStack.back().wstringsWritten.find(v); if (p != _encapsStack.back().wstringsWritten.end()) { @@ -728,6 +740,7 @@ IceInternal::BasicStream::write(const vector<wstring>& v) void IceInternal::BasicStream::read(wstring& v) { + // TODO: Needs to be revised. See comments in write(const string&). Int idx; read(idx); diff --git a/cpp/src/Ice/Endpoint.cpp b/cpp/src/Ice/Endpoint.cpp index 8fc2718a3d0..b3611f2bd23 100644 --- a/cpp/src/Ice/Endpoint.cpp +++ b/cpp/src/Ice/Endpoint.cpp @@ -32,34 +32,31 @@ IceInternal::Endpoint::endpointFromString(const string& str) { const string delim = " \t\n\r"; - string s(str); - transform(s.begin(), s.end(), s.begin(), tolower); - - string::size_type beg = s.find_first_not_of(delim); + string::size_type beg = str.find_first_not_of(delim); if (beg == string::npos) { throw EndpointParseException(__FILE__, __LINE__); } - string::size_type end = s.find_first_of(delim, beg); + string::size_type end = str.find_first_of(delim, beg); if (end == string::npos) { - end = s.length(); + end = str.length(); } - if (s.compare(beg, end - beg, "tcp") == 0) + if (str.compare(beg, end - beg, "tcp") == 0) { - return new TcpEndpoint(s.substr(end)); + return new TcpEndpoint(str.substr(end)); } - if (s.compare(beg, end - beg, "ssl") == 0) + if (str.compare(beg, end - beg, "ssl") == 0) { - return new SslEndpoint(s.substr(end)); + return new SslEndpoint(str.substr(end)); } - if (s.compare(beg, end - beg, "udp") == 0) + if (str.compare(beg, end - beg, "udp") == 0) { - return new UdpEndpoint(s.substr(end)); + return new UdpEndpoint(str.substr(end)); } throw EndpointParseException(__FILE__, __LINE__); @@ -252,62 +249,73 @@ IceInternal::TcpEndpoint::TcpEndpoint(const string& str) : { const string delim = " \t\n\r"; - string s(str); - transform(s.begin(), s.end(), s.begin(), tolower); - string::size_type beg; string::size_type end = 0; while (true) { - beg = s.find_first_not_of(delim, end); + beg = str.find_first_not_of(delim, end); if (beg == string::npos) { break; } - end = s.find_first_of(delim, beg); + end = str.find_first_of(delim, beg); if (end == string::npos) { - end = s.length(); + end = str.length(); } - string option = s.substr(beg, end - beg); + string option = str.substr(beg, end - beg); if (option.length() != 2 || option[0] != '-') { throw EndpointParseException(__FILE__, __LINE__); } - beg = s.find_first_not_of(delim, end); - if (beg == string::npos) - { - throw EndpointParseException(__FILE__, __LINE__); - } - - end = s.find_first_of(delim, beg); - if (end == string::npos) + string argument; + string::size_type argumentBeg = str.find_first_not_of(delim, end); + if (argumentBeg != string::npos && str[argumentBeg] != '-') { - end = s.length(); + beg = argumentBeg; + end = str.find_first_of(delim, beg); + if (end == string::npos) + { + end = str.length(); + } + argument = str.substr(beg, end - beg); } - - string argument = s.substr(beg, end - beg); switch (option[1]) { case 'h': { + if (argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<string&>(_host) = argument; break; } case 'p': { + if (argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Int&>(_port) = atoi(argument.c_str()); break; } case 't': { + if (argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Int&>(_timeout) = atoi(argument.c_str()); break; } @@ -567,45 +575,42 @@ IceInternal::SslEndpoint::SslEndpoint(const string& str) : { const string delim = " \t\n\r"; - string s(str); - transform(s.begin(), s.end(), s.begin(), tolower); - string::size_type beg; string::size_type end = 0; while (true) { - beg = s.find_first_not_of(delim, end); + beg = str.find_first_not_of(delim, end); if (beg == string::npos) { break; } - end = s.find_first_of(delim, beg); + end = str.find_first_of(delim, beg); if (end == string::npos) { - end = s.length(); + end = str.length(); } - string option = s.substr(beg, end - beg); + string option = str.substr(beg, end - beg); if (option.length() != 2 || option[0] != '-') { throw EndpointParseException(__FILE__, __LINE__); } - beg = s.find_first_not_of(delim, end); + beg = str.find_first_not_of(delim, end); if (beg == string::npos) { throw EndpointParseException(__FILE__, __LINE__); } - end = s.find_first_of(delim, beg); + end = str.find_first_of(delim, beg); if (end == string::npos) { - end = s.length(); + end = str.length(); } - string argument = s.substr(beg, end - beg); + string argument = str.substr(beg, end - beg); switch (option[1]) { @@ -880,45 +885,42 @@ IceInternal::UdpEndpoint::UdpEndpoint(const string& str) : { const string delim = " \t\n\r"; - string s(str); - transform(s.begin(), s.end(), s.begin(), tolower); - string::size_type beg; string::size_type end = 0; while (true) { - beg = s.find_first_not_of(delim, end); + beg = str.find_first_not_of(delim, end); if (beg == string::npos) { break; } - end = s.find_first_of(delim, beg); + end = str.find_first_of(delim, beg); if (end == string::npos) { - end = s.length(); + end = str.length(); } - string option = s.substr(beg, end - beg); + string option = str.substr(beg, end - beg); if (option.length() != 2 || option[0] != '-') { throw EndpointParseException(__FILE__, __LINE__); } - beg = s.find_first_not_of(delim, end); + beg = str.find_first_not_of(delim, end); if (beg == string::npos) { throw EndpointParseException(__FILE__, __LINE__); } - end = s.find_first_of(delim, beg); + end = str.find_first_of(delim, beg); if (end == string::npos) { - end = s.length(); + end = str.length(); } - string argument = s.substr(beg, end - beg); + string argument = str.substr(beg, end - beg); switch (option[1]) { diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 13439849428..63c783b7164 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -361,7 +361,7 @@ Ice::ObjectAdapterI::newProxy(const string& ident) transform(_collectorFactories.begin(), _collectorFactories.end(), back_inserter(endpoints), Ice::constMemFun(&CollectorFactory::endpoint)); - ReferencePtr reference = new Reference(_instance, ident, Reference::ModeTwoway, false, endpoints, endpoints); + ReferencePtr reference = new Reference(_instance, ident, "", Reference::ModeTwoway, false, endpoints, endpoints); return _instance->proxyFactory()->referenceToProxy(reference); } diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index fdd541f7866..4e6ec8120ba 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -114,13 +114,19 @@ IceProxy::Ice::Object::_flush() bool IceProxy::Ice::Object::operator==(const Object& r) const { - return _reference->identity == r._reference->identity; + return _reference == r._reference; } bool IceProxy::Ice::Object::operator<(const Object& r) const { - return _reference->identity < r._reference->identity; + return _reference < r._reference; +} + +Int +IceProxy::Ice::Object::_hash() const +{ + return _reference->hashValue; } std::string @@ -144,6 +150,27 @@ IceProxy::Ice::Object::_newIdentity(const std::string& newIdentity) const } } +std::string +IceProxy::Ice::Object::_getFacet() const +{ + return _reference->facet; +} + +::Ice::ObjectPrx +IceProxy::Ice::Object::_newFacet(const std::string& newFacet) const +{ + if (newFacet == _reference->facet) + { + return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + } + else + { + ObjectPrx proxy(new ::IceProxy::Ice::Object()); + proxy->setup(_reference->changeFacet(newFacet)); + return proxy; + } +} + ObjectPrx IceProxy::Ice::Object::_twoway() const { diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index b19f6b7a578..63cd658b101 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -20,15 +20,17 @@ using namespace IceInternal; void IceInternal::incRef(Reference* p) { p->__incRef(); } void IceInternal::decRef(Reference* p) { p->__decRef(); } -IceInternal::Reference::Reference(const InstancePtr& inst, const string& ident, Mode md, bool sec, +IceInternal::Reference::Reference(const InstancePtr& inst, const string& ident, const string& fac, Mode md, bool sec, const vector<EndpointPtr>& origEndpts, const vector<EndpointPtr>& endpts) : instance(inst), identity(ident), + facet(facet), mode(md), secure(sec), origEndpoints(origEndpts), endpoints(endpts) { + calcHashValue(); } IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : @@ -61,8 +63,6 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : const_cast<string&>(identity) = s.substr(beg, end - beg); - transform(s.begin(), s.end(), s.begin(), tolower); - while (true) { beg = s.find_first_not_of(delim, end); @@ -87,47 +87,106 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : { throw ReferenceParseException(__FILE__, __LINE__); } + + string argument; + string::size_type argumentBeg = str.find_first_not_of(delim, end); + if (argumentBeg != string::npos && str[argumentBeg] != '-') + { + beg = argumentBeg; + end = str.find_first_of(delim, beg); + if (end == string::npos) + { + end = str.length(); + } + argument = str.substr(beg, end - beg); + } switch (option[1]) { + case 'f': + { + if (argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + + const_cast<std::string&>(facet) = argument; + break; + } + case 't': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeTwoway; break; } case 'o': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeOneway; break; } case 'O': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeBatchOneway; break; } case 'd': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeDatagram; break; } case 'D': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeBatchDatagram; break; } case 's': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<bool&>(secure) = true; break; } default: { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + throw ReferenceParseException(__FILE__, __LINE__); } } @@ -177,6 +236,8 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : { throw ReferenceParseException(__FILE__, __LINE__); } + + calcHashValue(); } IceInternal::Reference::Reference(const string& ident, BasicStream* s) : @@ -190,6 +251,8 @@ IceInternal::Reference::Reference(const string& ident, BasicStream* s) : // constructor read the identity, and pass it as a parameter. // + s->read(const_cast<string&>(facet)); + vector<EndpointPtr>::const_iterator p; Ice::Int sz; @@ -215,6 +278,8 @@ IceInternal::Reference::Reference(const string& ident, BasicStream* s) : Endpoint::streamRead(s, const_cast<EndpointPtr&>(*p)); } } + + calcHashValue(); } void @@ -225,6 +290,8 @@ IceInternal::Reference::streamWrite(BasicStream* s) const // write the identity. // + s->write(facet); + vector<EndpointPtr>::const_iterator p; s->write(Ice::Int(origEndpoints.size())); @@ -281,7 +348,20 @@ IceInternal::Reference::changeIdentity(const string& newIdentity) const } else { - return new Reference(instance, newIdentity, mode, secure, origEndpoints, endpoints); + return new Reference(instance, newIdentity, facet, mode, secure, origEndpoints, endpoints); + } +} + +ReferencePtr +IceInternal::Reference::changeFacet(const string& newFacet) const +{ + if (newFacet == facet) + { + return ReferencePtr(const_cast<Reference*>(this)); + } + else + { + return new Reference(instance, identity, newFacet, mode, secure, origEndpoints, endpoints); } } @@ -302,7 +382,7 @@ IceInternal::Reference::changeTimeout(int timeout) const newEndpoints.push_back((*p)->timeout(timeout)); } - ReferencePtr ref(new Reference(instance, identity, mode, secure, newOrigEndpoints, newEndpoints)); + ReferencePtr ref(new Reference(instance, identity, facet, mode, secure, newOrigEndpoints, newEndpoints)); if (*ref.get() == *this) { @@ -321,7 +401,7 @@ IceInternal::Reference::changeMode(Mode newMode) const } else { - return new Reference(instance, identity, newMode, secure, origEndpoints, endpoints); + return new Reference(instance, identity, facet, newMode, secure, origEndpoints, endpoints); } } @@ -334,7 +414,7 @@ IceInternal::Reference::changeSecure(bool newSecure) const } else { - return new Reference(instance, identity, mode, newSecure, origEndpoints, endpoints); + return new Reference(instance, identity, facet, mode, newSecure, origEndpoints, endpoints); } } @@ -347,7 +427,7 @@ IceInternal::Reference::changeEndpoints(const std::vector<EndpointPtr>& newEndpo } else { - return new Reference(instance, identity, mode, secure, origEndpoints, newEndpoints); + return new Reference(instance, identity, facet, mode, secure, origEndpoints, newEndpoints); } } @@ -364,6 +444,11 @@ IceInternal::Reference::operator==(const Reference& r) const return false; } + if (facet != r.facet) + { + return false; + } + if (mode != r.mode) { return false; @@ -404,6 +489,15 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } + if (facet < r.facet) + { + return true; + } + else if (facet != r.facet) + { + return false; + } + if (mode < r.mode) { return true; @@ -442,3 +536,33 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } + +void +IceInternal::Reference::calcHashValue() +{ + Int h = 0; + + string::const_iterator p; + + for (p = identity.begin(); p != identity.end(); ++p) + { + h = 5 * h + *p; + } + + for (p = facet.begin(); p != facet.end(); ++p) + { + h = 5 * h + *p; + } + + h = 5 * h + static_cast<Int>(mode); + + h = 5 * h + static_cast<Int>(secure); + + // + // TODO: Should we also take the endpoints into account for hash + // calculation? Perhaps not, the code above should be good enough + // for a good hash value. + // + + const_cast<Int&>(hashValue) = h; +} diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 9c3f0924cc8..4327c528e08 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -34,7 +34,7 @@ public: ModeBatchDatagram }; - Reference(const InstancePtr&, const std::string&, Mode, bool, + Reference(const InstancePtr&, const std::string&, const std::string&, Mode, bool, const std::vector<EndpointPtr>&, const std::vector<EndpointPtr>&); Reference(const InstancePtr&, const std::string&); Reference(const std::string&, BasicStream*); @@ -54,16 +54,19 @@ public: // const InstancePtr instance; const std::string identity; + const std::string facet; const Mode mode; const bool secure; const std::vector<EndpointPtr> origEndpoints; // Original endpoints const std::vector<EndpointPtr> endpoints; // Actual endpoints (set by a location forward) + const Ice::Int hashValue; // // Get a new reference, based on the existing one, overwriting // certain values. // ReferencePtr changeIdentity(const std::string&) const; + ReferencePtr changeFacet(const std::string&) const; ReferencePtr changeTimeout(int) const; ReferencePtr changeMode(Mode) const; ReferencePtr changeSecure(bool) const; @@ -71,6 +74,10 @@ public: bool operator==(const Reference&) const; bool operator<(const Reference&) const; + +private: + + void calcHashValue(); }; } |