summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/RouterInfo.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-12-01 17:36:19 +0100
committerJose <jose@zeroc.com>2015-12-01 17:36:19 +0100
commit2029ff368e49fae489b8ec8fc12f7d126b182dfb (patch)
tree6075d652b7851831c39e6f22004d8720864f1a60 /cpp/src/Ice/RouterInfo.cpp
parentThe default LMDB map size for IceGrid and IceStorm is now 10MB (Windows) (diff)
downloadice-2029ff368e49fae489b8ec8fc12f7d126b182dfb.tar.bz2
ice-2029ff368e49fae489b8ec8fc12f7d126b182dfb.tar.xz
ice-2029ff368e49fae489b8ec8fc12f7d126b182dfb.zip
C++11 mapping initial commit
Diffstat (limited to 'cpp/src/Ice/RouterInfo.cpp')
-rw-r--r--cpp/src/Ice/RouterInfo.cpp115
1 files changed, 84 insertions, 31 deletions
diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp
index 49f3ac389ed..f0afc392990 100644
--- a/cpp/src/Ice/RouterInfo.cpp
+++ b/cpp/src/Ice/RouterInfo.cpp
@@ -30,27 +30,29 @@ void
IceInternal::RouterManager::destroy()
{
IceUtil::Mutex::Lock sync(*this);
-
- for_each(_table.begin(), _table.end(), Ice::secondVoidMemFun<const RouterPrx, RouterInfo>(&RouterInfo::destroy));
-
+#ifdef ICE_CPP11_MAPPING
+ for_each(_table.begin(), _table.end(), [](auto it){ it.second->destroy(); });
+#else
+ for_each(_table.begin(), _table.end(), Ice::secondVoidMemFun<const RouterPrxPtr, RouterInfo>(&RouterInfo::destroy));
+#endif
_table.clear();
_tableHint = _table.end();
}
RouterInfoPtr
-IceInternal::RouterManager::get(const RouterPrx& rtr)
+IceInternal::RouterManager::get(const RouterPrxPtr& rtr)
{
if(!rtr)
{
return 0;
}
- RouterPrx router = RouterPrx::uncheckedCast(rtr->ice_router(0)); // The router cannot be routed.
+ RouterPrxPtr router = ICE_UNCHECKED_CAST(RouterPrx, rtr->ice_router(0)); // The router cannot be routed.
IceUtil::Mutex::Lock sync(*this);
- map<RouterPrx, RouterInfoPtr>::iterator p = _table.end();
-
+ map<RouterPrxPtr, RouterInfoPtr>::iterator p = _table.end();
+
if(_tableHint != _table.end())
{
if(_tableHint->first == router)
@@ -58,7 +60,7 @@ IceInternal::RouterManager::get(const RouterPrx& rtr)
p = _tableHint;
}
}
-
+
if(p == _table.end())
{
p = _table.find(router);
@@ -66,7 +68,7 @@ IceInternal::RouterManager::get(const RouterPrx& rtr)
if(p == _table.end())
{
- _tableHint = _table.insert(_tableHint, pair<const RouterPrx, RouterInfoPtr>(router, new RouterInfo(router)));
+ _tableHint = _table.insert(_tableHint, pair<const RouterPrxPtr, RouterInfoPtr>(router, new RouterInfo(router)));
}
else
{
@@ -77,26 +79,26 @@ IceInternal::RouterManager::get(const RouterPrx& rtr)
}
RouterInfoPtr
-IceInternal::RouterManager::erase(const RouterPrx& rtr)
+IceInternal::RouterManager::erase(const RouterPrxPtr& rtr)
{
RouterInfoPtr info;
if(rtr)
{
- RouterPrx router = RouterPrx::uncheckedCast(rtr->ice_router(0)); // The router cannot be routed.
+ RouterPrxPtr router = ICE_UNCHECKED_CAST(RouterPrx, rtr->ice_router(ICE_NULLPTR)); // The router cannot be routed.
IceUtil::Mutex::Lock sync(*this);
- map<RouterPrx, RouterInfoPtr>::iterator p = _table.end();
+ map<RouterPrxPtr, RouterInfoPtr>::iterator p = _table.end();
if(_tableHint != _table.end() && _tableHint->first == router)
{
p = _tableHint;
_tableHint = _table.end();
}
-
+
if(p == _table.end())
{
p = _table.find(router);
}
-
+
if(p != _table.end())
{
info = p->second;
@@ -107,7 +109,7 @@ IceInternal::RouterManager::erase(const RouterPrx& rtr)
return info;
}
-IceInternal::RouterInfo::RouterInfo(const RouterPrx& router) :
+IceInternal::RouterInfo::RouterInfo(const RouterPrxPtr& router) :
_router(router)
{
assert(_router);
@@ -127,19 +129,31 @@ IceInternal::RouterInfo::destroy()
bool
IceInternal::RouterInfo::operator==(const RouterInfo& rhs) const
{
+#ifdef ICE_CPP11_MAPPING
+ return Ice::targetEquals(_router, rhs._router);
+#else
return _router == rhs._router;
+#endif
}
bool
IceInternal::RouterInfo::operator!=(const RouterInfo& rhs) const
{
+#ifdef ICE_CPP11_MAPPING
+ return !Ice::targetEquals(_router, rhs._router);
+#else
return _router != rhs._router;
+#endif
}
bool
IceInternal::RouterInfo::operator<(const RouterInfo& rhs) const
{
+#ifdef ICE_CPP11_MAPPING
+ return Ice::targetLess(_router, rhs._router);
+#else
return _router < rhs._router;
+#endif
}
vector<EndpointIPtr>
@@ -157,14 +171,14 @@ IceInternal::RouterInfo::getClientEndpoints()
}
void
-IceInternal::RouterInfo::getClientProxyResponse(const Ice::ObjectPrx& proxy,
+IceInternal::RouterInfo::getClientProxyResponse(const Ice::ObjectPrxPtr& proxy,
const GetClientEndpointsCallbackPtr& callback)
{
callback->setEndpoints(setClientEndpoints(proxy));
}
void
-IceInternal::RouterInfo::getClientProxyException(const Ice::Exception& ex,
+IceInternal::RouterInfo::getClientProxyException(const Ice::Exception& ex,
const GetClientEndpointsCallbackPtr& callback)
{
callback->setException(dynamic_cast<const Ice::LocalException&>(ex));
@@ -185,10 +199,29 @@ IceInternal::RouterInfo::getClientEndpoints(const GetClientEndpointsCallbackPtr&
return;
}
- _router->begin_getClientProxy(newCallback_Router_getClientProxy(this,
- &RouterInfo::getClientProxyResponse,
+#ifdef ICE_CPP11_MAPPING
+ _router->getClientProxy_async(
+ [this, callback](const Ice::ObjectPrxPtr& proxy)
+ {
+ this->getClientProxyResponse(proxy, callback);
+ },
+ [this, callback](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ this->getClientProxyException(ex, callback);
+ }
+ });
+#else
+ _router->begin_getClientProxy(newCallback_Router_getClientProxy(this,
+ &RouterInfo::getClientProxyResponse,
&RouterInfo::getClientProxyException),
callback);
+#endif
}
vector<EndpointIPtr>
@@ -206,7 +239,7 @@ IceInternal::RouterInfo::getServerEndpoints()
}
void
-IceInternal::RouterInfo::addProxy(const ObjectPrx& proxy)
+IceInternal::RouterInfo::addProxy(const ObjectPrxPtr& proxy)
{
assert(proxy); // Must not be called for null proxies.
@@ -240,7 +273,7 @@ IceInternal::RouterInfo::addProxyException(const Ice::Exception& ex, const AddPr
}
bool
-IceInternal::RouterInfo::addProxy(const Ice::ObjectPrx& proxy, const AddProxyCallbackPtr& callback)
+IceInternal::RouterInfo::addProxy(const Ice::ObjectPrxPtr& proxy, const AddProxyCallbackPtr& callback)
{
assert(proxy);
{
@@ -258,11 +291,31 @@ IceInternal::RouterInfo::addProxy(const Ice::ObjectPrx& proxy, const AddProxyCal
Ice::ObjectProxySeq proxies;
proxies.push_back(proxy);
AddProxyCookiePtr cookie = new AddProxyCookie(callback, proxy);
+
+#ifdef ICE_CPP11_MAPPING
+ _router->addProxies_async(proxies,
+ [this, cookie](const Ice::ObjectProxySeq& proxies)
+ {
+ this->addProxyResponse(proxies, cookie);
+ },
+ [this, cookie](exception_ptr e)
+ {
+ try
+ {
+ rethrow_exception(e);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ this->addProxyException(ex, cookie);
+ }
+ });
+#else
_router->begin_addProxies(proxies,
- newCallback_Router_addProxies(this,
- &RouterInfo::addProxyResponse,
- &RouterInfo::addProxyException),
+ newCallback_Router_addProxies(this,
+ &RouterInfo::addProxyResponse,
+ &RouterInfo::addProxyException),
cookie);
+#endif
return false;
}
@@ -288,7 +341,7 @@ IceInternal::RouterInfo::clearCache(const ReferencePtr& ref)
}
vector<EndpointIPtr>
-IceInternal::RouterInfo::setClientEndpoints(const Ice::ObjectPrx& proxy)
+IceInternal::RouterInfo::setClientEndpoints(const Ice::ObjectPrxPtr& proxy)
{
IceUtil::Mutex::Lock sync(*this);
if(_clientEndpoints.empty())
@@ -302,7 +355,7 @@ IceInternal::RouterInfo::setClientEndpoints(const Ice::ObjectPrx& proxy)
}
else
{
- Ice::ObjectPrx clientProxy = proxy->ice_router(0); // The client proxy cannot be routed.
+ Ice::ObjectPrxPtr clientProxy = proxy->ice_router(0); // The client proxy cannot be routed.
//
// In order to avoid creating a new connection to the router,
@@ -322,12 +375,12 @@ IceInternal::RouterInfo::setClientEndpoints(const Ice::ObjectPrx& proxy)
vector<EndpointIPtr>
-IceInternal::RouterInfo::setServerEndpoints(const Ice::ObjectPrx& /*serverProxy*/)
+IceInternal::RouterInfo::setServerEndpoints(const Ice::ObjectPrxPtr& /*serverProxy*/)
{
IceUtil::Mutex::Lock sync(*this);
if(_serverEndpoints.empty()) // Lazy initialization.
{
- ObjectPrx serverProxy = _router->getServerProxy();
+ ObjectPrxPtr serverProxy = _router->getServerProxy();
if(!serverProxy)
{
throw NoEndpointException(__FILE__, __LINE__);
@@ -341,12 +394,12 @@ IceInternal::RouterInfo::setServerEndpoints(const Ice::ObjectPrx& /*serverProxy*
}
void
-IceInternal::RouterInfo::addAndEvictProxies(const Ice::ObjectPrx& proxy, const Ice::ObjectProxySeq& evictedProxies)
+IceInternal::RouterInfo::addAndEvictProxies(const Ice::ObjectPrxPtr& proxy, const Ice::ObjectProxySeq& evictedProxies)
{
IceUtil::Mutex::Lock sync(*this);
//
- // Check if the proxy hasn't already been evicted by a concurrent addProxies call.
+ // Check if the proxy hasn't already been evicted by a concurrent addProxies call.
// If it's the case, don't add it to our local map.
//
multiset<Identity>::iterator p = _evictedIdentities.find(proxy->ice_getIdentity());
@@ -362,7 +415,7 @@ IceInternal::RouterInfo::addAndEvictProxies(const Ice::ObjectPrx& proxy, const I
//
_identities.insert(proxy->ice_getIdentity());
}
-
+
//
// We also must remove whatever proxies the router evicted.
//