uh the fucking tests are fucking compiling :sigh: fuck itgit add *git add *git add *git add *git add *

This commit is contained in:
Jonas Zeunert
2018-06-15 02:30:05 +02:00
parent 70b25595e6
commit ed450b0409
21 changed files with 182 additions and 252 deletions

View File

@@ -16,6 +16,13 @@
#include "IDetector.h"
#include <thread>
#include <map>
#include "../utilities/InputGPIOInterface.h"
#include "Event.h"
#include "IEventNotifier.h"
namespace Input
{

View File

@@ -7,19 +7,14 @@
#include "Event.h"
using namespace Input;
Event::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 Event::operator==(const Event& other)
{
return this->name == other.name;
}
friend bool operator<(const Event& left, const Event& right)
{
return left.priority < right.priority;
}
Event::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 Event::operator==(const Event& other)
{
return this->name == other.name;
}

View File

@@ -21,7 +21,10 @@ class Event
public:
Event(char address, char priority, std::string name);
bool operator==(const Event& other);
friend bool operator<(const Event& left, const Event& right);
friend bool operator<(const Event& left, const Event& right)
{
return left.priority < right.priority;
}
private:
char address;

View File

@@ -16,14 +16,14 @@ using namespace Input;
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
}
virtual EventHandler::~EventHandler()
EventHandler::~EventHandler()
{
this->input_driver->unregister_event_handler(this);
this->input_driver = NULL;
}
// This function is intended to be non pure, if it is called when the derived class doesn't exist anymore
virtual void EventHandler::handle(Event& event)
void EventHandler::handle(Event& event)
{
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
}

View File

@@ -14,7 +14,7 @@
#include <thread>
#include <mutex>
#include "../utilities/BlockingQueue.h"
#include "../utilities/BlockingQueue.hpp"
#include "Event.h"
#include "EventHandler.h"

View File

@@ -8,12 +8,6 @@
#ifndef SRC_INPUT_IDETECTOR_H_
#define SRC_INPUT_IDETECTOR_H_
#include <thread>
#include <map>
#include "../utilities/InputGPIOInterface.h"
#include "Event.h"
#include "EventNotifier.h"
namespace Input
{
@@ -22,7 +16,7 @@ class IDetector
{
public:
virtual ~IDetector() = 0;
virtual ~IDetector(){};
};
}

View File

@@ -17,7 +17,7 @@ namespace Input
class IEventNotifier
{
public:
virtual ~IEventNotifier() = 0;
virtual ~IEventNotifier(){};
virtual void register_event_handler(IEventHandler* handler) = 0;
virtual void unregister_event_handler(IEventHandler* handler) = 0;

View File

@@ -16,7 +16,7 @@ namespace Input {
class IInputDriver
{
public:
virtual ~IInputDriver() = 0;
virtual ~IInputDriver(){};
virtual void register_event_handler(IEventHandler* handler) = 0;
virtual void unregister_event_handler(IEventHandler* handler) = 0;
};

View File

@@ -7,6 +7,7 @@
#include "InputDriver.h"
using namespace Input;
InputDriver::InputDriver(IEventNotifier* event_notifier, IDetector* detector) :
event_notifier(event_notifier), detector(detector)
{

View File

@@ -22,8 +22,8 @@ public:
InputDriver(IEventNotifier* event_notifier, IDetector* detector);
~InputDriver();
void register_event_handler(IEventHandler* handler);
void unregister_event_handler(IEventHandler* handler);
virtual void register_event_handler(IEventHandler* handler) override;
virtual void unregister_event_handler(IEventHandler* handler) override;
private:
IEventNotifier* event_notifier;

View File

@@ -8,77 +8,71 @@
#include "InputDriverFactory.h"
#include "Detector.h"
#include "EventNotifier.h"
using namespace nlohmann;
using namespace Input;
static shared_ptr<IInputDriver*> InputDriverFactory::get_InputDriver(std::string& input_config_path, std::string& matrix_config_path)
{
this->ConfigureLogger();
auto event_notifier = new EventNotifier();
std::shared_ptr<InputDriver> InputDriverFactory::get_InputDriver(std::string& input_config_path, std::string& matrix_config_path)
{
ConfigureLogger();
auto event_notifier = new EventNotifier();
auto detector = this->get_detector(input_config_path, matrix_config_path);
auto detector = get_detector(input_config_path, matrix_config_path);
return shared_ptr<InputDriver*>(new InputDriver(event_notifier, detector));
}
static IDetector* get_detector(std::string& input_config_path, std::string& matrix_config_path)
{
std::ifstream input_config_stream(input_config_path);
json input_config;
input_config << input_config_stream;
std::ifstream matrix_config_stream(matrix_config_path);
json matrix_config;
matrix_config << matrix_config_stream;
auto input_gpio_interface = new InputGPIOInterface(input_config);
auto input_notifier = new InputEventNotifier();
std::map<char, Event> input_events = this->create_input_events(matrix_config);
return new Detector(input_gpio_interface, input_events, input_notifier);
}
static std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config)
{
std::map<char, Event> events;
for(auto& json_event : matrix_config)
{
try
{
std::string name = json_event.at("name");
char address = json_event.at("address");
int priority = json_event.at("priority");
Event event(address, priority, name);
events.emplace(address, event);
}
catch(json::exception& e)
{
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
exit(EXIT_FAILURE);
}
}
return events;
}
static void InputDriverFactory::ConfigureLogger()
{
el::Loggers::getLogger(INPUT_LOGGER);
//TODO may configure?
el::Configurations conf;
conf.setToDefault();
conf.set(el::Level::Global, el::ConfigurationType::Filename, DRIVER_LOG_FILE);
conf.set(el::Level::Global, el::ConfigurationType::Format, "%datetime [%level] [%func] : %msg");
el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
}
};
return std::shared_ptr<InputDriver>(new InputDriver(event_notifier, detector));
}
Detector* InputDriverFactory::get_detector(std::string& input_config_path, std::string& matrix_config_path)
{
std::ifstream matrix_config_stream(matrix_config_path);
json matrix_config;
matrix_config_stream >> matrix_config;
auto input_gpio_interface = new InputGPIOInterface(input_config_path);
auto input_notifier = new EventNotifier();
std::map<char, Event> input_events = create_input_events(matrix_config);
return new Detector(input_gpio_interface, input_events, input_notifier);
}
std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config)
{
std::map<char, Event> events;
for(auto& json_event : matrix_config)
{
try
{
std::string name = json_event.at("name");
char address = json_event.at("address").get<json::number_integer_t>();
int priority = json_event.at("priority").get<json::number_integer_t>();
Event event(address, priority, name);
events.emplace(address, event);
}
catch(json::exception& e)
{
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
exit(EXIT_FAILURE);
}
}
return events;
}
void InputDriverFactory::ConfigureLogger()
{
el::Loggers::getLogger(INPUT_LOGGER);
//TODO may configure?
el::Configurations conf;
conf.setToDefault();
conf.set(el::Level::Global, el::ConfigurationType::Filename, DRIVER_LOG_FILE);
conf.set(el::Level::Global, el::ConfigurationType::Format, "%datetime [%level] [%func] : %msg");
el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
}

View File

@@ -9,8 +9,10 @@
#define INPUTFACTORY_H_
#include <fstream>
#include <atomic>
#include "IDetector.h"
#include "Detector.h"
#include "InputDriver.h"
#include "../utilities/InputGPIOInterface.h"
#include "../utilities/config.h"
@@ -18,21 +20,21 @@
#include "../lib/easylogging/easylogging++.h"
#include "IEventNotifier.h"
using namespace nlohmann;
INITIALIZE_EASYLOGGINGPP
namespace Input
{
class InputFactory
class InputDriverFactory
{
public:
static shared_ptr<IInputDriver*> get_InputDriver(std::string& input_config_path, std::string& matrix_config_path);
static std::shared_ptr<InputDriver> get_InputDriver(std::string& input_config_path, std::string& matrix_config_path);
private:
static IDetector* get_detector(std::string& input_config_path, std::string& matrix_config_path);
static std::map<char, Event> create_input_events(json matrix_config);
static Detector* get_detector(std::string& input_config_path, std::string& matrix_config_path);
static std::map<char, Event> create_input_events(nlohmann::json matrix_config);
static void ConfigureLogger();
};
}
#endif /* INPUTFACTORY_H_ */