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

Add capability to load DynamicType directly from XML #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion modules/connextdds/src/dds/core/xtypes/DynamicType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,44 @@ void init_class_defs(py::class_<DynamicType>& 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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality exists in the QosProvider. Did you need to add it here for some reason?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds two things that, to the best of my knowledge, are not handled by the QosProvider public API type functions:

  • It allows for the use of a type's XML right out of rtiddsgen -convertToXml without having to first include it from a QoS file. Trying to load such an XML with QosProvider produces an error:
rti.connextdds.Error: 
 DDS_XMLStruct_initialize:!init XML struct object
  DDS_XMLStruct_newI:!init XML struct object
   RTIXMLParser_onStartTag:Parse error at line 3: Error processing tag 'struct'
  • A user can specify include search paths for XML type dependencies. This can be useful for specifying type locations relative to the script's path in code. I think there is a way to do this in QoS if you know all of the XML files and use environment variables to specify the path, but maybe there is a better way?

"from_xml",
[](
const std::string& file_name,
const std::string& type_name,
dds::core::optional<std::vector<std::string>>& 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<char*>
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<DynamicType>(*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<>
Expand Down