RTC Toolkit  1.0.0
Classes | Public Types | Public Member Functions | List of all members
rtctk::telSub::DdsSubscriber Class Referencefinal

Implements DDS communication using RTI DDS. More...

#include <ddsSubscriber.hpp>

Inheritance diagram for rtctk::telSub::DdsSubscriber:
rtctk::telSub::DdsSubscriberIf rtctk::telSub::SeqLoanerIf

Public Types

using Alloc = std::pmr::polymorphic_allocator< std::byte >
 

Public Member Functions

 DdsSubscriber (const DdsParams &params, Alloc const &alloc={})
 Constructs a DDS subscriber from given configuration parameters. More...
 
virtual ~DdsSubscriber () noexcept
 Destroys the DDS subscriber and releases all RTI DDS resources. More...
 
 DdsSubscriber (DdsSubscriber &&rhs)=delete
 
DdsSubscriberoperator= (DdsSubscriber &&rhs)=delete
 
AgnosticDataSamplesGetSamples () noexcept override
 Returns reference to data structure holding taken data samples. More...
 
std::error_code Take (std::chrono::nanoseconds timeout) noexcept override
 Takes new samples from DDS readers and updates data structure accessable from GetSamples() More...
 
size_t GetNumberOfTopics () const noexcept override
 Returns the number of configured topics. More...
 
const std::string & GetTopicName (size_t index) const noexcept override
 Returns a string containing the name of a configured topic. More...
 
std::error_code ReturnLoan (std::uint8_t idx, DdsSampleSeq &samples, DdsInfoSeq &infos) noexcept override
 Returns loaned sample sequence. More...
 
- Public Member Functions inherited from rtctk::telSub::DdsSubscriberIf
 DdsSubscriberIf () RTCTK_NOEXCEPT
 
virtual ~DdsSubscriberIf () RTCTK_NOEXCEPT
 

Detailed Description

Implements DDS communication using RTI DDS.

Member Typedef Documentation

◆ Alloc

using rtctk::telSub::DdsSubscriber::Alloc = std::pmr::polymorphic_allocator<std::byte>

Constructor & Destructor Documentation

◆ DdsSubscriber() [1/2]

rtctk::telSub::DdsSubscriber::DdsSubscriber ( const DdsParams params,
Alloc const &  alloc = {} 
)

Constructs a DDS subscriber from given configuration parameters.

The constructor will initialise the DDS subsystem and allocate necessary resources by constructing appropriate RTI DDS objects, such as the domain participant and RTI DDS subscriber. Individual DDS topic objects and DDS readers are created for each topic found in the params.m_topics vector.

There is a one to one correspondence between the topic in params.m_topics and the DDS reader and DDS topic object created. The order of the topics matters and is preserved, meaning that the n'th topic in params.m_topics will equal GetTopicName(n) after successful construction. In addition, the TakeSamples method will return DDS samples for the n'th DDS reader in its output parameter samples[n], which also corresponds to the configured topic GetTopicName(n).

Parameters
paramsThe structure containing all needed parameters to construct the DDS objects. using namespace eprosima::fastdds::dds;
Postcondition
GetNumberOfTopics() == params.m_topics.size(), i.e. the number of topics and corresponding DDS readers created will match the topic names passed in as configuration parameters.

◆ ~DdsSubscriber()

rtctk::telSub::DdsSubscriber::~DdsSubscriber ( )
virtualnoexcept

Destroys the DDS subscriber and releases all RTI DDS resources.

The destructor will release all resources associate with this subscriber object that were allocated by RTI DDS. This is done by deleting all RTI DDS object that were created and then calling the finalize_instance() method to shutdown the RTI DDS subsystem. Errors during this procedure cannot be propagated as exceptions, therefore the errors will simply be logged and execution allowed to continue.

◆ DdsSubscriber() [2/2]

rtctk::telSub::DdsSubscriber::DdsSubscriber ( DdsSubscriber &&  rhs)
delete

Member Function Documentation

◆ GetNumberOfTopics()

size_t rtctk::telSub::DdsSubscriber::GetNumberOfTopics ( ) const
overridevirtualnoexcept

Returns the number of configured topics.

This returns the number of topics that were configured during construction of the subscriber object. This corresponds to the size of the DdsParams::m_topics vector passed to the constructor.

Returns
The number of configured topics.

Implements rtctk::telSub::DdsSubscriberIf.

◆ GetSamples()

AgnosticDataSamples & rtctk::telSub::DdsSubscriber::GetSamples ( )
overridevirtualnoexcept

Returns reference to data structure holding taken data samples.

To update structure with new samples TakeSamples() must be used.

See also
TakeSamples()

Implements rtctk::telSub::DdsSubscriberIf.

◆ GetTopicName()

const std::string & rtctk::telSub::DdsSubscriber::GetTopicName ( size_t  index) const
overridevirtualnoexcept

Returns a string containing the name of a configured topic.

This returns the name of a configured DDS topic as a string. The topic name is associated with the index'th DDS reader and will also identify the topic for samples[index], which is the output parameter vector filled by TakeSamples containing newly arrived DDS samples for the index'th DDS reader.

Parameters
[in]indexThis selects which topic name to fetch. The value must be in the range 0 <= index and index < GetNumberOfTopics().
Returns
The index'th topic name.

Implements rtctk::telSub::DdsSubscriberIf.

◆ operator=()

DdsSubscriber& rtctk::telSub::DdsSubscriber::operator= ( DdsSubscriber &&  rhs)
delete

◆ ReturnLoan()

std::error_code rtctk::telSub::DdsSubscriber::ReturnLoan ( std::uint8_t  idx,
DdsSampleSeq samples,
DdsInfoSeq infos 
)
overridevirtualnoexcept

Returns loaned sample sequence.

After invoking this method successfully the provided sequences will be emptied.

Postcondition
samples.length() == 0u && infos.length() == 0
Parameters
idxTopic index.
samplesSample sequence.
infosSample information sequence.

Implements rtctk::telSub::SeqLoanerIf.

◆ Take()

std::error_code rtctk::telSub::DdsSubscriber::Take ( std::chrono::nanoseconds  timeout)
overridevirtualnoexcept

Takes new samples from DDS readers and updates data structure accessable from GetSamples()

The method waits for new DDS samples to become available on one or more of the DDS topic readers as needed to fill up AgnosticDataSamples from GetSamples() with a non-empty sample sequence for each topic.

An empty / zero error code is returned if the operation completed successfully, meaning at least one non-empty sample sequence was taken.

If no samples were available within the timeout period then a std::errc::timed_out error code is returned. If some other error occurred, an appropriate error code is returned.

It is expected that the caller processes the samples and when done with them calls AgnosticAgnosticDataSamples::Clear() to return the samples to DDS. It is not required that all sample sequences are cleared at the same time.

Parameters
[in]timeoutThe maximum amount of time to wait for this operation to complete, measured in nanoseconds.
Returns
An error code indicating success, failure or timeout of the operation.

The following is the list of possible error codes returned:

0
At least one samples was successfully returned.
std::errc::timed_out
The operation timed out while waiting for DDS samples.
std::errc::protocol_error
A call to the RTI DDS API failed.
std::errc::bad_address
Could not identify the associated topic reader for a sample.
See also
GetSamples()

Implements rtctk::telSub::DdsSubscriberIf.


The documentation for this class was generated from the following files: