Пример #1
0
	//------------------------------------------------------------------------
	Result EventManager::emit(const std::string& name, SharedPtr<Event> event)
	{
		// Profiling of the engine
		_nrEngineProfile("EventManager.emit");


		// if user want to send the message to all channels
		if (name.length() == 0){
			NR_Log(Log::LOG_ENGINE, Log::LL_CHATTY, "EventManager: Emit event '%s' to all channels", event->getEventType());
			ChannelDatabase::iterator it = mChannelDb.begin();
			for (; it != mChannelDb.end(); it++)
				it->second->push(event);

		}else{
			NR_Log(Log::LOG_ENGINE, Log::LL_CHATTY, "EventManager: Emit event '%s' to '%s'", event->getEventType(), name.c_str());
			// get the channel according to the name and emit the message
			SharedPtr<EventChannel> channel = getChannel(name);
			if (channel == NULL)
				return EVENT_CHANNEL_NOT_EXISTS;

			channel->push(event);
		}

		// ok
		return OK;
	}
	//------------------------------------------------------------------------
	void EventChannel::deliver()
	{
		// Profiling of the engine
		_nrEngineProfile("EventChannel.deliver");

		// we go through all elements in our event queue and deliver
		// the messages from the queue to connected actors
		while (!mEventQueue.empty()){
			emit(mEventQueue.top());
			mEventQueue.pop();
		}

	}
	//------------------------------------------------------------------------
	void EventChannel::_disconnectAll()
	{
		// Profiling of the engine
		_nrEngineProfile("EventChannel._disconnectAll");

		// some logging
		NR_Log(Log::LOG_ENGINE, Log::LL_DEBUG, "EventChannel (%s): Disconnect all actors", getName().c_str());

		// iterate through all connections and close them
		ActorDatabase::iterator it = mActorDb.begin();
		for (; it != mActorDb.end(); it++){
			mActorDb.erase(it);
			it->second->_noticeDisconnected(this);
		}

	}