From dda483a63217585bc22a3b3c5392efcc2117ec57 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 30 Dec 2015 12:52:26 +0100 Subject: Fixes to C++11 lambdas and this capture --- cpp/src/IceBox/ServiceManagerI.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'cpp/src/IceBox/ServiceManagerI.cpp') 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 +IceBox::ServiceManagerI::makeObserverCompletedCallback(const shared_ptr& 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& services, const set>& observers) { @@ -921,13 +929,7 @@ IceBox::ServiceManagerI::servicesStarted(const vector& 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& 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)); } } } -- cgit v1.2.3