Skip to content

Commit

Permalink
Participant discovery structures refactor (#5042)
Browse files Browse the repository at this point in the history
* Refs #21295: changing the name of the callback from onParticipantDiscovery to on_participant_discovery

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Change listener signature and DISCOVERY_STATUS to PARTICIPANT_DISCOVERY_STATUS

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Move PARTICIPANT_DISCOVERY_STATUS out of ParticipantDiscoveryInfo

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Substitute ParticipantDiscoveryInfo with ParticipantProxyData

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Remove ParticiapntDiscoveryInfo

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Extend ParticipantBuiltinTopicData

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Create ParticipantBuiltinTopicData in rtps namespace

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Create from_proxy_to_builtin method for participant

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Substitute ParticipantProxyData with ParticipantBuiltinTopicData

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Make ParticipantProxyData private

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Update version.md

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Uncrustify

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Fix compilation error after rebase

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Change name in camel case ParticipantDiscoveryStatus

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Change signature of fill_discovery_data_from_cdr_message

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Apply changes to new example

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Apply suggestions

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Apply suggestions

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295. Fix communication test build.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21295. Fix include order.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21295. Additional change on versions.md.

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>

* Refs #21295: Add missing guid conversion in the converter

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

* Refs #21295: Adjust after rebase

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>

---------

Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
elianalf and MiguelCompany authored Jul 24, 2024
1 parent c2dc6d2 commit aa80b72
Show file tree
Hide file tree
Showing 103 changed files with 546 additions and 441 deletions.
13 changes: 7 additions & 6 deletions examples/cpp/discovery_server/ServerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,20 @@ ServerApp::~ServerApp()

void ServerApp::on_participant_discovery(
DomainParticipant*,
fastdds::rtps::ParticipantDiscoveryInfo&& info,
fastdds::rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored)
{
static_cast<void>(should_be_ignored);
if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT)
if (status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT)
{
std::cout << "Discovered Participant with GUID " << info.info.m_guid << std::endl;
std::cout << "Discovered Participant with GUID " << info.guid << std::endl;
++matched_;
}
else if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT ||
info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT)
else if (status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT ||
status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT)
{
std::cout << "Dropped Participant with GUID " << info.info.m_guid << std::endl;
std::cout << "Dropped Participant with GUID " << info.guid << std::endl;
--matched_;
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/cpp/discovery_server/ServerApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <condition_variable>

#include <fastdds/dds/builtin/topic/ParticipantBuiltinTopicData.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>
Expand Down Expand Up @@ -49,7 +50,8 @@ class ServerApp : public Application, public DomainParticipantListener
//! Publisher matched method
void on_participant_discovery(
DomainParticipant* participant,
fastdds::rtps::ParticipantDiscoveryInfo&& info,
fastdds::rtps::ParticipantDiscoveryStatus status,
const fastdds::rtps::ParticipantBuiltinTopicData& info,
bool& should_be_ignored) override;

//! Run publisher
Expand Down
17 changes: 9 additions & 8 deletions examples/cpp/request_reply/ClientApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,18 @@ void ClientApp::stop()

void ClientApp::on_participant_discovery(
DomainParticipant* /* participant */,
rtps::ParticipantDiscoveryInfo&& info,
rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored)
{
std::lock_guard<std::mutex> lock(mtx_);

should_be_ignored = false;

rtps::GuidPrefix_t remote_participant_guid_prefix = info.info.m_guid.guidPrefix;
std::string status_str = TypeConverter::to_string(info.status);
rtps::GuidPrefix_t remote_participant_guid_prefix = info.guid.guidPrefix;
std::string status_str = TypeConverter::to_string(status);

if (info.info.m_userData.data_vec().size() != 1)
if (info.user_data.data_vec().size() != 1)
{
should_be_ignored = true;
request_reply_debug("ClientApp", "Ignoring participant with invalid user data: "
Expand All @@ -162,7 +163,7 @@ void ClientApp::on_participant_discovery(

if (!should_be_ignored)
{
CLIParser::EntityKind entity_kind = static_cast<CLIParser::EntityKind>(info.info.m_userData.data_vec()[0]);
CLIParser::EntityKind entity_kind = static_cast<CLIParser::EntityKind>(info.user_data.data_vec()[0]);
if (CLIParser::EntityKind::SERVER != entity_kind)
{
should_be_ignored = true;
Expand All @@ -176,12 +177,12 @@ void ClientApp::on_participant_discovery(
{
std::string server_str = CLIParser::parse_entity_kind(CLIParser::EntityKind::SERVER);

if (info.status == rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::DISCOVERED_PARTICIPANT)
if (status == rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT)
{
request_reply_debug("ClientApp", server_str << " " << status_str << ": " << remote_participant_guid_prefix);
}
else if (info.status == rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::REMOVED_PARTICIPANT ||
info.status == rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::DROPPED_PARTICIPANT)
else if (status == rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT ||
status == rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT)
{
request_reply_debug("ClientApp", server_str << " " << status_str << ": " << remote_participant_guid_prefix);
}
Expand Down
3 changes: 2 additions & 1 deletion examples/cpp/request_reply/ClientApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class ClientApp : public Application, public DomainParticipantListener
//! Participant discovery method
void on_participant_discovery(
DomainParticipant* participant,
rtps::ParticipantDiscoveryInfo&& info,
rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored) override;

//! Publication matched method
Expand Down
17 changes: 9 additions & 8 deletions examples/cpp/request_reply/ServerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,18 @@ void ServerApp::stop()

void ServerApp::on_participant_discovery(
DomainParticipant* /* participant */,
rtps::ParticipantDiscoveryInfo&& info,
rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored)
{
std::lock_guard<std::mutex> lock(mtx_);

should_be_ignored = false;

rtps::GuidPrefix_t remote_participant_guid_prefix = info.info.m_guid.guidPrefix;
std::string status_str = TypeConverter::to_string(info.status);
rtps::GuidPrefix_t remote_participant_guid_prefix = info.guid.guidPrefix;
std::string status_str = TypeConverter::to_string(status);

if (info.info.m_userData.data_vec().size() != 1)
if (info.user_data.data_vec().size() != 1)
{
should_be_ignored = true;
request_reply_debug("ServerApp", "Ignoring participant with invalid user data: "
Expand All @@ -149,7 +150,7 @@ void ServerApp::on_participant_discovery(

if (!should_be_ignored)
{
CLIParser::EntityKind entity_kind = static_cast<CLIParser::EntityKind>(info.info.m_userData.data_vec()[0]);
CLIParser::EntityKind entity_kind = static_cast<CLIParser::EntityKind>(info.user_data.data_vec()[0]);
if (CLIParser::EntityKind::CLIENT != entity_kind)
{
should_be_ignored = true;
Expand All @@ -163,12 +164,12 @@ void ServerApp::on_participant_discovery(
{
std::string client_str = CLIParser::parse_entity_kind(CLIParser::EntityKind::CLIENT);

if (info.status == rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::DISCOVERED_PARTICIPANT)
if (status == rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT)
{
request_reply_debug("ServerApp", client_str << " " << status_str << ": " << remote_participant_guid_prefix);
}
else if (info.status == rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::REMOVED_PARTICIPANT ||
info.status == rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::DROPPED_PARTICIPANT)
else if (status == rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT ||
status == rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT)
{
client_matched_status_.match_reply_reader(remote_participant_guid_prefix, false);
client_matched_status_.match_request_writer(remote_participant_guid_prefix, false);
Expand Down
3 changes: 2 additions & 1 deletion examples/cpp/request_reply/ServerApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class ServerApp : public Application, public DomainParticipantListener
//! Participant discovery method
void on_participant_discovery(
DomainParticipant* participant,
rtps::ParticipantDiscoveryInfo&& info,
rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored) override;

//! Publication matched method
Expand Down
12 changes: 6 additions & 6 deletions examples/cpp/request_reply/app_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,25 @@ struct TypeConverter
}

static std::string to_string(
const rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS& info)
const rtps::ParticipantDiscoveryStatus& info)
{
std::string info_str = "Unknown";

switch (info)
{
case rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::DISCOVERED_PARTICIPANT:
case rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT:
info_str = "discovered";
break;
case rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::CHANGED_QOS_PARTICIPANT:
case rtps::ParticipantDiscoveryStatus::CHANGED_QOS_PARTICIPANT:
info_str = "changed QoS";
break;
case rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::REMOVED_PARTICIPANT:
case rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT:
info_str = "removed";
break;
case rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::DROPPED_PARTICIPANT:
case rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT:
info_str = "dropped";
break;
case rtps::ParticipantDiscoveryInfo::DISCOVERY_STATUS::IGNORED_PARTICIPANT:
case rtps::ParticipantDiscoveryStatus::IGNORED_PARTICIPANT:
info_str = "ignored";
break;
default:
Expand Down
14 changes: 2 additions & 12 deletions include/fastdds/dds/builtin/topic/ParticipantBuiltinTopicData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,14 @@
#ifndef FASTDDS_DDS_BUILTIN_TOPIC__PARTICIPANTBUILTINTOPICDATA_HPP
#define FASTDDS_DDS_BUILTIN_TOPIC__PARTICIPANTBUILTINTOPICDATA_HPP

#include <fastdds/dds/builtin/topic/BuiltinTopicKey.hpp>
#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/rtps/builtin/data/ParticipantBuiltinTopicData.hpp>

namespace eprosima {
namespace fastdds {
namespace dds {
namespace builtin {

struct ParticipantBuiltinTopicData
{
//! Builtin topic Key
BuiltinTopicKey_t key;
using ParticipantBuiltinTopicData = rtps::ParticipantBuiltinTopicData;

//! UserData QoS
UserDataQosPolicy user_data;
};

} // builtin
} // dds
} // fastdds
} // eprosima
Expand Down
2 changes: 1 addition & 1 deletion include/fastdds/dds/domain/DomainParticipant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ class DomainParticipant : public Entity
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
*/
FASTDDS_EXPORTED_API ReturnCode_t get_discovered_participant_data(
builtin::ParticipantBuiltinTopicData& participant_data,
ParticipantBuiltinTopicData& participant_data,
const InstanceHandle_t& participant_handle) const;

/**
Expand Down
8 changes: 7 additions & 1 deletion include/fastdds/dds/domain/DomainParticipantListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <fastdds/dds/publisher/PublisherListener.hpp>
#include <fastdds/dds/subscriber/SubscriberListener.hpp>
#include <fastdds/dds/topic/TopicListener.hpp>
#include <fastdds/dds/builtin/topic/ParticipantBuiltinTopicData.hpp>
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.hpp>
#include <fastdds/rtps/reader/ReaderDiscoveryStatus.hpp>
#include <fastdds/rtps/writer/WriterDiscoveryStatus.hpp>
Expand All @@ -34,6 +35,7 @@ namespace fastdds {
namespace dds {

class DomainParticipant;
class ParticipantProxyData;

/**
* Class DomainParticipantListener, overrides behaviour towards certain events.
Expand Down Expand Up @@ -66,16 +68,20 @@ class DomainParticipantListener :
* its QOS or is removed.
*
* @param [out] participant Pointer to the Participant which discovered the remote participant.
* @param [out] reason Reason of the change in the status of the discovered participant.
* @param [out] info Remote participant information. User can take ownership of the object.
* @param [out] should_be_ignored Flag to indicate the library to automatically ignore the discovered Participant.
*/
virtual void on_participant_discovery(
DomainParticipant* participant,
rtps::ParticipantDiscoveryInfo&& info,
fastdds::rtps::ParticipantDiscoveryStatus reason,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored)
{
static_cast<void>(participant);
static_cast<void>(reason);
static_cast<void>(info);

should_be_ignored = false;
}

Expand Down
68 changes: 68 additions & 0 deletions include/fastdds/rtps/builtin/data/ParticipantBuiltinTopicData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file ParticipantBuiltinTopicData.hpp
*
*/

#ifndef FASTDDS_RTPS_BUILTIN_DATA__PARTICIPANTBUILTINTOPICDATA_HPP
#define FASTDDS_RTPS_BUILTIN_DATA__PARTICIPANTBUILTINTOPICDATA_HPP

#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/rtps/builtin/data/BuiltinTopicKey.hpp>
#include <fastdds/rtps/common/RemoteLocators.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

struct ParticipantBuiltinTopicData
{
/// Builtin topic Key
BuiltinTopicKey_t key;

/// UserData QoS
dds::UserDataQosPolicy user_data;

/// Participant GUID
GUID_t guid;

/// Properties
dds::ParameterPropertyList_t properties;

/// Participant name
fastcdr::string_255 participant_name;

/// Metatraffic locators
RemoteLocatorList metatraffic_locators;

/// Default locators
RemoteLocatorList default_locators;

/// Lease Duration
dds::Duration_t lease_duration;

/// Vendor id
VendorId_t vendor_id;

/// Participant domain id
dds::DomainId_t domain_id;
};

} // rtps
} // fastdds
} // eprosima

#endif // FASTDDS_RTPS_BUILTIN_DATA__PARTICIPANTBUILTINTOPICDATA_HPP
Loading

0 comments on commit aa80b72

Please sign in to comment.