changed pointer stuff

This commit is contained in:
Neeflix
2018-08-08 11:16:19 +02:00
parent 0c08b940f3
commit 844847edca
12 changed files with 56 additions and 36 deletions

View File

@@ -21,27 +21,24 @@ std::shared_ptr<InputDriver> InputDriverFactory::get_InputDriver(std::istream& i
LoggerFactory::CreateInputLogger();
IBlockingQueue<Event>* event_queue = new BlockingQueue<Event>;
std::shared_ptr<IEventNotifier> event_notifier = std::make_shared<EventNotifier>(event_queue);
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)));
}
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)
{
json matrix_config;
matrix_config_stream >> matrix_config;
std::map<char, Event> input_events = create_input_events(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);
return std::unique_ptr<Detector>(new Detector(std::move(input_gpio_interface), input_events, event_notifier));
std::shared_ptr<IEventNotifier> event_notifier = std::make_shared<EventNotifier>(event_queue);
std::unique_ptr<IInputGPIOInterface> input_gpio_interface = std::make_unique<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));
}
std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config)
{
std::map<char, Event> events;
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)
{
@@ -52,8 +49,10 @@ std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config
int priority = json_event.at("priority").get<json::number_integer_t>();
Event event(address, priority, name);
std::shared_ptr event_ptr = std::make_shared<Event>(event);
events.emplace(address, event);
address_event_map.emplace(address, event_ptr);
name_event_map.emplace(name, event_ptr);
}
catch(json::exception& e)
{
@@ -61,8 +60,6 @@ std::map<char, Event> InputDriverFactory::create_input_events(json matrix_config
exit(EXIT_FAILURE);
}
}
return events;
}