Skip to content

Commit

Permalink
[DSR] fix compatibility with fastdds3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanCarlosgg committed Oct 24, 2024
1 parent ef82441 commit 8ab1e83
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 35 deletions.
19 changes: 10 additions & 9 deletions api/dsr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ DSRGraph::DSRGraph(std::string name, uint32_t id, const std::string &dsr_input_f
// RTPS Create participant
auto[suc, participant_handle] = dsrparticipant.init(agent_id, agent_name, all_same_host,
ParticipantChangeFunctor(this, [&](DSR::DSRGraph *graph,
eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info)
eprosima::fastdds::rtps::ParticipantDiscoveryStatus status,
const eprosima::fastdds::rtps::ParticipantBuiltinTopicData& info)
{
if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT)
if (status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT)
{
std::unique_lock<std::mutex> lck(participant_set_mutex);
std::cout << "Participant matched [" <<info.info.m_participantName.to_string() << "]" << std::endl;
graph->participant_set.insert({info.info.m_participantName.to_string(), false});
std::cout << "Participant matched [" << info.participant_name.to_string() << "]" << std::endl;
graph->participant_set.emplace(info.participant_name.to_string(), false);
}
else if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT ||
info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT)
else if (status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT ||
status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT)
{
std::unique_lock<std::mutex> lck(participant_set_mutex);
graph->participant_set.erase(info.info.m_participantName.to_string());
std::cout << "Participant unmatched [" <<info.info.m_participantName.to_string() << "]" << std::endl;
graph->delete_node(info.info.m_participantName.to_string());
graph->participant_set.erase(info.participant_name.to_string());
std::cout << "Participant unmatched [" << info.participant_name.to_string() << "]" << std::endl;
graph->delete_node(info.participant_name.to_string());
}
}));

Expand Down
10 changes: 6 additions & 4 deletions api/include/dsr/api/dsr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,19 @@ namespace DSR
class ParticipantChangeFunctor {
public:
DSRGraph *graph{};
std::function<void(DSRGraph *graph_,eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&)> f;
std::function<void(DSRGraph *graph_,eprosima::fastdds::rtps::ParticipantDiscoveryStatus, const eprosima::fastdds::rtps::ParticipantBuiltinTopicData&)> f;

ParticipantChangeFunctor(DSRGraph *graph_,
std::function<void(DSRGraph *graph_, eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&)> f_)
std::function<void(DSRGraph *graph_, eprosima::fastdds::rtps::ParticipantDiscoveryStatus,
const eprosima::fastdds::rtps::ParticipantBuiltinTopicData&)> f_)
: graph(graph_), f(std::move(f_)) {}

ParticipantChangeFunctor() = default;

void operator()(eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info) const
void operator()(eprosima::fastdds::rtps::ParticipantDiscoveryStatus status,
const eprosima::fastdds::rtps::ParticipantBuiltinTopicData& info) const
{
f(graph, std::forward<eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&>(info));
f(graph, status, info);
};
};

Expand Down
28 changes: 15 additions & 13 deletions core/include/dsr/core/rtps/dsrparticipant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#define _PARTICIPANT_H_

#include <fastdds/dds/log/Log.hpp>
#include <fastdds/rtps/RTPSDomain.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/rtps/builtin/data/ParticipantBuiltinTopicData.hpp>

#include <dsr/core/topics/IDLGraphPubSubTypes.hpp>
#include <dsr/core/rtps/dsrpublisher.h>
Expand All @@ -17,14 +16,14 @@ class DSRParticipant
public:
DSRParticipant();
virtual ~DSRParticipant();
[[nodiscard]] std::tuple<bool, eprosima::fastdds::dds::DomainParticipant *> init(uint32_t agent_id, const std::string& agent_name, int localhost, std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&)> fn);
[[nodiscard]] std::tuple<bool, eprosima::fastdds::dds::DomainParticipant *> init(uint32_t agent_id, const std::string& agent_name, int localhost, std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryStatus, const eprosima::fastdds::rtps::ParticipantBuiltinTopicData&)> fn);
[[nodiscard]] const eprosima::fastdds::rtps::GUID_t& getID() const;
[[nodiscard]] const char *getNodeTopicName() const { return dsrgraphType->getName();}
[[nodiscard]] const char *getRequestTopicName() const { return graphrequestType->getName();}
[[nodiscard]] const char *getAnswerTopicName() const { return graphRequestAnswerType->getName();}
[[nodiscard]] const char *getEdgeTopicName() const { return dsrEdgeType->getName();}
[[nodiscard]] const char *getNodeAttrTopicName() const { return dsrNodeAttrType->getName();}
[[nodiscard]] const char *getEdgeAttrTopicName() const { return dsrEdgeAttrType->getName();}
[[nodiscard]] const char *getNodeTopicName() const { return dsrgraphType->get_name().data();}
[[nodiscard]] const char *getRequestTopicName() const { return graphrequestType->get_name().data();}
[[nodiscard]] const char *getAnswerTopicName() const { return graphRequestAnswerType->get_name().data();}
[[nodiscard]] const char *getEdgeTopicName() const { return dsrEdgeType->get_name().data();}
[[nodiscard]] const char *getNodeAttrTopicName() const { return dsrNodeAttrType->get_name().data();}
[[nodiscard]] const char *getEdgeAttrTopicName() const { return dsrEdgeAttrType->get_name().data();}

[[nodiscard]] eprosima::fastdds::dds::Topic* getNodeTopic() { return topic_node; }
[[nodiscard]] eprosima::fastdds::dds::Topic* getEdgeTopic() { return topic_edge; }
Expand Down Expand Up @@ -66,21 +65,24 @@ class DSRParticipant
class ParticpantListener : public eprosima::fastdds::dds::DomainParticipantListener
{
public:
explicit ParticpantListener(std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&)>&& fn)
explicit ParticpantListener(std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryStatus,
const eprosima::fastdds::rtps::ParticipantBuiltinTopicData&)>&& fn)
: eprosima::fastdds::dds::DomainParticipantListener(), f(std::move(fn)){};
~ParticpantListener() override = default;

void on_participant_discovery (
eprosima::fastdds::dds::DomainParticipant* participant,
eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info,
eprosima::fastdds::rtps::ParticipantDiscoveryStatus status,
const eprosima::fastdds::rtps::ParticipantBuiltinTopicData& info,
bool& should_be_ignored) override
{
//Callback
f(std::forward<eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&>(info));
f(status, info);
}


std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&)> f;
std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryStatus,
const eprosima::fastdds::rtps::ParticipantBuiltinTopicData&)> f;
//int n_matched;
};
std::unique_ptr<ParticpantListener> m_listener;
Expand Down
3 changes: 0 additions & 3 deletions core/include/dsr/core/rtps/dsrpublisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@


#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/utils/IPLocator.hpp>

#include <dsr/core/topics/IDLGraphPubSubTypes.hpp>

Expand Down
2 changes: 0 additions & 2 deletions core/include/dsr/core/rtps/dsrsubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>

#include <functional>

Expand Down
4 changes: 2 additions & 2 deletions core/rtps/dsrparticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DSRParticipant::~DSRParticipant()

}

std::tuple<bool, eprosima::fastdds::dds::DomainParticipant*> DSRParticipant::init(uint32_t agent_id, const std::string& agent_name, int localhost, std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryInfo&&)> fn)
std::tuple<bool, eprosima::fastdds::dds::DomainParticipant*> DSRParticipant::init(uint32_t agent_id, const std::string& agent_name, int localhost, std::function<void(eprosima::fastdds::rtps::ParticipantDiscoveryStatus, const eprosima::fastdds::rtps::ParticipantBuiltinTopicData&)> fn)
{
// Create RTPSParticipant
DomainParticipantQos PParam;
Expand Down Expand Up @@ -80,7 +80,7 @@ std::tuple<bool, eprosima::fastdds::dds::DomainParticipant*> DSRParticipant::ini

PParam.wire_protocol().builtin.discovery_config.leaseDuration = /*eprosima::fastdds::c_TimeInfinite;*/ Duration_t(6);
PParam.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod =
eprosima::fastdds::Duration_t(3, 0);
eprosima::fastdds::dds::Duration_t(3, 0);

eprosima::fastdds::dds::Log::SetVerbosity(eprosima::fastdds::dds::Log::Info);

Expand Down
3 changes: 1 addition & 2 deletions core/rtps/dsrsubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ using namespace eprosima::fastdds::rtps;
DSRSubscriber::DSRSubscriber() : mp_participant(nullptr), mp_subscriber(nullptr), mp_reader(nullptr) {}

DSRSubscriber::~DSRSubscriber()
{
}
= default;

std::tuple<bool, eprosima::fastdds::dds::Subscriber*, eprosima::fastdds::dds::DataReader*>
DSRSubscriber::init(eprosima::fastdds::dds::DomainParticipant *mp_participant_,
Expand Down

0 comments on commit 8ab1e83

Please sign in to comment.