示例#1
0
void foreign_callback_remove(ForeignCallback cb) {
	if(callback_list.empty())
		return;

	/* FIXME: lock this somehow */
	CallbackListIt it = callback_list.begin(), it_end = callback_list.end();
	while(it != it_end) {
		if((*it).cb == cb)
			it = callback_list.erase(it);
		else
			++it;
	}
}
示例#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;
}