refactoring to interfaces
This commit is contained in:
@@ -14,19 +14,12 @@
|
||||
#ifndef DETECTOR_H_
|
||||
#define DETECTOR_H_
|
||||
|
||||
#include <thread>
|
||||
#include <map>
|
||||
|
||||
#include "../utilities/InputGPIOInterface.h"
|
||||
#include "Event.hpp"
|
||||
#include "EventNotifier.h"
|
||||
|
||||
#define SLEEP_DURATION_NANO 900
|
||||
#include "IDetector.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
class Detector
|
||||
class Detector : IDetector
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
@@ -29,19 +29,19 @@ EventNotifier::~EventNotifier()
|
||||
notify_thread.join();
|
||||
}
|
||||
|
||||
void EventNotifier::register_event_handler(EventHandler* handler)
|
||||
void EventNotifier::register_event_handler(IEventHandler* handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||
event_handler.insert(handler);
|
||||
}
|
||||
|
||||
void EventNotifier::unregister_event_handler(EventHandler* handler)
|
||||
void EventNotifier::unregister_event_handler(IEventHandler* handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||
event_handler.erase(handler);
|
||||
}
|
||||
|
||||
void EventNotifier::distribute_event(Event& event)
|
||||
void EventNotifier::distribute_event(IEvent& event)
|
||||
{
|
||||
event_queue.push(event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#ifndef SRC_INPUT_EVENTNOTIFIER_H_
|
||||
#define SRC_INPUT_EVENTNOTIFIER_H_
|
||||
|
||||
#include "IEventNotifier.h"
|
||||
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
@@ -21,24 +23,24 @@
|
||||
namespace Input
|
||||
{
|
||||
|
||||
class EventNotifier
|
||||
class EventNotifier : IEventNotifier
|
||||
{
|
||||
|
||||
public:
|
||||
EventNotifier();
|
||||
~EventNotifier();
|
||||
|
||||
void register_event_handler(EventHandler* handler);
|
||||
void unregister_event_handler(EventHandler* handler);
|
||||
void register_event_handler(IEventHandler* handler);
|
||||
void unregister_event_handler(IEventHandler* handler);
|
||||
|
||||
void distribute_event(Event& event);
|
||||
void distribute_event(IEvent& event);
|
||||
|
||||
private:
|
||||
void notify();
|
||||
|
||||
private:
|
||||
BlockingQueue<Event> event_queue;
|
||||
std::set<EventHandler*> event_handler;
|
||||
BlockingQueue<IEvent> event_queue;
|
||||
std::set<IEventHandler*> event_handler;
|
||||
|
||||
bool is_running;
|
||||
std::thread notify_thread;
|
||||
|
||||
Reference in New Issue
Block a user