A generic collection of callbacks for event types represented as a bitmask, intended to be wrapped for each usage.
More...
|
void | addCallback (CallbackType callback, mask_t event_mask, void *userdata) |
| Add a new callback entry with the given callback function pointer, event mask, and user data. More...
|
|
int | removeCallback (CallbackType callback, mask_t event_mask, void *userdata, unsigned int num_skip=0, int max_remove=-1) |
| Remove some number of callback entries matching the given callback function pointer, event mask, and user data. More...
|
|
bool | contains (CallbackType callback, mask_t event_mask, void *userdata) |
| See if the collection contains at least one matching callback. More...
|
|
template<typename F > |
int | invokeCallbacks (EventBitflagType event, F &&invoker) |
| Invokes the callbacks, by passing the ones we should run to your "invoker" to add any desired context/event data and forward the call. More...
|
|
template<typename CallbackType, typename EventBitflagType>
struct xrt::auxiliary::util::GenericCallbacks< CallbackType, EventBitflagType >
A generic collection of callbacks for event types represented as a bitmask, intended to be wrapped for each usage.
A registered callback may identify one or more event types (bits in the bitmask) that it wants to be invoked for. A userdata void pointer is also stored for each callback. Bitmasks are tested at invocation time, and the general callback format allows for callbacks to indicate they should be removed from the collection. Actually calling each callback is left to a consumer-provided "invoker" to allow adding context and event data to the call. The "invoker" also allows the option of whether or how to expose the self-removal capability: yours might simply always return "false".
This generic structure supports callbacks that are included multiple times in the collection, if the consuming code needs it. GenericCallbacks::contains may be used by consuming code before conditionally calling addCallback, to limit to a single instance in a collection.
- Template Parameters
-
CallbackType | the function pointer type to store for each callback. |
EventBitflagType | the event enum type. |
template<typename CallbackType , typename EventBitflagType >
template<typename F >
Invokes the callbacks, by passing the ones we should run to your "invoker" to add any desired context/event data and forward the call.
Callbacks are called in order, filtering out those whose event mask does not include the given event.
- Parameters
-
event | The event type to invoke callbacks for. |
invoker | A function/functor accepting the event, a callback function pointer, and the callback entry's userdata as parameters, and returning true if the callback should be removed from the collection. It is assumed that the invoker will add any additional context or event data and call the provided callback. |
Typically, a lambda with some captures and a single return statement will be sufficient for an invoker.
- Returns
- the number of callbacks run