threading again

This commit is contained in:
Jonas Zeunert
2018-05-06 23:19:02 +02:00
parent c2fb59139b
commit c1a29d8bea
11 changed files with 20856 additions and 24 deletions

View File

@@ -8,18 +8,25 @@
#ifndef DETECTOR_H_
#define DETECTOR_H_
#include <queue>
#include <vector>
#include <thread>
#include <map>
#include <mutex>
#include "InputEvent.h"
#include "InputEventHandler.h"
#define SLEEP_DURATION_NANO 900
namespace Input
{
class InputEventHandler
{
public:
void handle(InputEvent& event);
};
class Detector
{
@@ -27,21 +34,27 @@ public:
Detector(std::map<std::string, char> input_config, std::map<char, InputEvent> events);
~Detector();
void detect();
void register_input_event_handler(InputEventHandler* handler);
void unregister_input_event_handler(InputEventHandler* handler);
private:
void notify_handlers();
void detect();
bool check_inputs(char& address);
void notify_handlers(InputEvent& event);
private:
std::map<std::string, char> gpio;
std::map<char, InputEvent> input_events;
std::queue<InputEvent> event_queue;
std::set<InputEventHandler*> event_handler;
bool is_running;
std::thread detect_thread;
std::thread notify_thread;
std::mutex event_handler_mutex;
};
}