A DataReader is attached to exactly one Subscriber that acts as a factory for it. Additionally, each DataReader is bound to a single Topic since its creation. This Topic must exist prior to the creation of the DataReader, and must be bound to the data type that the DataReader wants to publish.

The effect of creating a new DataReader in a Subscriber for a specific Topic is to initiate a new subscription with the name and data type described by the Topic.

Once the DataReader is created, the application will be informed when changes in the data value are received from remote publications. These changes can then be retrieved using the DataReader::read_next_sample() or DataReader::take_next_sample() member functions of the DataReader.

DataReaderQoS controls the behavior of the DataReader. Internally it contains the following QosPolicy objects:

Refer to the detailed description of each QosPolicy class for more information about their usage and default values.

Note

Reliability kind (whether the publication is reliable or best effort) is not mutable. However, the max_blocking_time data member of ReliabilityQosPolicy can be modified any time.

The QoS value of a previously created DataReader can be modified using the DataReader::set_qos() member function.

// Create a DataReader with default DataReaderQos
{
// Error
return;
}

// Get the current QoS or create a new one from scratch

// Modify QoS attributes
// (...)

// Assign the new Qos to the object


The default DataReaderQos refers to the value returned by the get_default_datareader_qos() member function on the Subscriber instance. The special value DATAREADER_QOS_DEFAULT can be used as QoS argument on create_datareader() or DataReader::set_qos() member functions to indicate that the current default DataReaderQos should be used.

When the system starts, the default DataReaderQos is equivalent to the default constructed value DataReaderQos(). The default DataReaderQos can be modified at any time using the set_default_datareader_qos() member function on the Subscriber instance. Modifying the default DataReaderQos will not affect already existing DataReader instances.

// Get the current QoS or create a new one from scratch

// Modify QoS attributes
// (...)

// Set as the new default DataReaderQos
{
// Error
return;
}

{
// Error
return;
}

// Get the current QoS or create a new one from scratch

// Modify QoS attributes
// (...)

// Set as the new default DataReaderQos
{
// Error
return;
}

{
// Error
return;
}

// Resetting the default DataReaderQos to the original default constructed values
!= ReturnCode_t::RETCODE_OK)
{
// Error
return;
}

// The previous instruction is equivalent to the following
!= ReturnCode_t::RETCODE_OK)
{
// Error
return;
}


set_default_datareader_qos() member function also accepts the special value DATAREADER_QOS_DEFAULT as input argument. This will reset the current default DataReaderQos to default constructed value DataReaderQos().

// Create a custom DataReaderQos

// Modify QoS attributes
// (...)

// Create a DataWriter with a custom DataReaderQos
{
// Error
return;
}

// Set the QoS on the DataWriter to the default
{
// Error
return;
}

// The previous instruction is equivalent to the following:

The value DATAREADER_QOS_DEFAULT has different meaning depending on where it is used: