Skip to content

Commit

Permalink
Make XML Parser API private (#4318)
Browse files Browse the repository at this point in the history
* Refs #20301: move XML Parser implementation to root source folder

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: sort alphabetically source files

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: make XML Parser private

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: remove private headers from Blackbox tests

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: new LibrarySettings class superseding LibrarySettingsAttributes

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: add library settings DDS & RTPS API. RTPSDomainTests testing the new API

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: library settings DDS API test

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: generate monitor service types in blackbox types and use them in corresponding test

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: XML profile manager get dynamic type builder wrapper and related test

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: refactor XML library settings, use new migrated structure

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: migrate to public API

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: reintroduce private headers in blackbox tests

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: update versions.md and copyright

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: remove exportation macro from private API

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: remove participant without using mocked code

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: apply review suggestion

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: linters

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: avoid using protected interface name

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: avoid using non-exported API in ParticipantTests

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: linters

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: fix Publisher and Subscriber tests

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: add get_topic_attributes_from_profile API

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: get topic attributes from profile test

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: fixes after rebase

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: fix Windows warning

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: linters

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: fix Windows warning

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: fix memory leak

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>

* Refs #20301: Run Github Windows CI on 3.0.x-devel PRs

Signed-off-by: EduPonz <eduardoponz@eprosima.com>

---------

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
Signed-off-by: EduPonz <eduardoponz@eprosima.com>
Co-authored-by: EduPonz <eduardoponz@eprosima.com>
  • Loading branch information
2 people authored and richiware committed Apr 11, 2024
1 parent 8ce4ee6 commit 006889e
Show file tree
Hide file tree
Showing 137 changed files with 13,015 additions and 1,078 deletions.
17 changes: 12 additions & 5 deletions examples/cpp/dds/DynamicHelloWorldExample/HelloWorldPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
#include <fastrtps/types/DynamicDataFactory.h>
#include <fastrtps/xmlparser/XMLProfileManager.h>

using namespace eprosima::fastdds::dds;

Expand All @@ -39,17 +38,25 @@ HelloWorldPublisher::HelloWorldPublisher()

bool HelloWorldPublisher::init()
{
if (eprosima::fastrtps::xmlparser::XMLP_ret::XML_OK !=
eprosima::fastrtps::xmlparser::XMLProfileManager::loadXMLFile("helloworld_example_type_profile.xml"))
if (ReturnCode_t::RETCODE_OK !=
DomainParticipantFactory::get_instance()->load_XML_profiles_file("helloworld_example_type_profile.xml"))
{
std::cout <<
"Cannot open XML file \"helloworld_example_type_profile.xml\". Please, run the publisher from the folder "
<< "that contatins this XML file." << std::endl;
return false;
}

eprosima::fastrtps::types::DynamicType_ptr dyn_type =
eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName("HelloWorld")->build();
eprosima::fastrtps::types::DynamicTypeBuilder* type;
if (ReturnCode_t::RETCODE_OK !=
DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name("HelloWorld", type))
{
std::cout <<
"Error getting dynamic type \"HelloWorld\"." << std::endl;
return false;
}

eprosima::fastrtps::types::DynamicType_ptr dyn_type = type->build();
TypeSupport m_type(new eprosima::fastrtps::types::DynamicPubSubType(dyn_type));
m_Hello = eprosima::fastrtps::types::DynamicDataFactory::get_instance()->create_data(dyn_type);

Expand Down
15 changes: 11 additions & 4 deletions examples/cpp/dds/TypeLookupService/TypeLookupPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
#include <fastrtps/types/DynamicDataFactory.h>
#include <fastrtps/xmlparser/XMLProfileManager.h>

using namespace eprosima::fastdds::dds;
using namespace eprosima::fastrtps;
Expand All @@ -41,15 +40,23 @@ TypeLookupPublisher::TypeLookupPublisher()

bool TypeLookupPublisher::init()
{
if (xmlparser::XMLP_ret::XML_OK !=
xmlparser::XMLProfileManager::loadXMLFile("example_type_profile.xml"))
if (ReturnCode_t::RETCODE_OK !=
DomainParticipantFactory::get_instance()->load_XML_profiles_file("example_type_profile.xml"))
{
std::cout << "Cannot open XML file \"example_type_profile.xml\". Please, run the publisher from the folder "
<< "that contatins this XML file." << std::endl;
return false;
}

types::DynamicType_ptr dyn_type = xmlparser::XMLProfileManager::getDynamicTypeByName("TypeLookup")->build();
eprosima::fastrtps::types::DynamicTypeBuilder* type;
if (ReturnCode_t::RETCODE_OK !=
DomainParticipantFactory::get_instance()->get_dynamic_type_builder_from_xml_by_name("TypeLookup", type))
{
std::cout <<
"Error getting dynamic type \"TypeLookup\"." << std::endl;
return false;
}
types::DynamicType_ptr dyn_type = type->build();
TypeSupport m_type(new types::DynamicPubSubType(dyn_type));
m_Hello = types::DynamicDataFactory::get_instance()->create_data(dyn_type);

Expand Down
6 changes: 3 additions & 3 deletions fuzz/C++/fuzz_XMLProfiles/fuzz_XMLProfiles.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <fastrtps/xmlparser/XMLProfileManager.h>

#include "fuzz_utils.h"

#include <fastdds/dds/domain/DomainParticipantFactory.hpp>

using namespace eprosima;
using namespace eprosima::fastrtps;

Expand Down Expand Up @@ -31,7 +31,7 @@ extern "C" int LLVMFuzzerTestOneInput(

// TODO change this to a func. taking buf + len (or C string)
// to avoid using `buf_to_file`
xmlparser::XMLProfileManager::loadXMLFile(filename);
fastdds::DomainParticipantFactory::get_instance()->load_XML_profiles_file(filename);

if (delete_file(filename) != 0)
{
Expand Down
66 changes: 66 additions & 0 deletions include/fastdds/LibrarySettings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.
// 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 LibrarySettings.hpp
*
*/

#ifndef _FASTDDS_LIBRARY_SETTINGS_HPP_
#define _FASTDDS_LIBRARY_SETTINGS_HPP_

namespace eprosima {
namespace fastdds {

enum IntraprocessDeliveryType
{
INTRAPROCESS_OFF,
INTRAPROCESS_USER_DATA_ONLY,
INTRAPROCESS_FULL
};

/**
* Class LibraySettings, used by the user to define the Fast DDS library behaviour
* @ingroup FASTDDS_MODULE
*/
class LibrarySettings
{
public:

LibrarySettings()
{
}

virtual ~LibrarySettings()
{
}

bool operator ==(
const LibrarySettings& b) const
{
return (intraprocess_delivery == b.intraprocess_delivery);
}

IntraprocessDeliveryType intraprocess_delivery =
#if HAVE_STRICT_REALTIME
INTRAPROCESS_OFF;
#else
INTRAPROCESS_FULL;
#endif // if HAVE_STRICT_REALTIME
};

} // namespace fastdds
} // namespace eprosima

#endif /* _FASTDDS_LIBRARY_SETTINGS_HPP_ */
38 changes: 38 additions & 0 deletions include/fastdds/dds/domain/DomainParticipantFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <fastdds/dds/core/status/StatusMask.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
#include <fastdds/LibrarySettings.hpp>
#include <fastrtps/types/DynamicTypeBuilder.h>
#include <fastrtps/types/TypesBase.h>

using eprosima::fastrtps::types::ReturnCode_t;
Expand Down Expand Up @@ -267,6 +269,42 @@ class DomainParticipantFactory
RTPS_DllAPI ReturnCode_t set_qos(
const DomainParticipantFactoryQos& qos);

/**
* @brief This operation returns the value of the DomainParticipant library settings.
*
* @param library_settings LibrarySettings reference where the settings are returned.
* @return RETCODE_OK
*/
RTPS_DllAPI ReturnCode_t get_library_settings(
LibrarySettings& library_settings) const;

/**
* @brief This operation sets the library settings.
*
* Library settings must be set before enabling the DomainParticipants.
* Otherwise, failure of the setting operation is expected.
*
* @param library_settings LibrarySettings to be set.
* @return RETCODE_PRECONDITION_NOT_MET if any DomainParticipant is already enabled.
* RETCODE_OK otherwise.
*/
RTPS_DllAPI ReturnCode_t set_library_settings(
const LibrarySettings& library_settings);

/**
* @brief Get the DynamicTypeBuilder defined in XML file.
* The XML file shall be previously loaded.
*
* @param type_name Dynamic type name.
* @param type Reference where the Dynamic type builder is returned.
* @return RETCODE_BAD_PARAMETER if type_name is empty.
* RETCODE_NO_DATA if type_name is unknown.
* RETCODE_OK otherwise.
*/
RTPS_DllAPI ReturnCode_t get_dynamic_type_builder_from_xml_by_name(
const std::string& type_name,
fastrtps::types::DynamicTypeBuilder*& type);

protected:

friend class DomainParticipant;
Expand Down
33 changes: 33 additions & 0 deletions include/fastdds/rtps/RTPSDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
#include <mutex>
#include <set>

#include <fastdds/LibrarySettings.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/common/Types.h>
#include <fastdds/rtps/history/IPayloadPool.h>
#include <fastdds/rtps/history/IChangePool.h>
#include <fastrtps/attributes/TopicAttributes.h>

namespace eprosima {
namespace fastrtps {
Expand Down Expand Up @@ -291,6 +293,37 @@ class RTPSDomain
RTPS_DllAPI static bool removeRTPSParticipant(
RTPSParticipant* p);

/**
* @brief Get the library settings.
*
* @param library_settings LibrarySettings reference where the settings are returned.
* @return True.
*/
RTPS_DllAPI static bool get_library_settings(
fastdds::LibrarySettings& library_settings);

/**
* @brief Set the library settings-
*
* @param library_settings LibrarySettings to be set.
* @return False if there is any RTPSParticipant already created.
* True if correctly set.
*/
RTPS_DllAPI static bool set_library_settings(
const fastdds::LibrarySettings& library_settings);

/**
* @brief Get the TopicAttributes from XML profile.
*
* @param profile_name Topic profile name.
* @param topic_att TopicAttributes object where the attributes are returned.
* @return bool true if the profile exists.
* false otherwise.
*/
RTPS_DllAPI static bool get_topic_attributes_from_profile(
const std::string& profile_name,
TopicAttributes& topic_att);

private:

RTPSDomain() = delete;
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,6 @@ set(${PROJECT_NAME}_source_files
rtps/writer/StatefulWriter.cpp
rtps/writer/StatelessPersistentWriter.cpp
rtps/writer/StatelessWriter.cpp
rtps/xmlparser/XMLDynamicParser.cpp
rtps/xmlparser/XMLElementParser.cpp
rtps/xmlparser/XMLEndpointParser.cpp
rtps/xmlparser/XMLParser.cpp
rtps/xmlparser/XMLParserCommon.cpp
rtps/xmlparser/XMLProfileManager.cpp
statistics/fastdds/domain/DomainParticipant.cpp
statistics/fastdds/publisher/qos/DataWriterQos.cpp
statistics/fastdds/subscriber/qos/DataReaderQos.cpp
Expand All @@ -234,6 +228,12 @@ set(${PROJECT_NAME}_source_files
utils/SystemInfo.cpp
utils/TimedConditionVariable.cpp
utils/UnitsParser.cpp
xmlparser/XMLDynamicParser.cpp
xmlparser/XMLElementParser.cpp
xmlparser/XMLEndpointParser.cpp
xmlparser/XMLParser.cpp
xmlparser/XMLParserCommon.cpp
xmlparser/XMLProfileManager.cpp
)

# Statistics support
Expand Down
40 changes: 37 additions & 3 deletions src/cpp/fastdds/domain/DomainParticipantFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*
*/

#include <fastdds/dds/domain/DomainParticipantFactory.hpp>

#include <thread>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/domain/DomainParticipantImpl.hpp>
Expand All @@ -31,14 +32,14 @@
#include <fastrtps/types/DynamicDataFactory.h>
#include <fastrtps/types/DynamicTypeBuilderFactory.h>
#include <fastrtps/types/TypeObjectFactory.h>
#include <fastrtps/xmlparser/XMLEndpointParser.h>
#include <fastrtps/xmlparser/XMLProfileManager.h>

#include <rtps/history/TopicPayloadPoolRegistry.hpp>
#include <rtps/RTPSDomainImpl.hpp>
#include <statistics/fastdds/domain/DomainParticipantImpl.hpp>
#include <utils/shared_memory/SharedMemWatchdog.hpp>
#include <utils/SystemInfo.hpp>
#include <xmlparser/XMLEndpointParser.h>
#include <xmlparser/XMLProfileManager.h>

using namespace eprosima::fastrtps::xmlparser;

Expand Down Expand Up @@ -481,6 +482,39 @@ void DomainParticipantFactory::participant_has_been_deleted(
}
}

ReturnCode_t DomainParticipantFactory::get_library_settings(
LibrarySettings& library_settings) const
{
rtps_domain_->get_library_settings(library_settings);
return ReturnCode_t::RETCODE_OK;
}

ReturnCode_t DomainParticipantFactory::set_library_settings(
const LibrarySettings& library_settings)
{
if (rtps_domain_->set_library_settings(library_settings))
{
return ReturnCode_t::RETCODE_OK;
}
return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET;
}

ReturnCode_t DomainParticipantFactory::get_dynamic_type_builder_from_xml_by_name(
const std::string& type_name,
fastrtps::types::DynamicTypeBuilder*& type)
{
if (type_name.empty())
{
return ReturnCode_t::RETCODE_BAD_PARAMETER;
}
type = XMLProfileManager::getDynamicTypeByName(type_name);
if (nullptr == type)
{
return ReturnCode_t::RETCODE_NO_DATA;
}
return ReturnCode_t::RETCODE_OK;
}

} /* namespace dds */
} /* namespace fastdds */
} /* namespace eprosima */
Loading

0 comments on commit 006889e

Please sign in to comment.