Skip to content

Commit

Permalink
Update repository for Fast DDS 3.0.0 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Lucia Echevarria <[email protected]>
  • Loading branch information
LuciaEchevarria99 committed May 20, 2024
1 parent 50219c8 commit 2bb44ca
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
#include <iostream>
#include <functional>
#include <shared_mutex>
#include <tuple>

#include <fastrtps/types/DynamicTypePtr.h>
#include <fastcdr/cdr/fixed_size_string.hpp>

#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>

#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
#include <ddspipe_core/types/dds/Payload.hpp>
Expand All @@ -39,7 +42,7 @@ class DataStreamer : public TopicRateCalculator

using CallbackType = std::function<void (
const ddspipe::core::types::DdsTopic&,
const fastrtps::types::DynamicType_ptr&,
const fastdds::dds::DynamicType::_ref_type&,
const ddspipe::core::types::RtpsPayloadData&)>;

FASTDDSSPY_PARTICIPANTS_DllAPI
Expand All @@ -56,7 +59,8 @@ class DataStreamer : public TopicRateCalculator

FASTDDSSPY_PARTICIPANTS_DllAPI
void add_schema(
const fastrtps::types::DynamicType_ptr& dynamic_type) override;
const fastdds::dds::DynamicType::_ref_type& dynamic_type,
const std::tuple<fastcdr::string_255, fastdds::dds::xtypes::TypeIdentifier>& type_ids_tuple) override;

FASTDDSSPY_PARTICIPANTS_DllAPI
void add_data(
Expand All @@ -80,7 +84,7 @@ class DataStreamer : public TopicRateCalculator

ddspipe::core::types::DdsTopic activated_topic_;

std::map<std::string, fastrtps::types::DynamicType_ptr> types_discovered_;
std::map<std::string, fastdds::dds::DynamicType::_ref_type> types_discovered_;

mutable std::shared_timed_mutex mutex_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include <fastrtps/types/DynamicTypePtr.h>
#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>

#include <cpp_utils/collection/database/SafeDatabase.hpp>
#include <cpp_utils/types/Atomicable.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ class SpyDdsParticipant : public ddspipe::participants::DynTypesParticipant
const ddspipe::core::ITopic& topic) override;

FASTDDSSPY_PARTICIPANTS_DllAPI
virtual void on_participant_discovery(
fastdds::dds::DomainParticipant* participant,
virtual void onParticipantDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;

FASTDDSSPY_PARTICIPANTS_DllAPI
virtual void on_subscriber_discovery(
fastdds::dds::DomainParticipant* participant,
virtual void onReaderDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::ReaderDiscoveryInfo&& info);

FASTDDSSPY_PARTICIPANTS_DllAPI
virtual void on_publisher_discovery(
fastdds::dds::DomainParticipant* participant,
virtual void onWriterDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::WriterDiscoveryInfo&& info);

protected:
Expand Down
2 changes: 1 addition & 1 deletion fastddsspy_participants/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<depend>cpp_utils</depend>
<depend>ddspipe_core</depend>
<depend>ddspipe_participants</depend>
<depend>fastrtps</depend>
<depend>fastdds</depend>

<doc_depend>doxygen</doc_depend>

Expand Down
4 changes: 2 additions & 2 deletions fastddsspy_participants/project_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ set(MODULE_SUMMARY

set(MODULE_FIND_PACKAGES
fastcdr
fastrtps
fastdds
cpp_utils
ddspipe_core
ddspipe_participants)

set(fastrtps_MINIMUM_VERSION "2.8")
set(fastdds_MINIMUM_VERSION "3.0.0")

set(MODULE_DEPENDENCIES
$<$<BOOL:${WIN32}>:iphlpapi$<SEMICOLON>Shlwapi>
Expand Down
18 changes: 10 additions & 8 deletions fastddsspy_participants/src/cpp/model/DataStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

#include <mutex>

#include <fastrtps/types/DynamicType.h>
#include <fastrtps/types/DynamicPubSubType.h>
#include <fastrtps/types/DynamicData.h>
#include <fastrtps/types/DynamicDataFactory.h>
#include <fastrtps/types/DynamicDataHelper.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicData.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicDataFactory.hpp>

#include <cpp_utils/utils.hpp>

Expand Down Expand Up @@ -73,13 +72,16 @@ void DataStreamer::deactivate()
}

void DataStreamer::add_schema(
const fastrtps::types::DynamicType_ptr& dynamic_type)
const fastdds::dds::DynamicType::_ref_type& dynamic_type,
const std::tuple<fastcdr::string_255, fastdds::dds::xtypes::TypeIdentifier>& type_ids_tuple)
{
static_cast<void>(type_ids_tuple);

std::unique_lock<std::shared_timed_mutex> _(mutex_);

// Add type to map if not yet
// NOTE: it does not matter if it is already in set
types_discovered_[dynamic_type->get_name()] = dynamic_type;
types_discovered_[dynamic_type->get_name().to_string()] = dynamic_type;

logInfo(FASTDDSSPY_DATASTREAMER, "\nAdding schema with name " << dynamic_type->get_name() << ".");
}
Expand All @@ -90,7 +92,7 @@ void DataStreamer::add_data(
{
TopicRateCalculator::add_data(topic, data);

fastrtps::types::DynamicType_ptr dyn_type;
fastdds::dds::DynamicType::_ref_type dyn_type;

{
std::shared_lock<std::shared_timed_mutex> _(mutex_);
Expand Down
41 changes: 27 additions & 14 deletions fastddsspy_participants/src/cpp/participant/SpyDdsParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fastdds/rtps/builtin/data/ParticipantProxyData.h>
#include <fastdds/rtps/builtin/data/ReaderProxyData.h>
#include <fastdds/rtps/builtin/data/WriterProxyData.h>
#include <fastdds/rtps/participant/RTPSParticipant.h>

#include <ddspipe_participants/utils/utils.hpp>
Expand Down Expand Up @@ -56,31 +59,37 @@ std::shared_ptr<ddspipe::core::IReader> SpyDdsParticipant::create_reader(
return ddspipe::participants::DynTypesParticipant::create_reader(topic);
}

void SpyDdsParticipant::on_participant_discovery(
fastdds::dds::DomainParticipant* participant,
void SpyDdsParticipant::onParticipantDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::ParticipantDiscoveryInfo&& discovery_info)
{
fastrtps::rtps::ParticipantProxyData proxy_copy_info(discovery_info.info);

// If comes from this participant is not interesting
if (come_from_this_participant_(discovery_info.info.m_guid))
if (come_from_this_participant_(proxy_copy_info.m_guid))
{
return;
}

ParticipantInfo info;
info.active = (discovery_info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT
|| discovery_info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::CHANGED_QOS_PARTICIPANT);
info.name = std::string(discovery_info.info.m_participantName);
info.guid = discovery_info.info.m_guid;
info.name = std::string(proxy_copy_info.m_participantName);
info.guid = proxy_copy_info.m_guid;

ddspipe::participants::rtps::CommonParticipant::onParticipantDiscovery(participant, std::move(discovery_info));

internal_notify_participant_discovered_(info);
}

void SpyDdsParticipant::on_subscriber_discovery(
fastdds::dds::DomainParticipant* participant,
void SpyDdsParticipant::onReaderDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::ReaderDiscoveryInfo&& info)
{
fastrtps::rtps::ReaderProxyData proxy_copy(info.info);

// If comes from this participant is not interesting
if (come_from_this_participant_(info.info.guid()))
if (come_from_this_participant_(proxy_copy.guid()))
{
return;
}
Expand All @@ -90,15 +99,19 @@ void SpyDdsParticipant::on_subscriber_discovery(
// If participant left or dropped, this notification arrives as well
endpoint_info.active = !(info.status == fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERY_STATUS::REMOVED_READER);

ddspipe::participants::DynTypesParticipant::onReaderDiscovery(participant, std::move(info));

internal_notify_endpoint_discovered_(endpoint_info);
}

void SpyDdsParticipant::on_publisher_discovery(
fastdds::dds::DomainParticipant* participant,
void SpyDdsParticipant::onWriterDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::WriterDiscoveryInfo&& info)
{
fastrtps::rtps::WriterProxyData proxy_copy(info.info);

// If comes from this participant is not interesting
if (come_from_this_participant_(info.info.guid()))
if (come_from_this_participant_(proxy_copy.guid()))
{
return;
}
Expand All @@ -108,6 +121,8 @@ void SpyDdsParticipant::on_publisher_discovery(
// If participant left or dropped, this notification arrives as well
endpoint_info.active = !(info.status == fastrtps::rtps::WriterDiscoveryInfo::DISCOVERY_STATUS::REMOVED_WRITER);

ddspipe::participants::DynTypesParticipant::onWriterDiscovery(participant, std::move(info));

internal_notify_endpoint_discovered_(endpoint_info);
}

Expand Down Expand Up @@ -140,9 +155,7 @@ void SpyDdsParticipant::internal_notify_endpoint_discovered_(
bool SpyDdsParticipant::come_from_this_participant_(
const ddspipe::core::types::Guid& guid) const noexcept
{
return (guid.guid_prefix() == dds_participant_->guid().guidPrefix
|| guid.guid_prefix() == rtps_participant_->getGuid().guidPrefix
);
return (guid.guid_prefix() == rtps_participant_->getGuid().guidPrefix);
}

} /* namespace participants */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ utils::ReturnCode SpyParticipant::new_participant_info_(
ParticipantInfo info = participant_info.info;
ddspipe::core::types::Guid guid = info.guid;
model_->participant_database_.add_or_modify(std::move(guid), std::move(info));
return utils::ReturnCode::RETCODE_OK;
return utils::ReturnCode::OK;
}

utils::ReturnCode SpyParticipant::new_endpoint_info_(
Expand All @@ -86,7 +86,7 @@ utils::ReturnCode SpyParticipant::new_endpoint_info_(
EndpointInfo info = endpoint_info.info;
ddspipe::core::types::Guid guid = info.guid;
model_->endpoint_database_.add_or_modify(std::move(guid), std::move(info));
return utils::ReturnCode::RETCODE_OK;
return utils::ReturnCode::OK;
}

} /* namespace participants */
Expand Down
2 changes: 1 addition & 1 deletion fastddsspy_tool/project_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(MODULE_SUMMARY
set(MODULE_FIND_PACKAGES
yaml-cpp
fastcdr
fastrtps
fastdds
cpp_utils
ddspipe_core
ddspipe_participants
Expand Down
41 changes: 24 additions & 17 deletions fastddsspy_tool/src/cpp/tool/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fastrtps/types/DynamicType.h>
#include <fastrtps/types/DynamicPubSubType.h>
#include <fastrtps/types/DynamicData.h>
#include <fastrtps/types/DynamicDataFactory.h>
#include <fastrtps/types/DynamicDataHelper.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicData.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicDataFactory.hpp>
#include <fastdds/dds/xtypes/utils.hpp>

#include <cpp_utils/user_interface/CommandReader.hpp>
#include <cpp_utils/macros/custom_enumeration.hpp>
Expand Down Expand Up @@ -111,25 +111,26 @@ void Controller::run_command_(
}
}

fastrtps::types::DynamicData_ptr Controller::get_dynamic_data_(
const fastrtps::types::DynamicType_ptr& dyn_type,
fastdds::dds::DynamicData::_ref_type Controller::get_dynamic_data_(
const fastdds::dds::DynamicType::_ref_type& dyn_type,
const ddspipe::core::types::RtpsPayloadData& data) noexcept
{
// TODO fast this should not be done, but dyn types API is like it is.
auto& data_no_const = const_cast<ddspipe::core::types::RtpsPayloadData&>(data);

// Create PubSub Type
fastrtps::types::DynamicPubSubType pubsub_type(dyn_type);
fastrtps::types::DynamicData_ptr dyn_data(fastrtps::types::DynamicDataFactory::get_instance()->create_data(dyn_type));
fastdds::dds::DynamicPubSubType pubsub_type(dyn_type);
fastdds::dds::DynamicData::_ref_type dyn_data(fastdds::dds::DynamicDataFactory::get_instance()->create_data(dyn_type));

pubsub_type.deserialize(&data_no_const.payload, dyn_data.get());
// pubsub_type.deserialize(&data_no_const.payload, dyn_data.get());
pubsub_type.deserialize(&data_no_const.payload, &dyn_data);

return dyn_data;
}

void Controller::data_stream_callback_(
const ddspipe::core::types::DdsTopic& topic,
const fastrtps::types::DynamicType_ptr& dyn_type,
const fastdds::dds::DynamicType::_ref_type& dyn_type,
const ddspipe::core::types::RtpsPayloadData& data)
{
// Block entrance so prints does not collapse
Expand All @@ -141,13 +142,16 @@ void Controller::data_stream_callback_(
// TODO fast this does not make much sense as dynamictypes::print does not allow to choose target
// change in dyn types to be able to print it in view
view_.show("---");
fastrtps::types::DynamicDataHelper::print(dyn_data.get());
std::stringstream ss;
ss << std::setw(4);
auto ret = fastdds::dds::json_serialize(dyn_data, ss, fastdds::dds::DynamicDataJsonFormat::EPROSIMA);
std::cout << ss.str() << std::endl;
view_.show("---\n");
}

void Controller::data_stream_callback_verbose_(
const ddspipe::core::types::DdsTopic& topic,
const fastrtps::types::DynamicType_ptr& dyn_type,
const fastdds::dds::DynamicType::_ref_type& dyn_type,
const ddspipe::core::types::RtpsPayloadData& data)
{
// Block entrance so prints does not collapse
Expand All @@ -170,7 +174,10 @@ void Controller::data_stream_callback_verbose_(

// Print data
view_.show("data:\n---");
fastrtps::types::DynamicDataHelper::print(dyn_data.get());
std::stringstream ss;
ss << std::setw(4);
auto ret = fastdds::dds::json_serialize(dyn_data, ss, fastdds::dds::DynamicDataJsonFormat::EPROSIMA);
std::cout << ss.str() << std::endl;
view_.show("---\n");
}

Expand Down Expand Up @@ -310,7 +317,7 @@ void Controller::print_command_(
std::make_shared<participants::DataStreamer::CallbackType>(
[this](
const ddspipe::core::types::DdsTopic& topic,
const fastrtps::types::DynamicType_ptr& dyn_type,
const fastdds::dds::DynamicType::_ref_type& dyn_type,
const ddspipe::core::types::RtpsPayloadData& data
)
{
Expand Down Expand Up @@ -363,7 +370,7 @@ void Controller::print_command_(
callback = std::make_shared<participants::DataStreamer::CallbackType>(
[this](
const ddspipe::core::types::DdsTopic& topic,
const fastrtps::types::DynamicType_ptr& dyn_type,
const fastdds::dds::DynamicType::_ref_type& dyn_type,
const ddspipe::core::types::RtpsPayloadData& data
)
{
Expand All @@ -375,7 +382,7 @@ void Controller::print_command_(
callback = std::make_shared<participants::DataStreamer::CallbackType>(
[this](
const ddspipe::core::types::DdsTopic& topic,
const fastrtps::types::DynamicType_ptr& dyn_type,
const fastdds::dds::DynamicType::_ref_type& dyn_type,
const ddspipe::core::types::RtpsPayloadData& data
)
{
Expand Down
Loading

0 comments on commit 2bb44ca

Please sign in to comment.