Template Class TWaitSet
Defined in File WaitSet.hpp
Inheritance Relationships
Base Type
public dds::core::Reference< DELEGATE >
(Template Class Reference)
Class Documentation
-
template<typename DELEGATE>
class TWaitSet : public dds::core::Reference<DELEGATE> A WaitSet object allows an application to wait until one or more of the attached Condition objects has a trigger_value of TRUE or else until the timeout expires.
A WaitSet is not necessarily associated with a single DomainParticipant and could be used to wait for Condition objects associated with different DomainParticipant objects.
When using the wait() operation, the triggered Conditions are returned in a list.
// Create a Condition to attach to a Waitset dds::core::cond::StatusCondition readerSC = dds::core::cond::StatusCondition(reader); readerSC.enabled_statuses(dds::core::status::StatusMask::data_available()); // Create WaitSet and attach Condition dds::core::cond::WaitSet waitset; waitset.attach_condition(readerSC); // or waitset += readerSC; dds::core::cond::WaitSet::ConditionSeq conditions; while(true) { // Wait for any Condition to trigger. conditions = waitset.wait(); // Loop through the triggered conditions. for (int i=0; i < conditions.size(); i++) { // Handle data_available when right Condition triggered. if (conditions[i] == readerSC) { // Read samples from the DataReader } } }
When using the dispatch() operation, the Functors of the triggered Conditions will be called.
// Functor to add to a Condition class FunctorStatusCondition { public: void operator()(const dds::core::cond::StatusCondition& condition) { // Possibly get reader from the condition and read some samples. } }; FunctorStatusCondition functor; // Create a Condition with functor to attach to a Waitset dds::core::cond::StatusCondition readerSC = dds::core::cond::StatusCondition(reader, functor); readerSC.enabled_statuses(dds::core::status::StatusMask::data_available()); // Create WaitSet and attach Condition dds::core::cond::WaitSet waitset; waitset.attach_condition(readerSC); // or waitset += readerSC; while(true) { // Wait for any Condition to trigger. // The functors of the Conditions are automatically called // when the Condition triggers. waitset.dispatch(); }
See also
WaitSet concept
Public Functions
- OMG_DDS_REF_TYPE_NO_DC (TWaitSet, Reference, DELEGATE) OMG_DDS_IMPLICIT_REF_BASE(TWaitSet) TWaitSet()
Create a WaitSet instance.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
-
const ConditionSeq wait(const dds::core::Duration &timeout)
This operation allows an application thread to wait for the occurrence of at least one of the conditions that is attached to the WaitSet.
This operation allows an application thread to wait for the occurrence of certain Conditions. If none of the Conditions attached to the WaitSet have a trigger_value of TRUE, the wait operation will block suspending the calling thread.
The wait operation takes a timeout argument that specifies the maximum duration for the wait. If this duration is exceeded and none of the attached Condition objects is true, a TimeoutError will be thrown.
It is not allowed for more than one application thread to be waiting on the same WaitSet. If the wait operation is invoked on a WaitSet that already has a thread blocking on it, the operation will immediately raise a PreconditionNotMetError exception.
The result of the wait operation is the list of all the attached Conditions that have a trigger_value of TRUE (i.e., the Conditions that unblocked the wait).
- Parameters:
timeout – The maximum amount of time for which the wait should block while waiting for a Condition to be triggered.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
dds::core::TimeoutError – The timeout has elapsed without any of the attached conditions becoming TRUE.
dds::core::PreconditionNotMetError – When multiple thread try to invoke the function concurrently.
- Returns:
ConditionSeq A vector containing the triggered Conditions
-
const ConditionSeq wait()
This operation allows an application thread to wait for the occurrence of at least one of the conditions that is attached to the WaitSet.
This operation allows an application thread to wait for the occurrence of certain Conditions. If none of the Conditions attached to the WaitSet have a trigger_value of TRUE, the wait operation will block suspending the calling thread.
It is not allowed for more than one application thread to be waiting on the same WaitSet. If the wait operation is invoked on a WaitSet that already has a thread blocking on it, the operation will immediately raise a PreconditionNotMetError exception.
The result of the wait operation is the list of all the attached Conditions that have a trigger_value of TRUE (i.e., the Conditions that unblocked the wait).
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
dds::core::PreconditionNotMetError – When multiple thread try to invoke the function concurrently.
- Returns:
ConditionSeq A vector containing the triggered Conditions
-
ConditionSeq &wait(ConditionSeq &triggered, const dds::core::Duration &timeout)
This operation allows an application thread to wait for the occurrence of at least one of the conditions that is attached to the WaitSet.
This operation allows an application thread to wait for the occurrence of certain Conditions. If none of the Conditions attached to the WaitSet have a trigger_value of TRUE, the wait operation will block suspending the calling thread.
The wait operation takes a timeout argument that specifies the maximum duration for the wait. If this duration is exceeded and none of the attached Condition objects is true, a TimeoutError will be thrown.
It is not allowed for more than one application thread to be waiting on the same WaitSet. If the wait operation is invoked on a WaitSet that already has a thread blocking on it, the operation will immediately raise a PreconditionNotMetError exception.
The result of the wait operation is the list of all the attached Conditions that have a trigger_value of TRUE (i.e., the Conditions that unblocked the wait).
- Parameters:
triggered – A ConditionSeq in which to put Conditions that were triggered during the wait.
timeout – The maximum amount of time for which the wait should block while waiting for a Condition to be triggered.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
dds::core::TimeoutError – The timeout has elapsed without any of the attached conditions becoming TRUE.
dds::core::PreconditionNotMetError – When multiple thread try to invoke the function concurrently.
- Returns:
ConditionSeq A vector containing the triggered Conditions
-
ConditionSeq &wait(ConditionSeq &triggered)
This operation allows an application thread to wait for the occurrence of at least one of the conditions that is attached to the WaitSet.
This operation allows an application thread to wait for the occurrence of certain Conditions. If none of the Conditions attached to the WaitSet have a trigger_value of TRUE, the wait operation will block suspending the calling thread.
It is not allowed for more than one application thread to be waiting on the same WaitSet. If the wait operation is invoked on a WaitSet that already has a thread blocking on it, the operation will immediately raise a PreconditionNotMetError exception.
The result of the wait operation is the list of all the attached Conditions that have a trigger_value of TRUE (i.e., the Conditions that unblocked the wait).
- Parameters:
triggered – A ConditionSeq in which to put Conditions that were triggered during the wait.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
dds::core::PreconditionNotMetError – When multiple thread try to invoke the function concurrently.
- Returns:
ConditionSeq A vector containing the triggered Conditions
-
void dispatch()
Waits for at least one of the attached Conditions to trigger and then dispatches the functor associated with the Condition.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
dds::core::PreconditionNotMetError – When multiple thread try to invoke the function concurrently.
- Returns:
void
-
void dispatch(const dds::core::Duration &timeout)
Waits for at least one of the attached Conditions to trigger and then dispatches the functor associated with the Condition, or, times out and throws a TimeoutError.
- Parameters:
timeout – The maximum amount of time for which the dispatch should block while waiting for a Condition to be triggered.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
dds::core::TimeoutError – The timeout has elapsed without any of the attached conditions becoming TRUE.
dds::core::PreconditionNotMetError – When multiple thread try to invoke the function concurrently.
- Returns:
void
-
TWaitSet &operator+=(const Condition &cond)
This operation attaches a Condition to the WaitSet.
Attaches a Condition to the WaitSet. It is possible to attach a Condition on a WaitSet that is currently being waited upon (via the wait operation). In this case, if the Condition has a trigger_value of TRUE, then attaching the Condition will unblock the WaitSet. Adding a Condition that is already attached to the WaitSet has no effect.
- Parameters:
cond – The Condition to be attached to this WaitSet.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
- Returns:
WaitSet The WaitSet itself so that attaching Conditions can be chained.
-
TWaitSet &operator-=(const Condition &cond)
This operation detaches a Condition to the WaitSet.
Detaches a Condition from the WaitSet. If the Condition was not attached to the WaitSet, the operation will return false.
- Parameters:
cond – The Condition to detach from this WaitSet
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
- Returns:
bool True if the Condition was found and detached, False if the Condition was not part of the WaitSet.
-
TWaitSet &attach_condition(const Condition &cond)
This operation attaches a Condition to the WaitSet.
Attaches a Condition to the WaitSet. It is possible to attach a Condition on a WaitSet that is currently being waited upon (via the wait operation). In this case, if the Condition has a trigger_value of TRUE, then attaching the Condition will unblock the WaitSet. Adding a Condition that is already attached to the WaitSet has no effect.
- Parameters:
cond – The Condition to be attached to this WaitSet.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
- Returns:
WaitSet The WaitSet itself so that attaching Conditions can be chained.
-
bool detach_condition(const Condition &cond)
This operation detaches a Condition to the WaitSet.
Detaches a Condition from the WaitSet. If the Condition was not attached to the WaitSet, the operation will return false.
- Parameters:
cond – The Condition to detach from this WaitSet
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
- Returns:
bool True if the Condition was found and detached, False if the Condition was not part of the WaitSet.
-
const ConditionSeq conditions() const
This operation retrieves the list of attached Conditions.
The resulting sequence will either be an empty sequence, meaning there were no conditions attached, or will contain a list of ReadCondition, QueryCondition, StatusCondition and GuardCondition.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
- Returns:
ConditionSeq The list of attached Conditions.
-
ConditionSeq &conditions(ConditionSeq &conds) const
This operation retrieves the list of attached Conditions.
The resulting sequence will either be an empty sequence, meaning there were no conditions attached, or will contain a list of ReadCondition, QueryCondition, StatusCondition and GuardCondition.
- Parameters:
conds – A ConditionSeq in which to put the attached Conditions.
- Throws:
dds::core::Error – An internal error has occurred.
dds::core::NullReferenceError – The WaitSet was not properly created and references to dds::core::null.
dds::core::OutOfResourcesError – The Data Distribution Service ran out of resources to complete this operation.
- Returns:
ConditionSeq The list of attached Conditions.