diff options
author | Benoit Foucher <benoit@zeroc.com> | 2014-11-25 11:51:58 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2014-11-25 11:51:58 +0100 |
commit | 60e2d367a2f249a10b406ca56929787c7cc7c4cc (patch) | |
tree | ff2bec97e9de12dcf11bbc473e9f1d856d52aba0 /cpp/src | |
parent | Fixed ICE-5978 & ICE-5973: ACM test failures (diff) | |
download | ice-60e2d367a2f249a10b406ca56929787c7cc7c4cc.tar.bz2 ice-60e2d367a2f249a10b406ca56929787c7cc7c4cc.tar.xz ice-60e2d367a2f249a10b406ca56929787c7cc7c4cc.zip |
Fix for ICE-5970: use smart pointer instead of raw pointer for the lookup object
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceDiscovery/LookupI.cpp | 50 | ||||
-rw-r--r-- | cpp/src/IceDiscovery/LookupI.h | 9 | ||||
-rw-r--r-- | cpp/src/IceDiscovery/PluginI.cpp | 11 | ||||
-rw-r--r-- | cpp/src/IceDiscovery/PluginI.h | 1 |
4 files changed, 39 insertions, 32 deletions
diff --git a/cpp/src/IceDiscovery/LookupI.cpp b/cpp/src/IceDiscovery/LookupI.cpp index 09a63cb85a7..4e7a74a63d2 100644 --- a/cpp/src/IceDiscovery/LookupI.cpp +++ b/cpp/src/IceDiscovery/LookupI.cpp @@ -19,7 +19,7 @@ using namespace std; using namespace Ice; using namespace IceDiscovery; -IceDiscovery::Request::Request(LookupI* lookup, int retryCount) : _lookup(lookup), _nRetry(retryCount) +IceDiscovery::Request::Request(const LookupIPtr& lookup, int retryCount) : _lookup(lookup), _nRetry(retryCount) { } @@ -110,6 +110,28 @@ LookupI::LookupI(const LocatorRegistryIPtr& registry, const LookupPrx& lookup, c { } +LookupI::~LookupI() +{ +} + +void +LookupI::destroy() +{ + Lock sync(*this); + for(map<Identity, ObjectRequestPtr>::const_iterator p = _objectRequests.begin(); p != _objectRequests.end(); ++p) + { + p->second->finished(0); + _timer->cancel(p->second); + } + + for(map<string, AdapterRequestPtr>::const_iterator p = _adapterRequests.begin(); p != _adapterRequests.end(); ++p) + { + p->second->finished(0); + _timer->cancel(p->second); + } + _adapterRequests.clear(); +} + void LookupI::setLookupReply(const LookupReplyPrx& lookupReply) { @@ -118,7 +140,7 @@ LookupI::setLookupReply(const LookupReplyPrx& lookupReply) void LookupI::findObjectById(const string& domainId, const Ice::Identity& id, const IceDiscovery::LookupReplyPrx& reply, - const Ice::Current& c) + const Ice::Current&) { if(domainId != _domainId) { @@ -131,13 +153,13 @@ LookupI::findObjectById(const string& domainId, const Ice::Identity& id, const I // // Reply to the mulicast request using the given proxy. // - getLookupReply(reply, c)->begin_foundObjectById(id, proxy); + reply->begin_foundObjectById(id, proxy); } } void LookupI::findAdapterById(const string& domainId, const std::string& adapterId, - const IceDiscovery::LookupReplyPrx& reply, const Ice::Current& c) + const IceDiscovery::LookupReplyPrx& reply, const Ice::Current&) { if(domainId != _domainId) { @@ -151,7 +173,7 @@ LookupI::findAdapterById(const string& domainId, const std::string& adapterId, // // Reply to the multicast request using the given proxy. // - getLookupReply(reply, c)->begin_foundAdapterById(adapterId, proxy, isReplicaGroup); + reply->begin_foundAdapterById(adapterId, proxy, isReplicaGroup); } } @@ -267,24 +289,6 @@ LookupI::adapterRequestTimedOut(const AdapterRequestPtr& request) } } -LookupReplyPrx -LookupI::getLookupReply(const LookupReplyPrx& reply, const Ice::Current& current) const -{ - // Ice::UDPConnectionInfoPtr info = Ice::UDPConnectionInfoPtr::dynamicCast(current.con->getInfo()); - // if(info) - // { - // Ice::CommunicatorPtr com = current.adapter->getCommunicator(); - // ostringstream os; - // os << "\"" << com->identityToString(reply->ice_getIdentity()) << "\""; - // os << ":udp -h " << info->remoteAddress << " -p " << info->remotePort; - // return LookupReplyPrx::uncheckedCast(com->stringToProxy(os.str())->ice_datagram()); - // } - // else - { - return reply; - } -} - LookupReplyI::LookupReplyI(const LookupIPtr& lookup) : _lookup(lookup) { } diff --git a/cpp/src/IceDiscovery/LookupI.h b/cpp/src/IceDiscovery/LookupI.h index 4a0f7a5c887..b97382d2c22 100644 --- a/cpp/src/IceDiscovery/LookupI.h +++ b/cpp/src/IceDiscovery/LookupI.h @@ -25,13 +25,13 @@ class Request : public IceUtil::TimerTask { public: - Request(LookupI*, int); + Request(const LookupIPtr&, int); virtual bool retry(); protected: - LookupI* _lookup; + LookupIPtr _lookup; int _nRetry; }; @@ -115,6 +115,9 @@ class LookupI : public Lookup, private IceUtil::Mutex public: LookupI(const LocatorRegistryIPtr&, const LookupPrx&, const Ice::PropertiesPtr&); + virtual ~LookupI(); + + void destroy(); void setLookupReply(const LookupReplyPrx&); @@ -146,8 +149,6 @@ public: private: - LookupReplyPrx getLookupReply(const LookupReplyPrx&, const Ice::Current&) const; - LocatorRegistryIPtr _registry; const LookupPrx _lookup; LookupReplyPrx _lookupReply; diff --git a/cpp/src/IceDiscovery/PluginI.cpp b/cpp/src/IceDiscovery/PluginI.cpp index ab9482cc1ce..f62b61e955a 100644 --- a/cpp/src/IceDiscovery/PluginI.cpp +++ b/cpp/src/IceDiscovery/PluginI.cpp @@ -121,16 +121,16 @@ PluginI::initialize() // // Add lookup and lookup reply Ice objects // - LookupIPtr lookup = new LookupI(locatorRegistry, LookupPrx::uncheckedCast(lookupPrx), properties); - _multicastAdapter->add(lookup, _communicator->stringToIdentity("IceDiscovery/Lookup")); + _lookup = new LookupI(locatorRegistry, LookupPrx::uncheckedCast(lookupPrx), properties); + _multicastAdapter->add(_lookup, _communicator->stringToIdentity("IceDiscovery/Lookup")); - Ice::ObjectPrx lookupReply = _replyAdapter->addWithUUID(new LookupReplyI(lookup))->ice_datagram(); - lookup->setLookupReply(LookupReplyPrx::uncheckedCast(lookupReply)); + Ice::ObjectPrx lookupReply = _replyAdapter->addWithUUID(new LookupReplyI(_lookup))->ice_datagram(); + _lookup->setLookupReply(LookupReplyPrx::uncheckedCast(lookupReply)); // // Setup locator on the communicator. // - Ice::ObjectPrx loc = _locatorAdapter->addWithUUID(new LocatorI(lookup, locatorRegistryPrx)); + Ice::ObjectPrx loc = _locatorAdapter->addWithUUID(new LocatorI(_lookup, locatorRegistryPrx)); _communicator->setDefaultLocator(Ice::LocatorPrx::uncheckedCast(loc)); _multicastAdapter->activate(); @@ -144,4 +144,5 @@ PluginI::destroy() _multicastAdapter->destroy(); _replyAdapter->destroy(); _locatorAdapter->destroy(); + _lookup->destroy(); } diff --git a/cpp/src/IceDiscovery/PluginI.h b/cpp/src/IceDiscovery/PluginI.h index f5d4eb9f478..32f7bf570e3 100644 --- a/cpp/src/IceDiscovery/PluginI.h +++ b/cpp/src/IceDiscovery/PluginI.h @@ -31,6 +31,7 @@ private: Ice::ObjectAdapterPtr _multicastAdapter; Ice::ObjectAdapterPtr _replyAdapter; Ice::ObjectAdapterPtr _locatorAdapter; + LookupIPtr _lookup; }; }; |