adapted tests

This commit is contained in:
Neeflix
2018-07-11 16:54:33 +02:00
parent 3e08697607
commit a52f67de01
5 changed files with 63 additions and 64 deletions

View File

@@ -14,10 +14,12 @@
namespace Input
{
EventNotifier::EventNotifier()
: is_running(true)
EventNotifier::EventNotifier() :
is_running(true)
{
notify_thread = std::thread(&EventNotifier::notify, this);
this->notify_thread = std::thread(&EventNotifier::notify, this);
this->event_queue = new BlockingQueue<Event>();
CLOG(INFO, INPUT_LOGGER) << "Created EventNotifier and started thread";
}
@@ -27,33 +29,35 @@ EventNotifier::~EventNotifier()
is_running = false;
Event end_event(0, 0, "END");
event_queue.push(end_event);
event_queue->push(end_event);
notify_thread.join();
delete this->event_queue;
}
void EventNotifier::register_event_handler(IEventHandler* handler)
{
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
event_handler.insert(handler);
event_handlers.insert(handler);
}
void EventNotifier::unregister_event_handler(IEventHandler* handler)
{
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
event_handler.erase(handler);
event_handlers.erase(handler);
}
void EventNotifier::distribute_event(Event& event)
{
event_queue.push(event);
event_queue->push(event);
}
void EventNotifier::notify()
{
while(is_running)
{
Event event = event_queue.pop();
Event event = event_queue->pop();
// TODO schoener machen
if(event.name == "END")
@@ -62,8 +66,8 @@ void EventNotifier::notify()
}
// getting a guard and calling all registered handlers
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
for(auto handler : event_handler)
std::lock_guard event_handler_guard(event_handler_mutex);
for(auto handler : event_handlers)
{
boost::thread handler_caller(boost::bind(&IEventHandler::handle, handler, event));