Skip to content

Commit

Permalink
Refs #20629: Review - Make ServerAttributes private
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
  • Loading branch information
cferreiragonz committed Jun 24, 2024
1 parent f1e71c3 commit 1a268c9
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 356 deletions.
15 changes: 1 addition & 14 deletions examples/cpp/dds/DiscoveryServerExample/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_COMMON_H_
#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_COMMON_H_

#include <fastdds/rtps/attributes/ServerAttributes.h>
#include <fastdds/rtps/common/GuidPrefix_t.hpp>
#include <fastdds/utils/IPLocator.h>

enum class TransportKind
Expand All @@ -32,19 +32,6 @@ enum class TransportKind
SHM,
};

inline eprosima::fastdds::rtps::GuidPrefix_t get_discovery_server_guid_from_id(
unsigned short id)
{
eprosima::fastdds::rtps::GuidPrefix_t result;

// Get default DS guid and modify the one value expected to be changed
std::istringstream(eprosima::fastdds::rtps::DEFAULT_ROS2_SERVER_GUIDPREFIX) >> result;
result.value[2] =
static_cast<eprosima::fastdds::rtps::octet>(id); // This is done like this in Fast

return result;
}

inline bool is_ip(
const std::string ip_str)
{
Expand Down
16 changes: 15 additions & 1 deletion include/fastdds/rtps/attributes/RTPSParticipantAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <fastdds/rtps/attributes/ExternalLocators.hpp>
#include <fastdds/rtps/attributes/PropertyPolicy.h>
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
#include <fastdds/rtps/attributes/ServerAttributes.h>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/common/Locator.h>
#include <fastdds/rtps/common/PortParameters.h>
Expand Down Expand Up @@ -129,6 +128,21 @@ inline std::ostream& operator <<(
return output;
}

/**
* Returns the guidPrefix associated to the given server id
* @param[in] id of the default server whose guidPrefix we want to retrieve
* @param[out] guid reference to the guidPrefix to modify
* @return true if the server guid can be delivered
*/
FASTDDS_EXPORTED_API bool get_server_client_default_guidPrefix(
int id,
fastdds::rtps::GuidPrefix_t& guid);

// Port used if the ros environment variable doesn't specify one
constexpr uint16_t DEFAULT_ROS2_SERVER_PORT = 11811;
// Port used by default for tcp transport
constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 42100;

//! Filtering flags when discovering participants
enum ParticipantFilteringFlags : uint32_t
{
Expand Down
1 change: 1 addition & 0 deletions include/fastdds/rtps/participant/RTPSParticipant.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fastdds/dds/subscriber/qos/ReaderQos.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/builtin/data/ContentFilterProperty.hpp>
#include <fastdds/rtps/builtin/data/ParticipantProxyData.hpp>
#include <fastdds/rtps/common/Guid.h>
#include <fastdds/statistics/IListeners.hpp>
#include <fastdds/fastdds_dll.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/fastdds_dll.hpp>
#include <fastdds/rtps/builtin/data/ParticipantProxyData.hpp>

namespace eprosima {
namespace fastdds {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ set(${PROJECT_NAME}_source_files
rtps/attributes/EndpointSecurityAttributes.cpp
rtps/attributes/PropertyPolicy.cpp
rtps/attributes/RTPSParticipantAttributes.cpp
rtps/attributes/ServerAttributes.cpp
rtps/attributes/ThreadSettings.cpp
rtps/attributes/TopicAttributes.cpp
rtps/builtin/BuiltinProtocols.cpp
Expand All @@ -136,7 +137,6 @@ set(${PROJECT_NAME}_source_files
rtps/builtin/discovery/participant/PDPServer.cpp
rtps/builtin/discovery/participant/PDPServerListener.cpp
rtps/builtin/discovery/participant/PDPSimple.cpp
rtps/builtin/discovery/participant/ServerAttributes.cpp
rtps/builtin/discovery/participant/timedevent/DSClientEvent.cpp
rtps/builtin/discovery/participant/timedevent/DServerEvent.cpp
rtps/builtin/liveliness/WLP.cpp
Expand Down
1 change: 1 addition & 0 deletions src/cpp/rtps/RTPSDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <fastdds/utils/IPLocator.h>
#include <fastdds/utils/md5.h>

#include <rtps/attributes/ServerAttributes.hpp>
#include <rtps/common/GuidUtils.hpp>
#include <rtps/network/utils/external_locators.hpp>
#include <rtps/participant/RTPSParticipantImpl.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

#include <fastdds/rtps/attributes/ServerAttributes.h>
#include <rtps/attributes/ServerAttributes.hpp>

namespace eprosima {
namespace fastdds {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// 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.
Expand All @@ -13,7 +13,7 @@
// limitations under the License.

/**
* @file ServerAttributes.h
* @file ServerAttributes.hpp
*
*/

Expand All @@ -29,9 +29,9 @@
#include <list>

namespace eprosima {

namespace fastdds {
namespace rtps {

class ParticipantProxyData;

/**
Expand All @@ -43,27 +43,27 @@ class RemoteServerAttributes
{
public:

FASTDDS_EXPORTED_API inline bool operator ==(
inline bool operator ==(
const RemoteServerAttributes& r) const
{
return guidPrefix == r.guidPrefix
&& metatrafficUnicastLocatorList == r.metatrafficUnicastLocatorList
&& metatrafficMulticastLocatorList == r.metatrafficMulticastLocatorList;
}

FASTDDS_EXPORTED_API void clear()
void clear()
{
guidPrefix = fastdds::rtps::GuidPrefix_t::unknown();
metatrafficUnicastLocatorList.clear();
metatrafficMulticastLocatorList.clear();
}

FASTDDS_EXPORTED_API fastdds::rtps::GUID_t GetParticipant() const;
fastdds::rtps::GUID_t GetParticipant() const;

FASTDDS_EXPORTED_API fastdds::rtps::GUID_t GetPDPReader() const;
FASTDDS_EXPORTED_API fastdds::rtps::GUID_t GetPDPWriter() const;
fastdds::rtps::GUID_t GetPDPReader() const;
fastdds::rtps::GUID_t GetPDPWriter() const;

FASTDDS_EXPORTED_API inline bool ReadguidPrefix(
inline bool ReadguidPrefix(
const char* pfx)
{
return bool(std::istringstream(pfx) >> guidPrefix);
Expand Down Expand Up @@ -92,8 +92,8 @@ typedef std::list<RemoteServerAttributes> RemoteServerList_t;
template<class charT>
struct server_ostream_separators
{
FASTDDS_EXPORTED_API static const charT* list_separator;
FASTDDS_EXPORTED_API static const charT* locator_separator;
static const charT* list_separator;
static const charT* locator_separator;
};

#ifndef _MSC_VER
Expand Down Expand Up @@ -133,12 +133,8 @@ std::basic_ostream<charT>& operator <<(
return output;
}

// port used if the ros environment variable doesn't specify one
constexpr uint16_t DEFAULT_ROS2_SERVER_PORT = 11811;
// default server base guidPrefix
// Default server base guidPrefix
const char* const DEFAULT_ROS2_SERVER_GUIDPREFIX = "44.53.00.5f.45.50.52.4f.53.49.4d.41";
// port used by default for tcp transport
constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 42100;

/* Environment variable to specify a semicolon-separated list of locators ([transport]ip:port) that define remote server
* locators. The [transport] specification is optional. The default transport is UDPv4.
Expand Down Expand Up @@ -166,7 +162,7 @@ const char* const ROS_SUPER_CLIENT = "ROS_SUPER_CLIENT";
* @param[out] servers_list reference to a LocatorList_t to populate.
* @return true if parsing succeeds, false otherwise (or if the list is empty)
*/
FASTDDS_EXPORTED_API bool load_environment_server_info(
bool load_environment_server_info(
const std::string& list,
LocatorList& servers_list);

Expand All @@ -181,30 +177,20 @@ FASTDDS_EXPORTED_API bool load_environment_server_info(
* @param[out] servers_list reference to a LocatorList_t to populate.
* @return true if parsing succeeds, false otherwise
*/
FASTDDS_EXPORTED_API bool load_environment_server_info(
bool load_environment_server_info(
LocatorList& servers_list);

/**
* Get the value of environment variable DEFAULT_ROS2_MASTER_URI
* @return The value of environment variable DEFAULT_ROS2_MASTER_URI. Empty string if the variable is not defined.
*/
FASTDDS_EXPORTED_API const std::string& ros_discovery_server_env();
const std::string& ros_discovery_server_env();

/**
* Get the value of environment variable ROS_SUPER_CLIENT
* @return The value of environment variable ROS_SUPER_CLIENT. False if the variable is not defined.
*/
FASTDDS_EXPORTED_API bool ros_super_client_env();

/**
* Returns the guidPrefix associated to the given server id
* @param[in] id of the default server whose guidPrefix we want to retrieve
* @param[out] guid reference to the guidPrefix to modify
* @return true if the server guid can be delivered
*/
FASTDDS_EXPORTED_API bool get_server_client_default_guidPrefix(
int id,
fastdds::rtps::GuidPrefix_t& guid);
bool ros_super_client_env();

} // rtps
} // fastdds
Expand Down
1 change: 1 addition & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define _FASTDDS_RTPS_PDPCLIENT_H_
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <rtps/attributes/ServerAttributes.hpp>
#include <rtps/builtin/discovery/participant/DS/DiscoveryServerPDPEndpoints.hpp>
#include <rtps/builtin/discovery/participant/DS/DiscoveryServerPDPEndpointsSecure.hpp>
#include <rtps/builtin/discovery/participant/PDP.h>
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <string>
#include <vector>

#include <fastdds/rtps/attributes/ServerAttributes.h>
#include <fastdds/rtps/history/History.h>
#include <rtps/attributes/ServerAttributes.hpp>
#include <rtps/builtin/discovery/database/DiscoveryDataBase.hpp>
#include <rtps/builtin/discovery/database/DiscoveryDataFilter.hpp>
#include <rtps/builtin/discovery/participant/DS/DiscoveryServerPDPEndpointsSecure.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/LibrarySettings.hpp>
#include <fastdds/rtps/attributes/BuiltinTransports.hpp>
#include <fastdds/rtps/attributes/ServerAttributes.h>
#include <fastdds/rtps/builtin/data/ParticipantProxyData.hpp>
#include <fastdds/rtps/common/EntityId_t.hpp>
#include <fastdds/rtps/common/LocatorList.hpp>
Expand All @@ -43,6 +42,7 @@
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
#include <fastdds/utils/IPFinder.h>

#include <rtps/attributes/ServerAttributes.hpp>
#include <rtps/builtin/BuiltinProtocols.h>
#include <rtps/builtin/discovery/endpoint/EDP.h>
#include <rtps/builtin/discovery/participant/PDP.h>
Expand Down
103 changes: 0 additions & 103 deletions src/cpp/xmlparser/XMLElementParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4030,109 +4030,6 @@ XMLP_ret XMLParser::getXMLEnum(
return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::getXMLRemoteServer(
tinyxml2::XMLElement* elem,
eprosima::fastdds::rtps::RemoteServerAttributes& server,
uint8_t ident)
{
/*
<xs:complexType name="RemoteServerAttributes">
<xs:all minOccurs="1">
<xs:element name="metatrafficUnicastLocatorList" type="locatorListType" minOccurs="0"/>
<xs:element name="metatrafficMulticastLocatorList" type="locatorListType" minOccurs="0"/>
</xs:all>
<xs:attribute name="guidPrefix" type="guid" use="required"/>
</xs:complexType>
*/

const char* Prefix = nullptr;
tinyxml2::XMLElement* pLU = nullptr, * pLM = nullptr;

if (nullptr == elem )
{
EPROSIMA_LOG_ERROR(XMLPARSER, "nullptr when getXMLRemoteServer XML_ERROR!");
return XMLP_ret::XML_ERROR;
}
else if (nullptr == (Prefix = elem->Attribute(PREFIX)))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "nullptr when getXMLRemoteServer try to recover server's guidPrefix XML_ERROR!");
return XMLP_ret::XML_ERROR;
}
else if (!server.ReadguidPrefix(Prefix))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "getXMLRemoteServer found an invalid server's guidPrefix XML_ERROR!");
return XMLP_ret::XML_ERROR;
}

pLU = elem->FirstChildElement(META_UNI_LOC_LIST);
pLM = elem->FirstChildElement(META_MULTI_LOC_LIST);

if ( pLU == nullptr && pLM == nullptr )
{
EPROSIMA_LOG_ERROR(XMLPARSER, "getXMLRemoteServer couldn't find any server's locator XML_ERROR!");
return XMLP_ret::XML_ERROR;
}

if (pLU && XMLP_ret::XML_OK != getXMLLocatorList(pLU, server.metatrafficUnicastLocatorList, ident))
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"getXMLRemoteServer was given a misformatted server's " << META_UNI_LOC_LIST << " XML_ERROR!");
return XMLP_ret::XML_ERROR;
}

if (pLM && XMLP_ret::XML_OK != getXMLLocatorList(pLM, server.metatrafficMulticastLocatorList, ident))
{
EPROSIMA_LOG_ERROR(XMLPARSER,
"getXMLRemoteServer was given a misformatted server's " << META_MULTI_LOC_LIST << " XML_ERROR!");
return XMLP_ret::XML_ERROR;
}

return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::getXMLList(
tinyxml2::XMLElement* elem,
eprosima::fastdds::rtps::RemoteServerList_t& list,
uint8_t ident)
{
/*
<xs:complexType name="DiscoveryServerList">
<xs:sequence>
<xs:element name="RemoteServer" type="RemoteServerAttributes" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
*/

tinyxml2::XMLElement* pS = nullptr;

if (nullptr == elem)
{
EPROSIMA_LOG_ERROR(XMLPARSER, "nullptr when getXMLList XML_ERROR!");
return XMLP_ret::XML_ERROR;
}
else if (nullptr == (pS = elem->FirstChildElement(RSERVER)))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "getXMLList couldn't find any RemoteServer XML_ERROR!");
return XMLP_ret::XML_ERROR;
}

while (pS)
{
eprosima::fastdds::rtps::RemoteServerAttributes server;
if (XMLP_ret::XML_OK != getXMLRemoteServer(pS, server, ident))
{
EPROSIMA_LOG_ERROR(XMLPARSER, "getXMLList was given a misformatted RemoteServer XML_ERROR!");
return XMLP_ret::XML_ERROR;
}
list.push_back(std::move(server));

pS = pS->NextSiblingElement(RSERVER);
}

return XMLP_ret::XML_OK;

}

XMLP_ret XMLParser::getXMLString(
tinyxml2::XMLElement* elem,
std::string* s,
Expand Down
Loading

0 comments on commit 1a268c9

Please sign in to comment.