diff --git a/include/tr/event_handler.h b/include/tr/event_handler.h index 2e3015b..ac49858 100644 --- a/include/tr/event_handler.h +++ b/include/tr/event_handler.h @@ -50,6 +50,10 @@ void TR_eventHandlerSetDispatcher(TR_EventHandler, TR_EventDispatcher); void TR_eventHandlerIssueEvent(TR_EventHandler, TR_EventSubject, int, void *); int TR_eventHandlerHandleEvent(TR_EventHandler, TR_Event); +#define TR_eventHandlerClassCleanup(cname) \ + (TR__eventHandlerClassCleanup(TR_CLASS_BY_NAME(cname))) +void TR__eventHandlerClassCleanup(TR_class_ptr); + #define TR_EVENT_HANDLER_SET_METHOD(cls, subject, id, method) \ do { \ intptr_t key = TR_eventSubjectId(subject, id); \ diff --git a/src/Makefile.am b/src/Makefile.am index 0e093c7..e77d6d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,7 @@ TREVENT = event.c \ event_handler_handle_event.c \ event_handler_issue_event.c \ event_handler_set_dispatcher.c \ + event_handler_class_cleanup.c \ event_subject.c \ event_subject_emit.c \ event_subject_id.c diff --git a/src/event_dispatcher.c b/src/event_dispatcher.c index 39ed9eb..e3114e9 100644 --- a/src/event_dispatcher.c +++ b/src/event_dispatcher.c @@ -44,10 +44,19 @@ eventDispatcherCtor(void * _this, va_list * params) { return 0; } +static +void +releaseHandlerQueues(const void * node, const void * data) +{ + TR_delete(*(void**)((TR_HashValue)node)->value); +} + static void eventDispatcherDtor(void * _this) { - TR_EventDispatcher this = _this; + TR_EventDispatcher this = _this; + + TR_hashEach(this->handler, NULL, releaseHandlerQueues); TR_hashCleanup(this->handler); TR_delete(this->handler); diff --git a/src/event_dispatcher_start.c b/src/event_dispatcher_start.c index d27b539..8a02349 100644 --- a/src/event_dispatcher_start.c +++ b/src/event_dispatcher_start.c @@ -39,7 +39,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this) time_t now = time(NULL); TR_Event current = NULL; - if (this->nextbeat && this->nextbeat < now) { + if (this->nextbeat && this->nextbeat <= now) { this->nextbeat += this->heartbeat; TR_eventDispatcherEnqueueEvent( this, @@ -86,6 +86,8 @@ TR_eventDispatcherStart(TR_EventDispatcher this) queue_node = queue_node->next; } } + + TR_delete(current); } } } diff --git a/src/event_handler_class_cleanup.c b/src/event_handler_class_cleanup.c new file mode 100644 index 0000000..933f655 --- /dev/null +++ b/src/event_handler_class_cleanup.c @@ -0,0 +1,39 @@ +/** + * \file + * + * \author Georg Hopp + * + * \copyright + * Copyright © 2014 Georg Hopp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "trbase.h" +#include "trhash.h" + +#include "tr/event_handler.h" + +void +TR__eventHandlerClassCleanup(TR_class_ptr class) +{ + while (class) { + struct c_TR_EventHandler_vars * vars; + vars = (struct c_TR_EventHandler_vars *)class->vars; + TR_delete(vars->event_methods); + class = class->parent; + } +} + +// vim: set ts=4 sw=4: