From 67253158d6b06a612e640d8f32dacad3441e9b80 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Tue, 27 Oct 2015 14:35:34 +0100 Subject: [PATCH] Change handler storage to TR_List and use TR_iterableForeach to iterate over them --- src/event_dispatcher_register_handler.c | 27 +++++++++++++------------ src/event_dispatcher_start.c | 19 ++++++++--------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/event_dispatcher_register_handler.c b/src/event_dispatcher_register_handler.c index d9864da..053374e 100644 --- a/src/event_dispatcher_register_handler.c +++ b/src/event_dispatcher_register_handler.c @@ -33,31 +33,32 @@ doRegister(const void * _node, const void * data) TR_HashValue node = (TR_HashValue)_node; TR_EventDispatcher dispatcher = ((void **)data)[0]; TR_EventHandler current_handler = ((void **)data)[1]; - TR_HashValue handler_queue_hv; - TR_Queue handler_queue; + TR_HashValue handler_list_hv; + TR_List handler_list; - handler_queue_hv = TR_hashGetByVal(dispatcher->handler, node->hash); + handler_list_hv = TR_hashGetByVal(dispatcher->handler, node->hash); - if (handler_queue_hv) { - handler_queue = *(TR_Queue *)handler_queue_hv->value; + if (handler_list_hv) { + handler_list = *(TR_List *)handler_list_hv->value; } else { - handler_queue = TR_new(TR_Queue); - ((TR_List)handler_queue)->free_msgs = 0; + handler_list = TR_new(TR_Queue); + handler_list->free_msgs = 0; // TODO change TR_Queue to TR_Dynarray as this is no queue. - handler_queue_hv = TR_new( + handler_list_hv = TR_new( TR_HashValue, node->key, node->nkey, - &handler_queue, - sizeof(TR_Queue)); - TR_hashAdd(dispatcher->handler, handler_queue_hv); + &handler_list, + sizeof(TR_List)); + TR_hashAdd(dispatcher->handler, handler_list_hv); } - TR_queuePut(handler_queue, current_handler); + TR_listPut(handler_list, current_handler); } void -TR_eventDispatcherRegisterHandler(TR_EventDispatcher this, TR_EventHandler handler) +TR_eventDispatcherRegisterHandler( + TR_EventDispatcher this, TR_EventHandler handler) { void * cb_data[] = { this, handler }; diff --git a/src/event_dispatcher_start.c b/src/event_dispatcher_start.c index 95aae95..5eaeab7 100644 --- a/src/event_dispatcher_start.c +++ b/src/event_dispatcher_start.c @@ -37,8 +37,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this) while (this->running || (! TR_queueEmpty(this->events))) { TR_Event event; - TR_Queue handler_queue; - TR_HashValue handler_queue_hv; + TR_List handler_list; + TR_HashValue handler_list_hv; TR_eventDispatcherGetBeatTime(this); @@ -59,28 +59,25 @@ TR_eventDispatcherStart(TR_EventDispatcher this) } } - handler_queue_hv = TR_hashGetByVal( + handler_list_hv = TR_hashGetByVal( this->handler, TR_sdbm( (unsigned char *)&(event->id), sizeof(event->id))); - handler_queue = handler_queue_hv - ? *(TR_Queue *)handler_queue_hv->value + handler_list = handler_list_hv + ? *(TR_List *)handler_list_hv->value : NULL; - if (handler_queue) { - size_t idx = TR_listFirst((TR_List)handler_queue); + if (handler_list) { TR_EventDone done = TR_EVENT_PENDING; - while (idx != TR_listLast((TR_List)handler_queue) + 1) { - TR_EventHandler handler = ((TR_List)handler_queue)->data[idx]; + TR_iterableForeach(handler_list) { + TR_EventHandler handler = TR_iterableCurrent(handler_list); TR_EventDone this_done; this_done = TR_eventHandlerHandleEvent(handler, event); done = TR_EVENT_DONE == done ? done : this_done; - - idx = idx + 1 == TR_queueSize((TR_List)handler_queue) ? 0 : idx + 1; } if (TR_EVENT_DONE == done) {