RTI Connext .NET API (legacy)
Version 6.1.2
|
<<interface>> Allows an application to wait until one or more of the attached DDS::Condition objects has a trigger_value
of true or else until the timeout expires.
More...
#include <managed_infrastructure.h>
Public Member Functions | |
void | wait (ConditionSeq^ active_conditions, Duration_t timeout) |
Allows an application thread to wait for the occurrence of certain conditions. More... | |
void | attach_condition (Condition^ cond) |
Attaches a DDS::Condition to the DDS::WaitSet. More... | |
void | detach_condition (Condition^ cond) |
Detaches a DDS::Condition from the DDS::WaitSet. More... | |
void | get_conditions (ConditionSeq^ attached_conditions) |
Retrieves the list of attached DDS::Condition (s). More... | |
void | set_property (WaitSetProperty_t prop) |
<<extension>> Sets the DDS::WaitSetProperty_t, to configure the associated DDS::WaitSet to return after one or more trigger events have occurred. More... | |
void | get_property (WaitSetProperty_t % prop) |
<<extension>> Retrieves the DDS::WaitSetProperty_t configuration of the associated DDS::WaitSet. More... | |
virtual | ~WaitSet () |
Destructor. More... | |
WaitSet () | |
Default no-argument constructor. More... | |
WaitSet (WaitSetProperty_t % prop) | |
<<extension>> Constructor for a DDS::WaitSet that may delay for more while specifying that will be woken up after the given number of events or delay period, whichever happens first More... | |
<<interface>> Allows an application to wait until one or more of the attached DDS::Condition objects has a trigger_value
of true or else until the timeout expires.
DDS::Condition (s) (in conjunction with wait-sets) provide an alternative mechanism to allow the middleware to communicate communication status changes (including arrival of data) to the application.
This mechanism is wait-based. Its general use pattern is as follows:
trigger_value
of one or several DDS::Condition objects become true. active_conditions
, the list of DDS::Condition objects with trigger_value
== true) to actually get the information: by calling DDS::Entity::get_status_changes and then get_<communication_status>
() on the relevant DDS::Entity, if the condition is a DDS::StatusCondition and the status changes, refer to plain communication status;
by calling DDS::Entity::get_status_changes and then DDS::Subscriber::get_datareaders on the relevant DDS::Subscriber (and then DDS::TypedDataReader::read() or DDS::TypedDataReader::take on the returned DDS::DataReader objects), if the condition is a DDS::StatusCondition and the status changes refers to DATA_ON_READERS_STATUS;
by calling DDS::Entity::get_status_changes and then DDS::TypedDataReader::read() or DDS::TypedDataReader::take on the relevant DDS::DataReader, if the condition is a DDS::StatusCondition and the status changes refers to DATA_AVAILABLE_STATUS;
Usually the first step is done in an initialization phase, while the others are put in the application main loop.
As there is no extra information passed from the middleware to the application when a wait returns (only the list of triggered DDS::Condition objects), DDS::Condition objects are meant to embed all that is needed to react properly when enabled. In particular, DDS::Entity-related conditions are related to exactly one DDS::Entity and cannot be shared.
The blocking behavior of the DDS::WaitSet is illustrated below.
The result of a DDS::WaitSet::wait operation depends on the state of the DDS::WaitSet, which in turn depends on whether at least one attached DDS::Condition has a trigger_value
of true. If the wait operation is called on DDS::WaitSet with state BLOCKED, it will block the calling thread. If wait is called on a DDS::WaitSet with state UNBLOCKED, it will return immediately. In addition, when the DDS::WaitSet transitions from BLOCKED to UNBLOCKED it wakes up any threads that had called wait on it.
A key aspect of the Condition and WaitSet mechanism is the setting of the trigger_value
of each DDS::Condition.
The DDS::WaitSet cannot be used after calling DDS::DomainParticipantFactory::finalize_instance.
The trigger_value
of a DDS::StatusCondition is the boolean OR of the ChangedStatusFlag of all the communication statuses (see Status Kinds) to which it is sensitive. That is, trigger_value
== false only if all the values of the ChangedStatusFlags are false.
The sensitivity of the DDS::StatusCondition to a particular communication status is controlled by the list of enabled_statuses
set on the condition by means of the DDS::StatusCondition::set_enabled_statuses operation.
Once the trigger_value
of a StatusCondition becomes true, it remains true until the status that changed is reset. To reset a status, call the related get_*_status() operation. Or, in the case of the data available status, call read(), take(), or one of their variants. Therefore, if you are using a DDS::StatusCondition on a DDS::WaitSet to be notified of events, your thread will wake up when one of the statuses associated with the StatusCondition becomes true. If you do not reset the status, the StatusCondition trigger_value
remains true and your WaitSet will not block again; it will immediately wake up when you call DDS::WaitSet::wait.
Similar to the DDS::StatusCondition, a DDS::ReadCondition also has a trigger_value
that determines whether the attached DDS::WaitSet is BLOCKED or UNBLOCKED. However, unlike the DDS::StatusCondition, the trigger_value
of the DDS::ReadCondition is tied to the presence of at least a sample managed by RTI Connext with DDS::SampleStateKind and DDS::ViewStateKind matching those of the DDS::ReadCondition. Furthermore, for the DDS::QueryCondition to have a trigger_value
== true, the data associated with the sample must be such that the query_expression
evaluates to true.
The fact that the trigger_value of a DDS::ReadCondition depends on the presence of samples on the associated DDS::DataReader implies that a single take operation can potentially change the trigger_value
of several DDS::ReadCondition or DDS::QueryCondition conditions. For example, if all samples are taken, any DDS::ReadCondition and DDS::QueryCondition conditions associated with the DDS::DataReader that had their trigger_value==TRUE
before will see the trigger_value
change to FALSE. Note that this does not guarantee that DDS::WaitSet objects that were separately attached to those conditions will not be woken up. Once we have trigger_value==TRUE
on a condition, it may wake up the attached DDS::WaitSet, the condition transitioning to trigger_value==FALSE
does not necessarily 'unwakeup' the WaitSet as 'unwakening' may not be possible in general.
The consequence is that an application blocked on a DDS::WaitSet may return from the wait with a list of conditions, some of which are not no longer 'active'. This is unavoidable if multiple threads are concurrently waiting on separate DDS::WaitSet objects and taking data associated with the same DDS::DataReader entity.
To elaborate further, consider the following example: A DDS::ReadCondition that has a sample_state_mask
= {DDS::SampleStateKind::NOT_READ_SAMPLE_STATE} will have trigger_value
of true whenever a new sample arrives and will transition to false as soon as all the newly-arrived samples are either read (so their sample state changes to READ) or taken (so they are no longer managed by RTI Connext). However if the same DDS::ReadCondition had a sample_state_mask
= { DDS::SampleStateKind::READ_SAMPLE_STATE, DDS::SampleStateKind::NOT_READ_SAMPLE_STATE }, then the trigger_value
would only become false once all the newly-arrived samples are taken (it is not sufficient to read them as that would only change the sample state to READ), which overlaps the mask on the DDS::ReadCondition.
The trigger_value
of a DDS::GuardCondition is completely controlled by the application via the operation DDS::GuardCondition::set_trigger_value.
|
virtual |
Destructor.
Releases the resources asociated with this DDS::WaitSet.
Calling this method multiple times on the same DDS::WaitSet is safe; subsequent deletions will have no effect.
DDS::WaitSet::WaitSet | ( | ) |
Default no-argument constructor.
Construct a new DDS::WaitSet.
DDS::WaitSet::WaitSet | ( | WaitSetProperty_t % | prop | ) |
<<extension>> Constructor for a DDS::WaitSet that may delay for more while specifying that will be woken up after the given number of events or delay period, whichever happens first
Constructs a new DDS::WaitSet.
void DDS::WaitSet::wait | ( | ConditionSeq^ | active_conditions, |
Duration_t | timeout | ||
) |
Allows an application thread to wait for the occurrence of certain conditions.
If none of the conditions attached to the DDS::WaitSet have a trigger_value
of true, the wait operation will block, suspending the calling thread.
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).
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 DDS::Condition objects are true, wait fails with DDS::Retcode_Timeout. In this case, the resulting list of conditions will be empty.
Note: The resolution of the timeout
period is constrained by the resolution of the system clock.
When the DDS::WaitSet is configured to wait for more than one trigger event and the timeout is exceeded before that number is reached, this function returns normally as long as at least one trigger event has occurred.
It is not allowable for more than one application thread to be waiting on the same DDS::WaitSet. If the wait operation is invoked on a DDS::WaitSet that already has a thread blocking on it, the operation will return immediately with the value DDS::Retcode_PreconditionNotMet.
active_conditions | <<inout>> a valid non-null DDS::ConditionSeq object. Note that RTI Connext will not allocate a new object if active_conditions is null; the method will return DDS::Retcode_PreconditionNotMet. |
timeout | <<in>> a wait timeout |
One | of the Standard Return Codes or DDS::Retcode_PreconditionNotMet or DDS::Retcode_Timeout. |
void DDS::WaitSet::attach_condition | ( | Condition^ | cond | ) |
Attaches a DDS::Condition to the DDS::WaitSet.
It is possible to attach a DDS::Condition on a DDS::WaitSet that is currently being waited upon (via the wait operation). In this case, if the DDS::Condition has a trigger_value
of true, then attaching the condition will unblock the DDS::WaitSet.
One | of the Standard Return Codes, or DDS::Retcode_OutOfResources. |
void DDS::WaitSet::detach_condition | ( | Condition^ | cond | ) |
Detaches a DDS::Condition from the DDS::WaitSet.
If the DDS::Condition was not attached to the DDS::WaitSet the operation will return DDS::Retcode_BadParameter.
One | of the Standard Return Codes, or DDS::Retcode_PreconditionNotMet. |
void DDS::WaitSet::get_conditions | ( | ConditionSeq^ | attached_conditions | ) |
Retrieves the list of attached DDS::Condition (s).
attached_conditions | <<inout>> a DDS::ConditionSeq object where the list of attached conditions will be returned |
One | of the Standard Return Codes, or DDS::Retcode_PreconditionNotMet. |
void DDS::WaitSet::set_property | ( | WaitSetProperty_t | prop | ) |
<<extension>> Sets the DDS::WaitSetProperty_t, to configure the associated DDS::WaitSet to return after one or more trigger events have occurred.
prop | <<in>> |
One | of the Standard Return Codes |
void DDS::WaitSet::get_property | ( | WaitSetProperty_t % | prop | ) |
<<extension>> Retrieves the DDS::WaitSetProperty_t configuration of the associated DDS::WaitSet.
prop | <<out>> |
One | of the Standard Return Codes |