Started implementing and deduplicating the error handling in events.c.

This commit is contained in:
Pietro Gagliardi 2019-05-15 23:11:21 -04:00
parent 55a7e3e56e
commit caa926feeb
1 changed files with 21 additions and 8 deletions

View File

@ -50,18 +50,27 @@ uiEvent *uiNewEvent(uiEventOptions *options)
{ {
} }
#define checkEventNonnull(e, ...) if ((e) == NULL) { \
uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEvent", __func__); \
return __VA_ARGS__; \
}
#define checkEventNotFiring(e, ...) if ((e)->firing) { \
uiprivProgrammerError(uiprivProgrammerErrorChangingEventDuringFire, __func__); \
return __VA_ARGS__; \
}
int uiEventAddHandler(uiEvent *e, uiEventHandler handler, void *sender, void *data) int uiEventAddHandler(uiEvent *e, uiEventHandler handler, void *sender, void *data)
{ {
checkEventNonnull(e, 0);
checkEventNotFiring(e, 0);
} }
void uiEventDeleteHandler(uiEvent *e, int id) void uiEventDeleteHandler(uiEvent *e, int id)
{ {
struct handler *h; struct handler *h;
if (e == NULL) checkEventNonnull(e);
TODO checkEventNotFiring(e);
if (e->firing)
TODO
if (e->len == 0) if (e->len == 0)
TODO TODO
h = handlerFind(e->handlers, e->len, id); h = handlerFind(e->handlers, e->len, id);
@ -76,10 +85,11 @@ void uiEventFire(uiEvent *e, void *sender, void *args)
struct handler *h; struct handler *h;
size_t i; size_t i;
if (e == NULL) checkEventNonnull(e);
TODO if (e->firing) {
if (e->firing) uiprivProgrammerError(uiprivProgrammerErrorRecursiveEventFire);
TODO return;
}
if (e->opts.Global && sender != NULL) if (e->opts.Global && sender != NULL)
TODO TODO
e->firing = true; e->firing = true;
@ -94,8 +104,11 @@ void uiEventFire(uiEvent *e, void *sender, void *args)
bool uiEventHandlerBlocked(const uiEvent *e, int id) bool uiEventHandlerBlocked(const uiEvent *e, int id)
{ {
checkEventNonnull(e, false);
} }
void uiEventSetHandlerBlocked(uiEvent *e, int id, bool blocked) void uiEventSetHandlerBlocked(uiEvent *e, int id, bool blocked)
{ {
checkEventNonnull(e);
checkEventNotFiring(e);
} }