refactoring to interfaces

This commit is contained in:
Jonas Zeunert
2018-06-14 21:09:40 +02:00
parent ceb677530c
commit 6a6a10517d
5 changed files with 43 additions and 367 deletions

View File

@@ -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:

View File

@@ -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);
}

View File

@@ -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;