Skip to content

Commit

Permalink
Merge pull request eclipse-cyclonedds#453 from eboasson/psmx
Browse files Browse the repository at this point in the history
PSMX support for C++
  • Loading branch information
eboasson authored Sep 20, 2023
2 parents 5316fff + 96b09a3 commit ef77160
Show file tree
Hide file tree
Showing 29 changed files with 751 additions and 447 deletions.
6 changes: 3 additions & 3 deletions .azure/templates/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ steps:
mkdir iceoryx/build
cd iceoryx/build
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_BUILD_SHARED_LIBS=on \
-DCMAKE_INSTALL_PREFIX=install \
-DBUILD_SHARED_LIBS=on \
-DROUDI_ENVIRONMENT=on \
${GENERATOR:+-G} "${GENERATOR}" -A "${PLATFORM}" -T "${TOOLSET}" ../iceoryx_meta
cmake --build . --config ${BUILD_TYPE} --target install -- ${BUILD_TOOL_OPTIONS}
Expand All @@ -105,7 +105,7 @@ steps:
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_PREFIX_PATH="${BUILD_SOURCESDIRECTORY}/iceoryx/build/install" \
-DSANITIZER=${SANITIZER:-none} \
-DENABLE_SHM=${ICEORYX:-off} \
-DENABLE_ICEORYX=${ICEORYX:-off} \
-DENABLE_TYPELIB=${TYPELIB:-on} \
-DENABLE_TOPIC_DISCOVERY=${TOPIC_DISCOVERY:-on} \
${GENERATOR:+-G} "${GENERATOR}" -A "${PLATFORM}" -T "${TOOLSET}" ..
Expand All @@ -120,7 +120,7 @@ steps:
-DCMAKE_PREFIX_PATH="${BUILD_SOURCESDIRECTORY}/cyclonedds/build/install;${BUILD_SOURCESDIRECTORY}/iceoryx/build/install;${BUILD_SOURCESDIRECTORY}/googletest/build/install" \
-DANALYZER=${ANALYZER:-off} \
-DSANITIZER=${SANITIZER:-none} \
-DENABLE_SHM=${ICEORYX:-off} \
-DENABLE_ICEORYX=${ICEORYX:-off} \
-DENABLE_COVERAGE=${COVERAGE:-off} \
-DENABLE_LEGACY=${LEGACY:-off} \
-DBUILD_TESTING=on \
Expand Down
22 changes: 2 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# By default building the testing tree is enabled by including CTest, but
# since it is not required to build the project, switch to off by default.
option(BUILD_TESTING "Build the testing tree." OFF)
option(ENABLE_ICEORYX "Enable testing PSMX with Iceoryx plugin" OFF)

# Disable building the examples by default until the Idlpp-cxx has been
# deprecated.
option(BUILD_EXAMPLES "Build examples." OFF)
Expand Down Expand Up @@ -223,26 +225,6 @@ install(
COMPONENT dev)

find_package(CycloneDDS REQUIRED)
# Support for shared memory in Cyclone DDS C++ depends on support for shared
# memory being compiled into Cyclone DDS and iceoryx_binding_c being available
# If Cyclone DDS is compiled with support for shared memory, Cyclone DDS C++
# must be compiled with shared memory too and vice versa.
get_target_property(cyclonedds_has_shm CycloneDDS::ddsc SHM_SUPPORT_IS_AVAILABLE)
mark_as_advanced(cyclonedds_has_shm)

option(ENABLE_SHM "Enable shared memory support" ${cyclonedds_has_shm})
if(ENABLE_SHM)
if(NOT cyclonedds_has_shm)
message(FATAL_ERROR "Cyclone DDS is NOT compiled with support for shared memory")
else()
find_package(iceoryx_binding_c REQUIRED)
endif()
message(STATUS "Found iceoryx_binding_c: (found version \"${iceoryx_binding_c_VERSION}\")")
set(ENABLE_SHM ON)
set(DDSCXX_HAS_SHM "1")
elseif(cyclonedds_has_shm)
message(FATAL_ERROR "Cyclone DDS is compiled with support for shared memory")
endif()

get_target_property(cyclonedds_has_typelib CycloneDDS::ddsc TYPELIB_IS_AVAILABLE)
mark_as_advanced(cyclonedds_has_typelib)
Expand Down
5 changes: 0 additions & 5 deletions PackageConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

find_package(CycloneDDS REQUIRED)

if(@ENABLE_SHM@)
include(CMakeFindDependencyMacro)
find_dependency(iceoryx_binding_c)
endif()

if(@ENABLE_LEGACY@)
include(CMakeFindDependencyMacro)
find_dependency(Boost)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ There are some configuration options specified using CMake defines in addition t
* `-DBUILD_TESTING=ON`: to build the testing tree
* `-DBUILD_EXAMPLES=ON`: to build examples
* `-DENABLE_LEGACY=YES`: to enable legacy c++11 mode, adds boost as dependency (otherwise it uses c++17)
* `-DENABLE_SHM=YES`: to enable shared memory support
* `-DENABLE_ICEORYX=YES`: to enable Iceoryx tests
* `-DENABLE_TYPELIB=YES`: to enable type library support
* `-DENABLE_TOPIC_DISCOVERY=YES`: to enable topic discovery support
* `-DENABLE_COVERAGE=YES`: to enable coverage build
Expand Down
3 changes: 0 additions & 3 deletions features.hpp.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef __OMG_DDS_DDSCXX_FEATURES_HPP__
#define __OMG_DDS_DDSCXX_FEATURES_HPP__

/* Whether or not support for shared memory is included */
#cmakedefine DDSCXX_HAS_SHM @DDSCXX_HAS_SHM@

/* Whether or not support for type discovery is included */
#cmakedefine DDSCXX_HAS_TYPELIB @DDSCXX_HAS_TYPELIB@

Expand Down
6 changes: 0 additions & 6 deletions src/ddscxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ddscxx>)

if(ENABLE_SHM)
# TODO: Ideally the C++ language binding shouldn't depend directly on
# Iceoryx, but should get it from Cyclone DDS
target_link_libraries(ddscxx PUBLIC iceoryx_binding_c::iceoryx_binding_c)
endif()

generate_export_header(
ddscxx
BASE_NAME OMG_DDS_API_DETAIL
Expand Down
4 changes: 4 additions & 0 deletions src/ddscxx/include/dds/core/policy/CorePolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ typedef dds::core::policy::detail::TypeConsistencyEnforcement
TypeConsistencyEnforcement;
#endif //OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT

typedef dds::core::policy::detail::PSMXInstances
PSMXInstances;

typedef dds::core::policy::detail::UserData
UserData;

Expand Down Expand Up @@ -195,6 +198,7 @@ OMG_DDS_POLICY_TRAITS(DataRepresentation, 23)
OMG_DDS_POLICY_TRAITS(TypeConsistencyEnforcement, 24)
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT
OMG_DDS_POLICY_TRAITS(WriterBatching, 25)
OMG_DDS_POLICY_TRAITS(PSMXInstances, 34)

}
}
Expand Down
52 changes: 52 additions & 0 deletions src/ddscxx/include/dds/core/policy/TCorePolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,58 @@ class TTypeConsistencyEnforcement : public dds::core::Value<D>
//==============================================================================



/**
* @brief QoSPolicy indicating which PSMX instances to use (if present).
*
* Restricts the PSMX instances used for data exchange to the ones in this QoSPolicy, if populated by the user.
* Populating this QoSPolicy with an empty list means no PSMX exchange will be used.
* Will be default constructed, but not set as populated in the default constructed DataWriter and DataReader QoSes.
* In this manner default constructed QoSes will allow all PSMX forms of exchange available to CycloneDDS.
*/
template <typename D>
class TPSMXInstances : public dds::core::Value<D>
{
public:

/**
* Constructs a copy of a TPSMXInstances QoS instance
*
* @param other The instance to copy.
*/
TPSMXInstances(const TPSMXInstances& other);

/**
* Constructs an initialized TPSMXInstances QoS instance
*
* @param instances the PSMX instances to support
*/
explicit TPSMXInstances(const dds::core::StringSeq &instances = {});

/**
* Copies a TPSMXInstances QoS instance
*
* @param other the instance to copy
*/
TPSMXInstances& operator=(const TPSMXInstances& other) = default;

/**
* Sets which PSMX instances are supported
*
* @param instances which instances to support
*
* @return the psmx instances QoSPolicy that was changed
*/
TPSMXInstances& instances(const dds::core::StringSeq &instances);

/**
* Get which PSMX instances are supported.
*
* @return sequence of strings of supported PSMX instances
*/
const dds::core::StringSeq instances() const;
};

}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ddscxx/include/dds/core/policy/detail/CorePolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ namespace dds { namespace core { namespace policy { namespace detail {
TypeConsistencyEnforcement;
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT

typedef dds::core::policy::TPSMXInstances<org::eclipse::cyclonedds::core::policy::PSMXInstancesDelegate>
PSMXInstances;

typedef dds::core::policy::TUserData<org::eclipse::cyclonedds::core::policy::UserDataDelegate>
UserData;

Expand Down
23 changes: 23 additions & 0 deletions src/ddscxx/include/dds/core/policy/detail/TCorePolicyImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,29 @@ bool TTypeConsistencyEnforcement<D>::force_type_validation() const

#endif // defined(OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT)

template <typename D>
TPSMXInstances<D>::TPSMXInstances(const TPSMXInstances<D>& other): dds::core::Value<D>(other)
{
}

template <typename D>
TPSMXInstances<D>::TPSMXInstances(const dds::core::StringSeq &instances): dds::core::Value<D>(instances)
{
}

template <typename D>
TPSMXInstances<D>& TPSMXInstances<D>::instances(const dds::core::StringSeq &instances)
{
this->delegate().instances(instances);
return *this;
}

template <typename D>
const dds::core::StringSeq TPSMXInstances<D>::instances() const
{
return this->delegate().instances();
}

}
}
}
Expand Down
44 changes: 2 additions & 42 deletions src/ddscxx/include/dds/sub/detail/SamplesHolder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,53 +104,13 @@ class CDRSamplesHolder : public SamplesHolder
org::eclipse::cyclonedds::topic::CDRBlob & cdr_blob) const
{
// update the CDR header
memcpy(cdr_blob.encoding().data(), buffer, CDR_HEADER_SIZE);
memcpy(cdr_blob.encoding().data(), buffer, DDSI_RTPS_HEADER_SIZE);
// if the data kind is not empty
if (data_kind != org::eclipse::cyclonedds::topic::BlobKind::Empty) {
// get the actual data from the buffer
cdr_blob.payload().assign(buffer + CDR_HEADER_SIZE, buffer + size);
cdr_blob.payload().assign(buffer + DDSI_RTPS_HEADER_SIZE, buffer + size);
}
}

bool update_cdrblob_from_iox_chunk (ddsi_serdata & current_blob,
org::eclipse::cyclonedds::topic::CDRBlob &sample_data) {
#ifdef DDSCXX_HAS_SHM
// if the data is available on SHM
if (current_blob.iox_chunk && current_blob.iox_subscriber) {
// get the user iox header
auto iox_header = iceoryx_header_from_chunk(current_blob.iox_chunk);
// if the iox chunk has the data in serialized form
if (iox_header->shm_data_state == IOX_CHUNK_CONTAINS_SERIALIZED_DATA) {
copy_buffer_to_cdr_blob(reinterpret_cast<uint8_t *>(current_blob.iox_chunk),
iox_header->data_size, sample_data.kind(), sample_data);
} else if (iox_header->shm_data_state == IOX_CHUNK_CONTAINS_RAW_DATA) {
// serialize the data
auto serialized_size = ddsi_sertype_get_serialized_size(current_blob.type,
current_blob.iox_chunk);
// create a buffer to serialize
std::vector<uint8_t> buffer(serialized_size);
// serialize into the buffer
ddsi_sertype_serialize_into(current_blob.type, current_blob.iox_chunk, buffer.data(),
serialized_size);
// update the CDR blob with the serialized data
copy_buffer_to_cdr_blob(buffer.data(), serialized_size, sample_data.kind(), sample_data);
} else {
// this shouldn't never happen
ISOCPP_THROW_EXCEPTION(ISOCPP_PRECONDITION_NOT_MET_ERROR,
"The received sample over SHM is not initialized");
}
// release the chunk
free_iox_chunk(static_cast<iox_sub_t *>(current_blob.iox_subscriber), &current_blob.iox_chunk);
return true;
} else {
return false;
}
#else
(void) current_blob;
(void) sample_data;
return false;
#endif // DDSCXX_HAS_SHM
}
};

template <typename T, typename SamplesFWIterator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,5 @@ bool max(xcdr_v2_stream& str, const T& max_sz, size_t N = 1) {
}
}
} /* namespace org / eclipse / cyclonedds / core / cdr */
#endif
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,25 @@ class OMG_DDS_API TypeConsistencyEnforcementDelegate {

#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT

class OMG_DDS_API PSMXInstancesDelegate {
public:
PSMXInstancesDelegate(const PSMXInstancesDelegate& other);
explicit PSMXInstancesDelegate(const dds::core::StringSeq &instances);
PSMXInstancesDelegate& operator=(const PSMXInstancesDelegate& other) = default;

void instances(const dds::core::StringSeq &instances);
const dds::core::StringSeq instances() const;

void check() const;

bool operator == (const PSMXInstancesDelegate &other) const;

void set_iso_policy(const dds_qos_t* qos);
void set_c_policy(dds_qos_t* qos) const;
private:
dds::core::StringSeq instances_;
};

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class OMG_DDS_API DataWriterQosDelegate
void policy(const dds::core::policy::TypeConsistencyEnforcement& typeconsistencyenforcement);
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT
void policy(const dds::core::policy::WriterBatching& writerbatching);
void policy(const dds::core::policy::PSMXInstances& psmxinstances);

template <typename POLICY> const POLICY& policy() const;
template <typename POLICY> POLICY& policy();
Expand Down Expand Up @@ -104,6 +105,7 @@ class OMG_DDS_API DataWriterQosDelegate
dds::core::policy::TypeConsistencyEnforcement typeconsistencyenforcement_;
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT
dds::core::policy::WriterBatching writerbatching_;
dds::core::policy::PSMXInstances psmxinstances_;
};


Expand Down Expand Up @@ -281,6 +283,17 @@ DataWriterQosDelegate::policy<dds::core::policy::WriterBatching>() const
template<> OMG_DDS_API dds::core::policy::WriterBatching&
DataWriterQosDelegate::policy<dds::core::policy::WriterBatching>();

template<>
OMG_DDS_API dds::core::policy::PSMXInstances&
DataWriterQosDelegate::policy<dds::core::policy::PSMXInstances>();

template<>
inline const dds::core::policy::PSMXInstances&
DataWriterQosDelegate::policy<dds::core::policy::PSMXInstances>() const
{
return psmxinstances_;
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class OMG_DDS_API DataReaderQosDelegate
void policy(const dds::core::policy::DataRepresentation& datarepresentation);
void policy(const dds::core::policy::TypeConsistencyEnforcement& typeconsistencyenforcement);
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT
void policy(const dds::core::policy::PSMXInstances& psmxinstances);

template <typename POLICY> const POLICY& policy() const;
template <typename POLICY> POLICY& policy();
Expand Down Expand Up @@ -88,6 +89,7 @@ class OMG_DDS_API DataReaderQosDelegate
dds::core::policy::DataRepresentation datarepresentation_;
dds::core::policy::TypeConsistencyEnforcement typeconsistencyenforcement_;
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT
dds::core::policy::PSMXInstances psmxinstances_;
};


Expand Down Expand Up @@ -238,6 +240,17 @@ OMG_DDS_API dds::core::policy::TypeConsistencyEnforcement&
DataReaderQosDelegate::policy<dds::core::policy::TypeConsistencyEnforcement>();
#endif // OMG_DDS_EXTENSIBLE_AND_DYNAMIC_TOPIC_TYPE_SUPPORT

template<>
OMG_DDS_API dds::core::policy::PSMXInstances&
DataReaderQosDelegate::policy<dds::core::policy::PSMXInstances>();

template<>
inline const dds::core::policy::PSMXInstances&
DataReaderQosDelegate::policy<dds::core::policy::PSMXInstances>() const
{
return psmxinstances_;
}

}
}
}
Expand Down
Loading

0 comments on commit ef77160

Please sign in to comment.