Fast DDS  Version 3.1.2
Fast DDS
Loading...
Searching...
No Matches
Subscriber.hpp
1// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19#ifndef FASTDDS_DDS_SUBSCRIBER__SUBSCRIBER_HPP
20#define FASTDDS_DDS_SUBSCRIBER__SUBSCRIBER_HPP
21
22#include <fastdds/dds/core/Entity.hpp>
23#include <fastdds/dds/core/ReturnCode.hpp>
24#include <fastdds/dds/subscriber/DataReaderListener.hpp>
25#include <fastdds/dds/subscriber/InstanceState.hpp>
26#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
27#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
28#include <fastdds/dds/subscriber/SampleState.hpp>
29#include <fastdds/dds/subscriber/ViewState.hpp>
30#include <fastdds/dds/topic/qos/TopicQos.hpp>
31#include <fastdds/dds/topic/TypeSupport.hpp>
32
33namespace dds {
34namespace sub {
35
36class Subscriber;
37
38} // namespace sub
39} // namespace dds
40
41namespace eprosima {
42namespace fastdds {
43namespace rtps {
44
45class IPayloadPool;
46
47} // namespace rtps
48
49namespace dds {
50
51class DomainParticipant;
52class SubscriberListener;
53class SubscriberImpl;
54class DataReader;
55class DataReaderListener;
56class DataReaderQos;
57class TopicDescription;
66{
67protected:
68
69 friend class SubscriberImpl;
71
77 SubscriberImpl* pimpl,
78 const StatusMask& mask = StatusMask::all());
79
83 SubscriberListener* listener = nullptr,
84 const StatusMask& mask = StatusMask::all());
85
86public:
87
91 virtual ~Subscriber()
92 {
93 }
94
101 FASTDDS_EXPORTED_API ReturnCode_t enable() override;
102
108 FASTDDS_EXPORTED_API const SubscriberQos& get_qos() const;
109
116 FASTDDS_EXPORTED_API ReturnCode_t get_qos(
117 SubscriberQos& qos) const;
118
127 FASTDDS_EXPORTED_API ReturnCode_t set_qos(
128 const SubscriberQos& qos);
129
135 FASTDDS_EXPORTED_API const SubscriberListener* get_listener() const;
136
143 FASTDDS_EXPORTED_API ReturnCode_t set_listener(
144 SubscriberListener* listener);
145
153 FASTDDS_EXPORTED_API ReturnCode_t set_listener(
154 SubscriberListener* listener,
155 const StatusMask& mask);
166 FASTDDS_EXPORTED_API DataReader* create_datareader(
167 TopicDescription* topic,
168 const DataReaderQos& reader_qos,
169 DataReaderListener* listener = nullptr,
170 const StatusMask& mask = StatusMask::all(),
171 std::shared_ptr<fastdds::rtps::IPayloadPool> payload_pool = nullptr);
172
184 TopicDescription* topic,
185 const std::string& profile_name,
186 DataReaderListener* listener = nullptr,
187 const StatusMask& mask = StatusMask::all(),
188 std::shared_ptr<fastdds::rtps::IPayloadPool> payload_pool = nullptr);
189
201 FASTDDS_EXPORTED_API ReturnCode_t delete_datareader(
202 const DataReader* reader);
203
214 FASTDDS_EXPORTED_API DataReader* lookup_datareader(
215 const std::string& topic_name) const;
216
223 FASTDDS_EXPORTED_API ReturnCode_t get_datareaders(
224 std::vector<DataReader*>& readers) const;
225
238 FASTDDS_EXPORTED_API ReturnCode_t get_datareaders(
239 std::vector<DataReader*>& readers,
240 const std::vector<SampleStateKind>& sample_states,
241 const std::vector<ViewStateKind>& view_states,
242 const std::vector<InstanceStateKind>& instance_states) const;
243
249 FASTDDS_EXPORTED_API bool has_datareaders() const;
250
259 FASTDDS_EXPORTED_API ReturnCode_t begin_access();
260
269 FASTDDS_EXPORTED_API ReturnCode_t end_access();
270
271
281 FASTDDS_EXPORTED_API ReturnCode_t notify_datareaders() const;
282
290
306 const DataReaderQos& qos);
307
318 FASTDDS_EXPORTED_API const DataReaderQos& get_default_datareader_qos() const;
319
320
332
345 DataReaderQos& qos) const;
346
355 const std::string& profile_name,
356 DataReaderQos& qos) const;
357
367 const std::string& profile_name,
368 DataReaderQos& qos,
369 std::string& topic_name) const;
370
379 const std::string& xml,
380 DataReaderQos& qos) const;
381
391 const std::string& xml,
392 DataReaderQos& qos,
393 std::string& topic_name) const;
394
404 const std::string& xml,
405 DataReaderQos& qos,
406 const std::string& profile_name) const;
407
418 const std::string& xml,
419 DataReaderQos& qos,
420 std::string& topic_name,
421 const std::string& profile_name) const;
422
433 const std::string& xml,
434 DataReaderQos& qos) const;
435
447 const std::string& xml,
448 DataReaderQos& qos,
449 std::string& topic_name) const;
450
460 FASTDDS_EXPORTED_API static ReturnCode_t copy_from_topic_qos(
461 DataReaderQos& reader_qos,
462 const TopicQos& topic_qos);
463
469 FASTDDS_EXPORTED_API const DomainParticipant* get_participant() const;
470
476 FASTDDS_EXPORTED_API const InstanceHandle_t& get_instance_handle() const;
477
478protected:
479
481
482 friend class ::dds::sub::Subscriber;
483};
484
485} // namespace dds
486} // namespace fastdds
487} // namespace eprosima
488
489#endif // FASTDDS_DDS_SUBSCRIBER__SUBSCRIBER_HPP
Class DataReader, contains the actual implementation of the behaviour of the Subscriber.
Definition DataReader.hpp:82
Class DataReaderListener, it should be used by the end user to implement specific callbacks to certai...
Definition DataReaderListener.hpp:41
Class DataReaderQos, containing all the possible Qos that can be set for a determined DataReader.
Definition DataReaderQos.hpp:133
The DomainEntity class is a subclass of Entity created in order to differentiate between DomainPartic...
Definition Entity.hpp:166
Class DomainParticipant used to group Publishers and Subscribers into a single working unit.
Definition DomainParticipant.hpp:78
StatusMask is a bitmap or bitset field.
Definition StatusMask.hpp:48
static StatusMask all()
Get all StatusMasks.
Definition StatusMask.hpp:104
Class Subscriber, contains the public API that allows the user to control the reception of messages.
Definition Subscriber.hpp:66
Subscriber(SubscriberImpl *pimpl, const StatusMask &mask=StatusMask::all())
Create a subscriber, assigning its pointer to the associated implementation.
SubscriberImpl * impl_
Definition Subscriber.hpp:480
FASTDDS_EXPORTED_API DataReaderQos & get_default_datareader_qos()
This operation returns the default value of the DataReader QoS, that is, the QoS policies which will ...
Subscriber(DomainParticipant *dp, const SubscriberQos &qos=SUBSCRIBER_QOS_DEFAULT, SubscriberListener *listener=nullptr, const StatusMask &mask=StatusMask::all())
FASTDDS_EXPORTED_API const InstanceHandle_t & get_instance_handle() const
Returns the Subscriber's handle.
FASTDDS_EXPORTED_API ReturnCode_t get_default_datareader_qos(DataReaderQos &qos) const
This operation retrieves the default value of the DataReader QoS, that is, the QoS policies which wil...
FASTDDS_EXPORTED_API ReturnCode_t get_datareaders(std::vector< DataReader * > &readers) const
This operation allows the application to access the DataReader objects.
FASTDDS_EXPORTED_API ReturnCode_t set_listener(SubscriberListener *listener, const StatusMask &mask)
Modifies the SubscriberListener.
static FASTDDS_EXPORTED_API ReturnCode_t copy_from_topic_qos(DataReaderQos &reader_qos, const TopicQos &topic_qos)
Copies TopicQos into the corresponding DataReaderQos.
FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_xml(const std::string &xml, DataReaderQos &qos, std::string &topic_name, const std::string &profile_name) const
Fills the DataReaderQos with the DataReader profile with profile_name to be found in the provided XML...
FASTDDS_EXPORTED_API ReturnCode_t delete_datareader(const DataReader *reader)
This operation deletes a DataReader that belongs to the Subscriber.
FASTDDS_EXPORTED_API DataReader * lookup_datareader(const std::string &topic_name) const
This operation retrieves a previously-created DataReader belonging to the Subscriber that is attached...
FASTDDS_EXPORTED_API ReturnCode_t begin_access()
Indicates that the application is about to access the data samples in any of the DataReader objects a...
FASTDDS_EXPORTED_API ReturnCode_t get_qos(SubscriberQos &qos) const
Retrieves the Subscriber Qos.
FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_xml(const std::string &xml, DataReaderQos &qos, std::string &topic_name) const
Fills the DataReaderQos with the first DataReader profile found in the provided XML,...
FASTDDS_EXPORTED_API DataReader * create_datareader(TopicDescription *topic, const DataReaderQos &reader_qos, DataReaderListener *listener=nullptr, const StatusMask &mask=StatusMask::all(), std::shared_ptr< fastdds::rtps::IPayloadPool > payload_pool=nullptr)
This operation creates a DataReader.
FASTDDS_EXPORTED_API ReturnCode_t set_default_datareader_qos(const DataReaderQos &qos)
This operation sets a default value of the DataReader QoS policies which will be used for newly creat...
virtual ~Subscriber()
Destructor.
Definition Subscriber.hpp:91
FASTDDS_EXPORTED_API ReturnCode_t end_access()
Indicates that the application has finished accessing the data samples in DataReader objects managed ...
FASTDDS_EXPORTED_API ReturnCode_t notify_datareaders() const
This operation invokes the operation on_data_available on the DataReaderListener objects attached to ...
FASTDDS_EXPORTED_API ReturnCode_t set_qos(const SubscriberQos &qos)
Allows modifying the Subscriber Qos.
FASTDDS_EXPORTED_API ReturnCode_t set_listener(SubscriberListener *listener)
Modifies the SubscriberListener, sets the mask to StatusMask::all()
FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_profile(const std::string &profile_name, DataReaderQos &qos, std::string &topic_name) const
Fills the DataReaderQos with the values of the XML profile, and also its corresponding topic name (if...
friend class SubscriberImpl
Definition Subscriber.hpp:69
FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_xml(const std::string &xml, DataReaderQos &qos) const
Fills the DataReaderQos with the first DataReader profile found in the provided XML.
FASTDDS_EXPORTED_API const DomainParticipant * get_participant() const
This operation returns the DomainParticipant to which the Subscriber belongs.
FASTDDS_EXPORTED_API ReturnCode_t delete_contained_entities()
Deletes all contained DataReaders.
FASTDDS_EXPORTED_API ReturnCode_t enable() override
This operation enables the Subscriber.
FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_profile(const std::string &profile_name, DataReaderQos &qos) const
Fills the DataReaderQos with the values of the XML profile.
FASTDDS_EXPORTED_API const SubscriberQos & get_qos() const
Allows accessing the Subscriber Qos.
FASTDDS_EXPORTED_API ReturnCode_t get_default_datareader_qos_from_xml(const std::string &xml, DataReaderQos &qos) const
Fills the DataReaderQos with the default DataReader profile found in the provided XML (if there is).
friend class DomainParticipantImpl
Definition Subscriber.hpp:70
FASTDDS_EXPORTED_API const DataReaderQos & get_default_datareader_qos() const
This operation returns the default value of the DataReader QoS, that is, the QoS policies which will ...
FASTDDS_EXPORTED_API bool has_datareaders() const
This operation checks if the subscriber has DataReaders.
FASTDDS_EXPORTED_API DataReader * create_datareader_with_profile(TopicDescription *topic, const std::string &profile_name, DataReaderListener *listener=nullptr, const StatusMask &mask=StatusMask::all(), std::shared_ptr< fastdds::rtps::IPayloadPool > payload_pool=nullptr)
This operation creates a DataReader.
FASTDDS_EXPORTED_API ReturnCode_t get_datareaders(std::vector< DataReader * > &readers, const std::vector< SampleStateKind > &sample_states, const std::vector< ViewStateKind > &view_states, const std::vector< InstanceStateKind > &instance_states) const
This operation allows the application to access the DataReader objects that contain samples with the ...
FASTDDS_EXPORTED_API const SubscriberListener * get_listener() const
Retrieves the attached SubscriberListener.
FASTDDS_EXPORTED_API ReturnCode_t get_default_datareader_qos_from_xml(const std::string &xml, DataReaderQos &qos, std::string &topic_name) const
Fills the DataReaderQos with the default DataReader profile found in the provided XML (if there is),...
FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_xml(const std::string &xml, DataReaderQos &qos, const std::string &profile_name) const
Fills the DataReaderQos with the DataReader profile with profile_name to be found in the provided XML...
Class SubscriberListener, it should be used by the end user to implement specific callbacks to certai...
Definition SubscriberListener.hpp:41
Class SubscriberQos, contains all the possible Qos that can be set for a determined Subscriber.
Definition SubscriberQos.hpp:38
Class TopicDescription, represents the fact that both publications and subscriptions are tied to a si...
Definition TopicDescription.hpp:38
Class TopicQos, containing all the possible Qos that can be set for a determined Topic.
Definition TopicQos.hpp:40
Definition DomainParticipant.hpp:45
FASTDDS_EXPORTED_API const SubscriberQos SUBSCRIBER_QOS_DEFAULT
int32_t ReturnCode_t
Definition DDSReturnCode.hpp:59
eProsima namespace.
Struct InstanceHandle_t, used to contain the key for WITH_KEY topics.
Definition InstanceHandle.hpp:154