refactored soo much for el
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "IInputDriver.h"
|
||||
|
||||
#include "IEventHandler.h"
|
||||
#include "utilities/config.h"
|
||||
#include "Event.h"
|
||||
|
||||
namespace FlippR_Driver::Input
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user