3.2.2. DomainParticipantListenerΒΆ
DomainParticipantListener
is an abstract class defining the callbacks that will be triggered
in response to state changes on the DomainParticipant.
By default, all these callbacks are empty and do nothing.
The user should implement a specialization of this class overriding the callbacks
that are needed on the application.
Callbacks that are not overridden will maintain their empty implementation.
DomainParticipantListener inherits from TopicListener,
PublisherListener, and SubscriberListener.
Therefore, it has the ability to react to every kind of event that is
reported to any of its attached Entities.
Since events are always notified to the most specific Entity Listener that can handle the event,
callbacks that DomainParticipantListener inherits from other Listeners will only be called
if no other Entity was able to handle the event,
either because it has no Listener attached,
or because the callback is disabled by the StatusMask
on the Entity.
Additionally, DomainParticipantListener adds the following callbacks:
on_participant_discovery()
: A new DomainParticipant is discovered in the same domain, a previously known DomainParticipant has been removed, or some DomainParticipant has changed its QoS.
on_subscriber_discovery()
: A new Subscriber is discovered in the same domain, a previously known Subscriber has been removed, or some Subscriber has changed its QoS.
on_publisher_discovery()
: A new Publisher is discovered in the same domain, a previously known Publisher has been removed, or some Publisher has changed its QoS.
on_type_discovery()
: A new data Type is discovered in the same domain.
on_type_dependencies_reply()
: The Type lookup client received a replay to agetTypeDependencies()
request. This callback can be used to retrieve the new type using thegetTypes()
request and create a new dynamic type using the retrieved type object.
on_type_information_received()
: A newTypeInformation
has been received from a newly discovered DomainParticipant.
onParticipantAuthentication()
: Informs about the result of the authentication process of a remote DomainParticipant (either on failure or success).
Important
For more information about callbacks and its hierarchy, please refer to Listener.
class CustomDomainParticipantListener : public DomainParticipantListener
{
public:
CustomDomainParticipantListener()
: DomainParticipantListener()
{
}
virtual ~CustomDomainParticipantListener()
{
}
virtual void on_participant_discovery(
DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info)
{
if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT)
{
std::cout << "New participant discovered" << std::endl;
}
else if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT ||
info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT)
{
std::cout << "New participant lost" << std::endl;
}
}
#if HAVE_SECURITY
virtual void onParticipantAuthentication(
DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::ParticipantAuthenticationInfo&& info)
{
if (info.status == eprosima::fastrtps::rtps::ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT)
{
std::cout << "A participant was authorized" << std::endl;
}
else if (info.status == eprosima::fastrtps::rtps::ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT)
{
std::cout << "A participant failed authorization" << std::endl;
}
}
#endif // if HAVE_SECURITY
virtual void on_subscriber_discovery(
DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::ReaderDiscoveryInfo&& info)
{
if (info.status == eprosima::fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERED_READER)
{
std::cout << "New subscriber discovered" << std::endl;
}
else if (info.status == eprosima::fastrtps::rtps::ReaderDiscoveryInfo::REMOVED_READER)
{
std::cout << "New subscriber lost" << std::endl;
}
}
virtual void on_publisher_discovery(
DomainParticipant* /*participant*/,
eprosima::fastrtps::rtps::WriterDiscoveryInfo&& info)
{
if (info.status == eprosima::fastrtps::rtps::WriterDiscoveryInfo::DISCOVERED_WRITER)
{
std::cout << "New publisher discovered" << std::endl;
}
else if (info.status == eprosima::fastrtps::rtps::WriterDiscoveryInfo::REMOVED_WRITER)
{
std::cout << "New publisher lost" << std::endl;
}
}
virtual void on_type_discovery(
DomainParticipant* participant,
const eprosima::fastrtps::rtps::SampleIdentity& request_sample_id,
const eprosima::fastrtps::string_255& topic,
const eprosima::fastrtps::types::TypeIdentifier* identifier,
const eprosima::fastrtps::types::TypeObject* object,
eprosima::fastrtps::types::DynamicType_ptr dyn_type)
{
(void)participant, (void)request_sample_id, (void)topic, (void)identifier, (void)object, (void)dyn_type;
std::cout << "New data type discovered" << std::endl;
}
virtual void on_type_dependencies_reply(
DomainParticipant* participant,
const eprosima::fastrtps::rtps::SampleIdentity& request_sample_id,
const eprosima::fastrtps::types::TypeIdentifierWithSizeSeq& dependencies)
{
(void)participant, (void)request_sample_id, (void)dependencies;
std::cout << "Answer to a request for type dependencies was received" << std::endl;
}
virtual void on_type_information_received(
DomainParticipant* participant,
const eprosima::fastrtps::string_255 topic_name,
const eprosima::fastrtps::string_255 type_name,
const eprosima::fastrtps::types::TypeInformation& type_information)
{
(void)participant, (void)topic_name, (void)type_name, (void)type_information;
std::cout << "New data type information received" << std::endl;
}
};