diff options
author | Jose <jose@zeroc.com> | 2015-12-29 14:07:58 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2015-12-29 14:07:58 +0100 |
commit | 2715a0e3b479b84fc24efa93882df47c2b373d73 (patch) | |
tree | a5971eb833bdb5a13def11910a47e56302213d2c /cpp/src/IceBox/ServiceManagerI.cpp | |
parent | .gitignore update (diff) | |
download | ice-2715a0e3b479b84fc24efa93882df47c2b373d73.tar.bz2 ice-2715a0e3b479b84fc24efa93882df47c2b373d73.tar.xz ice-2715a0e3b479b84fc24efa93882df47c2b373d73.zip |
C++11 mapping fixes for IceBox
Diffstat (limited to 'cpp/src/IceBox/ServiceManagerI.cpp')
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 109 |
1 files changed, 103 insertions, 6 deletions
diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index 6dfd8a55001..bd8ba14f4d7 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -77,7 +77,9 @@ IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator, int& argc _pendingStatusChanges(false), _traceServiceObserver(0) { +#ifndef ICE_CPP11_MAPPING const_cast<CallbackPtr&>(_observerCompletedCB) = newCallback(this, &ServiceManagerI::observerCompleted); +#endif _logger = _communicator->getLogger(); PropertiesPtr props = _communicator->getProperties(); @@ -118,7 +120,7 @@ IceBox::ServiceManagerI::getSliceChecksums(const Current&) const } void -IceBox::ServiceManagerI::startService(const string& name, const Current&) +IceBox::ServiceManagerI::startService(ICE_IN(string) name, const Current&) { ServiceInfo info; { @@ -194,7 +196,7 @@ IceBox::ServiceManagerI::startService(const string& name, const Current&) } void -IceBox::ServiceManagerI::stopService(const string& name, const Current&) +IceBox::ServiceManagerI::stopService(ICE_IN(string) name, const Current&) { ServiceInfo info; { @@ -270,7 +272,7 @@ IceBox::ServiceManagerI::stopService(const string& name, const Current&) } void -IceBox::ServiceManagerI::addObserver(const ServiceObserverPrx& observer, const Current&) +IceBox::ServiceManagerI::addObserver(ICE_IN(ServiceObserverPrxPtr) observer, const Current&) { // // Null observers and duplicate registrations are ignored @@ -297,7 +299,15 @@ IceBox::ServiceManagerI::addObserver(const ServiceObserverPrx& observer, const C if(activeServices.size() > 0) { +#ifdef ICE_CPP11_MAPPING + observer->servicesStarted_async(activeServices, nullptr, + [this, observer](exception_ptr ex) + { + this->observerCompleted(observer, ex); + }); +#else observer->begin_servicesStarted(activeServices, _observerCompletedCB); +#endif } } } @@ -313,7 +323,7 @@ IceBox::ServiceManagerI::start() { try { - ServiceManagerPtr obj = this; + ServiceManagerPtr obj = ICE_SHARED_FROM_THIS; PropertiesPtr properties = _communicator->getProperties(); // @@ -470,7 +480,7 @@ IceBox::ServiceManagerI::start() // try { - _communicator->addAdminFacet(this, "IceBox.ServiceManager"); + _communicator->addAdminFacet(ICE_SHARED_FROM_THIS, "IceBox.ServiceManager"); _communicator->getAdmin(); } catch(const ObjectAdapterDeactivatedException&) @@ -667,7 +677,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, SERVICE_FACTORY factory = reinterpret_cast<SERVICE_FACTORY>(sym); try { - info.service = factory(_communicator); + info.service = ServicePtr(factory(_communicator)); } catch(const FailureException&) { @@ -897,8 +907,75 @@ IceBox::ServiceManagerI::stopAll() servicesStopped(stoppedServices, _observers); +#ifndef ICE_CPP11_MAPPING _observerCompletedCB = 0; // Break cyclic reference count. +#endif +} + +#ifdef ICE_CPP11_MAPPING + +void +IceBox::ServiceManagerI::servicesStarted(const vector<string>& services, const set<shared_ptr<ServiceObserverPrx>>& observers) +{ + if(services.size() > 0) + { + for(auto p : observers) + { + p->servicesStarted_async( + services, + nullptr, + [this, p](exception_ptr ex) + { + this->observerCompleted(p, ex); + }); + } + } +} + +void +IceBox::ServiceManagerI::servicesStopped(const vector<string>& services, const set<shared_ptr<ServiceObserverPrx>>& observers) +{ + if(services.size() > 0) + { + for(auto p : observers) + { + p->servicesStopped_async( + services, + nullptr, + [this, p](exception_ptr ex) + { + this->observerCompleted(p, ex); + }); + } + } +} + +void +IceBox::ServiceManagerI::observerRemoved(const shared_ptr<ServiceObserverPrx>& observer, exception_ptr err) +{ + if(_traceServiceObserver >= 1) + { + try + { + rethrow_exception(err); + } + catch(const CommunicatorDestroyedException&) + { + // + // CommunicatorDestroyedException may occur during shutdown. The observer notification has + // been sent, but the communicator was destroyed before the reply was received. We do not + // log a message for this exception. + // + } + catch(const exception& ex) + { + Trace out(_logger, "IceBox.ServiceObserver"); + out << "Removed service observer " << _communicator->proxyToString(observer) + << "\nafter catching " << ex.what(); + } + } } +#else void IceBox::ServiceManagerI::servicesStarted(const vector<string>& services, const set<ServiceObserverPrx>& observers) @@ -942,6 +1019,7 @@ IceBox::ServiceManagerI::observerRemoved(const ServiceObserverPrx& observer, con } } } +#endif Ice::PropertiesPtr IceBox::ServiceManagerI::createServiceProperties(const string& service) @@ -976,6 +1054,24 @@ IceBox::ServiceManagerI::createServiceProperties(const string& service) return properties; } +#ifdef ICE_CPP11_MAPPING +void +ServiceManagerI::observerCompleted(const shared_ptr<ServiceObserverPrx>& observer, exception_ptr ex) +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this); + // + // It's possible to remove several times the same observer, e.g. multiple concurrent + // requests that fail + // + auto p = _observers.find(observer); + if(p != _observers.end()) + { + auto observer = *p; + _observers.erase(p); + observerRemoved(observer, ex); + } +} +#else void ServiceManagerI::observerCompleted(const Ice::AsyncResultPtr& result) { @@ -1001,6 +1097,7 @@ ServiceManagerI::observerCompleted(const Ice::AsyncResultPtr& result) } } } +#endif void IceBox::ServiceManagerI::destroyServiceCommunicator(const string& service, const CommunicatorPtr& communicator) |