carb::EventSubscribers

Defined in omni/kit/EventSubscribers.h

template<class FuncT, typename SubIdT>
class EventSubscribers

A class that manages subscribers.

Thread Safety

This class is not thread safe. Consider using carb::delegate::Delegate which is thread-safe.

Warning

This class does not conform to Basic Callback Hygiene as described in the Coding Style Guidelines . It’s use should be avoided. Instead use carb::delegate::Delegate. This class is also not thread-safe.

Template Parameters
  • FuncT – The function pointer type to manage

  • SubIdT – A type that is used as the subscriber type

Public Functions

inline SubIdT subscribe(FuncT fn, void *userData)

Create a subscription, returning a handle to reference it.

Warning

This class does not conform to Basic Callback Hygiene as described in the Coding Style Guidelines . It’s use should be avoided. Instead use carb::delegate::Delegate. This class is also not thread-safe.

Parameters
  • fn – The function pointer to register

  • userData – The user data that should be passed to fn when called

Returns

a SubIdT to reference the registered function. There is no invalid value, so 0 may be returned. Subscription IDs may also be reused as soon as they are unsubscribed. Call unsubscribe() when finished with the subscription.

inline void unsubscribe(SubIdT id)

Removes a subscriber previously subscribed with subscribe().

Warning

This class does not conform to Basic Callback Hygiene as described in the Coding Style Guidelines . It’s use should be avoided. Instead use carb::delegate::Delegate. This class is also not thread-safe.

Warning

Calling this function with an invalid Subscription ID will cause undefined behavior.

Parameters

id – The subscriber ID previously passed to subscribe().

template<typename ...Ts>
inline void send(Ts... args)

Calls all subscribers.

Warning

This class does not conform to Basic Callback Hygiene as described in the Coding Style Guidelines . It’s use should be avoided. Instead use carb::delegate::Delegate. This class is also not thread-safe.

Parameters

args – Arguments passed to the subscribed FuncT functions. These arguments are passed by value prior to the userData parameter that was registered with subscribe().

template<typename ...Ts>
inline void sendForId(uint64_t id, Ts... args)

Calls a single subscriber.

Warning

This class does not conform to Basic Callback Hygiene as described in the Coding Style Guidelines . It’s use should be avoided. Instead use carb::delegate::Delegate. This class is also not thread-safe.

Warning

Calling this function with an invalid Subscription ID will cause undefined behavior.

Parameters
  • id – The subscriber ID previously passed to subscribe().

  • args – Arguments passed to the subscribed FuncT functions. These arguments are passed by value prior to the userData parameter that was registered with subscribe().