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

Add Zenoh-Pico matching support and rename Zenoh-C methods #389

Merged
merged 3 commits into from
Jan 29, 2025
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
4 changes: 2 additions & 2 deletions examples/universal/z_pub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int _main(int argc, char **argv) {
.named_value({"k", "key"}, "KEY_EXPRESSION", "Key expression to publish to (string)", default_keyexpr)
.named_value({"p", "payload"}, "PAYLOAD", "Payload to publish (string)", default_value)
.named_value({"a", "attach"}, "ATTACHMENT", "Attachment to add to each put (string)", "")
#if defined(Z_FEATURE_UNSTABLE_API) && defined(ZENOHCXX_ZENOHC)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
.named_flag({"add-matching-listener"}, "Add matching listener")
#endif
.run();
Expand All @@ -56,7 +56,7 @@ int _main(int argc, char **argv) {

std::cout << "Declaring Publisher on '" << keyexpr << "'..." << std::endl;
auto pub = session.declare_publisher(KeyExpr(keyexpr));
#if defined(Z_FEATURE_UNSTABLE_API) && defined(ZENOHCXX_ZENOHC)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
if (args.flag("add-matching-listener")) {
pub.declare_background_matching_listener(
[](const MatchingStatus &s) {
Expand Down
4 changes: 2 additions & 2 deletions examples/universal/z_querier.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int _main(int argc, char **argv) {
.named_value({"t", "target"}, "TARGET", "Query target (BEST_MATCHING | ALL | ALL_COMPLETE)",
"BEST_MATCHING")
.named_value({"o", "timeout"}, "TIMEOUT", "Timeout in ms (number)", "10000")
#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
.named_flag({"add-matching-listener"}, "Add matching listener")
#endif
.run();
Expand All @@ -53,7 +53,7 @@ int _main(int argc, char **argv) {
options.timeout_ms = timeout_ms;
auto querier = session.declare_querier(selector.key_expr, std::move(options));

#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
if (args.flag("add-matching-listener")) {
querier.declare_background_matching_listener(
[](const MatchingStatus &s) {
Expand Down
8 changes: 4 additions & 4 deletions include/zenoh/api/ext/advanced_publisher.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class AdvancedPublisher : public Owned<::ze_owned_advanced_publisher_t> {
"zenoh::MatchingStatus& status)");
static_assert(std::is_invocable_r<void, D>::value,
"on_drop should be callable with the following signature: void on_drop()");
::zc_owned_closure_matching_status_t c_closure;
::z_owned_closure_matching_status_t c_closure;
using Cval = std::remove_reference_t<C>;
using Dval = std::remove_reference_t<D>;
using ClosureType = typename zenoh::detail::closures::Closure<Cval, Dval, void, const zenoh::MatchingStatus&>;
Expand Down Expand Up @@ -190,7 +190,7 @@ class AdvancedPublisher : public Owned<::ze_owned_advanced_publisher_t> {
Channel channel, zenoh::ZResult* err = nullptr) const {
auto cb_handler_pair = channel.template into_cb_handler_pair<Query>();
auto m = zenoh::interop::detail::null<MatchingListener<void>>();
zenoh::ZResult res = ::zc_publisher_declare_matching_listener(
zenoh::ZResult res = ::z_publisher_declare_matching_listener(
interop::as_loaned_c_ptr(*this), interop::as_owned_c_ptr(m), ::z_move(cb_handler_pair.first));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Matching Listener");
if (res != Z_OK) ::z_drop(zenoh::interop::as_moved_c_ptr(cb_handler_pair.second));
Expand All @@ -216,7 +216,7 @@ class AdvancedPublisher : public Owned<::ze_owned_advanced_publisher_t> {
"zenoh::MatchingStatus& status)");
static_assert(std::is_invocable_r<void, D>::value,
"on_drop should be callable with the following signature: void on_drop()");
::zc_owned_closure_matching_status_t c_closure;
::z_owned_closure_matching_status_t c_closure;
using Cval = std::remove_reference_t<C>;
using Dval = std::remove_reference_t<D>;
using ClosureType = typename zenoh::detail::closures::Closure<Cval, Dval, void, const zenoh::MatchingStatus&>;
Expand All @@ -235,7 +235,7 @@ class AdvancedPublisher : public Owned<::ze_owned_advanced_publisher_t> {
/// thrown in case of error.
/// @note Zenoh-c only.
MatchingStatus get_matching_status(zenoh::ZResult* err = nullptr) const {
::zc_matching_status_t m;
::z_matching_status_t m;
zenoh::ZResult res = ::ze_advanced_publisher_get_matching_status(zenoh::interop::as_loaned_c_ptr(*this), &m);
__ZENOH_RESULT_CHECK(res, err, "Failed to get matching status");
return {m.matching};
Expand Down
12 changes: 6 additions & 6 deletions include/zenoh/api/matching.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ struct MatchingStatus {

namespace detail::closures {
extern "C" {
inline void _zenoh_on_status_change_call(const ::zc_matching_status_t* status, void* context) {
inline void _zenoh_on_status_change_call(const ::z_matching_status_t* status, void* context) {
IClosure<void, const MatchingStatus&>::call_from_context(context, MatchingStatus{status->matching});
}
}
} // namespace detail::closures

namespace detail {
class MatchingListenerBase : public Owned<::zc_owned_matching_listener_t> {
class MatchingListenerBase : public Owned<::z_owned_matching_listener_t> {
protected:
MatchingListenerBase(zenoh::detail::null_object_t) : Owned(nullptr){};
MatchingListenerBase(::zc_owned_matching_listener_t* m) : Owned(m){};
MatchingListenerBase(::z_owned_matching_listener_t* m) : Owned(m){};
friend struct interop::detail::Converter;
};
} // namespace detail
Expand All @@ -68,7 +68,7 @@ class MatchingListener<void> : public detail::MatchingListenerBase {
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
void undeclare(ZResult* err = nullptr) && {
__ZENOH_RESULT_CHECK(::zc_undeclare_matching_listener(interop::as_moved_c_ptr(*this)), err,
__ZENOH_RESULT_CHECK(::z_undeclare_matching_listener(interop::as_moved_c_ptr(*this)), err,
"Failed to undeclare matching listener");
}
};
Expand Down Expand Up @@ -103,7 +103,7 @@ class MatchingListener : public detail::MatchingListenerBase {
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
Handler undeclare(ZResult* err = nullptr) && {
__ZENOH_RESULT_CHECK(::zc_undeclare_matching_listener(interop::as_moved_c_ptr(*this)), err,
__ZENOH_RESULT_CHECK(::z_undeclare_matching_listener(interop::as_moved_c_ptr(*this)), err,
"Failed to undeclare matching listener");
return std::move(this->_handler);
}
Expand Down Expand Up @@ -154,4 +154,4 @@ auto move_to_c_obj(MatchingListener<Handler>&& m) {
}
} // namespace interop

} // namespace zenoh
} // namespace zenoh
24 changes: 13 additions & 11 deletions include/zenoh/api/publisher.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include "interop.hxx"
#include "keyexpr.hxx"
#include "timestamp.hxx"
#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
#include "matching.hxx"
#endif
#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#include "source_info.hxx"
#endif
#include <optional>
Expand Down Expand Up @@ -145,7 +147,7 @@ class Publisher : public Owned<::z_owned_publisher_t> {
}
#endif

#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Construct matching listener, registering a callback for notifying subscribers matching with a given
Expand All @@ -166,16 +168,16 @@ class Publisher : public Owned<::z_owned_publisher_t> {
"zenoh::MatchingStatus& status)");
static_assert(std::is_invocable_r<void, D>::value,
"on_drop should be callable with the following signature: void on_drop()");
::zc_owned_closure_matching_status_t c_closure;
::z_owned_closure_matching_status_t c_closure;
using Cval = std::remove_reference_t<C>;
using Dval = std::remove_reference_t<D>;
using ClosureType = typename detail::closures::Closure<Cval, Dval, void, const MatchingStatus&>;
auto closure = ClosureType::into_context(std::forward<C>(on_status_change), std::forward<D>(on_drop));
::z_closure(&c_closure, detail::closures::_zenoh_on_status_change_call, detail::closures::_zenoh_on_drop,
closure);
MatchingListener<void> m(zenoh::detail::null_object);
ZResult res = ::zc_publisher_declare_matching_listener(interop::as_loaned_c_ptr(*this),
interop::as_owned_c_ptr(m), ::z_move(c_closure));
ZResult res = ::z_publisher_declare_matching_listener(interop::as_loaned_c_ptr(*this),
interop::as_owned_c_ptr(m), ::z_move(c_closure));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Matching Listener");
return m;
}
Expand All @@ -196,7 +198,7 @@ class Publisher : public Owned<::z_owned_publisher_t> {
Channel channel, ZResult* err = nullptr) const {
auto cb_handler_pair = channel.template into_cb_handler_pair<Query>();
MatchingListener<void> m(zenoh::detail::null_object);
ZResult res = ::zc_publisher_declare_matching_listener(
ZResult res = ::z_publisher_declare_matching_listener(
interop::as_loaned_c_ptr(*this), interop::as_owned_c_ptr(m), ::z_move(cb_handler_pair.first));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Matching Listener");
if (res != Z_OK) ::z_drop(interop::as_moved_c_ptr(cb_handler_pair.second));
Expand All @@ -222,15 +224,15 @@ class Publisher : public Owned<::z_owned_publisher_t> {
"zenoh::MatchingStatus& status)");
static_assert(std::is_invocable_r<void, D>::value,
"on_drop should be callable with the following signature: void on_drop()");
::zc_owned_closure_matching_status_t c_closure;
::z_owned_closure_matching_status_t c_closure;
using Cval = std::remove_reference_t<C>;
using Dval = std::remove_reference_t<D>;
using ClosureType = typename detail::closures::Closure<Cval, Dval, void, const MatchingStatus&>;
auto closure = ClosureType::into_context(std::forward<C>(on_status_change), std::forward<D>(on_drop));
::z_closure(&c_closure, detail::closures::_zenoh_on_status_change_call, detail::closures::_zenoh_on_drop,
closure);
ZResult res =
::zc_publisher_declare_background_matching_listener(interop::as_loaned_c_ptr(*this), ::z_move(c_closure));
::z_publisher_declare_background_matching_listener(interop::as_loaned_c_ptr(*this), ::z_move(c_closure));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare background Matching Listener");
}

Expand All @@ -241,13 +243,13 @@ class Publisher : public Owned<::z_owned_publisher_t> {
/// thrown in case of error.
/// @note Zenoh-c only.
MatchingStatus get_matching_status(ZResult* err = nullptr) const {
::zc_matching_status_t m;
ZResult res = ::zc_publisher_get_matching_status(interop::as_loaned_c_ptr(*this), &m);
::z_matching_status_t m;
ZResult res = ::z_publisher_get_matching_status(interop::as_loaned_c_ptr(*this), &m);
__ZENOH_RESULT_CHECK(res, err, "Failed to get matching status");
return {m.matching};
}
#endif
};

} // namespace zenoh
#endif
#endif
24 changes: 14 additions & 10 deletions include/zenoh/api/querier.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include "interop.hxx"
#include "keyexpr.hxx"
#include "reply.hxx"
#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
#include "matching.hxx"
#endif
#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
#include "source_info.hxx"
#endif
#include <optional>
Expand Down Expand Up @@ -148,7 +150,9 @@ class Querier : public Owned<::z_owned_querier_t> {
EntityGlobalId get_id() const {
return interop::into_copyable_cpp_obj<EntityGlobalId>(::z_querier_id(interop::as_loaned_c_ptr(*this)));
}
#endif

#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_MATCHING == 1)
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Construct matching listener, registering a callback for notifying queryables matching with a given
Expand All @@ -169,16 +173,16 @@ class Querier : public Owned<::z_owned_querier_t> {
"zenoh::MatchingStatus& status)");
static_assert(std::is_invocable_r<void, D>::value,
"on_drop should be callable with the following signature: void on_drop()");
::zc_owned_closure_matching_status_t c_closure;
::z_owned_closure_matching_status_t c_closure;
using Cval = std::remove_reference_t<C>;
using Dval = std::remove_reference_t<D>;
using ClosureType = typename detail::closures::Closure<Cval, Dval, void, const MatchingStatus&>;
auto closure = ClosureType::into_context(std::forward<C>(on_status_change), std::forward<D>(on_drop));
::z_closure(&c_closure, detail::closures::_zenoh_on_status_change_call, detail::closures::_zenoh_on_drop,
closure);
MatchingListener<void> m(zenoh::detail::null_object);
ZResult res = ::zc_querier_declare_matching_listener(interop::as_loaned_c_ptr(*this),
interop::as_owned_c_ptr(m), ::z_move(c_closure));
ZResult res = ::z_querier_declare_matching_listener(interop::as_loaned_c_ptr(*this), interop::as_owned_c_ptr(m),
::z_move(c_closure));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Matching Listener");
return m;
}
Expand All @@ -199,8 +203,8 @@ class Querier : public Owned<::z_owned_querier_t> {
Channel channel, ZResult* err = nullptr) const {
auto cb_handler_pair = channel.template into_cb_handler_pair<Query>();
MatchingListener<void> m(zenoh::detail::null_object);
ZResult res = ::zc_querier_declare_matching_listener(
interop::as_loaned_c_ptr(*this), interop::as_owned_c_ptr(m), ::z_move(cb_handler_pair.first));
ZResult res = ::z_querier_declare_matching_listener(interop::as_loaned_c_ptr(*this), interop::as_owned_c_ptr(m),
::z_move(cb_handler_pair.first));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare Matching Listener");
if (res != Z_OK) ::z_drop(interop::as_moved_c_ptr(cb_handler_pair.second));
return MatchingListener<typename Channel::template HandlerType<MatchingStatus>>(
Expand All @@ -225,15 +229,15 @@ class Querier : public Owned<::z_owned_querier_t> {
"zenoh::MatchingStatus& status)");
static_assert(std::is_invocable_r<void, D>::value,
"on_drop should be callable with the following signature: void on_drop()");
::zc_owned_closure_matching_status_t c_closure;
::z_owned_closure_matching_status_t c_closure;
using Cval = std::remove_reference_t<C>;
using Dval = std::remove_reference_t<D>;
using ClosureType = typename detail::closures::Closure<Cval, Dval, void, const MatchingStatus&>;
auto closure = ClosureType::into_context(std::forward<C>(on_status_change), std::forward<D>(on_drop));
::z_closure(&c_closure, detail::closures::_zenoh_on_status_change_call, detail::closures::_zenoh_on_drop,
closure);
ZResult res =
::zc_querier_declare_background_matching_listener(interop::as_loaned_c_ptr(*this), ::z_move(c_closure));
::z_querier_declare_background_matching_listener(interop::as_loaned_c_ptr(*this), ::z_move(c_closure));
__ZENOH_RESULT_CHECK(res, err, "Failed to declare background Matching Listener");
}

Expand All @@ -244,8 +248,8 @@ class Querier : public Owned<::z_owned_querier_t> {
/// thrown in case of error.
/// @note Zenoh-c only.
MatchingStatus get_matching_status(ZResult* err = nullptr) const {
::zc_matching_status_t m;
ZResult res = ::zc_querier_get_matching_status(interop::as_loaned_c_ptr(*this), &m);
::z_matching_status_t m;
ZResult res = ::z_querier_get_matching_status(interop::as_loaned_c_ptr(*this), &m);
__ZENOH_RESULT_CHECK(res, err, "Failed to get matching status");
return {m.matching};
}
Expand Down
Loading