diff options
author | Jose <jose@zeroc.com> | 2015-12-30 12:52:26 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2015-12-30 12:52:26 +0100 |
commit | dda483a63217585bc22a3b3c5392efcc2117ec57 (patch) | |
tree | 2bad562df5f525c9112eee08146a3ccdaafe8c03 /cpp/src | |
parent | Remove unnecessary usage of ICE_CLOSE_CALLBACK (diff) | |
download | ice-dda483a63217585bc22a3b3c5392efcc2117ec57.tar.bz2 ice-dda483a63217585bc22a3b3c5392efcc2117ec57.tar.xz ice-dda483a63217585bc22a3b3c5392efcc2117ec57.zip |
Fixes to C++11 lambdas and this capture
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Glacier2Lib/Application.cpp | 13 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerAdminI.cpp | 20 | ||||
-rw-r--r-- | cpp/src/Ice/RouterInfo.cpp | 18 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 34 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.h | 1 |
5 files changed, 45 insertions, 41 deletions
diff --git a/cpp/src/Glacier2Lib/Application.cpp b/cpp/src/Glacier2Lib/Application.cpp index 7cd7ea8583c..24e6c35afc2 100644 --- a/cpp/src/Glacier2Lib/Application.cpp +++ b/cpp/src/Glacier2Lib/Application.cpp @@ -200,10 +200,15 @@ Glacier2::Application::doMain(Ice::StringSeq& args, const Ice::InitializationDat assert(connection); connection->setACM(acmTimeout, IceUtil::None, Ice::HeartbeatAlways); #ifdef ICE_CPP11_MAPPING - connection->setCloseCallback([this](Ice::ConnectionPtr) - { - this->sessionDestroyed(); - }); + connection->setCloseCallback( + [self = weak_from_this()](Ice::ConnectionPtr) + { + auto s = self.lock(); + if(s) + { + s->sessionDestroyed(); + } + }); #else connection->setCloseCallback(ICE_MAKE_SHARED(CloseCallbackI, this)); #endif diff --git a/cpp/src/Ice/LoggerAdminI.cpp b/cpp/src/Ice/LoggerAdminI.cpp index de1e29429c9..113283a8d77 100644 --- a/cpp/src/Ice/LoggerAdminI.cpp +++ b/cpp/src/Ice/LoggerAdminI.cpp @@ -27,7 +27,7 @@ namespace const char* traceCategory = "Admin.Logger"; -class LoggerAdminI : public Ice::LoggerAdmin +class LoggerAdminI : public Ice::LoggerAdmin, public Ice::EnableSharedFromThis<LoggerAdminI> { public: @@ -416,15 +416,15 @@ LoggerAdminI::attachRemoteLogger(const RemoteLoggerPrx& prx, try { remoteLogger->init_async(logger->getPrefix(), initLogMessages, - [this, logger, remoteLogger]() + [self = shared_from_this(), logger, remoteLogger]() { - if(this->_traceLevel > 1) + if(self->_traceLevel > 1) { Trace trace(logger, traceCategory); trace << "init on `" << remoteLogger << "' completed successfully"; } }, - [this, logger, remoteLogger](exception_ptr e) + [self = shared_from_this(), logger, remoteLogger](exception_ptr e) { try { @@ -432,7 +432,7 @@ LoggerAdminI::attachRemoteLogger(const RemoteLoggerPrx& prx, } catch(const Ice::LocalException& e) { - this->deadRemoteLogger(remoteLogger, logger, e, "init"); + self->deadRemoteLogger(remoteLogger, logger, e, "init"); } }); } @@ -854,15 +854,15 @@ LoggerAdminLoggerI::run() #ifdef ICE_CPP11_MAPPING RemoteLoggerPrxPtr remoteLogger = *p; remoteLogger->log_async(job->logMessage, - [this, remoteLogger]() + [self = shared_from_this(), remoteLogger]() { - if(this->_loggerAdmin->getTraceLevel() > 1) + if(self->_loggerAdmin->getTraceLevel() > 1) { - Trace trace(_localLogger, traceCategory); + Trace trace(self->_localLogger, traceCategory); trace << "log on `" << remoteLogger << "' completed successfully"; } }, - [this, remoteLogger](exception_ptr e) + [self = shared_from_this(), remoteLogger](exception_ptr e) { try { @@ -874,7 +874,7 @@ LoggerAdminLoggerI::run() } catch(const LocalException& ex) { - this->_loggerAdmin->deadRemoteLogger(remoteLogger, _localLogger, ex, "log"); + self->_loggerAdmin->deadRemoteLogger(remoteLogger, self->_localLogger, ex, "log"); } }); #else diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp index f0afc392990..b12e1f88394 100644 --- a/cpp/src/Ice/RouterInfo.cpp +++ b/cpp/src/Ice/RouterInfo.cpp @@ -200,12 +200,13 @@ IceInternal::RouterInfo::getClientEndpoints(const GetClientEndpointsCallbackPtr& } #ifdef ICE_CPP11_MAPPING + RouterInfoPtr self = this; _router->getClientProxy_async( - [this, callback](const Ice::ObjectPrxPtr& proxy) + [self, callback](const Ice::ObjectPrxPtr& proxy) { - this->getClientProxyResponse(proxy, callback); + self->getClientProxyResponse(proxy, callback); }, - [this, callback](exception_ptr e) + [self, callback](exception_ptr e) { try { @@ -213,7 +214,7 @@ IceInternal::RouterInfo::getClientEndpoints(const GetClientEndpointsCallbackPtr& } catch(const Ice::Exception& ex) { - this->getClientProxyException(ex, callback); + self->getClientProxyException(ex, callback); } }); #else @@ -293,12 +294,13 @@ IceInternal::RouterInfo::addProxy(const Ice::ObjectPrxPtr& proxy, const AddProxy AddProxyCookiePtr cookie = new AddProxyCookie(callback, proxy); #ifdef ICE_CPP11_MAPPING + RouterInfoPtr self = this; _router->addProxies_async(proxies, - [this, cookie](const Ice::ObjectProxySeq& proxies) + [self, cookie](const Ice::ObjectProxySeq& proxies) { - this->addProxyResponse(proxies, cookie); + self->addProxyResponse(proxies, cookie); }, - [this, cookie](exception_ptr e) + [self, cookie](exception_ptr e) { try { @@ -306,7 +308,7 @@ IceInternal::RouterInfo::addProxy(const Ice::ObjectPrxPtr& proxy, const AddProxy } catch(const Ice::Exception& ex) { - this->addProxyException(ex, cookie); + self->addProxyException(ex, cookie); } }); #else diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index bd8ba14f4d7..27f7eb5db94 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -300,11 +300,7 @@ IceBox::ServiceManagerI::addObserver(ICE_IN(ServiceObserverPrxPtr) observer, con if(activeServices.size() > 0) { #ifdef ICE_CPP11_MAPPING - observer->servicesStarted_async(activeServices, nullptr, - [this, observer](exception_ptr ex) - { - this->observerCompleted(observer, ex); - }); + observer->servicesStarted_async(activeServices, nullptr, makeObserverCompletedCallback(observer)); #else observer->begin_servicesStarted(activeServices, _observerCompletedCB); #endif @@ -914,6 +910,18 @@ IceBox::ServiceManagerI::stopAll() #ifdef ICE_CPP11_MAPPING +function<void (exception_ptr)> +IceBox::ServiceManagerI::makeObserverCompletedCallback(const shared_ptr<ServiceObserverPrx>& observer) +{ + return [self = weak_from_this(), observer](exception_ptr ex) + { + auto s = self.lock(); + if(s) + { + s->observerCompleted(observer, ex); + } + }; +} void IceBox::ServiceManagerI::servicesStarted(const vector<string>& services, const set<shared_ptr<ServiceObserverPrx>>& observers) { @@ -921,13 +929,7 @@ IceBox::ServiceManagerI::servicesStarted(const vector<string>& services, const s { for(auto p : observers) { - p->servicesStarted_async( - services, - nullptr, - [this, p](exception_ptr ex) - { - this->observerCompleted(p, ex); - }); + p->servicesStarted_async(services, nullptr, makeObserverCompletedCallback(p)); } } } @@ -939,13 +941,7 @@ IceBox::ServiceManagerI::servicesStopped(const vector<string>& services, const s { for(auto p : observers) { - p->servicesStopped_async( - services, - nullptr, - [this, p](exception_ptr ex) - { - this->observerCompleted(p, ex); - }); + p->servicesStopped_async(services, nullptr, makeObserverCompletedCallback(p)); } } } diff --git a/cpp/src/IceBox/ServiceManagerI.h b/cpp/src/IceBox/ServiceManagerI.h index 19dbf7db8ac..8f543ba37ab 100644 --- a/cpp/src/IceBox/ServiceManagerI.h +++ b/cpp/src/IceBox/ServiceManagerI.h @@ -76,6 +76,7 @@ private: void servicesStopped(const std::vector<std::string>&, const std::set<ServiceObserverPrxPtr>&); #ifdef ICE_CPP11_MAPPING + std::function<void (std::exception_ptr)> makeObserverCompletedCallback(const std::shared_ptr<ServiceObserverPrx>&); void observerRemoved(const std::shared_ptr<ServiceObserverPrx>&, std::exception_ptr); #else void observerRemoved(const ServiceObserverPrx&, const std::exception&); |