compiling with distevents
This commit is contained in:
@@ -4,16 +4,19 @@
|
||||
|
||||
#include "DistributingEvent.h"
|
||||
|
||||
FlippR_Driver::Input::DistributingEvent::DistributingEvent(char address, int priority, std::string name,
|
||||
std::chrono::milliseconds deactivation_time, std::shared_ptr<IEventNotifier> event_notifier)
|
||||
: Event(address, priority, name), deactivation_time(deactivation_time), event_notifier(event_notifier)
|
||||
{}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::distribute()
|
||||
{
|
||||
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - last_activation);
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_activation);
|
||||
if(elapsed_time > deactivation_time)
|
||||
{
|
||||
event_notifier->distribute_event(std::shared_ptr<Event>(this)); // todo why new shared ptr?
|
||||
this->last_activation = now;
|
||||
}
|
||||
}
|
||||
|
||||
FlippR_Driver::Input::DistributingEvent::DistributingEvent(char address, int priority, std::string name,
|
||||
std::chrono::milliseconds deactivation_time, std::shared_ptr<IEventNotifier> event_notifier)
|
||||
: Event(address, priority, name), deactivation_time(deactivation_time), event_notifier(event_notifier)
|
||||
{}
|
||||
|
||||
@@ -31,11 +31,13 @@ std::shared_ptr<IInputDriver> InputDriverFactory::get_InputDriver(std::istream &
|
||||
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::shared_ptr<IEventNotifier> event_notifier(new EventNotifier(event_queue));
|
||||
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> 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, event_notifier);
|
||||
|
||||
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));
|
||||
@@ -44,7 +46,7 @@ std::shared_ptr<IInputDriver> InputDriverFactory::get_InputDriver(std::istream &
|
||||
}
|
||||
|
||||
|
||||
void InputDriverFactory::create_input_events(json matrix_config, std::map<char, std::shared_ptr<Event>>& address_event_map,
|
||||
void InputDriverFactory::create_input_events(json matrix_config, std::map<char, std::shared_ptr<DistributingEvent>>& address_event_map,
|
||||
std::map<std::string, std::shared_ptr<Event>>& name_event_map,
|
||||
std::shared_ptr<IEventNotifier> event_notifier)
|
||||
{
|
||||
@@ -59,7 +61,7 @@ void InputDriverFactory::create_input_events(json matrix_config, std::map<char,
|
||||
int priority = json_event.at("priority").get<json::number_integer_t>();
|
||||
int deactivation_time = json_event.at("deactivation_time_milli").get<json::number_integer_t>();
|
||||
|
||||
std::shared_ptr<Event> event_ptr(new DistributingEvent(address, priority, name,
|
||||
std::shared_ptr<DistributingEvent> event_ptr(new DistributingEvent(address, priority, name,
|
||||
std::chrono::milliseconds(deactivation_time), event_notifier));
|
||||
|
||||
address_event_map.emplace(address, event_ptr);
|
||||
|
||||
@@ -30,9 +30,9 @@ 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,
|
||||
std::shared_ptr<IEventNotifier> event_notifier);
|
||||
std::map<char, std::shared_ptr<DistributingEvent>>& address_event_map,
|
||||
std::map<std::string, std::shared_ptr<Event>>& name_event_map,
|
||||
std::shared_ptr<IEventNotifier> event_notifier);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#define private public
|
||||
|
||||
#include "input/IEventNotifier.h"
|
||||
#include "Event.h"
|
||||
#include "input/DistributingEvent.h"
|
||||
#include "input/Detector.h"
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utilities/InputGPIOInterface.h"
|
||||
@@ -42,7 +42,7 @@ SCENARIO("Creating a Detector object", "")
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||
|
||||
std::map<char, std::shared_ptr<Event>> events;
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
WHEN("Detector is created")
|
||||
{
|
||||
@@ -70,16 +70,17 @@ SCENARIO("There are events at the input", "")
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||
|
||||
Event event1(1, '1', "event 1");
|
||||
Event event2(2, '2', "event 2");
|
||||
auto event2ptr = std::make_shared<Event>(event2);
|
||||
Event event3(3, '3', "event 3");
|
||||
std::shared_ptr<IEventNotifier> event_notifier;
|
||||
DistributingEvent event1(1, '1', "event 1", std::chrono::milliseconds(0), event_notifier);
|
||||
DistributingEvent event2(2, '2', "event 2", std::chrono::milliseconds(0), event_notifier);
|
||||
DistributingEvent event3(3, '3', "event 3", std::chrono::milliseconds(0), event_notifier);
|
||||
|
||||
std::map<char, std::shared_ptr<Event>> events;
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
events.insert(std::make_pair(1, std::make_shared<Event>(event1)));
|
||||
auto event2ptr = std::make_shared<DistributingEvent>(event2);
|
||||
events.insert(std::make_pair(1, std::make_shared<DistributingEvent>(event1)));
|
||||
events.insert(std::make_pair(2, event2ptr));
|
||||
events.insert(std::make_pair(3, std::make_shared<Event>(event3)));
|
||||
events.insert(std::make_pair(3, std::make_shared<DistributingEvent>(event3)));
|
||||
|
||||
WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
@@ -110,15 +111,16 @@ SCENARIO("There are events at the input but no suitable event in map", "")
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||
|
||||
Event event1(1, '1', "event 1");
|
||||
Event event2(2, '2', "event 2");
|
||||
Event event3(3, '3', "event 3");
|
||||
std::shared_ptr<IEventNotifier> event_notifier;
|
||||
DistributingEvent event1(1, '1', "event 1", std::chrono::milliseconds(0), event_notifier);
|
||||
DistributingEvent event2(2, '2', "event 2", std::chrono::milliseconds(0), event_notifier);
|
||||
DistributingEvent event3(3, '3', "event 3", std::chrono::milliseconds(0), event_notifier);
|
||||
|
||||
std::map<char, std::shared_ptr<Event>> events;
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
events.insert(std::make_pair(1, std::make_shared<Event>(event1)));
|
||||
events.insert(std::make_pair(2, std::make_shared<Event>(event2)));
|
||||
events.insert(std::make_pair(3, std::make_shared<Event>(event3)));
|
||||
events.insert(std::make_pair(1, std::make_shared<DistributingEvent>(event1)));
|
||||
events.insert(std::make_pair(2, std::make_shared<DistributingEvent>(event2)));
|
||||
events.insert(std::make_pair(3, std::make_shared<DistributingEvent>(event3)));
|
||||
|
||||
WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user