Beispiel #1
0
// *****************************************************************************
void cEventManager::VRemoveListener(const EventListenerCallBackFn & fnListener,
	const EventType & eventType)
{
	bool success = false;
	Log_Write(ILogger::LT_EVENT, 2, "Attempting to remove delegate function from event type " + eventType.GetString());
	
	EventListenerList & eventListeners = m_eventListeners[eventType.GetHash()];

	auto findIt = m_eventListeners.find(eventType.GetHash());
    if (findIt != m_eventListeners.end())
	{
		EventListenerList & listeners = findIt->second;
		for (auto it = listeners.begin(); it != listeners.end(); it++)
		{
			if (fnListener == (*it))
			{
				listeners.erase(it);
				Log_Write(ILogger::LT_EVENT, 2, "Successfully removed delegate for event type " + eventType.GetString());
				return;
			}
		}
	}

	if(!success)
	{
		Log_Write(ILogger::LT_WARNING, 2, "Attempting to double-register a listener for event " + eventType.GetString());
	}
}
Beispiel #2
0
// *****************************************************************************
void cEventManager::VAbortEvent(const EventType & eventType, const bool allEVents)
{
	EventListenerMap::iterator findIt = m_eventListeners.find(eventType.GetHash());

	if (findIt != m_eventListeners.end())
    {
        EventQueue& eventQueue = m_queues[m_activeQueue];
        auto it = eventQueue.begin();
        while (it != eventQueue.end())
        {
            // Removing an item from the queue will invalidate the iterator, so have it point to the next member.  All
            // work inside this loop will be done using thisIt.
            auto thisIt = it;
            ++it;

			if ((*thisIt)->VGetEventID() == eventType.GetHash())
	        {
		        eventQueue.erase(thisIt);
		        if (!allEVents)
			        break;
	        }
        }
    }
}
Beispiel #3
0
// *****************************************************************************
void cEventManager::VAddListener(const EventListenerCallBackFn & fnListener,
	const EventType & eventType)
{
	Log_Write(ILogger::LT_EVENT, 2, "Attempting to add listener for event " + eventType.GetString());
	
	EventListenerList & eventListeners = m_eventListeners[eventType.GetHash()];

    for (auto it = eventListeners.begin(); it != eventListeners.end(); it++)
    {
		if (fnListener.target_type() == (*it).target_type())
        {
			Log_Write(ILogger::LT_WARNING, 2, "Attempting to double-register a listener for event " + eventType.GetString());
            return;
        }
    }

	eventListeners.push_back(fnListener);
	Log_Write(ILogger::LT_EVENT, 2, "Successfully added delegate for event type " + eventType.GetString());
}