refactoring to h and cpp

This commit is contained in:
Jonas Zeunert
2018-06-15 00:16:29 +02:00
parent d027d32e2f
commit bacf59ba71
9 changed files with 156 additions and 134 deletions

View File

@@ -6,5 +6,79 @@
*/
#include "InputDriverFactory.h"
#include "Detector.h"
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();
auto detector = this->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);
}
};
}