Files
plains/src/core/include/EventBus.hpp
T

56 lines
900 B
C++

#ifndef EVENT_BUS_HPP
#define EVENT_BUS_HPP
#include "Logger.hpp"
#include <thread>
#include <string>
#include <vector>
#include <memory>
#include <mutex>
namespace Plains {
namespace Core {
using std::thread;
using std::string;
using std::vector;
using std::mutex;
using std::unique_ptr;
class EventSubscriber {
public:
virtual void callback() = 0;
};
class Event {
public:
Event(const string _id);
~Event();
const string& getID() const;
void fire();
void subscribe(EventSubscriber* es);
private:
const string _id;
vector<EventSubscriber*> _subscribers;
mutex _mutex;
};
class EventBus {
public:
EventBus(Logger& logger);
~EventBus();
Event& registerEvent(const string& eventID);
private:
void run();
private:
Logger& _logger;
thread _thread;
vector<Event*> _events;
mutex _mutex;
};
}}
#endif