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

[17138] Refactor of DynamicTypes #479

Closed
wants to merge 12 commits into from
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ add_custom_target(doc-dirs
COMMENT "Creating documentation directories" VERBATIM)

# Doxygen related variables
set(DOXYGEN_INPUT_DIR "${FAST_INCLUDE_DIR}/fastdds")
set(DOXYGEN_INPUT_DIR "${FAST_INCLUDE_DIR}/fastdds\" \"${FAST_INCLUDE_DIR}/fastrtps/types")
set(DOXYGEN_OUTPUT_DIR "${PROJECT_BINARY_DIR}/doxygen")
set(DOXYGEN_STRIP_PATH "${FAST_INCLUDE_DIR}")
set(DOXYGEN_EXCLUDE_PATH "${FAST_INCLUDE_DIR}/fastdds/thirdparty")
set(DOXYGEN_INDEX_FILE "${PROJECT_BINARY_DIR}/doxygen/xml/index.xml")
set(DOXYFILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/code/doxygen-config.in")
set(DOXYFILE_OUT ${PROJECT_BINARY_DIR}/doxygen-config)
Expand Down
25 changes: 22 additions & 3 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,26 @@ add_subdirectory(Examples/C++/DDSHelloWorld)
add_executable(doctest CodeTester.cpp)
target_include_directories(doctest PRIVATE ${FAST_INCLUDE_DIR})
target_link_libraries(doctest fastrtps)
if(MSVC)
target_compile_definitions(doctest PRIVATE _CRT_SECURE_NO_WARNINGS)
endif(MSVC)

# DDSCodeTester utilizes Fast DDS API
add_executable(dds-doctest DDSCodeTester.cpp FastDDSGenCodeTester.cpp)
target_include_directories(dds-doctest PRIVATE ${FAST_INCLUDE_DIR})
target_link_libraries(dds-doctest fastrtps)
target_link_libraries(dds-doctest fastrtps fastcdr)

####################################################################################################
# Add tests
####################################################################################################

if(WIN32)
# Use fastdds.bat for cli testing
# cmd can no longer be used because ctest resolves all commands binaries to forward slashes, see:
# https://gitlab.kitware.com/cmake/cmake/-/issues/17067
set(SHELL_INVOKE powershell -C)
endif(WIN32)

# Copy the neccessary files over to the build directory
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XMLTester.xml
${CMAKE_CURRENT_BINARY_DIR}/XMLTester.xml COPYONLY)
Expand Down Expand Up @@ -118,9 +128,9 @@ add_test(NAME xml.profiles COMMAND dds-doctest XMLTester.xml)
# Check validity of XML full example
add_test(NAME xml.example COMMAND dds-doctest XMLTesterExample.xml)
# Validate XML full example against XSD schema
add_test(NAME xml.validate COMMAND fastdds xml validate XMLTesterExample.xml -x fastRTPS_profiles.xsd)
add_test(NAME xml.validate COMMAND ${SHELL_INVOKE} fastdds xml validate XMLTesterExample.xml -x fastRTPS_profiles.xsd)
# Validate XML snippets doc against XSD schema
add_test(NAME xml.snippets COMMAND fastdds xml validate XMLTester.xml -x fastRTPS_profiles.xsd)
add_test(NAME xml.snippets COMMAND ${SHELL_INVOKE} fastdds xml validate XMLTester.xml -x fastRTPS_profiles.xsd)
# Check validity of Permissions and Governance XML files using Fast DDS API
add_test(NAME xml.fastdds_permissions_test
COMMAND dds-doctest
Expand Down Expand Up @@ -176,3 +186,12 @@ add_test(NAME docs.spell_check
-d "${PROJECT_BINARY_DIR}/doctrees"
${CMAKE_SOURCE_DIR}/docs
${CMAKE_BINARY_DIR}/spelling)

# Populate environment variables for tests
if(WIN32)
get_directory_property(DOCS_TESTS TESTS)
set_tests_properties(${DOCS_TESTS} PROPERTIES
ENVIRONMENT_MODIFICATION "PATH=path_list_append:$<TARGET_FILE_DIR:fastrtps>"
ENVIRONMENT_MODIFICATION "PATH=path_list_append:$<TARGET_FILE_DIR:fastcdr>"
)
endif(WIN32)
704 changes: 401 additions & 303 deletions code/CodeTester.cpp

Large diffs are not rendered by default.

62 changes: 44 additions & 18 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <fastdds/dds/topic/TopicListener.hpp>
#include <fastrtps/xmlparser/XMLProfileManager.h>

#include <fastrtps/types/DynamicTypePtr.h>
#include <fastrtps/types/DynamicDataFactory.h>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/log/OStreamConsumer.hpp>
Expand Down Expand Up @@ -215,7 +214,7 @@ class CustomDomainParticipantListener : public DomainParticipantListener
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
eprosima::fastrtps::types::v1_3::DynamicType_ptr dyn_type) override
{
static_cast<void>(participant);
static_cast<void>(request_sample_id);
Expand Down Expand Up @@ -888,7 +887,7 @@ class DiscoveryDomainParticipantListener : public DomainParticipantListener
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
eprosima::fastrtps::types::v1_3::DynamicType_ptr dyn_type) override
{
static_cast<void>(participant);
static_cast<void>(request_sample_id);
Expand Down Expand Up @@ -1089,7 +1088,11 @@ void dds_discovery_examples()
}

{
DomainParticipant* client_or_server;
DomainParticipant* client_or_server = nullptr;
/* ... additional code to get the DomainParticipant
client_or_server = get_participant_somehow(...);
*/

//CONF_SERVER_ADD_SERVERS
// Get existing QoS for the server or client
DomainParticipantQos client_or_server_qos;
Expand Down Expand Up @@ -1637,6 +1640,8 @@ void dds_topic_examples()

{
//DDS_DYNAMIC_TYPES
namespace xtypes = eprosima::fastrtps::types::v1_3;

// Create a DomainParticipant in the desired domain
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
Expand All @@ -1650,8 +1655,15 @@ void dds_topic_examples()
eprosima::fastrtps::xmlparser::XMLProfileManager::loadXMLFile("example_type.xml");

// Retrieve the an instance of the desired type and register it
eprosima::fastrtps::types::DynamicType_ptr dyn_type =
eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName("DynamicType")->build();
xtypes::DynamicTypeBuilder_ptr dyn_builder;
if (eprosima::fastrtps::xmlparser::XMLP_ret::XML_OK !=
eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName(dyn_builder, "DynamicType"))
{
// Error
return;
}

xtypes::DynamicType_ptr dyn_type = dyn_builder->build();
TypeSupport dyn_type_support(new eprosima::fastrtps::types::DynamicPubSubType(dyn_type));
dyn_type_support.register_type(participant, nullptr);

Expand Down Expand Up @@ -4345,6 +4357,8 @@ void xml_profiles_examples()
}
{
//XML-USAGE
namespace xtypes = eprosima::fastrtps::types::v1_3;

// Create a DomainParticipant
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
Expand All @@ -4359,8 +4373,17 @@ void xml_profiles_examples()
DomainParticipantFactory::get_instance()->load_XML_profiles_file("my_profiles.xml"))
{
// Retrieve the an instance of MyStruct type
eprosima::fastrtps::types::DynamicType_ptr my_struct_type =
eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName("MyStruct")->build();
xtypes::DynamicTypeBuilder_ptr my_struct_builder;
if (eprosima::fastrtps::xmlparser::XMLP_ret::XML_OK !=
eprosima::fastrtps::xmlparser::XMLProfileManager::getDynamicTypeByName(my_struct_builder, "MyStruct"))
{
// Error
return;
}

// Retrieve the an instance of MyStruct type
xtypes::DynamicType_ptr my_struct_type = my_struct_builder->build();

// Register MyStruct type
TypeSupport my_struct_type_support(new eprosima::fastrtps::types::DynamicPubSubType(my_struct_type));
my_struct_type_support.register_type(participant, nullptr);
Expand Down Expand Up @@ -5282,6 +5305,9 @@ void dds_persistence_examples()
* };
*/

using namespace eprosima::fastrtps::types;
namespace xtypes = v1_3;

// Configure persistence service plugin for DomainParticipant
DomainParticipantQos pqos;
pqos.properties().properties().emplace_back("dds.persistence.plugin", "builtin.SQLITE3");
Expand All @@ -5297,28 +5323,28 @@ void dds_persistence_examples()
********************************************************************************************************/
// Create a struct builder for a type with name "persistence_topic_type"
const std::string topic_type_name = "persistence_topic_type";
eprosima::fastrtps::types::DynamicTypeBuilder_ptr struct_type_builder(
eprosima::fastrtps::types::DynamicTypeBuilderFactory::get_instance()->create_struct_builder());
xtypes::DynamicTypeBuilder_ptr struct_type_builder(
xtypes::DynamicTypeBuilderFactory::get_instance().create_struct_builder());
struct_type_builder->set_name(topic_type_name);

// The type consists of two members, and index and a message. Add members to the struct.
struct_type_builder->add_member(0, "index",
eprosima::fastrtps::types::DynamicTypeBuilderFactory::get_instance()->create_uint32_type());
xtypes::DynamicTypeBuilderFactory::get_instance().create_uint32_type());
struct_type_builder->add_member(1, "message",
eprosima::fastrtps::types::DynamicTypeBuilderFactory::get_instance()->create_string_type());
xtypes::DynamicTypeBuilderFactory::get_instance().create_string_type());

// Build the type
eprosima::fastrtps::types::DynamicType_ptr dyn_type_ptr = struct_type_builder->build();
xtypes::DynamicType_ptr dyn_type_ptr = struct_type_builder->build();

// Create type support and register the type
TypeSupport type_support(new eprosima::fastrtps::types::DynamicPubSubType(dyn_type_ptr));
TypeSupport type_support(new DynamicPubSubType(dyn_type_ptr));
type_support.register_type(participant);

// Create data sample a populate data. This is to be used when calling `writer->write()`
eprosima::fastrtps::types::DynamicData* dyn_helloworld;
dyn_helloworld = eprosima::fastrtps::types::DynamicDataFactory::get_instance()->create_data(dyn_type_ptr);
dyn_helloworld->set_uint32_value(0, 0);
dyn_helloworld->set_string_value("HelloWorld", 1);
xtypes::DynamicData* dyn_helloworld;
dyn_helloworld = xtypes::DynamicDataFactory::get_instance()->create_data(dyn_type_ptr);
dyn_helloworld->set_uint32_value(0, 0_id);
dyn_helloworld->set_string_value("HelloWorld", 1_id);
/********************************************************************************************************
* END CREATE TYPE AND TYPE SUPPORT
********************************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class HelloWorldSubscriber
void run(
uint32_t samples)
{
while(listener_.samples_ < samples)
while((uint32_t)listener_.samples_ < samples)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down
8 changes: 4 additions & 4 deletions code/doxygen-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ FULL_PATH_NAMES = YES
# will be relative from the directory where doxygen is started.
# This tag requires that the tag FULL_PATH_NAMES is set to YES.

STRIP_FROM_PATH = @DOXYGEN_INPUT_DIR@/..
STRIP_FROM_PATH = "@DOXYGEN_STRIP_PATH@"

# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
# path mentioned in the documentation of a class, which tells the reader which
Expand All @@ -179,7 +179,7 @@ STRIP_FROM_PATH = @DOXYGEN_INPUT_DIR@/..
# specify the list of include paths that are normally passed to the compiler
# using the -I flag.

STRIP_FROM_INC_PATH = @DOXYGEN_INPUT_DIR@/..
STRIP_FROM_INC_PATH = "@DOXYGEN_STRIP_PATH@"

# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
# less readable) file names. This can be useful is your file systems doesn't
Expand Down Expand Up @@ -594,7 +594,7 @@ INTERNAL_DOCS = NO
# YES.
# The default value is: system dependent.

CASE_SENSE_NAMES = YES
CASE_SENSE_NAMES = SYSTEM

# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
# their full class and namespace scopes in the documentation. If set to YES, the
Expand Down Expand Up @@ -952,7 +952,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = @DOXYGEN_INPUT_DIR@/thirdparty
EXCLUDE = "@DOXYGEN_EXCLUDE_PATH@"

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
2 changes: 1 addition & 1 deletion code/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
occurrences = []
rst_files = list(Path(directory).rglob('*.{}'.format(args.file_format)))
for rst_file in rst_files:
with open(rst_file) as f:
with open(rst_file, encoding='utf-8') as f:
line_number = 1
for line in f:
if re.search(args.regex, line):
Expand Down
1 change: 1 addition & 0 deletions docs/fastdds/api_reference/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ For more information about the API reference, please refer to
/fastdds/api_reference/dds_pim/dds_pim
/fastdds/api_reference/rtps/rtps
/fastdds/api_reference/transport/transport
/fastdds/api_reference/xtypes/xtypes
/fastdds/api_reference/log/log
/fastdds/api_reference/statistics/statistics
4 changes: 4 additions & 0 deletions docs/fastdds/api_reference/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ DurabilityQosPolicy
DurabilityServiceQosPolicy
dyn
DynamicPubSubType
emplaces
Endianness
entityId
Enum
Expand Down Expand Up @@ -100,6 +101,7 @@ Num
OfferedDeadlineMissedStatus
OfferedIncompatibleQosStatus
ok
ostream
OStream
OwnershipQosPolicy
OwnershipStrengthQosPolicy
Expand Down Expand Up @@ -168,6 +170,7 @@ typedef
TypeIdentifier
TypeIdV
TypeInformation
TypeKind
typelookup
TypeLookup
TypeLookup
Expand All @@ -187,5 +190,6 @@ UserAllocatedSequence
wakeup
wdata
WLPListener
wstring
xml
xtypes
10 changes: 10 additions & 0 deletions docs/fastdds/api_reference/xtypes/DynamicData.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _api_dynamic_data:

.. rst-class:: api-ref

DynamicType
-----------

.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicData
:project: FastDDS
:members:
10 changes: 10 additions & 0 deletions docs/fastdds/api_reference/xtypes/DynamicType.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _api_dynamic_type:

.. rst-class:: api-ref

DynamicType
-----------

.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicType
:project: FastDDS
:members:
10 changes: 10 additions & 0 deletions docs/fastdds/api_reference/xtypes/DynamicTypeBuilder.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _api_dynamic_type_builder:

.. rst-class:: api-ref

DynamicTypeBuilder
------------------

.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicTypeBuilder
:project: FastDDS
:members:
10 changes: 10 additions & 0 deletions docs/fastdds/api_reference/xtypes/DynamicTypeBuilderFactory.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _api_dynamic_type_builder_factory:

.. rst-class:: api-ref

DynamicTypeBuilderFactory
-------------------------

.. doxygenclass:: eprosima::fastrtps::types::v1_3::DynamicTypeBuilderFactory
:project: FastDDS
:members:
13 changes: 13 additions & 0 deletions docs/fastdds/api_reference/xtypes/xtypes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _api_xtypes:

Xtypes
======

*eProsima Fast DDS* XTypes API

.. toctree::

/fastdds/api_reference/xtypes/DynamicTypeBuilderFactory.rst
/fastdds/api_reference/xtypes/DynamicTypeBuilder.rst
/fastdds/api_reference/xtypes/DynamicType.rst
/fastdds/api_reference/xtypes/DynamicData.rst
2 changes: 2 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ initializations
interoperability
intra
Intra
iOS
IPv
json
kB
Expand Down Expand Up @@ -248,6 +249,7 @@ Valgrind
vcstool
wget
whitelist
whitelisting
whitelists
WiFi
Wireshark
Expand Down