Merge branch 'master' of https://github.com/swinginbird/flippr-code
This commit is contained in:
@@ -19,6 +19,8 @@ Detector::Detector(InputGPIOInterface* input_gpio_interface, std::map<char, Even
|
||||
input_gpio_interface(input_gpio_interface), events(events), is_running(true), event_notifier(event_notifier)
|
||||
{
|
||||
detect_thread = std::thread(&Detector::detect, this);
|
||||
|
||||
CLOG(WARNING, INPUT_LOGGER) << "Created Detector";
|
||||
}
|
||||
|
||||
Detector::~Detector()
|
||||
|
||||
@@ -11,13 +11,18 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "../utilities/config.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
Event(char address, char priority, std::string name) : address(address), priority(priority), name(name){}
|
||||
Event(char address, char priority, std::string name) : address(address), priority(priority), name(name)
|
||||
{
|
||||
CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
||||
}
|
||||
|
||||
bool operator==(const Event& other)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "InputDriver.hpp"
|
||||
#include "Event.hpp"
|
||||
#include "Detector.h"
|
||||
#include "../utilities/config.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
@@ -26,6 +27,8 @@ public:
|
||||
input_driver(input_driver)
|
||||
{
|
||||
this->input_driver->register_event_handler(this);
|
||||
|
||||
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
|
||||
}
|
||||
|
||||
virtual ~EventHandler()
|
||||
@@ -35,7 +38,10 @@ public:
|
||||
}
|
||||
|
||||
// This function is intended to be non pure, if it is called when the derived class doesn't exist anymore
|
||||
virtual void handle(Event& event);
|
||||
virtual void handle(Event& event)
|
||||
{
|
||||
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<InputDriver> input_driver;
|
||||
|
||||
@@ -18,6 +18,8 @@ EventNotifier::EventNotifier()
|
||||
: is_running(true)
|
||||
{
|
||||
notify_thread = std::thread(&EventNotifier::notify, this);
|
||||
|
||||
CLOG(INFO, INPUT_LOGGER) << "Created EventNotifier and started thread";
|
||||
}
|
||||
|
||||
EventNotifier::~EventNotifier()
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#include "../utilities/config.h"
|
||||
|
||||
|
||||
#ifndef SRC_INPUT_INPUTDRIVER_HPP_
|
||||
#define SRC_INPUT_INPUTDRIVER_HPP_
|
||||
|
||||
@@ -25,7 +28,9 @@ class InputDriver
|
||||
public:
|
||||
InputDriver(EventNotifier* event_notifier) :
|
||||
event_notifier(event_notifier)
|
||||
{}
|
||||
{
|
||||
CLOG(INFO, INPUT_LOGGER) << "Created InputDriver";
|
||||
}
|
||||
|
||||
~InputDriver()
|
||||
{
|
||||
|
||||
@@ -10,32 +10,34 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <boost/heap/priority_queue.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
template <typename T>
|
||||
class BlockingQueue
|
||||
{
|
||||
private:
|
||||
std::mutex d_mutex;
|
||||
std::condition_variable d_condition;
|
||||
std::priority_queue<T> d_queue;
|
||||
public:
|
||||
void push(T const& value) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
d_queue.push_front(value);
|
||||
}
|
||||
this->d_condition.notify_one();
|
||||
}
|
||||
std::mutex d_mutex;
|
||||
std::condition_variable d_condition;
|
||||
heap::priority_queue<T, heap::stable<T>> p_queue;
|
||||
|
||||
T pop() {
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
this->d_condition.wait(lock, [=]{ return !this->d_queue.empty(); });
|
||||
T rc(std::move(this->d_queue.back()));
|
||||
this->d_queue.pop_back();
|
||||
return rc;
|
||||
}
|
||||
public:
|
||||
void push(T const& value)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
p_queue.push_front(value);
|
||||
this->d_condition.notify_one();
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
||||
T rc(std::move(this->p_queue.back()));
|
||||
this->p_queue.pop_back();
|
||||
return rc;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,4 +10,6 @@
|
||||
#define INPUT_LOGGER "driver_logger"
|
||||
#define DRIVER_LOG_FILE "/var/log/flippr_driver.conf"
|
||||
|
||||
#define HIGH_VERBOSITY 10
|
||||
|
||||
#define INPUT_MATRIX_SIZE 8
|
||||
|
||||
Reference in New Issue
Block a user