summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Reference.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/Reference.cpp')
-rw-r--r--cpp/src/Ice/Reference.cpp137
1 files changed, 72 insertions, 65 deletions
diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp
index b157f5c4d86..a14df7e35cc 100644
--- a/cpp/src/Ice/Reference.cpp
+++ b/cpp/src/Ice/Reference.cpp
@@ -13,7 +13,7 @@
#include <Ice/Instance.h>
#include <Ice/EndpointI.h>
#include <Ice/OpaqueEndpointI.h>
-#include <Ice/BasicStream.h>
+#include <Ice/OutputStream.h>
#include <Ice/RouterInfo.h>
#include <Ice/Router.h>
#include <Ice/LocatorInfo.h>
@@ -27,11 +27,14 @@
#include <Ice/RequestHandlerFactory.h>
#include <Ice/ConnectionRequestHandler.h>
#include <Ice/DefaultsAndOverrides.h>
-#include <IceUtil/StringUtil.h>
+#include <Ice/Comparable.h>
+#include <Ice/StringUtil.h>
+
#include <IceUtil/Random.h>
#include <IceUtil/MutexPtrLock.h>
#include <functional>
+#include <algorithm>
using namespace std;
using namespace Ice;
@@ -171,6 +174,25 @@ IceInternal::Reference::changeCompress(bool newCompress) const
return r;
}
+bool
+IceInternal::Reference::getCompressOverride(bool& compress) const
+{
+ DefaultsAndOverridesPtr defaultsAndOverrides = getInstance()->defaultsAndOverrides();
+ if(defaultsAndOverrides->overrideCompress)
+ {
+ compress = defaultsAndOverrides->overrideCompressValue;
+ }
+ else if(_overrideCompress)
+ {
+ compress = _compress;
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+}
+
Int
Reference::hash() const
{
@@ -184,7 +206,7 @@ Reference::hash() const
}
void
-IceInternal::Reference::streamWrite(BasicStream* s) const
+IceInternal::Reference::streamWrite(OutputStream* s) const
{
//
// Don't write the identity here. Operations calling streamWrite
@@ -207,7 +229,7 @@ IceInternal::Reference::streamWrite(BasicStream* s) const
s->write(_secure);
- if(s->getWriteEncoding() != Ice::Encoding_1_0)
+ if(s->getEncoding() != Ice::Encoding_1_0)
{
s->write(_protocol);
s->write(_encoding);
@@ -228,13 +250,18 @@ IceInternal::Reference::toString() const
//
ostringstream s;
+ ToStringMode toStringMode = _instance->toStringMode();
+ const string separators = " :@";
+
+ string id = Ice::identityToString(_identity, toStringMode);
+
//
// If the encoded identity string contains characters which
// the reference parser uses as separators, then we enclose
// the identity string in quotes.
//
- string id = _instance->identityToString(_identity);
- if(id.find_first_of(" :@") != string::npos)
+
+ if(id.find_first_of(separators) != string::npos)
{
s << '"' << id << '"';
}
@@ -247,14 +274,13 @@ IceInternal::Reference::toString() const
{
s << " -f ";
+ string fs = escapeString(_facet, "", toStringMode);
//
// If the encoded facet string contains characters which
// the reference parser uses as separators, then we enclose
// the facet string in quotes.
//
- string fs = nativeToUTF8(_facet, _instance->getStringConverter());
- fs = IceUtilInternal::escapeString(fs, "");
- if(fs.find_first_of(" :@") != string::npos)
+ if(fs.find_first_of(separators) != string::npos)
{
s << '"' << fs << '"';
}
@@ -376,17 +402,10 @@ IceInternal::Reference::operator==(const Reference& r) const
{
return false;
}
-
return true;
}
bool
-IceInternal::Reference::operator!=(const Reference& r) const
-{
- return !operator==(r);
-}
-
-bool
IceInternal::Reference::operator<(const Reference& r) const
{
//
@@ -624,7 +643,7 @@ IceInternal::FixedReference::getPreferSecure() const
Ice::EndpointSelectionType
IceInternal::FixedReference::getEndpointSelection() const
{
- return Random;
+ return ICE_ENUM(EndpointSelectionType, Random);
}
int
@@ -654,14 +673,14 @@ IceInternal::FixedReference::changeAdapterId(const string& /*newAdapterId*/) con
}
ReferencePtr
-IceInternal::FixedReference::changeLocator(const LocatorPrx&) const
+IceInternal::FixedReference::changeLocator(const LocatorPrxPtr&) const
{
throw FixedProxyException(__FILE__, __LINE__);
return 0; // Keep the compiler happy.
}
ReferencePtr
-IceInternal::FixedReference::changeRouter(const RouterPrx&) const
+IceInternal::FixedReference::changeRouter(const RouterPrxPtr&) const
{
throw FixedProxyException(__FILE__, __LINE__);
return 0; // Keep the compiler happy.
@@ -729,18 +748,9 @@ IceInternal::FixedReference::isWellKnown() const
}
void
-IceInternal::FixedReference::streamWrite(BasicStream*) const
-{
- throw FixedProxyException(__FILE__, __LINE__);
-}
-
-string
-IceInternal::FixedReference::toString() const
+IceInternal::FixedReference::streamWrite(OutputStream*) const
{
throw FixedProxyException(__FILE__, __LINE__);
-
- assert(false); // Cannot be reached.
- return string(); // To keep the compiler from complaining.
}
PropertyDict
@@ -753,7 +763,7 @@ IceInternal::FixedReference::toProperty(const string&) const
}
RequestHandlerPtr
-IceInternal::FixedReference::getRequestHandler(const Ice::ObjectPrx& proxy) const
+IceInternal::FixedReference::getRequestHandler(const Ice::ObjectPrxPtr& proxy) const
{
switch(getMode())
{
@@ -800,7 +810,7 @@ IceInternal::FixedReference::getRequestHandler(const Ice::ObjectPrx& proxy) cons
_fixedConnection->throwException(); // Throw in case our connection is already destroyed.
- bool compress;
+ bool compress = false;
if(defaultsAndOverrides->overrideCompress)
{
compress = defaultsAndOverrides->overrideCompressValue;
@@ -809,13 +819,9 @@ IceInternal::FixedReference::getRequestHandler(const Ice::ObjectPrx& proxy) cons
{
compress = _compress;
}
- else
- {
- compress = _fixedConnection->endpoint()->compress();
- }
ReferencePtr ref = const_cast<FixedReference*>(this);
- return proxy->__setRequestHandler(new ConnectionRequestHandler(ref, _fixedConnection, compress));
+ return proxy->_setRequestHandler(ICE_MAKE_SHARED(ConnectionRequestHandler, ref, _fixedConnection, compress));
}
BatchRequestQueuePtr
@@ -840,12 +846,6 @@ IceInternal::FixedReference::operator==(const Reference& r) const
}
bool
-IceInternal::FixedReference::operator!=(const Reference& r) const
-{
- return !operator==(r);
-}
-
-bool
IceInternal::FixedReference::operator<(const Reference& r) const
{
if(this == &r)
@@ -1039,7 +1039,7 @@ IceInternal::RoutableReference::changeAdapterId(const string& newAdapterId) cons
}
ReferencePtr
-IceInternal::RoutableReference::changeLocator(const LocatorPrx& newLocator) const
+IceInternal::RoutableReference::changeLocator(const LocatorPrxPtr& newLocator) const
{
LocatorInfoPtr newLocatorInfo = getInstance()->locatorManager()->get(newLocator);
if(newLocatorInfo == _locatorInfo)
@@ -1052,7 +1052,7 @@ IceInternal::RoutableReference::changeLocator(const LocatorPrx& newLocator) cons
}
ReferencePtr
-IceInternal::RoutableReference::changeRouter(const RouterPrx& newRouter) const
+IceInternal::RoutableReference::changeRouter(const RouterPrxPtr& newRouter) const
{
RouterInfoPtr newRouterInfo = getInstance()->routerManager()->get(newRouter);
if(newRouterInfo == _routerInfo)
@@ -1180,7 +1180,7 @@ IceInternal::RoutableReference::isWellKnown() const
}
void
-IceInternal::RoutableReference::streamWrite(BasicStream* s) const
+IceInternal::RoutableReference::streamWrite(OutputStream* s) const
{
Reference::streamWrite(s);
@@ -1234,8 +1234,7 @@ IceInternal::RoutableReference::toString() const
// reference parser uses as separators, then we enclose the
// adapter id string in quotes.
//
- string a = nativeToUTF8(_adapterId, getInstance()->getStringConverter());
- a = IceUtilInternal::escapeString(a, "");
+ string a = escapeString(_adapterId, "", getInstance()->toStringMode());
if(a.find_first_of(" :@") != string::npos)
{
result.append("\"");
@@ -1263,7 +1262,7 @@ IceInternal::RoutableReference::toProperty(const string& prefix) const
properties[prefix + ".CollocationOptimized"] = _collocationOptimized ? "1" : "0";
properties[prefix + ".ConnectionCached"] = _cacheConnection ? "1" : "0";
properties[prefix + ".PreferSecure"] = _preferSecure ? "1" : "0";
- properties[prefix + ".EndpointSelection"] = _endpointSelection == Random ? "Random" : "Ordered";
+ properties[prefix + ".EndpointSelection"] = _endpointSelection == ICE_ENUM(EndpointSelectionType, Random) ? "Random" : "Ordered";
{
ostringstream s;
s << _locatorCacheTimeout;
@@ -1276,7 +1275,7 @@ IceInternal::RoutableReference::toProperty(const string& prefix) const
}
if(_routerInfo)
{
- PropertyDict routerProperties = _routerInfo->getRouter()->__reference()->toProperty(prefix + ".Router");
+ PropertyDict routerProperties = _routerInfo->getRouter()->_getReference()->toProperty(prefix + ".Router");
for(PropertyDict::const_iterator p = routerProperties.begin(); p != routerProperties.end(); ++p)
{
properties[p->first] = p->second;
@@ -1285,7 +1284,7 @@ IceInternal::RoutableReference::toProperty(const string& prefix) const
if(_locatorInfo)
{
- PropertyDict locatorProperties = _locatorInfo->getLocator()->__reference()->toProperty(prefix + ".Locator");
+ PropertyDict locatorProperties = _locatorInfo->getLocator()->_getReference()->toProperty(prefix + ".Locator");
for(PropertyDict::const_iterator p = locatorProperties.begin(); p != locatorProperties.end(); ++p)
{
properties[p->first] = p->second;
@@ -1351,7 +1350,16 @@ IceInternal::RoutableReference::operator==(const Reference& r) const
{
return false;
}
+#ifdef ICE_CPP11_MAPPING
+ //
+ // TODO: With C++14 we could use the version that receives four iterators and we don't need to explicitly
+ // check the sizes are equal.
+ //
+ if(_endpoints.size() != rhs->_endpoints.size() ||
+ !equal(_endpoints.begin(), _endpoints.end(), rhs->_endpoints.begin(), Ice::TargetCompare<shared_ptr<EndpointI>, std::equal_to>()))
+#else
if(_endpoints != rhs->_endpoints)
+#endif
{
return false;
}
@@ -1367,12 +1375,6 @@ IceInternal::RoutableReference::operator==(const Reference& r) const
}
bool
-IceInternal::RoutableReference::operator!=(const Reference& r) const
-{
- return !operator==(r);
-}
-
-bool
IceInternal::RoutableReference::operator<(const Reference& r) const
{
if(this == &r)
@@ -1479,7 +1481,12 @@ IceInternal::RoutableReference::operator<(const Reference& r) const
{
return false;
}
+#ifdef ICE_CPP11_MAPPING
+ if(lexicographical_compare(_endpoints.begin(), _endpoints.end(), rhs->_endpoints.begin(), rhs->_endpoints.end(),
+ Ice::TargetCompare<shared_ptr<EndpointI>, std::less>()))
+#else
if(_endpoints < rhs->_endpoints)
+#endif
{
return true;
}
@@ -1505,7 +1512,7 @@ IceInternal::RoutableReference::clone() const
}
RequestHandlerPtr
-IceInternal::RoutableReference::getRequestHandler(const Ice::ObjectPrx& proxy) const
+IceInternal::RoutableReference::getRequestHandler(const Ice::ObjectPrxPtr& proxy) const
{
return getInstance()->requestHandlerFactory()->getRequestHandler(const_cast<RoutableReference*>(this), proxy);
}
@@ -1640,7 +1647,7 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal
vector<EndpointIPtr> endpts = endpoints;
_reference->applyOverrides(endpts);
- _reference->createConnection(endpts, new Callback2(_reference, _callback, cached));
+ _reference->createConnection(endpts, ICE_MAKE_SHARED(Callback2, _reference, _callback, cached));
}
virtual void
@@ -1669,7 +1676,7 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal
if(_locatorInfo)
{
RoutableReference* self = const_cast<RoutableReference*>(this);
- _locatorInfo->getEndpointsWithCallback(self, _locatorCacheTimeout, new Callback(self, callback));
+ _locatorInfo->getEndpoints(self, _locatorCacheTimeout, new Callback(self, callback));
}
else
{
@@ -1761,14 +1768,14 @@ IceInternal::RoutableReference::createConnection(const vector<EndpointIPtr>& all
virtual void
setException(const Ice::LocalException& ex)
{
- if(!_exception.get())
+ if(!_exception)
{
- _exception.reset(ex.ice_clone());
+ ICE_SET_EXCEPTION_FROM_CLONE(_exception, ex.ice_clone());
}
if(++_i == _endpoints.size())
{
- _callback->setException(*_exception.get());
+ _callback->setException(*_exception);
return;
}
@@ -1795,7 +1802,7 @@ IceInternal::RoutableReference::createConnection(const vector<EndpointIPtr>& all
const vector<EndpointIPtr> _endpoints;
const GetConnectionCallbackPtr _callback;
size_t _i;
- IceUtil::UniquePtr<Ice::LocalException> _exception;
+ IceInternal::UniquePtr<Ice::LocalException> _exception;
};
//
@@ -1909,13 +1916,13 @@ IceInternal::RoutableReference::filterEndpoints(const vector<EndpointIPtr>& allE
//
switch(getEndpointSelection())
{
- case Random:
+ case ICE_ENUM(EndpointSelectionType, Random):
{
RandomNumberGenerator rng;
random_shuffle(endpoints.begin(), endpoints.end(), rng);
break;
}
- case Ordered:
+ case ICE_ENUM(EndpointSelectionType, Ordered):
{
// Nothing to do.
break;