Skip to content

Commit 8892ff8

Browse files
Ref 22890. Feature idl parsing documentation
Signed-off-by: Eugenio Collado <[email protected]>
1 parent e225f5a commit 8892ff8

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

code/DDSCodeTester.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,45 @@ void dds_topic_examples()
20322032
}
20332033
//!--
20342034
}
2035+
2036+
{
2037+
//DDS_DYNAMIC_TYPES_IDL_PARSING
2038+
// Create a DomainParticipant in the desired domain
2039+
DomainParticipant* participant =
2040+
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
2041+
if (nullptr == participant)
2042+
{
2043+
// Error
2044+
return;
2045+
}
2046+
2047+
// Optional: Set the preprocessor to be executed before parsing the IDL
2048+
DynamicTypeBuilderFactory::get_instance()->set_preprocessor("<optional_path_to_your_preprocessor_executable>");
2049+
2050+
// Load the IDL file
2051+
std::string idl_file = "<path_to_idl>.idl";
2052+
std::string type_name = "YourType";
2053+
std::vector<std::string> include_paths;
2054+
include_paths.push_back("<path_to_included_idl>.idl");
2055+
2056+
// Retrieve the instance of the desired type
2057+
DynamicTypeBuilder::_ref_type dyn_type_builder =
2058+
DomainParticipantFactory::get_instance()->create_type_w_uri(idl_file, type_name, include_paths);
2059+
2060+
// Register dynamic type
2061+
TypeSupport dyn_type_support(new DynamicPubSubType(dyn_type_builder->build()));
2062+
dyn_type_support.register_type(participant, nullptr);
2063+
2064+
// Create a Topic with the registered type.
2065+
Topic* topic =
2066+
participant->create_topic("topic_name", dyn_type_support.get_type_name(), TOPIC_QOS_DEFAULT);
2067+
if (nullptr == topic)
2068+
{
2069+
// Error
2070+
return;
2071+
}
2072+
//!--
2073+
}
20352074
}
20362075

20372076
void dds_content_filtered_topic_examples()

docs/fastdds/xtypes/idl_parsing.rst

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 data types.
11+
The |DomainParticipantFactory::create_type_w_uri-api| API allows users to provide a URI pointing to an IDL file.
12+
Fast DDS will process the file and return the corresponding DynamicTypeBuilder, which can then be used to
13+
create a DynamicType.
14+
15+
This feature enables applications to dynamically load type definitions from IDL files instead of relying
16+
solely on pre-generated types or XML profiles. This enhances flexibility, as new data types can be introduced
17+
without modifying and recompiling the application.
18+
19+
Type definition
20+
^^^^^^^^^^^^^^^
21+
Below, the types supported by *eProsima Fast DDS* IDL parsing are presented.
22+
For further information about the supported |DynamicTypes|, please, refer to :ref:`xtypes_supportedtypes`.
23+
24+
* :ref:`xtypes_supportedtypes_primitive`
25+
* :ref:`xtypes_supportedtypes_string`
26+
* :ref:`xtypes_supportedtypes_structure`
27+
* :ref:`xtypes_supportedtypes_alias`
28+
* :ref:`xtypes_supportedtypes_array`
29+
* :ref:`xtypes_supportedtypes_union`
30+
* :ref:`xtypes_supportedtypes_enumeration`
31+
* :ref:`xtypes_annotations` (you can see the full table in :ref:`xtypes_builtin_annotations`)
32+
33+
- TODO (Eugenio): arithmetic expressions, union/struct forward declarations, switch-case.
34+
35+
The following types are currently not supported by the IDL parsing feature:
36+
37+
* :ref:`xtypes_supportedtypes_bitmask`
38+
* :ref:`xtypes_supportedtypes_sequence`
39+
* :ref:`xtypes_supportedtypes_map`
40+
* :ref:`xtypes_supportedtypes_bitset`
41+
42+
43+
- TODO (Eugenio): module,inheritance, member id
44+
45+
Example
46+
^^^^^^^
47+
48+
*Fast DDS* application can use dynamic types generated in runtime just by loading the corresponding IDL files into the
49+
|DomainParticipantFactory-api| using |DomainParticipantFactory::create_type_w_uri-api|.
50+
After getting the DynamicType, objects of |DynamicPubSubType-api| class might be instantiated and used to write/read
51+
data.
52+
53+
.. note::
54+
55+
The preprocessor can be manually selected using |DomainParticipantFactory::set_preprocessor-api|
56+
57+
The following snippet shows the previously explained steps:
58+
59+
.. literalinclude:: /../code/DDSCodeTester.cpp
60+
:language: c++
61+
:start-after: //DDS_DYNAMIC_TYPES_IDL_PARSING
62+
: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.
@@ -896,6 +897,7 @@ The annotation parameter value must be converted to its string representation.
896897
:start-after: //!--CPP_CUSTOM_ANNOTATION
897898
:end-before: //!--
898899

900+
.. _xtypes_builtin_annotations:
899901

900902
Builtin annotations
901903
"""""""""""""""""""
@@ -914,71 +916,88 @@ Please, refer to :ref:`builtin annotations <builtin_annotations>` for the comple
914916
- Dynamic Language Binding API
915917
- Dynamic Language Binding support
916918
- XML Dynamic Type profiles support
919+
- IDL Parsing Dynamic Type support
917920
* - :code:`@appendable`
918921
- |TypeDescriptor-api| :code:`extensibility_kind` property.
919922
- ✅
920923
- ❌
924+
- ❌
921925
* - :code:`@bit_bound`
922926
- |TypeDescriptor-api| :code:`bound` property for :ref:`xtypes_supportedtypes_bitset`. |br|
923927
|MemberDescriptor-api| :code:`type` property for :ref:`xtypes_supportedtypes_enumeration`.
924928
- ✅
925929
- ✅❌ (`Enumeration types`_ not configurable).
930+
- TODO (Eugenio)
926931
* - :code:`@default`
927932
- |MemberDescriptor-api| :code:`default_value` property.
928933
- ✅
929934
- ❌
935+
- TODO (Eugenio)
930936
* - :code:`default_literal`
931937
- |MemberDescriptor-api| :code:`is_default_label` property.
932938
- ✅
933939
- ❌
940+
- TODO (Eugenio)
934941
* - :code:`@extensibility`
935942
- |TypeDescriptor-api| :code:`extensibility_kind` property.
936943
- ✅
937944
- ❌
945+
- TODO (Eugenio)
938946
* - :code:`@external`
939947
- |MemberDescriptor-api| :code:`is_shared` property.
940948
- ❌
941949
- ❌
950+
- ❌
942951
* - :code:`@final`
943952
- |TypeDescriptor-api| :code:`extensibility_kind` property.
944953
- ✅
945954
- ❌
955+
- ❌
946956
* - :code:`@id`
947957
- |MemberDescriptor-api| :code:`id` property.
948958
- ✅
949959
- ❌
960+
- TODO (Eugenio)
950961
* - :code:`@key` / :code:`@Key`
951962
- |MemberDescriptor-api| :code:`is_key` property.
952963
- ✅
953964
- ❌
965+
- ❌
954966
* - :code:`@mutable`
955967
- |TypeDescriptor-api| :code:`extensibility_kind` property.
956968
- ✅
957969
- ❌
970+
- ❌
958971
* - :code:`@nested`
959972
- |TypeDescriptor-api| :code:`is_nested` property.
960973
- ❌
961974
- ❌
975+
- TODO (Eugenio)
962976
* - :code:`@optional`
963977
- |MemberDescriptor-api| :code:`is_optional` property.
964978
- ❌
965979
- ❌
980+
- ❌
966981
* - :code:`@position`
967982
- |MemberDescriptor-api| :code:`id` property.
968983
- ✅
969984
- ✅
985+
- TODO (Eugenio)
970986
* - :code:`@try_construct`
971987
- |MemberDescriptor-api| :code:`try_construct_kind` property.
972988
- ❌
973989
- ❌
990+
- TODO (Eugenio)
974991
* - :code:`@value`
975992
- |MemberDescriptor-api| :code:`default_value` property.
976993
- ✅
977994
- ✅
995+
- TODO (Eugenio)
978996
* - :code:`@verbatim`
979997
- |VerbatimTextDescriptor-api|
980998
- ❌
981999
- ❌
1000+
- TODO (Eugenio)
9821001

9831002
.. _xtypes_complextypes:
9841003

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)