DDS::WaitSet Class Reference
[Conditions and WaitSets]

<<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>

List of all members.

Public Member Functions

void wait (ConditionSeq^ active_conditions, Duration_t timeout)
 Allows an application thread to wait for the occurrence of certain conditions.
void attach_condition (Condition^ cond)
 Attaches a DDS::Condition to the DDS::WaitSet.
void detach_condition (Condition^ cond)
 Detaches a DDS::Condition from the DDS::WaitSet.
void get_conditions (ConditionSeq^ attached_conditions)
 Retrieves the list of attached DDS::Condition (s).
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.
void get_property (WaitSetProperty_t% prop)
 <<eXtension>> Retrieves the DDS::WaitSetProperty_t configuration of the associated DDS::WaitSet.
virtual ~WaitSet ()
 Destructor.
 WaitSet ()
 Default no-argument constructor.
 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


Detailed Description

<<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.

Usage

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.

DDSWaitSetConditions.png

::DDS::WaitSet and ::DDS::Condition (s)

This mechanism is wait-based. Its general use pattern is as follows:

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.

DDSWaitSetBlocking.png

::DDS::WaitSet blocking behavior

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 DDS::Condition/DDS::WaitSet mechanism is the setting of the trigger_value of each DDS::Condition.

Trigger State of a ::DDS::StatusCondition

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.

Trigger State of a ::DDS::ReadCondition

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 Data Distribution Service 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 Data Distribution Service). 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.

Trigger State of a ::DDS::GuardCondition

The trigger_value of a DDS::GuardCondition is completely controlled by the application via the operation DDS::GuardCondition::set_trigger_value.

See also:
Status Kinds

DDS::StatusCondition, DDS::GuardCondition

DDS::Listener


Constructor & Destructor Documentation

virtual DDS::WaitSet::~WaitSet (  )  [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.

Returns:
A new DDS::WaitSet or null if one could not be allocated.

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.

Returns:
A new DDS::WaitSet or null if one could not be allocated.


Member Function Documentation

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 is true, wait will return with the return code DDS::Retcode_Timeout. In this case, the resulting list of conditions will be empty.

DDS::Retcode_Timeout will not be returned when the timeout duration is exceeded if attached DDS::Condition objects are true, or in the case of a DDS::WaitSet waiting for more than one trigger event, if one or more trigger events have occurred.

It is not allowable for 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.

Parameters:
active_conditions <<inout>> a valid non-null DDS::ConditionSeq object. Note that RTI Data Distribution Service will not allocate a new object if active_conditions is null; the method will return DDS::Retcode_PreconditionNotMet.
timeout <<in>> a wait timeout
Exceptions:
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.

Parameters:
cond <<in>> Contition to be attached.
Exceptions:
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.

Parameters:
cond <<in>> Condition to be detached.
Exceptions:
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).

Parameters:
attached_conditions <<inout>> a DDS::ConditionSeq object where the list of attached conditions will be returned
Exceptions:
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.

Parameters:
prop <<in>>
Exceptions:
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.

Parameters:
prop <<out>>
Exceptions:
One of the Standard Return Codes


RTI Data Distribution Service .Net APIs Version 4.5c Copyright © 9 Jun 2010 Real-Time Innovations, Inc