Commit b255fc9a7ee80db958cff3ae097f1cd46462dde6
1 parent
db9b87b2
Add abitility to get a string representation of an event. Used as DEBUG logging of event.
Showing
8 changed files
with
76 additions
and
6 deletions
| @@ -42,6 +42,8 @@ TR_CLASSVARS_DECL(TR_Event) { | @@ -42,6 +42,8 @@ TR_CLASSVARS_DECL(TR_Event) { | ||
| 42 | 42 | ||
| 43 | #define TR_eventSetData(event, data) (((TR_Event)event)->data = (void *)data) | 43 | #define TR_eventSetData(event, data) (((TR_Event)event)->data = (void *)data) |
| 44 | 44 | ||
| 45 | +const char * TR_getEventString(TR_Event); | ||
| 46 | + | ||
| 45 | #endif // __TR_EVENT_H__ | 47 | #endif // __TR_EVENT_H__ |
| 46 | 48 | ||
| 47 | // vim: set ts=4 sw=4: | 49 | // vim: set ts=4 sw=4: |
| @@ -34,8 +34,9 @@ TR_CLASS(TR_EventSubject) { | @@ -34,8 +34,9 @@ TR_CLASS(TR_EventSubject) { | ||
| 34 | }; | 34 | }; |
| 35 | TR_INSTANCE_INIT(TR_EventSubject); | 35 | TR_INSTANCE_INIT(TR_EventSubject); |
| 36 | TR_CLASSVARS_DECL(TR_EventSubject) { | 36 | TR_CLASSVARS_DECL(TR_EventSubject) { |
| 37 | - size_t nevents; | ||
| 38 | - intptr_t * events; | 37 | + const char ** eventStrings; |
| 38 | + size_t nevents; | ||
| 39 | + intptr_t * events; | ||
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | #include "tr/event.h" | 42 | #include "tr/event.h" |
| @@ -53,8 +54,8 @@ TR_CLASSVARS_DECL(TR_EventSubject) { | @@ -53,8 +54,8 @@ TR_CLASSVARS_DECL(TR_EventSubject) { | ||
| 53 | 54 | ||
| 54 | #define TR_eventSubjectHasUnhandledEvents(es) ((es)->emitted > 0) | 55 | #define TR_eventSubjectHasUnhandledEvents(es) ((es)->emitted > 0) |
| 55 | 56 | ||
| 56 | -intptr_t TR__eventSubjectId(TR_class_ptr, size_t); | ||
| 57 | -TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *); | 57 | +intptr_t TR__eventSubjectId(TR_class_ptr, size_t); |
| 58 | +TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *); | ||
| 58 | 59 | ||
| 59 | #define TR_eventSubjectFinalize(es) ((es)->fin = TRUE) | 60 | #define TR_eventSubjectFinalize(es) ((es)->fin = TRUE) |
| 60 | 61 |
| @@ -4,6 +4,7 @@ AUTOMAKE_OPTIONS = subdir-objects | @@ -4,6 +4,7 @@ AUTOMAKE_OPTIONS = subdir-objects | ||
| 4 | AM_CFLAGS += -I../include/ | 4 | AM_CFLAGS += -I../include/ |
| 5 | 5 | ||
| 6 | TREVENT = event.c \ | 6 | TREVENT = event.c \ |
| 7 | + get_event_string.c \ | ||
| 7 | event_dispatcher.c \ | 8 | event_dispatcher.c \ |
| 8 | event_dispatcher_register_handler.c \ | 9 | event_dispatcher_register_handler.c \ |
| 9 | event_dispatcher_set_hearbeat.c \ | 10 | event_dispatcher_set_hearbeat.c \ |
| @@ -112,6 +112,13 @@ eventDispatcherCvInit(TR_class_ptr cls) | @@ -112,6 +112,13 @@ eventDispatcherCvInit(TR_class_ptr cls) | ||
| 112 | TR_EVENT_CREATE(cls, TR_DISPATCHER_EVENT_SHUTDOWN); | 112 | TR_EVENT_CREATE(cls, TR_DISPATCHER_EVENT_SHUTDOWN); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | +const char * TR_eventDispatcherStrings[] = { | ||
| 116 | + "TR_DISPATCHER_EVENT_HEARTBEAT", | ||
| 117 | + "TR_DISPATCHER_EVENT_USER_WAIT", | ||
| 118 | + "TR_DISPATCHER_EVENT_DATA_WAIT", | ||
| 119 | + "TR_DISPATCHER_EVENT_SHUTDOWN" | ||
| 120 | +}; | ||
| 121 | + | ||
| 115 | intptr_t dispatcher_events[TR_DISPATCHER_EVENT_MAX + 1]; | 122 | intptr_t dispatcher_events[TR_DISPATCHER_EVENT_MAX + 1]; |
| 116 | TR_INIT_IFACE(TR_Class, eventDispatcherCtor, eventDispatcherDtor, NULL); | 123 | TR_INIT_IFACE(TR_Class, eventDispatcherCtor, eventDispatcherDtor, NULL); |
| 117 | TR_CREATE_CLASS( | 124 | TR_CREATE_CLASS( |
| @@ -120,6 +127,7 @@ TR_CREATE_CLASS( | @@ -120,6 +127,7 @@ TR_CREATE_CLASS( | ||
| 120 | eventDispatcherCvInit, | 127 | eventDispatcherCvInit, |
| 121 | TR_IF(TR_Class)) = { | 128 | TR_IF(TR_Class)) = { |
| 122 | { | 129 | { |
| 130 | + TR_eventDispatcherStrings, | ||
| 123 | TR_DISPATCHER_EVENT_MAX + 1, | 131 | TR_DISPATCHER_EVENT_MAX + 1, |
| 124 | dispatcher_events | 132 | dispatcher_events |
| 125 | } | 133 | } |
| @@ -20,6 +20,8 @@ | @@ -20,6 +20,8 @@ | ||
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | +#include <stdio.h> | ||
| 24 | + | ||
| 23 | #include "trbase.h" | 25 | #include "trbase.h" |
| 24 | #include "trdata.h" | 26 | #include "trdata.h" |
| 25 | #include "trhash.h" | 27 | #include "trhash.h" |
| @@ -35,6 +37,12 @@ TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event) | @@ -35,6 +37,12 @@ TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event) | ||
| 35 | TR_CLASSVARS(TR_EventHandler, TR_GET_CLASS(this))->event_methods, | 37 | TR_CLASSVARS(TR_EventHandler, TR_GET_CLASS(this))->event_methods, |
| 36 | TR_sdbm((unsigned char *)&event->id, sizeof(event->id))); | 38 | TR_sdbm((unsigned char *)&event->id, sizeof(event->id))); |
| 37 | 39 | ||
| 40 | + TR_loggerLog(TR_logger, TR_LOGGER_DEBUG, | ||
| 41 | + "HANDLE: %s event on %p with no. %d\n", | ||
| 42 | + TR_getEventString(event), | ||
| 43 | + event->subject, | ||
| 44 | + event->serial); | ||
| 45 | + | ||
| 38 | if (! handle_func_hv) { | 46 | if (! handle_func_hv) { |
| 39 | return 0; | 47 | return 0; |
| 40 | } | 48 | } |
| @@ -20,6 +20,8 @@ | @@ -20,6 +20,8 @@ | ||
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | +#include <stdio.h> | ||
| 24 | + | ||
| 23 | #include "trbase.h" | 25 | #include "trbase.h" |
| 24 | 26 | ||
| 25 | #include "tr/event.h" | 27 | #include "tr/event.h" |
| @@ -28,9 +30,15 @@ | @@ -28,9 +30,15 @@ | ||
| 28 | void | 30 | void |
| 29 | TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event) | 31 | TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event) |
| 30 | { | 32 | { |
| 31 | - int i; | ||
| 32 | - | ||
| 33 | if (event) { | 33 | if (event) { |
| 34 | + int i; | ||
| 35 | + | ||
| 36 | + TR_loggerLog(TR_logger, TR_LOGGER_DEBUG, | ||
| 37 | + "ISSUE: %s event on %p with no. %d\n", | ||
| 38 | + TR_getEventString(event), | ||
| 39 | + event->subject, | ||
| 40 | + event->serial); | ||
| 41 | + | ||
| 34 | for (i=0; i<this->ndispatcher; i++) { | 42 | for (i=0; i<this->ndispatcher; i++) { |
| 35 | TR_eventDispatcherEnqueueEvent(this->dispatcher[i], event); | 43 | TR_eventDispatcherEnqueueEvent(this->dispatcher[i], event); |
| 36 | } | 44 | } |
| @@ -32,6 +32,7 @@ static void eventSubjectDtor(void * _this) {} | @@ -32,6 +32,7 @@ static void eventSubjectDtor(void * _this) {} | ||
| 32 | 32 | ||
| 33 | TR_INIT_IFACE(TR_Class, eventSubjectCtor, eventSubjectDtor, NULL); | 33 | TR_INIT_IFACE(TR_Class, eventSubjectCtor, eventSubjectDtor, NULL); |
| 34 | TR_CREATE_CLASS(TR_EventSubject, NULL, NULL, TR_IF(TR_Class)) = { | 34 | TR_CREATE_CLASS(TR_EventSubject, NULL, NULL, TR_IF(TR_Class)) = { |
| 35 | + NULL, | ||
| 35 | 0, | 36 | 0, |
| 36 | NULL | 37 | NULL |
| 37 | }; | 38 | }; |
src/get_event_string.c
0 → 100644
| 1 | +/** | ||
| 2 | + * \file | ||
| 3 | + * | ||
| 4 | + * \author Georg Hopp | ||
| 5 | + * | ||
| 6 | + * \copyright | ||
| 7 | + * Copyright © 2014 Georg Hopp | ||
| 8 | + * | ||
| 9 | + * This program is free software: you can redistribute it and/or modify | ||
| 10 | + * it under the terms of the GNU General Public License as published by | ||
| 11 | + * the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + * (at your option) any later version. | ||
| 13 | + * | ||
| 14 | + * This program is distributed in the hope that it will be useful, | ||
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + * GNU General Public License for more details. | ||
| 18 | + * | ||
| 19 | + * You should have received a copy of the GNU General Public License | ||
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | + */ | ||
| 22 | + | ||
| 23 | +#include <stdint.h> | ||
| 24 | + | ||
| 25 | +#include "tr/event.h" | ||
| 26 | +#include "tr/event_subject.h" | ||
| 27 | +#include "tr/logger.h" | ||
| 28 | +#include "trbase.h" | ||
| 29 | + | ||
| 30 | +const char * | ||
| 31 | +TR_getEventString(TR_Event event) | ||
| 32 | +{ | ||
| 33 | + TR_class_ptr cls = (TR_class_ptr)(event->id >> 8); | ||
| 34 | + size_t idx = event->id & 0xFF; | ||
| 35 | + | ||
| 36 | + idx -= TR_CLASSVARS(TR_EventSubject, cls->parent)->nevents; | ||
| 37 | + | ||
| 38 | + return TR_CLASSVARS(TR_EventSubject, cls)->eventStrings[idx]; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +// vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment