refactored soo much for el

This commit is contained in:
Jonas Zeunert
2018-09-13 23:54:48 +02:00
parent 9f0bad92a1
commit 66ec3f3438
25 changed files with 101 additions and 83 deletions

View File

@@ -3,22 +3,28 @@
//
#include <iostream>
#include <fstream>
#include <memory>
#include "DriverFactory.h"
#include "IInputDriver.h"
using namespace FlippR_Driver;
int main (int argc, char *argv[])
{
if(argc != 2)
if(argc != 3)
{
std::cout << "Usage: " << argv[0] << " <config_file>";
std::cout << "Usage: " << argv[0] << " <input_config_file> <matrix_config_file>";
}
std::string config_file = argv[1];
std::string input_config_file = argv[1];
std::string matrix_config_file = argv[2];
std::ifstream config;
std::ifstream input_config;
std::ifstream matrix_config;
try
{
config.open(config_file);
input_config.open(input_config_file);
matrix_config.open(matrix_config_file);
}
catch(const std::exception& e)
{
@@ -26,6 +32,6 @@ int main (int argc, char *argv[])
exit(1);
}
std::shared_ptr<Input::IInputDriver> driver = FlippR_Driver::get_InputDriver(input_config, matrix_config);
}

View File

@@ -12,7 +12,7 @@
namespace FlippR_Driver
{
static std::shared_ptr<FlippR_Driver::Input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
std::shared_ptr<Input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
}
#endif //FLIPPR_DRIVER_DRIVERFACTORY_H

View File

@@ -7,7 +7,7 @@
namespace FlippR_Driver
{
static std::shared_ptr<FlippR_Driver::Input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
std::shared_ptr<Input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
{
return FlippR_Driver::Input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
}

View File

@@ -5,6 +5,7 @@
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
*/
#include "EventHandler.h"
#include "utilities/config.h"
namespace FlippR_Driver::Input
{

View File

@@ -15,7 +15,6 @@
#include "IInputDriver.h"
#include "IEventHandler.h"
#include "utilities/config.h"
#include "Event.h"
namespace FlippR_Driver::Input

View File

@@ -4,9 +4,12 @@
* Created on: Jun 15, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
*/
#include <input/ErrorEvent.hpp>
#include "InputDriver.h"
#include "utilities/config.h"
#include <input/ErrorEvent.hpp>
namespace FlippR_Driver::Input
{

View File

@@ -7,7 +7,7 @@
#ifndef SRC_INPUT_INPUTDRIVER_H_
#define SRC_INPUT_INPUTDRIVER_H_
#include "utilities/config.h"
#include <map>
#include "IEventNotifier.h"
#include "IInputDriver.h"

View File

@@ -7,60 +7,60 @@
#include "InputDriverFactory.h"
#include "utilities/config.h"
#include "utilities/LoggerFactory.h"
#include "InputDriver.h"
#include "utilities/LoggerFactory.hpp"
#include "EventNotifier.h"
using namespace nlohmann;
namespace FlippR_Driver::Input
{
namespace FlippR_Driver::Input {
std::shared_ptr<IInputDriver> InputDriverFactory::get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
{
LoggerFactory::CreateInputLogger();
std::shared_ptr<IInputDriver>
InputDriverFactory::get_InputDriver(std::istream &input_config_stream, std::istream &matrix_config_stream) {
LoggerFactory::CreateInputLogger();
IBlockingQueue<Event>* event_queue = new BlockingQueue<Event>;
IBlockingQueue<Event> *event_queue = new BlockingQueue<Event>;
json matrix_config;
matrix_config_stream >> matrix_config;
json matrix_config;
matrix_config_stream >> matrix_config;
std::map<char, std::shared_ptr<Event>> address_event_map;
std::map<std::string, std::shared_ptr<Event>> name_event_map;
create_input_events(matrix_config, address_event_map, name_event_map);
std::map<char, std::shared_ptr<Event>> address_event_map;
std::map<std::string, std::shared_ptr<Event>> name_event_map;
create_input_events(matrix_config, address_event_map, name_event_map);
std::shared_ptr<IEventNotifier> event_notifier(new EventNotifier(event_queue));
std::unique_ptr<IInputGPIOInterface> input_gpio_interface(new InputGPIOInterface(input_config_stream));
std::unique_ptr<IDetector> detector(new Detector(std::move(input_gpio_interface), address_event_map, event_notifier));
std::shared_ptr<IEventNotifier> event_notifier(new EventNotifier(event_queue));
std::unique_ptr<IInputGPIOInterface> input_gpio_interface(new InputGPIOInterface(input_config_stream));
std::unique_ptr<IDetector> detector(
new Detector(std::move(input_gpio_interface), address_event_map, event_notifier));
return std::shared_ptr<InputDriver>(new InputDriver(event_notifier, std::move(detector), name_event_map));
}
return std::shared_ptr<InputDriver>(new InputDriver(event_notifier, std::move(detector), name_event_map));
}
void InputDriverFactory::create_input_events(json matrix_config, std::map<char, std::shared_ptr<Event>> address_event_map, std::map<std::string, std::shared_ptr<Event>> name_event_map)
{
for(auto& json_event : matrix_config)
{
void
InputDriverFactory::create_input_events(json matrix_config, std::map<char, std::shared_ptr<Event>> address_event_map,
std::map<std::string, std::shared_ptr<Event>> name_event_map) {
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>();
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>();
std::shared_ptr<Event> event_ptr(new Event(address, priority, name));
std::shared_ptr<Event> event_ptr(new Event(address, priority, name));
address_event_map.emplace(address, event_ptr);
name_event_map.emplace(name, event_ptr);
}
catch(json::exception& e)
{
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
exit(EXIT_FAILURE);
address_event_map.emplace(address, event_ptr);
name_event_map.emplace(name, event_ptr);
}
catch (json::exception &e) {
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
exit(EXIT_FAILURE);
}
}
}
}
}

View File

@@ -15,15 +15,9 @@
#include "IInputDriver.h"
#include "utilities/InputGPIOInterface.h"
#include "utilities/config.h"
#include "json/json.hpp"
#include "easylogging/easylogging++.h"
#include "IEventNotifier.h"
INITIALIZE_EASYLOGGINGPP
namespace FlippR_Driver::Input
{
class InputDriverFactory
@@ -34,7 +28,6 @@ public:
private:
static void create_input_events(nlohmann::json matrix_config, std::map<char, std::shared_ptr<Event>> address_event_map, std::map<std::string, std::shared_ptr<Event>> name_event_map);
static void ConfigureLogger();
};
}
#endif /* INPUTFACTORY_H_ */

View File

@@ -15,7 +15,8 @@
#include <mutex>
#include <fstream>
#include "config.h"
//#include "config.h"
class GPIOInterface
{
public:

View File

@@ -1,18 +1,18 @@
/*
* LoggerFactory.hpp
*
* Created on: Jun 19, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
*/
//
// Created by rhetenor on 13.09.18.
//
#ifndef SRC_UTILITIES_LOGGERFACTORY_HPP_
#define SRC_UTILITIES_LOGGERFACTORY_HPP_
#include "LoggerFactory.h"
#include "config.h"
#ifndef EASYLOGGING_IS_INITIALIZED
#define EASYLOGGING_IS_INITIALIZED
INITIALIZE_EASYLOGGINGPP
#endif
namespace LoggerFactory
{
static void CreateInputTestLogger()
void CreateInputTestLogger()
{
el::Loggers::getLogger(INPUT_LOGGER);
el::Configurations conf;
@@ -25,7 +25,7 @@ namespace LoggerFactory
el::Loggers::reconfigureAllLoggers(conf);
}
static void CreateInputLogger()
void CreateInputLogger()
{
el::Loggers::getLogger(INPUT_LOGGER);
@@ -39,7 +39,3 @@ namespace LoggerFactory
el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
}
};
#endif /* SRC_UTILITIES_LOGGERFACTORY_HPP_ */

View File

@@ -0,0 +1,18 @@
/*
* LoggerFactory.hpp
*
* Created on: Jun 19, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
*/
#ifndef SRC_UTILITIES_LOGGERFACTORY_HPP_
#define SRC_UTILITIES_LOGGERFACTORY_HPP_
namespace LoggerFactory
{
void CreateInputTestLogger();
void CreateInputLogger();
};
#endif /* SRC_UTILITIES_LOGGERFACTORY_HPP_ */

View File

@@ -7,13 +7,14 @@
#include "easylogging++.h"
// initialize easylogging once
#define INPUT_LOGGER "driver_logger"
#define OUTPUT_LOGGER "output_logger"
#define LOGGER_FILE "input_driver.log"
#define DRIVER_CONF_FILE "/var/log/flippr_driver.conf"
#define HIGH_VERBOSITY 10

View File

@@ -18,7 +18,7 @@
#include "input/IEventNotifier.h"
#include "Event.h"
#include "input/Detector.h"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
#include "utilities/InputGPIOInterface.h"

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
#include "input/EventHandler.h"
#include "IInputDriver.h"

View File

@@ -10,7 +10,7 @@
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
#include "IEventHandler.h"
#include "utilities/IBlockingQueue.h"

View File

@@ -7,7 +7,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes
#define private public

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -11,7 +11,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -11,7 +11,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -10,7 +10,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/LoggerFactory.h"
// testing purposes