CoreDX DDS Modern C++ API
Conditions and WaitSets

A WaitSet is a mechanism to block until one of a set of Conditions are triggered. There are several different types of conditions that are supported by the DDS API.

Additionally, the GuardCondition provides an application controlled Condition.

Using Conditions and WaitSets

Create a WaitSet and attach Conditions to it

Block on the WaitSet

dds::core::cond::WaitSet::ConditionSeq triggered;
ws.wait( triggered, dds::core::Duration( 10 ) );
// if none of the conditions trigger during the elapsed 10 seconds
// then it will throw a dds::core::TimeoutError
// If one or more of the conditions trigger before the timeout,
// then they will be added to the 'triggered' sequence.
for (const auto& c : triggered) {
if ( c == rc ) {
// handle the fact that the read condition triggered
}
else if ( ... ) {
}
}

Instead of simply blocking, you can associate a functor a condition. The functor will be invoked when the WaitSet detects that the condition has triggered. The functor can be a lambda expression, or a functor object (that is, an object that overloads operator()").

// functor object
class ConditionTriggered {
public:
ConditionTriggered() : triggered(false) {}
bool triggered;
void operator()() {
triggered = true;
}
};
ConditionTriggered trigger;
ws += rc; // alias for ws.attach_condition( rc );
// or, with a lambda function
dds::core::cond::GuardCondition gc( []() { std::cout << "GuardCondition triggered!" << std::endl; } );
ws += gc;
ws.dispatch( dds::core::Duration(10, 0) ); // wait for up to 10 seconds calling 'trigger()' the 'rc' condition is detected

© 2009-2020 Twin Oaks Computing, Inc
Castle Rock, CO 80104
All rights reserved.