Merge branch 'master' of https://github.com/swinginbird/flippr-code
This commit is contained in:
@@ -25,9 +25,9 @@ Detector::Detector(IInputGPIOInterface* input_gpio_interface, std::map<char, Eve
|
|||||||
|
|
||||||
Detector::~Detector()
|
Detector::~Detector()
|
||||||
{
|
{
|
||||||
is_running = false;
|
this->is_running = false;
|
||||||
|
|
||||||
detect_thread.join();
|
this->detect_thread.join();
|
||||||
|
|
||||||
delete this->input_gpio_interface;
|
delete this->input_gpio_interface;
|
||||||
this->input_gpio_interface = NULL;
|
this->input_gpio_interface = NULL;
|
||||||
@@ -39,7 +39,7 @@ Detector::~Detector()
|
|||||||
// Cycles over all s and enqueues an event if detected.
|
// Cycles over all s and enqueues an event if detected.
|
||||||
void Detector::detect()
|
void Detector::detect()
|
||||||
{
|
{
|
||||||
while(is_running)
|
while(this->is_running)
|
||||||
{
|
{
|
||||||
char address;
|
char address;
|
||||||
if(this->check_inputs(address))
|
if(this->check_inputs(address))
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ EventNotifier::~EventNotifier()
|
|||||||
{
|
{
|
||||||
is_running = false;
|
is_running = false;
|
||||||
|
|
||||||
event_queue.release();
|
Event end_event(0, 0, "END");
|
||||||
|
event_queue.push(end_event);
|
||||||
|
|
||||||
notify_thread.join();
|
notify_thread.join();
|
||||||
}
|
}
|
||||||
@@ -54,6 +55,12 @@ void EventNotifier::notify()
|
|||||||
{
|
{
|
||||||
Event event = event_queue.pop();
|
Event event = event_queue.pop();
|
||||||
|
|
||||||
|
// TODO schoener machen
|
||||||
|
if(event.name == "END")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// getting a guard and calling all registered handlers
|
// getting a guard and calling all registered handlers
|
||||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||||
for(auto handler : event_handler)
|
for(auto handler : event_handler)
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ public:
|
|||||||
|
|
||||||
T pop()
|
T pop()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
// TODO die queue funzt net weil wir nich pushen koennen wenn wir im pop warten
|
||||||
|
// TODO denk ma ueber future nach
|
||||||
|
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||||
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
||||||
T rc = *this->p_queue.end();
|
T rc = *this->p_queue.end();
|
||||||
this->p_queue.pop();
|
this->p_queue.pop();
|
||||||
|
|||||||
@@ -55,15 +55,16 @@ SCENARIO("Creating a Detector object", "")
|
|||||||
Detector detector(&gpio_interface_mock.get(), events, &event_notifier_mock.get());
|
Detector detector(&gpio_interface_mock.get(), events, &event_notifier_mock.get());
|
||||||
THEN("a thread should be created")
|
THEN("a thread should be created")
|
||||||
{
|
{
|
||||||
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
|
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
AND_WHEN("an event can be found at gpio interface")
|
AND_WHEN("an event can be found at gpio interface")
|
||||||
{
|
{
|
||||||
THEN("only the fitting event should be distributed by event notifier")
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
{
|
THEN("only the fitting event should be distributed by event notifier")
|
||||||
REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
|
{
|
||||||
}
|
REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ SCENARIO("An EventHandler gets created", "[construction}")
|
|||||||
Mock<Input::IInputDriver> input_driver_mock;
|
Mock<Input::IInputDriver> input_driver_mock;
|
||||||
Fake(Dtor(input_driver_mock));
|
Fake(Dtor(input_driver_mock));
|
||||||
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
|
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
|
||||||
When(Method(input_driver_mock, operator=)).AlwaysReturn();
|
When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn();
|
||||||
|
|
||||||
WHEN("the event handler gets created")
|
WHEN("the event handler gets created")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ SCENARIO("An EventNotifier gets created", "[construction]")
|
|||||||
}
|
}
|
||||||
THEN("It creates a notify thread")
|
THEN("It creates a notify thread")
|
||||||
{
|
{
|
||||||
//REQUIRE(typeid(notifier.notify_thread).hash_code() == typeid(std::thread).hash_code());
|
REQUIRE(typeid(notifier.notify_thread).hash_code() == typeid(std::thread).hash_code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user