Commit 2c2cb317e513309b6c7dbc29e6bb46e138c4d88c
1 parent
8fb77893
keep track of the anount of pending events on a subject
Showing
3 changed files
with
13 additions
and
2 deletions
| @@ -28,7 +28,9 @@ | @@ -28,7 +28,9 @@ | ||
| 28 | 28 | ||
| 29 | #include "trbase.h" | 29 | #include "trbase.h" |
| 30 | 30 | ||
| 31 | -TR_CLASS(TR_EventSubject) {}; | 31 | +TR_CLASS(TR_EventSubject) { |
| 32 | + size_t emitted; | ||
| 33 | +}; | ||
| 32 | TR_INSTANCE_INIT(TR_EventSubject); | 34 | TR_INSTANCE_INIT(TR_EventSubject); |
| 33 | TR_CLASSVARS_DECL(TR_EventSubject) { | 35 | TR_CLASSVARS_DECL(TR_EventSubject) { |
| 34 | size_t nevents; | 36 | size_t nevents; |
| @@ -48,6 +50,8 @@ TR_CLASSVARS_DECL(TR_EventSubject) { | @@ -48,6 +50,8 @@ TR_CLASSVARS_DECL(TR_EventSubject) { | ||
| 48 | #define TR_eventSubjectGetId(obj, idx) \ | 50 | #define TR_eventSubjectGetId(obj, idx) \ |
| 49 | TR__eventSubjectId(TR_GET_CLASS(obj), idx) | 51 | TR__eventSubjectId(TR_GET_CLASS(obj), idx) |
| 50 | 52 | ||
| 53 | +#define TR_eventSubjectHasUnhandledEvents(es) ((es)->emitted > 0) | ||
| 54 | + | ||
| 51 | intptr_t TR__eventSubjectId(TR_class_ptr, size_t); | 55 | intptr_t TR__eventSubjectId(TR_class_ptr, size_t); |
| 52 | TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *); | 56 | TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *); |
| 53 | 57 |
| @@ -41,7 +41,12 @@ eventCtor(void * _this, va_list * params) | @@ -41,7 +41,12 @@ eventCtor(void * _this, va_list * params) | ||
| 41 | return 0; | 41 | return 0; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | -static void eventDtor(void * _this) {} | 44 | +static void eventDtor(void * _this) |
| 45 | +{ | ||
| 46 | + TR_Event this = _this; | ||
| 47 | + | ||
| 48 | + this->subject->emitted--; | ||
| 49 | +} | ||
| 45 | 50 | ||
| 46 | TR_INIT_IFACE(TR_Class, eventCtor, eventDtor, NULL); | 51 | TR_INIT_IFACE(TR_Class, eventCtor, eventDtor, NULL); |
| 47 | TR_CREATE_CLASS(TR_Event, NULL, NULL, TR_IF(TR_Class)) = { 0 }; | 52 | TR_CREATE_CLASS(TR_Event, NULL, NULL, TR_IF(TR_Class)) = { 0 }; |
| @@ -38,6 +38,8 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data) | @@ -38,6 +38,8 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data) | ||
| 38 | TR_eventSetData(event, data); | 38 | TR_eventSetData(event, data); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | + this->emitted++; | ||
| 42 | + | ||
| 41 | return event; | 43 | return event; |
| 42 | } | 44 | } |
| 43 | 45 |
Please
register
or
login
to post a comment