Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dynamic Types routing participants #43

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions ddspipe_core/include/ddspipe_core/types/dds/CustomTransport.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 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,
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// limitations under the License.

#pragma once

namespace eprosima {
namespace ddspipe {
namespace core {
namespace types {

//! Different options for transport configuration
enum class TransportDescriptors
{
builtin,
udp_only,
shm_only
};

//! Possible values for Ignore Participant Flags
enum class IgnoreParticipantFlags
{
no_filter,
filter_different_host,
filter_different_process,
filter_same_process,
filter_different_and_same_process
};

} /* namespace types */
} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

#pragma once

#include <ddspipe_core/types/dds/CustomTransport.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_participants/configuration/ParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_participants/types/address/Address.hpp>

namespace eprosima {
namespace ddspipe {
Expand Down Expand Up @@ -48,6 +50,12 @@ struct SimpleParticipantConfiguration : public ParticipantConfiguration
/////////////////////////

core::types::DomainId domain {0u};

std::set<participants::types::IpType> whitelist {};

core::types::TransportDescriptors transport {core::types::TransportDescriptors::builtin};

core::types::IgnoreParticipantFlags ignore_participant_flags {core::types::IgnoreParticipantFlags::no_filter};
};

} /* namespace participants */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2023 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.

#pragma once

#include <mutex>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>

#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
#include <ddspipe_core/dynamic/DiscoveryDatabase.hpp>

#include <ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/writer/auxiliar/InternalWriter.hpp>

namespace eprosima {
namespace ddspipe {
namespace participants {
namespace dds {

/**
* TODO comment
*/
class DdsCommonParticipant : public core::IParticipant, public eprosima::fastdds::dds::DomainParticipantListener
{
public:

DDSPIPE_PARTICIPANTS_DllAPI
virtual ~DdsCommonParticipant();

DDSPIPE_PARTICIPANTS_DllAPI
virtual core::types::ParticipantId id() const noexcept override;

DDSPIPE_PARTICIPANTS_DllAPI
virtual bool is_rtps_kind() const noexcept override;

// NOTE: This should not be initialized here, but it is just for simplicity and less code in childs
DDSPIPE_PARTICIPANTS_DllAPI
virtual bool is_repeater() const noexcept override;

DDSPIPE_PARTICIPANTS_DllAPI
virtual void init();

protected:

// TODO
DDSPIPE_PARTICIPANTS_DllAPI
DdsCommonParticipant(
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration);

eprosima::fastdds::dds::DomainParticipant* dds_participant_;
eprosima::fastdds::dds::Publisher* dds_publisher_;
eprosima::fastdds::dds::Subscriber* dds_subscriber_;

core::types::ParticipantId id_;

std::shared_ptr<SimpleParticipantConfiguration> participant_configuration_;
};

} /* namespace dds */
} /* namespace participants */
} /* namespace ddspipe */
} /* namespace eprosima */
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2023 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.

#pragma once

#include <mutex>
#include <map>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/topic/Topic.hpp>

#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>

#include <ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/writer/auxiliar/InternalWriter.hpp>
#include <ddspipe_participants/participant/dds/DdsCommonParticipant.hpp>

namespace eprosima {
namespace ddspipe {
namespace participants {

/**
* TODO comment
*/
class DynTypesPublicationParticipant : public dds::DdsCommonParticipant
{
public:

// TODO
DDSPIPE_PARTICIPANTS_DllAPI
DynTypesPublicationParticipant(
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration,
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database);

DDSPIPE_PARTICIPANTS_DllAPI
virtual ~DynTypesPublicationParticipant();

DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<core::IWriter> create_writer(
const core::ITopic& topic) override;

DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<core::IReader> create_reader(
const core::ITopic& topic) override;

protected:

DDSPIPE_PARTICIPANTS_DllAPI
utils::ReturnCode receive_type_object_(
eprosima::fastrtps::types::DynamicType_ptr dynamic_type);

DDSPIPE_PARTICIPANTS_DllAPI
utils::ReturnCode receive_type_object_(
ddspipe::core::IRoutingData& data);

DDSPIPE_PARTICIPANTS_DllAPI
void create_empty_datawriter_nts_(
const core::types::DdsTopic& topic);

static
DDSPIPE_PARTICIPANTS_DllAPI
fastdds::dds::DataWriterQos
default_empty_datawriter_qos_(
const core::types::DdsTopic& topic) noexcept;

static
DDSPIPE_PARTICIPANTS_DllAPI
fastdds::dds::TopicQos
default_topic_qos_(
const core::types::DdsTopic& topic) noexcept;

std::map<
core::types::DdsTopic,
std::pair<
fastdds::dds::Topic*,
fastdds::dds::DataWriter*>> writers_;

std::map<std::string, eprosima::fastrtps::types::DynamicType_ptr> types_discovered_;

//! Type Object Internal Writer
std::shared_ptr<InternalWriter> type_object_writer_;

std::mutex mutex_;
};

} /* namespace participants */
} /* namespace ddspipe */
} /* namespace eprosima */
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2023 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 DynTypesSubscriptionParticipant.hpp
*/

#pragma once

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>

#include <ddspipe_core/interface/IParticipant.hpp>

#include <ddspipe_participants/configuration/SimpleParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/reader/auxiliar/InternalReader.hpp>
#include <ddspipe_participants/participant/dds/DdsCommonParticipant.hpp>

namespace eprosima {
namespace ddspipe {
namespace participants {

/**
* TODO comment
*/
class DynTypesSubscriptionParticipant : public dds::DdsCommonParticipant
{
public:

// TODO
DDSPIPE_PARTICIPANTS_DllAPI
DynTypesSubscriptionParticipant(
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration,
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database);

DDSPIPE_PARTICIPANTS_DllAPI
virtual ~DynTypesSubscriptionParticipant() = default;

DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<core::IWriter> create_writer(
const core::ITopic& topic) override;

DDSPIPE_PARTICIPANTS_DllAPI
std::shared_ptr<core::IReader> create_reader(
const core::ITopic& topic) override;

DDSPIPE_PARTICIPANTS_DllAPI
virtual void on_type_discovery(
eprosima::fastdds::dds::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) override;

DDSPIPE_PARTICIPANTS_DllAPI
virtual void on_type_information_received(
eprosima::fastdds::dds::DomainParticipant* participant,
const eprosima::fastrtps::string_255 topic_name,
const eprosima::fastrtps::string_255 type_name,
const eprosima::fastrtps::types::TypeInformation& type_information) override;

protected:

DDSPIPE_PARTICIPANTS_DllAPI
void internal_notify_type_object_(
eprosima::fastrtps::types::DynamicType_ptr dynamic_type);

//! Type Object Internal Reader
std::shared_ptr<InternalReader> type_object_reader_;
};

} /* namespace participants */
} /* namespace ddspipe */
} /* namespace eprosima */
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
#include <fastdds/rtps/rtps_fwd.h>
#include <fastdds/rtps/writer/WriterDiscoveryInfo.h>
#include <fastrtps/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastrtps/rtps/RTPSDomain.h>
#include <fastrtps/rtps/participant/RTPSParticipantListener.h>
#include <fastrtps/rtps/RTPSDomain.h>


#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_core/dynamic/DiscoveryDatabase.hpp>
#include <ddspipe_core/efficiency/payload/PayloadPool.hpp>
#include <ddspipe_core/interface/IParticipant.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>

#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/configuration/ParticipantConfiguration.hpp>
#include <ddspipe_participants/library/library_dll.h>
#include <ddspipe_participants/types/address/Address.hpp>

namespace eprosima {
namespace ddspipe {
Expand Down Expand Up @@ -156,6 +158,15 @@ class CommonParticipant
const core::types::DdsTopic& topic,
const core::types::ParticipantId& discoverer_id);

/**
* @brief Create a transport descriptor with whitelist and type given by specialization.
*
*/
template<typename T>
DDSPIPE_PARTICIPANTS_DllAPI
static std::shared_ptr<T> create_descriptor_(
std::set<types::IpType> whitelist = {});

protected:

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class SimpleParticipant : public CommonParticipant
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration,
const std::shared_ptr<core::PayloadPool>& payload_pool,
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database);

protected:

/**
* @brief Static method that gives the attributes for a Simple Participant.
*/
static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
const SimpleParticipantConfiguration* configuration);
};

} /* namespace rtps */
Expand Down
Loading