Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#if FASTRTPS_VERSION_MINOR >= 2
#if FASTRTPS_VERSION_MAJOR >= 2 && FASTRTPS_VERSION_MINOR >= 2
#include <fastdds/dds/subscriber/InstanceState.hpp>
#endif // if FASTRTPS_VERSION_MINOR >= 2
#endif // if FASTRTPS_VERSION_MAJOR >= 2 && FASTRTPS_VERSION_MINOR >= 2

#include <iostream>

Expand Down
352 changes: 243 additions & 109 deletions src/Participant.cpp

Large diffs are not rendered by default.

59 changes: 46 additions & 13 deletions src/Participant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <fastdds/dds/core/Entity.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastrtps/types/DynamicType.h>
Expand Down Expand Up @@ -68,7 +69,7 @@ class Participant
* in the *YAML* configuration file.
*
* @param[in] config The configuration provided by the user.
* It must contain two keys in the *YAML* map:
* In case of fastdds type it can contain two keys in the *YAML* map:
*
* - `file_path`: Specifies the path to the XML profile that will be used to configure the
* *DomainParticipant*. More information on how to write these XML profiles can be found
Expand All @@ -79,6 +80,24 @@ class Participant
* that corresponds to the configuration profile that we want this Participant
* to be configured with.
*
* In case of databroker type it can contain three keys in the *YAML* map:
*
* - `server_id`: Specifies the Discovery Server ID in order to generate its GUID.
* It is incompatible with setting the GUID.
*
* - `server_guid`: Specifies the Discovery Server GUID.
* It is incompatible with setting the ID.
*
* - `listening_addresses`: Specifies a list of TCP listening addresses.
* - `ip`: Provides the public IP where the Server will be listening.
* - `port`: Provides the port where the Server will be listening.
*
* - `connection_addresses`: Specifies a list of TCP connection addresses.
* - `ip`: Provides the public IP of the Server to connect to.
* - `port`: Provides the port of the Server to connect to.
* - `server_id`: Provides the ID of the remote Server to connect to [incompatible with GUID].
* - `server_guid`: Provides the GUID of the remote Server to connect to [incompatible with ID].
*
* @throws DDSMiddlewareException If the XML profile was incorrect and, thus, the
* *DomainParticipant* could not be created.
*/
Expand All @@ -93,12 +112,12 @@ class Participant
/**
* @brief Construct a *Fast DDS DomainParticipant*, given its DDS domain ID.
*
* @param[in] domain_id The DDS domain ID for this participant.
* @param[in] config The configuration provided by the user.
*
* @throws DDSMiddlewareException If the *DomainParticipant* could not be created.
*/
void build_participant(
const ::fastdds::dds::DomainId_t& domain_id = 0);
const YAML::Node& config);

/**
* @brief Get the associate *FastDDS DomainParticipant* attribute.
Expand Down Expand Up @@ -193,23 +212,37 @@ class Participant
::fastdds::dds::Topic* topic,
::fastdds::dds::DomainEntity* entity);

private:
protected:

/**
* @brief Create a *Fast DDS DomainParticipant* using a certain profile.
* @brief Get Fast DDS System Handle Participant default QoS
*
* @note This method is a workaround due to `v2.0.X` versions of *Fast DDS* not including
* this method inside the *DomainParticipantFactory* class.
*
* @param[in] profile_name The XML profile name for the participant.
* @return Default Participant QoS
*/
eprosima::fastdds::dds::DomainParticipantQos get_default_participant_qos();

/**
* @brief Get Databroker DomainParticipantQos.
* @details The transport used over WAN is TCP.
* It calls \c get_participant_qos to reuse Participant YAML tags and then applies the specific Databroker tags:
* Databroker tags:
* * server_id: ID of the Discovery Server. It must be within the valid range [0:256).
* * listening_addresses: Listening addresses (public) for Discovery Server to listen in TCP.
* * ip
* * port
* * connection_addresses: Connection addresses for Discovery Server to connect to other servers.
* * ip
* * port
* * server_id
*
* @returns A correctly initialized DomainParticipant.
* @param[in] config The configuration provided by the user.
*
* @throws DDSMiddlewareException if some error occurs during the creation process.
* @return Specific QoS by user configuration.
*/
::fastdds::dds::DomainParticipant* create_participant_with_profile(
const std::string& profile_name);
eprosima::fastdds::dds::DomainParticipantQos get_databroker_qos(
const YAML::Node& config);

private:

/**
* Class members.
Expand Down
8 changes: 4 additions & 4 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#if FASTRTPS_VERSION_MINOR >= 2
#if FASTRTPS_VERSION_MAJOR >= 2 && FASTRTPS_VERSION_MINOR >= 2
#include <fastdds/dds/subscriber/InstanceState.hpp>
#endif // if FASTRTPS_VERSION_MINOR >= 2
#endif // if FASTRTPS_VERSION_MAJOR >= 2 && FASTRTPS_VERSION_MINOR >= 2

#include <functional>
#include <iostream>
Expand Down Expand Up @@ -546,11 +546,11 @@ void Server::on_data_available(
if (!stop_cleaner_ && fastrtps::types::ReturnCode_t::RETCODE_OK
== reply_entities_.dds_datareader->take_next_sample(reply_entities_.dynamic_data, &info))
{
#if FASTRTPS_VERSION_MINOR < 2
#if FASTRTPS_VERSION_MAJOR < 2 || FASTRTPS_VERSION_MINOR < 2
if (::fastdds::dds::InstanceStateKind::ALIVE == info.instance_state)
#else
if (::fastdds::dds::InstanceStateKind::ALIVE_INSTANCE_STATE == info.instance_state)
#endif // if FASTRTPS_VERSION_MINOR < 2
#endif // if FASTRTPS_VERSION_MAJOR < 2 || FASTRTPS_VERSION_MINOR < 2
{
logger_ << utils::Logger::Level::DEBUG
<< "Process incoming data available for service reply topic '"
Expand Down
8 changes: 4 additions & 4 deletions src/Subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include <fastdds/dds/subscriber/SubscriberListener.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#if FASTRTPS_VERSION_MINOR >= 2
#if FASTRTPS_VERSION_MAJOR >= 2 && FASTRTPS_VERSION_MINOR >= 2
#include <fastdds/dds/subscriber/InstanceState.hpp>
#endif // if FASTRTPS_VERSION_MINOR >= 2
#endif // if FASTRTPS_VERSION_MAJOR >= 2 && FASTRTPS_VERSION_MINOR >= 2

#include <functional>
#include <iostream>
Expand Down Expand Up @@ -214,11 +214,11 @@ void Subscriber::on_data_available(
if (!stop_cleaner_ && fastrtps::types::ReturnCode_t::RETCODE_OK
== dds_datareader_->take_next_sample(dynamic_data_, &info))
{
#if FASTRTPS_VERSION_MINOR < 2
#if FASTRTPS_VERSION_MAJOR < 2 || FASTRTPS_VERSION_MINOR < 2
if (::fastdds::dds::InstanceStateKind::ALIVE == info.instance_state)
#else
if (::fastdds::dds::InstanceStateKind::ALIVE_INSTANCE_STATE == info.instance_state)
#endif // if FASTRTPS_VERSION_MINOR < 2
#endif // if FASTRTPS_VERSION_MAJOR < 2 || FASTRTPS_VERSION_MINOR < 2
{
logger_ << utils::Logger::Level::DEBUG
<< "Processing incoming data available for topic '"
Expand Down
4 changes: 3 additions & 1 deletion src/SystemHandle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright 2021 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.
Expand Down Expand Up @@ -85,6 +85,7 @@ class SystemHandle : public virtual FullSystem
}
catch (DDSMiddlewareException& e)
{
logger_ << utils::Logger::Level::ERROR << "Participant creation failed." << std::endl;
e.from_logger << utils::Logger::Level::ERROR << e.what() << std::endl;
return false;
}
Expand Down Expand Up @@ -301,4 +302,5 @@ class SystemHandle : public virtual FullSystem
} // namespace is
} // namespace eprosima

// TODO aliases must come from CMAKE
IS_REGISTER_SYSTEM("fastdds", eprosima::is::sh::fastdds::SystemHandle)
81 changes: 81 additions & 0 deletions src/utils/databroker/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2019 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.
*
*/

#include "Participant.hpp"
#include "DDSMiddlewareException.hpp"
#include "Conversion.hpp"
#include "utils/databroker/utils.hpp"

#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>

#include <fastrtps/types/DynamicDataFactory.h>
#include <fastrtps/xmlparser/XMLProfileManager.h>

#include <sstream>

namespace eprosima {
namespace is {
namespace sh {
namespace fastdds {
namespace utils {

eprosima::fastrtps::rtps::GuidPrefix_t guid_server(
uint8_t id)
{
eprosima::fastrtps::rtps::GuidPrefix_t guid;
std::istringstream(SERVER_DEFAULT_GUID) >> guid;
guid.value[SERVER_DEFAULT_GUID_ID_INDEX] = static_cast<unsigned char>(id);
return guid;
}

eprosima::fastrtps::rtps::GuidPrefix_t guid_server(
const YAML::Node& server_id,
const YAML::Node& server_guid)
{
if (server_guid)
{
// Server GUID set and used
eprosima::fastrtps::rtps::GuidPrefix_t guid;
std::istringstream(server_guid.as<std::string>()) >> guid;
return guid; // There is no easy wat to directly return the guid
}
else if (server_id && !server_guid)
{
// Server ID set without GUID set
return guid_server(server_id.as<uint32_t>() % std::numeric_limits<uint8_t>::max());
}
else
{
// Server GUID by default with ID 0
return guid_server(0);
}
}

std::string guid_to_string(
const eprosima::fastrtps::rtps::GuidPrefix_t& guid)
{
std::ostringstream guid_ostream;
guid_ostream << guid;
return guid_ostream.str();
}

} // namespace utils
} // namespace fastdds
} // namespace sh
} // namespace is
} // namespace eprosima
84 changes: 84 additions & 0 deletions src/utils/databroker/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2021 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 utils.hpp
*
*/

#ifndef _IS_SH_FASTDDS__INTERNAL__UTILS_HPP_
#define _IS_SH_FASTDDS__INTERNAL__UTILS_HPP_

#include <sstream>
#include <vector>

#include <fastdds/rtps/common/GuidPrefix_t.hpp>

namespace eprosima {
namespace is {
namespace sh {
namespace fastdds {

namespace utils {

#define SERVER_DEFAULT_GUID "01.0f.00.44.41.54.95.42.52.4f.4b.45.52"
#define SERVER_DEFAULT_GUID_ID_INDEX 2

inline eprosima::fastrtps::rtps::GuidPrefix_t guid_server(
uint8_t id)
{
eprosima::fastrtps::rtps::GuidPrefix_t guid;
std::istringstream(SERVER_DEFAULT_GUID) >> guid;
guid.value[SERVER_DEFAULT_GUID_ID_INDEX] = static_cast<unsigned char>(id);
return guid;
}

inline eprosima::fastrtps::rtps::GuidPrefix_t guid_server(
const YAML::Node& server_id,
const YAML::Node& server_guid)
{
if (server_guid)
{
// Server GUID set and used
eprosima::fastrtps::rtps::GuidPrefix_t guid;
std::istringstream(server_guid.as<std::string>()) >> guid;
return guid; // There is no easy wat to directly return the guid
}
else if (server_id)
{
// Server ID set without GUID set
return guid_server(server_id.as<uint32_t>() % std::numeric_limits<uint8_t>::max());
}
else
{
// Server GUID by default with ID 0
return guid_server(0);
}
}

inline std::string guid_to_string(
const eprosima::fastrtps::rtps::GuidPrefix_t& guid)
{
std::ostringstream guid_ostream;
guid_ostream << guid;
return guid_ostream.str();
}

} // namespace utils
} // namespace fastdds
} // namespace sh
} // namespace is
} // namespace eprosima

#endif // _IS_SH_FASTDDS__INTERNAL__UTILS_HPP_
Loading