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

Implement QosProvider for C++ API. #480

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
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
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_ */
2 changes: 1 addition & 1 deletion src/ddscxx/include/dds/topic/detail/TTopicImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ dds::topic::detail::Topic<T>::discover_topic(
ret = dds_get_qos(ddsc_topic, ddsc_qos);
dds::topic::qos::TopicQos qos;
if (ret == DDS_RETCODE_OK) {
qos.delegate().ddsc_qos(ddsc_qos);
qos.delegate().ddsc_qos(ddsc_qos, false);
}
dds_delete_qos(ddsc_qos);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ret, "Failed to get the qos from discovered topic");
Expand Down
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_flags);

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_flags);

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_flags);

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_flags);

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_flags);

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_flags);

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, false);

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, false);

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, false);

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, false);

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, false);

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, false);

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 @@ -32,7 +32,7 @@ namespace qos

DomainParticipantQosDelegate::DomainParticipantQosDelegate()
{
ddsc_qos(&ddsi_default_qos_participant);
ddsc_qos(&ddsi_default_qos_participant, true);
check();
}

Expand Down Expand Up @@ -67,13 +67,14 @@ DomainParticipantQosDelegate::ddsc_qos() const
}

void
DomainParticipantQosDelegate::ddsc_qos(const dds_qos_t* qos)
DomainParticipantQosDelegate::ddsc_qos(const dds_qos_t* qos, bool copy_flags)
{
assert(qos);
present_ = qos->present;
if (present_ & DDSI_QP_USER_DATA)
if (copy_flags)
present_ = qos->present;
if (qos->present & DDSI_QP_USER_DATA)
user_data_.delegate().set_iso_policy(qos);
if (present_ & DDSI_QP_ADLINK_ENTITY_FACTORY)
if (qos->present & DDSI_QP_ADLINK_ENTITY_FACTORY)
entity_factory_.delegate().set_iso_policy(qos);
}

Expand Down Expand Up @@ -103,7 +104,7 @@ DomainParticipantQosDelegate::check() const
bool
DomainParticipantQosDelegate::operator ==(const DomainParticipantQosDelegate& other) const
{
return other.present_ == present_ &&
eboasson marked this conversation as resolved.
Show resolved Hide resolved
return other.present_ == present_ &&
other.user_data_ == user_data_ &&
other.entity_factory_ == entity_factory_;

Expand Down
Loading
Loading