Commit 67253158d6b06a612e640d8f32dacad3441e9b80
1 parent
bdf3cb4b
Change handler storage to TR_List and use TR_iterableForeach to iterate over them
Showing
2 changed files
with
22 additions
and
24 deletions
| @@ -33,31 +33,32 @@ doRegister(const void * _node, const void * data) | @@ -33,31 +33,32 @@ doRegister(const void * _node, const void * data) | ||
| 33 | TR_HashValue node = (TR_HashValue)_node; | 33 | TR_HashValue node = (TR_HashValue)_node; |
| 34 | TR_EventDispatcher dispatcher = ((void **)data)[0]; | 34 | TR_EventDispatcher dispatcher = ((void **)data)[0]; |
| 35 | TR_EventHandler current_handler = ((void **)data)[1]; | 35 | TR_EventHandler current_handler = ((void **)data)[1]; |
| 36 | - TR_HashValue handler_queue_hv; | ||
| 37 | - TR_Queue handler_queue; | 36 | + TR_HashValue handler_list_hv; |
| 37 | + TR_List handler_list; | ||
| 38 | 38 | ||
| 39 | - handler_queue_hv = TR_hashGetByVal(dispatcher->handler, node->hash); | 39 | + handler_list_hv = TR_hashGetByVal(dispatcher->handler, node->hash); |
| 40 | 40 | ||
| 41 | - if (handler_queue_hv) { | ||
| 42 | - handler_queue = *(TR_Queue *)handler_queue_hv->value; | 41 | + if (handler_list_hv) { |
| 42 | + handler_list = *(TR_List *)handler_list_hv->value; | ||
| 43 | } else { | 43 | } else { |
| 44 | - handler_queue = TR_new(TR_Queue); | ||
| 45 | - ((TR_List)handler_queue)->free_msgs = 0; | 44 | + handler_list = TR_new(TR_Queue); |
| 45 | + handler_list->free_msgs = 0; | ||
| 46 | // TODO change TR_Queue to TR_Dynarray as this is no queue. | 46 | // TODO change TR_Queue to TR_Dynarray as this is no queue. |
| 47 | - handler_queue_hv = TR_new( | 47 | + handler_list_hv = TR_new( |
| 48 | TR_HashValue, | 48 | TR_HashValue, |
| 49 | node->key, | 49 | node->key, |
| 50 | node->nkey, | 50 | node->nkey, |
| 51 | - &handler_queue, | ||
| 52 | - sizeof(TR_Queue)); | ||
| 53 | - TR_hashAdd(dispatcher->handler, handler_queue_hv); | 51 | + &handler_list, |
| 52 | + sizeof(TR_List)); | ||
| 53 | + TR_hashAdd(dispatcher->handler, handler_list_hv); | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | - TR_queuePut(handler_queue, current_handler); | 56 | + TR_listPut(handler_list, current_handler); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | void | 59 | void |
| 60 | -TR_eventDispatcherRegisterHandler(TR_EventDispatcher this, TR_EventHandler handler) | 60 | +TR_eventDispatcherRegisterHandler( |
| 61 | + TR_EventDispatcher this, TR_EventHandler handler) | ||
| 61 | { | 62 | { |
| 62 | void * cb_data[] = { this, handler }; | 63 | void * cb_data[] = { this, handler }; |
| 63 | 64 |
| @@ -37,8 +37,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -37,8 +37,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
| 37 | 37 | ||
| 38 | while (this->running || (! TR_queueEmpty(this->events))) { | 38 | while (this->running || (! TR_queueEmpty(this->events))) { |
| 39 | TR_Event event; | 39 | TR_Event event; |
| 40 | - TR_Queue handler_queue; | ||
| 41 | - TR_HashValue handler_queue_hv; | 40 | + TR_List handler_list; |
| 41 | + TR_HashValue handler_list_hv; | ||
| 42 | 42 | ||
| 43 | TR_eventDispatcherGetBeatTime(this); | 43 | TR_eventDispatcherGetBeatTime(this); |
| 44 | 44 | ||
| @@ -59,28 +59,25 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -59,28 +59,25 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | - handler_queue_hv = TR_hashGetByVal( | 62 | + handler_list_hv = TR_hashGetByVal( |
| 63 | this->handler, | 63 | this->handler, |
| 64 | TR_sdbm( | 64 | TR_sdbm( |
| 65 | (unsigned char *)&(event->id), | 65 | (unsigned char *)&(event->id), |
| 66 | sizeof(event->id))); | 66 | sizeof(event->id))); |
| 67 | 67 | ||
| 68 | - handler_queue = handler_queue_hv | ||
| 69 | - ? *(TR_Queue *)handler_queue_hv->value | 68 | + handler_list = handler_list_hv |
| 69 | + ? *(TR_List *)handler_list_hv->value | ||
| 70 | : NULL; | 70 | : NULL; |
| 71 | 71 | ||
| 72 | - if (handler_queue) { | ||
| 73 | - size_t idx = TR_listFirst((TR_List)handler_queue); | 72 | + if (handler_list) { |
| 74 | TR_EventDone done = TR_EVENT_PENDING; | 73 | TR_EventDone done = TR_EVENT_PENDING; |
| 75 | 74 | ||
| 76 | - while (idx != TR_listLast((TR_List)handler_queue) + 1) { | ||
| 77 | - TR_EventHandler handler = ((TR_List)handler_queue)->data[idx]; | 75 | + TR_iterableForeach(handler_list) { |
| 76 | + TR_EventHandler handler = TR_iterableCurrent(handler_list); | ||
| 78 | TR_EventDone this_done; | 77 | TR_EventDone this_done; |
| 79 | 78 | ||
| 80 | this_done = TR_eventHandlerHandleEvent(handler, event); | 79 | this_done = TR_eventHandlerHandleEvent(handler, event); |
| 81 | done = TR_EVENT_DONE == done ? done : this_done; | 80 | done = TR_EVENT_DONE == done ? done : this_done; |
| 82 | - | ||
| 83 | - idx = idx + 1 == TR_queueSize((TR_List)handler_queue) ? 0 : idx + 1; | ||
| 84 | } | 81 | } |
| 85 | 82 | ||
| 86 | if (TR_EVENT_DONE == done) { | 83 | if (TR_EVENT_DONE == done) { |
Please
register
or
login
to post a comment