Skip to content

Commit f2e1c8b

Browse files
XTYPES IDL parsing feature (#1046)
* Ref 22890. Feature IDL parsing documentation Signed-off-by: Eugenio Collado <[email protected]> * Fix doc8 checks Signed-off-by: Eugenio Collado <[email protected]> * Update supported features Signed-off-by: Eugenio Collado <[email protected]> * Applied suggestions Signed-off-by: Eugenio Collado <[email protected]> * Fix line length Signed-off-by: Eugenio Collado <[email protected]> * Fix code identation Signed-off-by: Eugenio Collado <[email protected]> --------- Signed-off-by: Eugenio Collado <[email protected]>
1 parent ced1813 commit f2e1c8b

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

code/DDSCodeTester.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,45 @@ void dds_topic_examples()
20402040
}
20412041
//!--
20422042
}
2043+
2044+
{
2045+
//DDS_DYNAMIC_TYPES_IDL_PARSING
2046+
// Create a DomainParticipant in the desired domain
2047+
DomainParticipant* participant =
2048+
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
2049+
if (nullptr == participant)
2050+
{
2051+
// Error
2052+
return;
2053+
}
2054+
2055+
// Optional: Set the preprocessor to be executed before parsing the IDL
2056+
DynamicTypeBuilderFactory::get_instance()->set_preprocessor("<optional_path_to_your_preprocessor_executable>");
2057+
2058+
// Load the IDL file
2059+
std::string idl_file = "<path_to_idl>.idl";
2060+
std::string type_name = "YourType";
2061+
std::vector<std::string> include_paths;
2062+
include_paths.push_back("<path/to/folder/containing/included/idl/files>");
2063+
2064+
// Retrieve the instance of the desired type
2065+
DynamicTypeBuilder::_ref_type dyn_type_builder =
2066+
DynamicTypeBuilderFactory::get_instance()->create_type_w_uri(idl_file, type_name, include_paths);
2067+
2068+
// Register dynamic type
2069+
TypeSupport dyn_type_support(new DynamicPubSubType(dyn_type_builder->build()));
2070+
dyn_type_support.register_type(participant, nullptr);
2071+
2072+
// Create a Topic with the registered type.
2073+
Topic* topic =
2074+
participant->create_topic("topic_name", dyn_type_support.get_type_name(), TOPIC_QOS_DEFAULT);
2075+
if (nullptr == topic)
2076+
{
2077+
// Error
2078+
return;
2079+
}
2080+
//!--
2081+
}
20432082
}
20442083

20452084
void dds_content_filtered_topic_examples()

docs/03-exports/aliases-api.include

+3
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,12 @@
10401040
.. |DynamicTypeBuilderFactory::create_sequence_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_sequence_type <eprosima::fastdds::dds::DynamicTypeBuilderFactory::create_sequence_type>`
10411041
.. |DynamicTypeBuilderFactory::create_string_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_string_type <eprosima::fastdds::dds::DynamicTypeBuilderFactory::create_string_type>`
10421042
.. |DynamicTypeBuilderFactory::create_type_w_type_object| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_type_w_type_object <eprosima::fastdds::dds::DynamicTypeBuilderFactory::create_type_w_type_object>`
1043+
.. |DynamicTypeBuilderFactory::create_type_w_uri| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_type_w_uri <eprosima::fastdds::dds::DynamicTypeBuilderFactory::create_type_w_uri>`
10431044
.. |DynamicTypeBuilderFactory::create_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_type <eprosima::fastdds::dds::DynamicTypeBuilderFactory::create_type>`
10441045
.. |DynamicTypeBuilderFactory::create_wstring_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::create_wstring_type <eprosima::fastdds::dds::DynamicTypeBuilderFactory::create_wstring_type>`
10451046
.. |DynamicTypeBuilderFactory::get_primitive_type| replace:: :cpp:func:`DynamicTypeBuilderFactory::get_primitive_type <eprosima::fastdds::dds::DynamicTypeBuilderFactory::get_primitive_type>`
1047+
.. |DynamicTypeBuilderFactory::set_preprocessor| replace:: :cpp:func:`DynamicTypeBuilderFactory::set_preprocessor <eprosima::fastdds::dds::DynamicTypeBuilderFactory::set_preprocessor>`
1048+
10461049
.. |DynamicTypeMember-api| replace:: :cpp:class:`DynamicTypeMember <eprosima::fastdds::dds::DynamicTypeMember>`
10471050
.. |MemberDescriptor-api| replace:: :cpp:class:`MemberDescriptor <eprosima::fastdds::dds::MemberDescriptor>`
10481051
.. |TypeDescriptor-api| replace:: :cpp:class:`TypeDescriptor <eprosima::fastdds::dds::TypeDescriptor>`

docs/fastdds/xtypes/idl_parsing.rst

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. include:: ../../03-exports/aliases.include
2+
.. include:: ../../03-exports/aliases-api.include
3+
.. include:: ../../03-exports/roles.include
4+
5+
.. _dynamic-types-idl-parsing:
6+
7+
Dynamic Types IDL Parsing
8+
=========================
9+
10+
*Fast DDS* supports the implementation of |DynamicTypes| for parsing IDL files at runtime to generate dynamic
11+
data types.
12+
The |DynamicTypeBuilderFactory::create_type_w_uri| API allows users to provide a URI pointing to an IDL file.
13+
Fast DDS will process the file and return the corresponding DynamicTypeBuilder, which can then be used to create a
14+
DynamicType.
15+
16+
This feature enables applications to dynamically load type definitions from IDL files instead of relying solely on
17+
pre-generated types or XML profiles.
18+
This enhances flexibility, as new data types can be introduced without modifying and recompiling the application.
19+
20+
Type definition
21+
^^^^^^^^^^^^^^^
22+
Below, the types supported by *eProsima Fast DDS* IDL parsing are presented.
23+
For further information about the supported |DynamicTypes|, please, refer to :ref:`xtypes_supportedtypes`.
24+
25+
* :ref:`xtypes_supportedtypes_primitive`
26+
* :ref:`xtypes_supportedtypes_string`
27+
* :ref:`xtypes_supportedtypes_structure`
28+
* :ref:`xtypes_supportedtypes_alias`
29+
* :ref:`xtypes_supportedtypes_array`
30+
* :ref:`xtypes_supportedtypes_union`
31+
* :ref:`xtypes_supportedtypes_enumeration`
32+
* :ref:`xtypes_annotations`
33+
* Arithmetic expressions
34+
* Union/struct forward declarations
35+
36+
The following types are currently not supported by the IDL parsing feature:
37+
38+
* :ref:`xtypes_supportedtypes_bitmask`
39+
* :ref:`xtypes_supportedtypes_sequence`
40+
* :ref:`xtypes_supportedtypes_map`
41+
* :ref:`xtypes_supportedtypes_bitset`
42+
* :ref:`xtypes_builtin_annotations`
43+
* Module
44+
* Inheritance
45+
* Member ID
46+
47+
Example
48+
^^^^^^^
49+
50+
*Fast DDS* application can use dynamic types generated in runtime just by loading the corresponding IDL files into the
51+
|DynamicTypeBuilderFactory-api| using |DynamicTypeBuilderFactory::create_type_w_uri|.
52+
After getting the DynamicType, objects of |DynamicPubSubType-api| class might be instantiated and used to write/read
53+
data.
54+
55+
.. note::
56+
57+
The preprocessor can be manually selected using |DynamicTypeBuilderFactory::set_preprocessor|
58+
59+
The following snippet shows the previously explained steps:
60+
61+
.. literalinclude:: /../code/DDSCodeTester.cpp
62+
:language: c++
63+
:dedent: 8
64+
:start-after: //DDS_DYNAMIC_TYPES_IDL_PARSING
65+
:end-before: //!--

docs/fastdds/xtypes/language_binding.rst

+20-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Dynamic Language Binding
1010
The Dynamic Language Binding API allows to define data types at runtime instead of having the types predefined as it is
1111
required by the Plain Language Binding.
1212
This API includes both the type definition and, the getters and setters required to use the defined types.
13-
Type definition can also be done using a XML configuration file as explained in :ref:`xmldynamictypes` section.
13+
Type definition can also be done using a XML configuration file as explained in :ref:`xmldynamictypes` section or by
14+
parsing an IDL file at runtime, as explained in :ref:`dynamic-types-idl-parsing` section.
1415

1516
This section presents first the Dynamic Language Binding API, and then the supported types and specific examples
1617
defining and using those types.
@@ -836,6 +837,7 @@ The annotation parameter value must be converted to its string representation.
836837
:end-before: //!--
837838
:dedent: 8
838839

840+
.. _xtypes_builtin_annotations:
839841

840842
Builtin annotations
841843
"""""""""""""""""""
@@ -854,71 +856,88 @@ Please, refer to :ref:`builtin annotations <builtin_annotations>` for the comple
854856
- Dynamic Language Binding API
855857
- Dynamic Language Binding support
856858
- XML Dynamic Type profiles support
859+
- IDL Parsing Dynamic Type support
857860
* - :code:`@appendable`
858861
- |TypeDescriptor-api| :code:`extensibility_kind` property.
859862
- ✅
860863
- ❌
864+
- ❌
861865
* - :code:`@bit_bound`
862866
- |TypeDescriptor-api| :code:`bound` property for :ref:`xtypes_supportedtypes_bitset`. |br|
863867
|MemberDescriptor-api| :code:`type` property for :ref:`xtypes_supportedtypes_enumeration`.
864868
- ✅
865869
- ✅❌ (`Enumeration types`_ not configurable).
870+
- ❌
866871
* - :code:`@default`
867872
- |MemberDescriptor-api| :code:`default_value` property.
868873
- ✅
869874
- ❌
875+
- ❌
870876
* - :code:`default_literal`
871877
- |MemberDescriptor-api| :code:`is_default_label` property.
872878
- ✅
873879
- ❌
880+
- ❌
874881
* - :code:`@extensibility`
875882
- |TypeDescriptor-api| :code:`extensibility_kind` property.
876883
- ✅
877884
- ❌
885+
- ❌
878886
* - :code:`@external`
879887
- |MemberDescriptor-api| :code:`is_shared` property.
880888
- ❌
881889
- ❌
890+
- ❌
882891
* - :code:`@final`
883892
- |TypeDescriptor-api| :code:`extensibility_kind` property.
884893
- ✅
885894
- ❌
895+
- ❌
886896
* - :code:`@id`
887897
- |MemberDescriptor-api| :code:`id` property.
888898
- ✅
889899
- ❌
900+
- ❌
890901
* - :code:`@key` / :code:`@Key`
891902
- |MemberDescriptor-api| :code:`is_key` property.
892903
- ✅
893904
- ❌
905+
- ❌
894906
* - :code:`@mutable`
895907
- |TypeDescriptor-api| :code:`extensibility_kind` property.
896908
- ✅
897909
- ❌
910+
- ❌
898911
* - :code:`@nested`
899912
- |TypeDescriptor-api| :code:`is_nested` property.
900913
- ❌
901914
- ❌
915+
- ❌
902916
* - :code:`@optional`
903917
- |MemberDescriptor-api| :code:`is_optional` property.
904918
- ❌
905919
- ❌
920+
- ❌
906921
* - :code:`@position`
907922
- |MemberDescriptor-api| :code:`id` property.
908923
- ✅
909924
- ✅
925+
- ❌
910926
* - :code:`@try_construct`
911927
- |MemberDescriptor-api| :code:`try_construct_kind` property.
912928
- ❌
913929
- ❌
930+
- ❌
914931
* - :code:`@value`
915932
- |MemberDescriptor-api| :code:`default_value` property.
916933
- ✅
917934
- ✅
935+
- ❌
918936
* - :code:`@verbatim`
919937
- |VerbatimTextDescriptor-api|
920938
- ❌
921939
- ❌
940+
- ❌
922941

923942
.. _xtypes_complextypes:
924943

docs/fastdds/xtypes/xtypes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This specification defines the following concepts:
2424
/fastdds/xtypes/discovery_matching.rst
2525
/fastdds/xtypes/language_binding.rst
2626
/fastdds/xtypes/type_serializing.rst
27+
/fastdds/xtypes/idl_parsing.rst
2728

2829
.. note::
2930

0 commit comments

Comments
 (0)