Template Class WaitSet

Class Documentation

template<uint64_t Capacity = MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET>
class WaitSet

Logical disjunction of a certain number of Triggers.

The WaitSet stores Triggers and allows the user to wait till one or more of those Triggers are triggered. It works over process borders. With the creation of a WaitSet it requests a condition variable from RouDi and destroys it with the destructor. Hence the lifetime of the condition variable is bound to the lifetime of the WaitSet.

Param Capacity:

[in] the amount of events/states which can be attached to the waitset

Public Types

using TriggerArray = cxx::optional<Trigger>[Capacity]
using NotificationInfoVector = cxx::vector<const NotificationInfo*, CAPACITY>

Public Functions

WaitSet() noexcept
~WaitSet() noexcept
WaitSet(const WaitSet &rhs) = delete

all the Trigger have a pointer pointing to this waitset for cleanup calls, therefore the WaitSet cannot be moved

WaitSet(WaitSet &&rhs) = delete
WaitSet &operator=(const WaitSet &rhs) = delete
WaitSet &operator=(WaitSet &&rhs) = delete
void markForDestruction() noexcept

Non-reversible call. After this call wait() and timedWait() do not block any longer and never return triggered events/states. This method can be used to manually initialize destruction and to wakeup any thread which is waiting in wait() or timedWait().

template<typename T, typename EventType, typename ContextDataType = internal::NoType_t, typename = std::enable_if_t<std::is_enum<EventType>::value>>
cxx::expected<WaitSetError> attachEvent(T &eventOrigin, const EventType eventType, const uint64_t notificationId = 0U, const NotificationCallback<T, ContextDataType> &eventCallback = {}) noexcept

attaches an event of a given class to the WaitSet.

Note

attachEvent does not take ownership of callback in the underlying eventCallback or the optional contextData. The user has to ensure that both will live as long as the event is attached.

Parameters:
  • eventOrigin[in] the class from which the event originates.

  • eventType[in] the event specified by the class

  • notificationId[in] an arbitrary user defined id for the event

  • eventCallback[in] a callback which should be assigned to the event

template<typename T, typename EventType, typename ContextDataType = internal::NoType_t, typename = std::enable_if_t<std::is_enum<EventType>::value, void>>
cxx::expected<WaitSetError> attachEvent(T &eventOrigin, const EventType eventType, const NotificationCallback<T, ContextDataType> &eventCallback) noexcept

attaches an event of a given class to the WaitSet.

Note

attachEvent does not take ownership of callback in the underlying eventCallback or the optional contextData. The user has to ensure that both will live as long as the event is attached.

Parameters:
  • eventOrigin[in] the class from which the event originates.

  • eventType[in] the event specified by the class

  • eventCallback[in] a callback which should be assigned to the event

template<typename T, typename ContextDataType = internal::NoType_t>
cxx::expected<WaitSetError> attachEvent(T &eventOrigin, const uint64_t notificationId = 0U, const NotificationCallback<T, ContextDataType> &eventCallback = {}) noexcept

attaches an event of a given class to the WaitSet.

Note

attachEvent does not take ownership of callback in the underlying eventCallback or the optional contextData. The user has to ensure that both will live as long as the event is attached.

Parameters:
  • eventOrigin[in] the class from which the event originates.

  • notificationId[in] an arbitrary user defined id for the event

  • eventCallback[in] a callback which should be assigned to the event

template<typename T, typename ContextDataType = internal::NoType_t>
cxx::expected<WaitSetError> attachEvent(T &eventOrigin, const NotificationCallback<T, ContextDataType> &eventCallback) noexcept

attaches an event of a given class to the WaitSet.

Note

attachEvent does not take ownership of callback in the underlying eventCallback or the optional contextData. The user has to ensure that both will live as long as the event is attached.

Parameters:
  • eventOrigin[in] the class from which the event originates.

  • eventCallback[in] a callback which should be assigned to the event

template<typename T, typename StateType, typename ContextDataType = internal::NoType_t, typename = std::enable_if_t<std::is_enum<StateType>::value>>
cxx::expected<WaitSetError> attachState(T &stateOrigin, const StateType stateType, const uint64_t id = 0U, const NotificationCallback<T, ContextDataType> &stateCallback = {}) noexcept

attaches a state of a given class to the WaitSet.

Note

attachState does not take ownership of callback in the underlying stateCallback or the optional contextData. The user has to ensure that both will live as long as the state is attached.

Parameters:
  • stateOrigin[in] the class from which the state originates.

  • stateType[in] the state specified by the class

  • id[in] an arbitrary user defined id for the state

  • stateCallback[in] a callback which should be assigned to the state

template<typename T, typename StateType, typename ContextDataType = internal::NoType_t, typename = std::enable_if_t<std::is_enum<StateType>::value, void>>
cxx::expected<WaitSetError> attachState(T &stateOrigin, const StateType stateType, const NotificationCallback<T, ContextDataType> &stateCallback) noexcept

attaches a state of a given class to the WaitSet.

Note

attachState does not take ownership of callback in the underlying stateCallback or the optional contextData. The user has to ensure that both will live as long as the state is attached.

Parameters:
  • stateOrigin[in] the class from which the state originates.

  • stateType[in] the state specified by the class

  • stateCallback[in] a callback which should be assigned to the state

template<typename T, typename ContextDataType = internal::NoType_t>
cxx::expected<WaitSetError> attachState(T &stateOrigin, const uint64_t id = 0U, const NotificationCallback<T, ContextDataType> &stateCallback = {}) noexcept

attaches a state of a given class to the WaitSet.

Note

attachState does not take ownership of callback in the underlying stateCallback or the optional contextData. The user has to ensure that both will live as long as the state is attached.

Parameters:
  • stateOrigin[in] the class from which the state originates.

  • id[in] an arbitrary user defined id for the state

  • stateCallback[in] a callback which should be assigned to the state

template<typename T, typename ContextDataType = internal::NoType_t>
cxx::expected<WaitSetError> attachState(T &stateOrigin, const NotificationCallback<T, ContextDataType> &stateCallback) noexcept

attaches a state of a given class to the WaitSet.

Note

attachState does not take ownership of callback in the underlying stateCallback or the optional contextData. The user has to ensure that both will live as long as the state is attached.

Parameters:
  • stateOrigin[in] the class from which the state originates.

  • stateCallback[in] a callback which should be assigned to the state

template<typename T, typename ...Targs>
void detachEvent(T &eventOrigin, const Targs&... args) noexcept

detaches an event from the WaitSet

Parameters:
  • eventOrigin[in] the origin of the event that should be detached

  • args...[in] additional event identifying arguments

template<typename T, typename ...Targs>
void detachState(T &stateOrigin, const Targs&... args) noexcept

detaches a state based trigger from the WaitSet

Parameters:
  • stateOrigin[in] the origin of the state that should be detached

  • args...[in] additional state identifying arguments

NotificationInfoVector timedWait(const units::Duration timeout) noexcept

Blocking wait with time limit till one or more of the triggers are triggered.

Parameters:

timeout[in] How long shall we waite for a trigger

Returns:

NotificationInfoVector of NotificationInfos that have been triggered

NotificationInfoVector wait() noexcept

Blocking wait till one or more of the triggers are triggered.

Returns:

NotificationInfoVector of NotificationInfos that have been triggered

uint64_t size() const noexcept

Returns the amount of stored Trigger inside of the WaitSet.

Public Static Functions

static constexpr uint64_t capacity() noexcept

returns the maximum amount of triggers which can be acquired from a waitset

Public Static Attributes

static constexpr uint64_t CAPACITY = Capacity

Protected Functions

explicit WaitSet(ConditionVariableData &condVarData) noexcept