weis nimmer
This commit is contained in:
59
FlippR-Driver/src/input/InputEventNotifier.cpp
Normal file
59
FlippR-Driver/src/input/InputEventNotifier.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* InputEventNotifier.cpp
|
||||
*
|
||||
* Created on: May 17, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#include "InputEventNotifier.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
InputEventNotifier::InputEventNotifier()
|
||||
: is_running(true)
|
||||
{
|
||||
notify_thread = std::thread(&InputEventNotifier::notify, this);
|
||||
}
|
||||
|
||||
InputEventNotifier::~InputEventNotifier()
|
||||
{
|
||||
is_running = false;
|
||||
|
||||
notify_thread.join();
|
||||
}
|
||||
|
||||
void InputEventNotifier::register_input_event_handler(InputEventHandler* handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||
event_handler.insert(handler);
|
||||
}
|
||||
|
||||
void InputEventNotifier::unregister_input_event_handler(InputEventHandler* handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||
event_handler.erase(handler);
|
||||
}
|
||||
|
||||
void InputEventNotifier::distribute_event(InputEvent& event)
|
||||
{
|
||||
event_queue.push(event);
|
||||
}
|
||||
|
||||
void InputEventNotifier::notify()
|
||||
{
|
||||
while(is_running)
|
||||
{
|
||||
InputEvent event = event_queue.pop();
|
||||
|
||||
// getting a guard and calling all registered handlers
|
||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||
for(auto handler : event_handler)
|
||||
{
|
||||
// todo timeout!
|
||||
handler->handle(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user