Skip to content

Commit

Permalink
Implement QosProvider for C++ API.
Browse files Browse the repository at this point in the history
  • Loading branch information
e-hndrks committed Apr 9, 2024
1 parent a903265 commit a8905fa
Show file tree
Hide file tree
Showing 24 changed files with 1,174 additions and 49 deletions.
1 change: 1 addition & 0 deletions .azure/templates/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ steps:
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_PREFIX_PATH="${BUILD_SOURCESDIRECTORY}/cyclonedds/build/install;${BUILD_SOURCESDIRECTORY}/iceoryx/build/install;${BUILD_SOURCESDIRECTORY}/googletest/build/install" \
-DCYCLONE_SOURCE_DIR="${BUILD_SOURCESDIRECTORY}/cyclonedds" \
-DANALYZER=${ANALYZER:-off} \
-DSANITIZER=${SANITIZER:-none} \
-DENABLE_ICEORYX=${ICEORYX:-off} \
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ if(ENABLE_TOPIC_DISCOVERY)
set(DDSCXX_HAS_TOPIC_DISCOVERY "1")
endif()

get_target_property(cyclonedds_has_qos_provider CycloneDDS::ddsc QOS_PROVIDER_IS_AVAILABLE)
mark_as_advanced(cyclonedds_has_qos_provider)
option(ENABLE_QOS_PROVIDER "Enable QoS Provider support" ${cyclonedds_has_qos_provider})
if(ENABLE_QOS_PROVIDER)
if (NOT cyclonedds_has_qos_provider)
message(FATAL_ERROR "Cyclone DDS is not compiled with qos provider enabled")
endif()
message(STATUS "Compiling with qos provider support")
set(DDSCXX_HAS_QOS_PROVIDER "1")
endif()



configure_file(features.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/src/ddscxx/include/dds/features.hpp")

add_subdirectory(src)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ There are some configuration options specified using CMake defines in addition t
* `-DENABLE_TYPELIB=YES`: to enable type library support
* `-DENABLE_TOPIC_DISCOVERY=YES`: to enable topic discovery support
* `-DENABLE_COVERAGE=YES`: to enable coverage build
* `-DENABLE_QOS_PROVIDER=YES`: to enable qos provider support

### For application developers

Expand Down
3 changes: 3 additions & 0 deletions features.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
/* Whether to use boost for c++11 compatibility or not */
#cmakedefine DDSCXX_USE_BOOST @DDSCXX_USE_BOOST@

/* Whether or not support for qos provider is included */
#cmakedefine DDSCXX_HAS_QOS_PROVIDER @DDSCXX_HAS_QOS_PROVIDER@

#endif /* __OMG_DDS_DDSCXX_FEATURES_HPP__ */
6 changes: 6 additions & 0 deletions src/ddscxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ set(sources
src/org/eclipse/cyclonedds/topic/TopicDescriptionDelegate.cpp
src/org/eclipse/cyclonedds/topic/qos/TopicQosDelegate.cpp)

if (ENABLE_QOS_PROVIDER)
list(APPEND sources
src/org/eclipse/cyclonedds/core/QosProviderDelegate.cpp)
endif()

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
add_library(ddscxx SHARED ${sources})
else()
Expand All @@ -91,6 +96,7 @@ add_library(${PROJECT_NAME}::ddscxx ALIAS ddscxx)
add_coverage(ddscxx)

set_property(TARGET ddscxx PROPERTY CXX_STANDARD ${cyclonedds_cpp_std_to_use})

target_link_libraries(ddscxx PUBLIC CycloneDDS::ddsc)
target_include_directories(
ddscxx
Expand Down
4 changes: 4 additions & 0 deletions src/ddscxx/include/dds/core/QosProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifdef DDS_HAS_QOS_PROVIDER

#include <dds/core/detail/QosProvider.hpp>


Expand All @@ -29,4 +31,6 @@ typedef dds::core::detail::QosProvider QosProvider;
}
}

#endif /* DDS_HAS_QOS_PROVIDER */

#endif /* OMG_DDS_CORE_QOS_PROVIDER_HPP_ */
4 changes: 4 additions & 0 deletions src/ddscxx/include/dds/core/detail/QosProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifdef DDS_HAS_QOS_PROVIDER

#include <dds/core/detail/TQosProviderImpl.hpp>
#include <org/eclipse/cyclonedds/core/QosProviderDelegate.hpp>

Expand All @@ -30,4 +32,6 @@ namespace dds {
}
}

#endif /* DDS_HAS_QOS_PROVIDER */

#endif /* OMG_DDS_CORE_DETAIL_QOS_PROVIDER_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
#include <dds/pub/qos/PublisherQos.hpp>
#include <dds/pub/qos/DataWriterQos.hpp>

#if 0
C_CLASS(cmn_qosProvider);
C_CLASS(cmn_qosProviderInputAttr);
#endif

namespace org
{
namespace eclipse
Expand All @@ -41,6 +36,8 @@ class QosProviderDelegate;
}
}

struct dds_qos_provider;

class OMG_DDS_API org::eclipse::cyclonedds::core::QosProviderDelegate
{
public:
Expand All @@ -49,30 +46,25 @@ class OMG_DDS_API org::eclipse::cyclonedds::core::QosProviderDelegate
~QosProviderDelegate();

dds::domain::qos::DomainParticipantQos
participant_qos(const char* id);
participant_qos(const std::string& id = "");

dds::topic::qos::TopicQos
topic_qos(const char* id);
topic_qos(const std::string& id = "");

dds::sub::qos::SubscriberQos
subscriber_qos(const char* id);
subscriber_qos(const std::string& id = "");

dds::sub::qos::DataReaderQos
datareader_qos(const char* id);
datareader_qos(const std::string& id = "");

dds::pub::qos::PublisherQos
publisher_qos(const char* id);
publisher_qos(const std::string& id = "");

dds::pub::qos::DataWriterQos
datawriter_qos(const char* id);
datawriter_qos(const std::string& id = "");

private:
template <typename FROM, typename TO>
static void named_qos__copyOut(void *from, void *to);
#if 0
cmn_qosProvider qosProvider;
static const C_STRUCT(cmn_qosProviderInputAttr) qosProviderAttr;
#endif
dds_qos_provider *qosProvider;
};

#endif /* CYCLONEDDS_CORE_QOSPROVIDERDELEGATE_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OMG_DDS_API DomainParticipantQosDelegate

/* The returned ddsc QoS has to be freed. */
dds_qos_t* ddsc_qos() const;
void ddsc_qos(const dds_qos_t* qos);
void ddsc_qos(const dds_qos_t* qos, bool copy_present);

void named_qos(const struct _DDS_NamedDomainParticipantQos &qos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class OMG_DDS_API DataWriterQosDelegate

/* The returned ddsc QoS has to be freed. */
dds_qos_t* ddsc_qos() const;
void ddsc_qos(const dds_qos_t* qos);
void ddsc_qos(const dds_qos_t* qos, bool copy_present);

void named_qos(const struct _DDS_NamedDataWriterQos &qos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OMG_DDS_API PublisherQosDelegate

/* The returned ddsc QoS has to be freed. */
dds_qos_t* ddsc_qos() const;
void ddsc_qos(const dds_qos_t* qos);
void ddsc_qos(const dds_qos_t* qos, bool copy_present);

void named_qos(const struct _DDS_NamedPublisherQos &qos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OMG_DDS_API DataReaderQosDelegate

/* The returned ddsc QoS has to be freed. */
dds_qos_t* ddsc_qos() const;
void ddsc_qos(const dds_qos_t* qos);
void ddsc_qos(const dds_qos_t* qos, bool copy_present);

void named_qos(const struct _DDS_NamedDataReaderQos &qos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OMG_DDS_API SubscriberQosDelegate

/* The returned ddsc QoS has to be freed. */
dds_qos_t* ddsc_qos() const;
void ddsc_qos(const dds_qos_t* qos);
void ddsc_qos(const dds_qos_t* qos, bool copy_present);

void named_qos(const struct _DDS_NamedSubscriberQos &qos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OMG_DDS_API TopicQosDelegate

/* The returned ddsc QoS has to be freed. */
dds_qos_t* ddsc_qos() const;
void ddsc_qos(const dds_qos_t* qos);
void ddsc_qos(const dds_qos_t* qos, bool copy_present);

void named_qos(const struct _DDS_NamedTopicQos &qos);

Expand Down
135 changes: 135 additions & 0 deletions src/ddscxx/src/org/eclipse/cyclonedds/core/QosProviderDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright(c) 2006 to 2021 ZettaScale Technology and others
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
// v. 1.0 which is available at
// http://www.eclipse.org/org/documents/edl-v10.php.
//
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

/**
* @file
*/

#include <org/eclipse/cyclonedds/core/QosProviderDelegate.hpp>

#include <dds/ddsc/dds_public_qos_provider.h>

namespace org
{
namespace eclipse
{
namespace cyclonedds
{
namespace core
{

QosProviderDelegate::QosProviderDelegate(const std::string& uri, const std::string& id) : qosProvider(nullptr)
{
dds_return_t ret;

ret = dds_create_qos_provider_scope(uri.c_str(), &qosProvider, id.c_str());
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to create QosProvider.");
}

QosProviderDelegate::~QosProviderDelegate()
{
dds_delete_qos_provider(qosProvider);
}

dds::domain::qos::DomainParticipantQos
QosProviderDelegate::participant_qos(const std::string &id)
{
dds::domain::qos::DomainParticipantQos dpq;
const dds_qos_t *c_dpq = NULL;
dds_return_t ret;

ret = dds_qos_provider_get_qos(qosProvider, DDS_PARTICIPANT_QOS, id.c_str(), &c_dpq);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to obtain requested participant QoS.");

dpq.delegate().ddsc_qos(c_dpq);

return dpq;
}

dds::topic::qos::TopicQos
QosProviderDelegate::topic_qos(const std::string &id)
{
dds::topic::qos::TopicQos tq;
const dds_qos_t *c_tq = NULL;
dds_return_t ret;

ret = dds_qos_provider_get_qos(qosProvider, DDS_TOPIC_QOS, id.c_str(), &c_tq);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to obtain requested topic QoS.");

tq.delegate().ddsc_qos(c_tq);

return tq;
}


dds::sub::qos::SubscriberQos
QosProviderDelegate::subscriber_qos(const std::string &id)
{
dds::sub::qos::SubscriberQos sq;
const dds_qos_t *c_sq = NULL;
dds_return_t ret;

ret = dds_qos_provider_get_qos(qosProvider, DDS_SUBSCRIBER_QOS, id.c_str(), &c_sq);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to obtain requested subscriber QoS.");

sq.delegate().ddsc_qos(c_sq);

return sq;
}

dds::sub::qos::DataReaderQos
QosProviderDelegate::datareader_qos(const std::string &id)
{
dds::sub::qos::DataReaderQos drq;
const dds_qos_t *c_drq = NULL;
dds_return_t ret;

ret = dds_qos_provider_get_qos(qosProvider, DDS_READER_QOS, id.c_str(), &c_drq);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to obtain requested datareader QoS.");

drq.delegate().ddsc_qos(c_drq);

return drq;
}

dds::pub::qos::PublisherQos
QosProviderDelegate::publisher_qos(const std::string &id)
{
dds::pub::qos::PublisherQos pq;
const dds_qos_t *c_pq = NULL;
dds_return_t ret;

ret = dds_qos_provider_get_qos(qosProvider, DDS_PUBLISHER_QOS, id.c_str(), &c_pq);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to obtain requested publisher QoS.");

pq.delegate().ddsc_qos(c_pq);

return pq;
}

dds::pub::qos::DataWriterQos
QosProviderDelegate::datawriter_qos(const std::string &id)
{
dds::pub::qos::DataWriterQos dwq;
const dds_qos_t *c_dwq = NULL;
dds_return_t ret;

ret = dds_qos_provider_get_qos(qosProvider, DDS_WRITER_QOS, id.c_str(), &c_dwq);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Unable to obtain requested datawriter QoS.");

dwq.delegate().ddsc_qos(c_dwq);

return dwq;
}

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ void GroupDataDelegate::set_c_policy(dds_qos_t* qos) const
void* data = NULL;
org::eclipse::cyclonedds::core::convertByteSeq(value_, data, static_cast<int32_t>(value_.size()));
dds_qset_groupdata(qos, data, value_.size());
dds_free(data);
}
}

Expand Down Expand Up @@ -1465,6 +1466,7 @@ void TopicDataDelegate::set_c_policy(dds_qos_t* qos) const
void* data = NULL;
org::eclipse::cyclonedds::core::convertByteSeq(value_, data, static_cast<int32_t>(value_.size()));
dds_qset_topicdata(qos, data, value_.size());
dds_free(data);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ DomainParticipantQosDelegate::ddsc_qos() const
}

void
DomainParticipantQosDelegate::ddsc_qos(const dds_qos_t* qos)
DomainParticipantQosDelegate::ddsc_qos(const dds_qos_t* qos, bool copy_present)
{
assert(qos);
present_ = qos->present;
if (copy_present)
present_ = qos->present;
if (present_ & DDSI_QP_USER_DATA)
user_data_.delegate().set_iso_policy(qos);
if (present_ & DDSI_QP_ADLINK_ENTITY_FACTORY)
Expand Down Expand Up @@ -103,7 +104,7 @@ DomainParticipantQosDelegate::check() const
bool
DomainParticipantQosDelegate::operator ==(const DomainParticipantQosDelegate& other) const
{
return other.present_ == present_ &&
return other.present_ == present_ &&
other.user_data_ == user_data_ &&
other.entity_factory_ == entity_factory_;

Expand Down
Loading

0 comments on commit a8905fa

Please sign in to comment.