M2-PT-DRP/source/EventManager.hpp

30 lines
916 B
C++

#pragma once
#include <map>
#include <memory>
#include <thread>
#include "Context.hpp"
#include "events/types.hpp"
#include "events/base/BaseEvent.hpp"
#include "tasks/types.hpp"
#include "tasks/base/BaseTask.hpp"
class EventManager {
public:
EventManager(const std::string& address, const std::string& port, bool useIpv6 = false);
void loop();
void loopSender();
void loopReceiver();
private:
std::thread senderThread; /// the thread sending communication
std::thread receiverThread; /// the thread receiving communication
std::map<drp::event::EventType, std::shared_ptr<drp::event::BaseEvent>> eventRegistry; /// hold the event to call depending on the event type
std::map<drp::task::TaskType, std::shared_ptr<drp::task::BaseTask>> taskRegistry; /// hold the task to call depending on the server status
Context context; /// context used between the events types
};