Added uiEvent-specific programmer errors. Next up: actually implementing uiEvent.
This commit is contained in:
parent
7c128e7bcd
commit
101df7a469
|
@ -24,11 +24,13 @@ void uiprivInternalError(const char *fmt, ...)
|
|||
uiprivReportError(internalErrorPrefix, buf, internalErrorSuffix, true);
|
||||
}
|
||||
|
||||
static const char *messages[] = {
|
||||
static const char *messages[uiprivNumProgrammerErrors] = {
|
||||
[uiprivProgrammerErrorWrongStructSize] = "wrong size %zu for %s",
|
||||
[uiprivProgrammerErrorIndexOutOfRange] = "index %d out of range in %s()",
|
||||
[uiprivProgrammerErrorNullPointer] = "invalid null pointer for %s passed into %s()",
|
||||
[uiprivProgrammerErrorIntIDNotFound] = "%s identifier %d not found in %s()",
|
||||
[uiprivProgrammerErrorChangingEventDuringFire] = "attempt to change a uiEvent with %s() while it is firing",
|
||||
[uiprivProgrammerErrorRecursiveEventFire] = "attempt to fire a uiEvent while it is already being fired",
|
||||
};
|
||||
|
||||
static void prepareProgrammerError(char *buf, int size, unsigned int which, va_list ap)
|
||||
|
@ -37,6 +39,8 @@ static void prepareProgrammerError(char *buf, int size, unsigned int which, va_l
|
|||
|
||||
if (which >= uiprivNumProgrammerErrors)
|
||||
uiprivInternalError("bad programmer error value %u", which);
|
||||
if (messages[which] == NULL)
|
||||
uiprivInternalError("programmer error %u has no message", which);
|
||||
n = vsnprintf(buf, size, messages[which], ap);
|
||||
if (n < 0)
|
||||
uiprivInternalError("programmer error string for %u has encoding error", which);
|
||||
|
|
|
@ -18,7 +18,8 @@ enum {
|
|||
uiprivProgrammerErrorNullPointer, // arguments: const char *paramDesc, __func__
|
||||
uiprivProgrammerErrorIntIDNotFound, // arguments: const char *idDesc, int badID, __func__
|
||||
// TODO type mismatch
|
||||
// TODO attempt to change event during uiEventFire()
|
||||
uiprivProgrammerErrorChangingEventDuringFire, // arguments: __func__
|
||||
uiprivProgrammerErrorRecursiveEventFire, // no arguments
|
||||
uiprivNumProgrammerErrors,
|
||||
};
|
||||
extern void uiprivProgrammerError(unsigned int which, ...);
|
||||
|
|
|
@ -64,7 +64,7 @@ The return value is an identifier that may be used to delete or block the event.
|
|||
|
||||
Note that event handlers are NOT deduplicated; if you call `uiEventAddHandler()` twice with the same `handler`, then `handler` will be registered twice and will thus be called twice, even if `sender` and/or `data` are the same, and `uiEventAddHandler()` will return two distinct identifiers.
|
||||
|
||||
It is a programmer error to specify `NULL` for `e` or `handler`.
|
||||
It is a programmer error to specify `NULL` for `e` or `handler`. It is also a programmer error to call `uiEventAddHandler()` on an event while that event is being fired.
|
||||
|
||||
### `uiEventDeleteHandler()`
|
||||
|
||||
|
@ -72,7 +72,7 @@ It is a programmer error to specify `NULL` for `e` or `handler`.
|
|||
void uiEventDeleteHandler(uiEvent *e, int id);
|
||||
```
|
||||
|
||||
It is a programmer error to specify `NULL` for `e` or a currently unregistered value for `id`.
|
||||
It is a programmer error to specify `NULL` for `e` or a currently unregistered value for `id`. It is also a programmer error to call `uiEventDeleteHandler()` on an event while that event is being fired.
|
||||
|
||||
### `uiEventFire()`
|
||||
|
||||
|
@ -88,12 +88,12 @@ Each handler that is to be called will receive whatever you pass in as `args` to
|
|||
|
||||
Note that the order that handler functions are called in is unspecified.
|
||||
|
||||
It is a programmer error to specify `NULL` for `e`.
|
||||
It is a programmer error to specify `NULL` for `e`. It is also a programmer error to fire an event again while it is already being fired.
|
||||
|
||||
### `uiEventHandlerBlocked()`
|
||||
|
||||
```c
|
||||
bool uiEventHandlerBlocked(uiEvent *e, int id);
|
||||
bool uiEventHandlerBlocked(const uiEvent *e, int id);
|
||||
```
|
||||
|
||||
`uiEventHandlerBlocked()` returns whether or not the given registered event handler is *blocked*. A blocked event handler will not be called by `uiEventFire()`, even if that handler matches the parameters passed to `uiEventFire()`. `id` should be the identifier of a previously registered event handler as returned by `uiEventAddHandler()`.
|
||||
|
@ -108,6 +108,4 @@ void uiEventSetHandlerBlocked(uiEvent *e, int id, bool blocked);
|
|||
|
||||
`uiEventSetHandlerBlocked()` changes whether or not the given registered event handler is bocked. `id` should be the identifier of a previously registered event handler as returned by `uiEventAddHandler()`.
|
||||
|
||||
The effect of calling this function on a handler that matches a currently active `uiEventFire()` is unspecified.
|
||||
|
||||
It is a programmer error to specify `NULL` for `e` or a currently unregistered event identifier for `id`.
|
||||
It is a programmer error to specify `NULL` for `e` or a currently unregistered event identifier for `id`. It is also a programmer error to call `uiEventSetHandlerBlocked()` on an event while that event is being fired.
|
||||
|
|
Loading…
Reference in New Issue