changed to smart ptrs and trying to fix event_handler_tests

This commit is contained in:
Jonas Zeunert
2018-07-11 19:00:24 +02:00
parent 26c63d946d
commit 8b9ec68662
12 changed files with 47 additions and 61 deletions

View File

@@ -18,28 +18,27 @@ using namespace nlohmann;
namespace Input
{
std::shared_ptr<InputDriver> InputDriverFactory::get_InputDriver(std::string& input_config_path, std::string& matrix_config_path)
std::shared_ptr<InputDriver> InputDriverFactory::get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
{
ConfigureLogger();
auto event_notifier = new EventNotifier();
auto detector = get_detector(input_config_path, matrix_config_path);
std::shared_ptr<IEventNotifier> event_notifier = std::make_shared<EventNotifier>();
return std::shared_ptr<InputDriver>(new InputDriver(event_notifier, detector));
std::unique_ptr<IInputGPIOInterface> input_gpio_interface = std::make_unique<InputGPIOInterface>(input_config_stream);
std::unique_ptr<IDetector> detector(std::move(get_detector(matrix_config_stream, std::move(input_gpio_interface), event_notifier)));
return std::shared_ptr<InputDriver>(new InputDriver(event_notifier, std::move(detector)));
}
Detector* InputDriverFactory::get_detector(std::string& input_config_path, std::string& matrix_config_path)
std::unique_ptr<IDetector> InputDriverFactory::get_detector(std::istream& matrix_config_stream, std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::shared_ptr<IEventNotifier> event_notifier)
{
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);
return std::unique_ptr<Detector>(new Detector(std::move(input_gpio_interface), input_events, event_notifier));
}
std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config)