Skip to content

Proposal: @optional support

Justin Wilson edited this page Dec 4, 2023 · 3 revisions

Introduction

This document is about supporting the @optional annotation. Section 7.5.1.2.4 in the XType spec has directions for C, C++, and Java language bindings.

C++11 Bindings

There is work underway in #4364 to implement @optional for the C++11 Bindings. As currently formulated, the user would need to choose the C++11 Bindings and use a compiler that supports std::optional (C++17). If we want to back the required language standard down to C++11, then will we have to provide our own implementation of std::optional.

Classic C++ Bindings

To support @optional using the Classic C++ Bindings, then we will need to update tao_idl_BE to support the @optional annotation. If we do this, we can use @optional in the spec-defined IDL which is one step towards compiling the XTypes/DynamicData IDL (see Annex B). However, in some future version (OpenDDS5?), the dependency on tao_idl will be removed and the Classic C++ Bindings will no longer be supported.

Java

Java currently requires the Classic C++ Bindings. Options include

  1. Wait until the Classic C++ Bindings are obsolete, at which point the Java bindings will have to be converted to the C++11 Bindings.
  2. Convert the Java Bindings to use the C++11 bindings. The user must have an appropriate C++ compiler. This would force all Java users to use at least C++11 and those using @optional to potentially using C++17.
  3. Convert Java to DynamicData. The implementation of @optional for DynamicData is probably complete or near completion. In this scenario, there is no C++ code generation.

The binding in node is based on ValueWriter/ValueReader. Users would need to use the C++11 bindings and a new enough compiler for @optional. We would need to test and fill in gaps.

pyopendds can use either the classic or the C++11 bindings. Users would need to use the C++11 bindings and a new enough compiler for @optional. We would need to test and fill in gaps.

See https://github.com/jmmorato/openddsharp/discussions/215 for complete details. Action items from @jmmorato

Based on that, here a short list that came to my mind of the work expected to support the optional feature in OpenDDSharp:

  • Migrate OpenDDSharp to the latest OpenDDS version.
    • I foresee some breaking changes due to the ConfigStore modifications in OpenDDS.
  • Ensure using the correct C++ bindings (11/17) when generating the OpenDDS project for the data types
  • Ensure JSON writers and JSON readers support optional feature in OpenDDS and OpenDDSharp
    • The implementation of the binding using CDR serialization is planned for future work in OpenDDSharp, similar requirement would be needed to support optional feature
    • The implementation of the binding using DynamicData is planned for future work in OpenDDSharp, similar requirement would be needed to support optional feature
  • Provide a new C# OpenDDSharp.Omg.Types.OptionalAttribute
  • Modify openddsharp_idl code generator to support nullable value types as described in the mapping documentation
  • Unit Test optional feature code generation and publication/subcription
  • Update IDL documentation