From 00ce82442a06475e6ceeccfc45ad88e8fc8cb9e7 Mon Sep 17 00:00:00 2001 From: Andrea Sorbini Date: Tue, 27 Apr 2021 16:22:16 -0700 Subject: [PATCH] Allow sharing DomainParticipant with C++ applications (#25) * Allow sharing DomainParticipant with C++ applications * Add comment about UserObjectQosPolicy * Resolve uncrustify errors Signed-off-by: Andrea Sorbini --- .../include/rmw_connextdds/static_config.hpp | 8 ++++++++ rmw_connextdds_common/src/ndds/dds_api_ndds.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp b/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp index 2ad1c9fc..41bac860 100644 --- a/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp +++ b/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp @@ -280,6 +280,14 @@ #define RMW_CONNEXT_FAST_ENDPOINT_DISCOVERY 1 #endif /* RMW_CONNEXT_FAST_ENDPOINT_DISCOVERY */ +/****************************************************************************** + * Modify DomainParticipantQos to allow sharing of DDS entities created with + * the Connext C API with applications using the C++11 API. + ******************************************************************************/ +#ifndef RMW_CONNEXT_SHARE_DDS_ENTITIES_WITH_CPP +#define RMW_CONNEXT_SHARE_DDS_ENTITIES_WITH_CPP 1 +#endif /* RMW_CONNEXT_SHARE_DDS_ENTITIES_WITH_CPP */ + /****************************************************************************** * Override dds.transport.UDPv4.builtin.ignore_loopback_interface in * DomainParticipantQos to force communication over loopback (in addition to diff --git a/rmw_connextdds_common/src/ndds/dds_api_ndds.cpp b/rmw_connextdds_common/src/ndds/dds_api_ndds.cpp index 0e4dfc12..3a093ab1 100644 --- a/rmw_connextdds_common/src/ndds/dds_api_ndds.cpp +++ b/rmw_connextdds_common/src/ndds/dds_api_ndds.cpp @@ -207,6 +207,20 @@ rmw_connextdds_initialize_participant_qos_impl( } #endif /* RMW_CONNEXT_FAST_ENDPOINT_DISCOVERY */ +#if RMW_CONNEXT_SHARE_DDS_ENTITIES_WITH_CPP + // UserObjectQosPolicy is an internal, undocumented Connext policy used by the + // implementations of different language bindings to control the memory + // representations of various objects created by user applications. In this + // case, the settings match the requirements of the "modern C++" API, and they + // allow the DomainParticipant to be used directly by applications that want + // to create new entities in C++11, even though the participant was created + // using the C API. If these settings are not specified, an application will + // receive a SIGSEGV when trying to create one of these entities. + dp_qos->user_object.flow_controller_user_object.size = sizeof(void *); + dp_qos->user_object.topic_user_object.size = sizeof(void *); + dp_qos->user_object.content_filtered_topic_user_object.size = sizeof(void *); +#endif /* RMW_CONNEXT_SHARE_DDS_ENTITIES_WITH_CPP */ + return RMW_RET_OK; }