Waitsets

The Waitsets tool in Cyclone DDS holds execution of the program until a specific condition is reached, or an amount of time has expired. Waitsets and listeners have two different requirement sets:

  • A Waitset allows the code to react when nothing changes.

  • Listeners can only react to changes in state. Listeners allow instant callbacks to specific changes.

A StatusCondition (linked to an entity) signals to the waitset that its wait is finished. The StatusCondition has a list of conditions (changes in status) that can trigger the waitset to finish its wait. When creating a StatusCondition, the enabled statuses should match the type of entity it is attached to. Different StatusConditions linked to different Entities can be attached to a Waitset through the attach_condition function, and detached through the detach_condition function. After creating a waitset with StatusConditions attached, a wait can be triggered for the Duration specified. Triggering the wait causes one of two things to happen:

  • The wait will time out, causing an exception of the type dds::core::TimeoutError.

  • A status change of one of the attached conditions occurs, and the returned container contains the conditions that have triggered the end of the wait.

The following code does not work because the subscription_matched is a status associated with a DataReader:

C code sample TBD

The following code does not work because the liveliness_lost is not a status associated with a Topic:

C code sample TBD

The following code attempts to wait a specified amount of time for readers and writers to see their counterparts, allowing two-way communication to occur:

C code sample TBD

The above function returns true if the reader and writer have encountered matching publications and subscriptions before the timeout’s duration expired, and false otherwise.