void ObserverTopic::unsubscribe(const Ice::ObjectPrx& observer, const string& name) { Lock sync(*this); Ice::EncodingVersion v = IceInternal::getCompatibleEncoding(observer->ice_getEncodingVersion()); map<Ice::EncodingVersion, IceStorm::TopicPrx>::const_iterator p = _topics.find(v); if(p == _topics.end()) { return; } try { p->second->unsubscribe(observer); } catch(const Ice::ObjectAdapterDeactivatedException&) { } assert(observer); if(!name.empty()) { assert(_syncSubscribers.find(name) != _syncSubscribers.end()); _syncSubscribers.erase(name); map<int, set<string> >::iterator p = _waitForUpdates.begin(); bool notifyMonitor = false; while(p != _waitForUpdates.end()) { p->second.erase(name); if(p->second.empty()) { _waitForUpdates.erase(p++); notifyMonitor = true; } else { ++p; } } if(notifyMonitor) { notifyAll(); } } }
int ObserverTopic::subscribe(const Ice::ObjectPrx& obsv, const string& name) { Lock sync(*this); if(_topics.empty()) { return -1; } assert(obsv); try { IceStorm::QoS qos; qos["reliability"] = "ordered"; Ice::EncodingVersion v = IceInternal::getCompatibleEncoding(obsv->ice_getEncodingVersion()); map<Ice::EncodingVersion, IceStorm::TopicPrx>::const_iterator p = _topics.find(v); if(p == _topics.end()) { Ice::Warning out(_logger); out << "unsupported encoding version for observer `" << obsv << "'"; return -1; } initObserver(p->second->subscribeAndGetPublisher(qos, obsv->ice_twoway())); } catch(const IceStorm::AlreadySubscribed&) { throw ObserverAlreadyRegisteredException(obsv->ice_getIdentity()); } if(!name.empty()) { assert(_syncSubscribers.find(name) == _syncSubscribers.end()); _syncSubscribers.insert(name); addExpectedUpdate(_serial, name); return _serial; } return -1; }