Exemplo n.º 1
0
void MessageService::publish(std::string message, StringMap params) {
    comsSem.wait();
    
    SubscriptionMap::const_iterator got = subscriptions.find(message);
    
    if(got != subscriptions.end()) {
        CallbackList messageList = got->second;
        
        for(CallbackList::size_type i = 0; i < messageList.size(); i++) {
            messageList[i](params);
        }
    }
    
    comsSem.signal();
}
Exemplo n.º 2
0
bool CallbackMainDispatcher::unregisterCallback(int callbackId) {
	CallbackList newEventList;
	{
		TelldusCore::MutexLocker locker(&d->mutex);
		for(CallbackList::iterator callback_it = d->callbackList.begin(); callback_it != d->callbackList.end(); ++callback_it) {
			if ( (*callback_it)->id != callbackId ) {
				continue;
			}
			newEventList.splice(newEventList.begin(), d->callbackList, callback_it);
			break;
		}
	}
	if (newEventList.size()) {
		CallbackList::iterator it = newEventList.begin();
		{ //Lock and unlock to make sure no one else uses the object
			TelldusCore::MutexLocker locker( &(*it)->mutex );
		}
		delete (*it);
		newEventList.erase(it);
		return true;
	}
	return false;
}