wip
This commit is contained in:
1 parent
f25a834fbd
commit
062f9c8c69
6 files changed
+99
-34
No files matched your search
+34
-16
@@ -1,10 +1,9 @@
|
||||
#include "EventBus.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace Plains {
|
||||
namespace Core {
|
||||
|
||||
// EventBus Class
|
||||
// ============================== EventBus Class ==============================
|
||||
|
||||
EventBus::EventBus(Logger& logger) : _logger(logger) {
|
||||
_logger.debug.ln ("Starting Event Bus...");
|
||||
@@ -17,29 +16,48 @@ EventBus::~EventBus() {
|
||||
_logger.debug.ln ("EventBus has been shut down.");
|
||||
}
|
||||
|
||||
Event* EventBus::registerEvent(const string eventID) {
|
||||
_logger.debug << "Registering new Event " << eventID << Logger::commit;
|
||||
Event& EventBus::registerEvent(const string& eventID) {
|
||||
bool eventFound = false;
|
||||
for ( const auto event : _events ) {
|
||||
if (event->getID() == eventID) {
|
||||
_logger.debug << "Event '" << eventID << "' found" << Logger::commit;
|
||||
return *event;
|
||||
}
|
||||
}
|
||||
//If event with that id does not exist, create it:
|
||||
Event* event = new Event(eventID);
|
||||
_events.push_back(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
Event* EventBus::getEvent(const string& eventID) {
|
||||
_logger.debug.ln("Registering new Event...");
|
||||
//Temporarily return nothing:
|
||||
return NULL;
|
||||
if (!eventFound) {
|
||||
_logger.debug << "Registering new Event '" << eventID << "'" << Logger::commit;
|
||||
Event* event = new Event(eventID);
|
||||
_events.push_back(event);
|
||||
return *event;
|
||||
}
|
||||
}
|
||||
|
||||
void EventBus::run() {
|
||||
_logger.debug.ln("Hi from EventBus run method! From within Event Thread!");
|
||||
//_logger.debug.ln("Hi from EventBus run method! From within Event Thread!");
|
||||
}
|
||||
|
||||
// Event Class
|
||||
// =============================== Event Class ================================
|
||||
|
||||
Event::Event(const string id) : _id(id) {}
|
||||
|
||||
void Event::subscribe(EventSubscriber* es) { _subscribers.push_back(es); }
|
||||
Event::~Event() {
|
||||
|
||||
}
|
||||
|
||||
const string& Event::getID() const {
|
||||
return _id;
|
||||
};
|
||||
|
||||
void Event::subscribe(EventSubscriber* es) {
|
||||
_subscribers.push_back(es);
|
||||
}
|
||||
|
||||
void Event::fire() {
|
||||
for (auto subscriber : _subscribers) {
|
||||
subscriber->callback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user