From cd7e81310d061f5cd8cb79be235d28b0fe9a3ba7 Mon Sep 17 00:00:00 2001 From: Marc Chiesa Date: Fri, 30 Oct 2020 22:24:44 -0400 Subject: [PATCH] Add capability to load DynamicType directly from XML output of rtiddsgen -convertToXml and specify include paths programmatically --- .../src/dds/core/xtypes/DynamicType.cpp | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/modules/connextdds/src/dds/core/xtypes/DynamicType.cpp b/modules/connextdds/src/dds/core/xtypes/DynamicType.cpp index b41aa12d..efd99062 100644 --- a/modules/connextdds/src/dds/core/xtypes/DynamicType.cpp +++ b/modules/connextdds/src/dds/core/xtypes/DynamicType.cpp @@ -124,7 +124,44 @@ void init_class_defs(py::class_& cls) .def(py::self == py::self, "Compare DynamicType objects for equality.") .def(py::self != py::self, - "Compare DynamicType objects for inequality."); + "Compare DynamicType objects for inequality.") + .def_static( + "from_xml", + []( + const std::string& file_name, + const std::string& type_name, + dds::core::optional>& include_paths, + uint32_t unbounded_str_max, + uint32_t unbounded_seq_max) { + DDS_TypeCodeFactory* factory = DDS_TypeCodeFactory_get_instance(); + DDS_ExceptionCode_t ex; + DDS_StringSeq native_paths = DDS_SEQUENCE_INITIALIZER; + rti::core::detail::NativeSequenceAdapter + paths_adapter(native_paths); + if (has_value(include_paths)) { + rti::core::native_conversions::to_native(native_paths, get_value(include_paths)); + } + DDS_TypeCode* tc = DDS_TypeCodeFactory_create_tc_from_xml_file( + factory, + file_name.c_str(), + type_name.c_str(), + &native_paths, + unbounded_str_max, + unbounded_seq_max, + &ex + ); + rti::core::check_tc_ex_code(ex, "DynamicType.from_xml error"); + return py_cast_type( + rti::core::native_conversions::cast_from_native(*tc)); + }, + py::arg("filename"), + py::arg("typename"), + py::arg("include_paths") = py::none(), + py::arg("unbounded_string_max_len") = 255, + py::arg("unbounded_seq_max_len") = 100, + py::return_value_policy::reference, + "Load a DynamicType from an XML file." + ); } template<>