|
@@ -10,13 +10,13 @@
|
|
#include <ls-std/core/exception/EventNotHandledException.hpp>
|
|
#include <ls-std/core/exception/EventNotHandledException.hpp>
|
|
#include <ls-std/event/EventListener.hpp>
|
|
#include <ls-std/event/EventListener.hpp>
|
|
#include <ls-std/event/EventManager.hpp>
|
|
#include <ls-std/event/EventManager.hpp>
|
|
-#include <utility>
|
|
|
|
|
|
|
|
using ls::std::core::Class;
|
|
using ls::std::core::Class;
|
|
using ls::std::core::EventNotHandledException;
|
|
using ls::std::core::EventNotHandledException;
|
|
using ls::std::event::Event;
|
|
using ls::std::event::Event;
|
|
using ls::std::event::EventListener;
|
|
using ls::std::event::EventListener;
|
|
using ls::std::event::EventManager;
|
|
using ls::std::event::EventManager;
|
|
|
|
+using ls::std::event::EventParameter;
|
|
using ls::std::event::type::event_action;
|
|
using ls::std::event::type::event_action;
|
|
using ls::std::event::type::event_listeners;
|
|
using ls::std::event::type::event_listeners;
|
|
using ls::std::event::type::listener_id;
|
|
using ls::std::event::type::listener_id;
|
|
@@ -60,11 +60,21 @@ void EventManager::invoke(const Event &_event)
|
|
{
|
|
{
|
|
throw EventNotHandledException("event " + _event.getClassName() + " is not known by event manager");
|
|
throw EventNotHandledException("event " + _event.getClassName() + " is not known by event manager");
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+
|
|
|
|
+ const auto &listeners = this->inventory[_event.getClassName()];
|
|
|
|
+ EventManager::_notifyListeners(listeners);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EventManager::invoke(const Event &_event, const EventParameter &_parameter)
|
|
|
|
+{
|
|
|
|
+ if (!this->_observesEvent(_event))
|
|
{
|
|
{
|
|
- const auto &listeners = this->inventory[_event.getClassName()];
|
|
|
|
- EventManager::_notifyListeners(listeners);
|
|
|
|
|
|
+ throw EventNotHandledException("event " + _event.getClassName() + " is not known by event manager");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ const auto &listeners = this->inventory[_event.getClassName()];
|
|
|
|
+ EventManager::_giveListenersParameter(listeners, _parameter);
|
|
|
|
+ EventManager::_notifyListeners(listeners);
|
|
}
|
|
}
|
|
|
|
|
|
listener_id EventManager::requestListenerId()
|
|
listener_id EventManager::requestListenerId()
|
|
@@ -101,6 +111,14 @@ void EventManager::unsubscribeListenerForEvent(const shared_ptr<EventListener> &
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void EventManager::_giveListenersParameter(const event_listeners &_listeners, const EventParameter &_parameter)
|
|
|
|
+{
|
|
|
|
+ for (const auto &[listener, action] : _listeners)
|
|
|
|
+ {
|
|
|
|
+ listener->setParameter(_parameter);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void EventManager::_notifyListeners(const event_listeners &_listeners)
|
|
void EventManager::_notifyListeners(const event_listeners &_listeners)
|
|
{
|
|
{
|
|
for (const auto &[listener, eventAction] : _listeners)
|
|
for (const auto &[listener, eventAction] : _listeners)
|