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

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