diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-08-19 17:20:51 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-08-19 17:20:51 +0200 |
commit | f24107368fa47f911f4491f644ff3755525c91e1 (patch) | |
tree | 02dc3583ed82d81139b17191af9a9bfae40c45a9 /old/core/Event.cpp | |
parent | 2017-08-18 (diff) | |
download | AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.tar AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.tar.gz AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.tar.bz2 AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.tar.lz AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.tar.xz AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.tar.zst AltCraft-f24107368fa47f911f4491f644ff3755525c91e1.zip |
Diffstat (limited to 'old/core/Event.cpp')
-rw-r--r-- | old/core/Event.cpp | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/old/core/Event.cpp b/old/core/Event.cpp deleted file mode 100644 index 3b2cc7f..0000000 --- a/old/core/Event.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "Event.hpp" -#include <easylogging++.h> - -std::queue <Event> EventAgregator::eventsToHandle; -std::mutex EventAgregator::queueMutex; -bool EventAgregator::isStarted = false; -std::vector<EventListener*> EventAgregator::listeners; -std::mutex EventAgregator::listenersMutex; - -void EventAgregator::EventHandlingLoop() { - while (true) { - queueMutex.lock(); - if (!eventsToHandle.empty()) { - auto queue = eventsToHandle; - while (!eventsToHandle.empty()) - eventsToHandle.pop(); - queueMutex.unlock(); - - while (!queue.empty()) { - auto event = queue.front(); - listenersMutex.lock(); - for (auto& listener : listeners) { - LOG(INFO)<<"Listener notified about event"; - listener->PushEvent(event); - } - listenersMutex.unlock(); - queue.pop(); - } - - queueMutex.lock(); - } - queueMutex.unlock(); - } -} - -void EventAgregator::RegisterListener(EventListener &listener) { - listenersMutex.lock(); - LOG(INFO)<<"Registered handler "<<&listener; - listeners.push_back(&listener); - listenersMutex.unlock(); -} - -void EventAgregator::UnregisterListener(EventListener &listener) { - listenersMutex.lock(); - LOG(INFO)<<"Unregistered handler "<<&listener; - listeners.erase(std::find(listeners.begin(), listeners.end(), &listener)); - listenersMutex.unlock(); -} - - - -EventListener::EventListener() { - EventAgregator::RegisterListener(*this); -} - -EventListener::~EventListener() { - EventAgregator::UnregisterListener(*this); -} - -void EventListener::PushEvent(Event event) { - eventsMutex.lock(); - LOG(INFO)<<"Pushed event to queue"; - events.push(event); - eventsMutex.unlock(); -} - -/*void EventListener::RegisterHandler(EventType type, std::function<void(void*)> handler) { - handlers[type] = handler; -}*/ - -bool EventListener::IsEventsQueueIsNotEmpty() { - eventsMutex.lock(); - bool value = !events.empty(); - eventsMutex.unlock(); - return value; -}
\ No newline at end of file |