Interoperability with zenoh-c / zenoh-pico

This is the list of the functions that can be use for interoperability between zenoh-c/zenoh-pico and zenoh-cpp. These functions essentially perform conversion of c-structs into c++ classes and back. They should be used with care, and it is up to the user to ensure that all necessary invariants uphold.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(zenoh::ext::AdvancedSubscriber<Handler> &s)

Return a pair of pointers to owned zenoh-c representations of advanced subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(const zenoh::ext::AdvancedSubscriber<Handler> &s)

Return a pair of pointers to owned zenoh-c representations of advanced subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(zenoh::ext::AdvancedSubscriber<Handler> &s)

Return a pair of pointers to loaned zenoh-c representations of advanced subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(const zenoh::ext::AdvancedSubscriber<Handler> &s)

Return a pair of pointers to loaned zenoh-c representations of advanced subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(zenoh::ext::AdvancedSubscriber<Handler> &s)

Return a pair of pointers to moved zenoh-c representations of advanced subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(std::optional<zenoh::ext::AdvancedSubscriber<Handler>> &s) -> decltype(as_moved_c_ptr(s.value()))

Return a pair of pointers to moved zenoh-c representations of advanced subscriber and its callback. Will return a pair of null pointers if option is empty.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::move_to_c_obj(zenoh::ext::AdvancedSubscriber<Handler> &&s)

Move advanced subscriber and its handler to a pair containing corresponding zenoh-c structs.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(zenoh::ext::SampleMissListener<Handler> &m)

Return a pair of pointers to owned zenoh-c representations of sample miss listener and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(const zenoh::ext::SampleMissListener<Handler> &m)

Return a pair of pointers to owned zenoh-c representations of sample miss listener and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(zenoh::ext::SampleMissListener<Handler> &m)

Return a pair of pointers to moved zenoh-c representations of sample miss listener and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(std::optional<zenoh::ext::SampleMissListener<Handler>> &m) -> decltype(as_moved_c_ptr(m.value()))

Return a pair of pointers to moved zenoh-c representations of sample miss listener and its callback. Will return a pair of null pointers if option is empty.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::move_to_c_obj(zenoh::ext::SampleMissListener<Handler> &&m)

Move sample miss listener and its handler to a pair containing corresponding zenoh-c structs.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(zenoh::ext::QueryingSubscriber<Handler> &s)

Return a pair of pointers to owned zenoh-c representations of querying subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(const zenoh::ext::QueryingSubscriber<Handler> &s)

Return a pair of pointers to owned zenoh-c representations of querying subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(zenoh::ext::QueryingSubscriber<Handler> &s)

Return a pair of pointers to loaned zenoh-c representations of querying subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(const zenoh::ext::QueryingSubscriber<Handler> &s)

Return a pair of pointers to loaned zenoh-c representations of querying subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(zenoh::ext::QueryingSubscriber<Handler> &s)

Return a pair of pointers to moved zenoh-c representations of querying subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(std::optional<zenoh::ext::QueryingSubscriber<Handler>> &s) -> decltype(as_moved_c_ptr(s.value()))

Return a pair of pointers to moved zenoh-c representations of querying subscriber and its callback. Will return a pair of null pointers if option is empty.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::move_to_c_obj(zenoh::ext::QueryingSubscriber<Handler> &&s)

Move querying subscriber and its handler to a pair containing corresponding zenoh-c structs.

template<class CopyableType>
CopyableType *zenoh::interop::as_copyable_c_ptr(Copyable<CopyableType> &cpp_obj)

Get zenoh-c representation of trivially copyable zenoh-cpp object.

template<class CopyableType>
const CopyableType *zenoh::interop::as_copyable_c_ptr(const Copyable<CopyableType> &cpp_obj)

Get zenoh-c representation of trivially copyable zenoh-cpp object.

template<class CopyableCppObj>
auto *zenoh::interop::as_copyable_c_ptr(std::optional<CopyableCppObj> &cpp_obj)

Get zenoh-c representation of std::optional of trivially copyable zenoh-cpp object.

Returns:

pointer to zenoh-c representation of trivially copyable zenoh-cpp object, or NULL if cpp_obj is empty.

template<class CopyableCppObj>
const auto *zenoh::interop::as_copyable_c_ptr(const std::optional<CopyableCppObj> &cpp_obj)

Get zenoh-c representation of std::optional of trivially copyable zenoh-cpp object.

Returns:

pointer to zenoh-c representation of trivially copyable zenoh-cpp object, or NULL if cpp_obj is empty.

template<class OwnedType>
OwnedType *zenoh::interop::as_owned_c_ptr(Owned<OwnedType> &cpp_obj)

Get owned zenoh-c representation of owned zenoh-cpp object.

template<class OwnedType>
const OwnedType *zenoh::interop::as_owned_c_ptr(const Owned<OwnedType> &cpp_obj)

Get owned zenoh-c representation of owned zenoh-cpp object.

template<class OwnedType, class Loaned = typename ::z_owned_to_loaned_type_t<OwnedType>::type, class LoanAvailable = std::enable_if_t<zenoh::detail::is_loan_available_v<OwnedType>, Loaned>>
const Loaned *zenoh::interop::as_loaned_c_ptr(const Owned<OwnedType> &cpp_obj)

Get loaned zenoh-c representation of owned zenoh-cpp object.

template<class OwnedCppObj>
const auto *zenoh::interop::as_loaned_c_ptr(const std::optional<OwnedCppObj> &cpp_obj)

Get loaned zenoh-c representation of owned zenoh-cpp object.

Returns:

pointer to zenoh-c representation of loaned zenoh-cpp object, or NULL if cpp_obj is empty.

template<class OwnedType, class Loaned = typename ::z_owned_to_loaned_type_t<OwnedType>::type, class LoanAvailable = std::enable_if_t<zenoh::detail::is_loan_mut_available_v<OwnedType>, Loaned>>
Loaned *zenoh::interop::as_loaned_c_ptr(Owned<OwnedType> &cpp_obj)

Get loaned zenoh-c representation of owned zenoh-cpp object.

template<class OwnedCppObj>
auto *zenoh::interop::as_loaned_c_ptr(std::optional<OwnedCppObj> &cpp_obj)

Get loaned zenoh-c representation of owned zenoh-cpp object.

Returns:

pointer to zenoh-c representation of loaned zenoh-cpp object, or NULL if cpp_obj is empty.

template<class OwnedType>
auto *zenoh::interop::as_moved_c_ptr(Owned<OwnedType> &cpp_obj)

Get moved zenoh-c representation of owned zenoh-cpp object.

template<class OwnedCppObj>
auto *zenoh::interop::as_moved_c_ptr(std::optional<OwnedCppObj> &cpp_obj)

Get moved zenoh-c representation of std::optional of owned zenoh-cpp object.

Returns:

pointer to zenoh-c representation of moved owned zenoh-cpp object, or NULL if cpp_obj is empty.

template<class T, class LoanedType, class OwnedType = typename ::z_loaned_to_owned_type_t<LoanedType>::type>
const auto &zenoh::interop::as_owned_cpp_ref(const LoanedType *loaned_c_obj)

Get zenoh-cpp representation of owned zenoh-c struct, from its loaned ptr.

template<class T, class LoanedType, class OwnedType = typename ::z_loaned_to_owned_type_t<LoanedType>::type>
auto &zenoh::interop::as_owned_cpp_ref(LoanedType *loaned_c_obj)

Get zenoh-cpp representation of owned zenoh-c struct, from its loaned ptr.

template<class T, class OwnedType>
std::enable_if_t<std::is_base_of_v<zenoh::Owned<OwnedType>, T>, T&> zenoh::interop::as_owned_cpp_ref(OwnedType *owned_c_obj)

Get zenoh-cpp representation of owned zenoh-c struct.

template<class T, class CopyableType>
const auto &zenoh::interop::as_copyable_cpp_ref(const CopyableType *copyable_c_obj)

Get zenoh-cpp representation of copyable zenoh-c struct.

template<class T, class CopyableType>
auto &zenoh::interop::as_copyable_cpp_ref(CopyableType *copyable_c_obj)

Get zenoh-cpp representation of copyable zenoh-c struct.

template<class OwnedType>
OwnedType zenoh::interop::move_to_c_obj(Owned<OwnedType> &&owned_cpp_obj)

Move owned Zenoh zenoh-cpp object object into zenoh-c struct.

template<class T, class CopyableType>
T zenoh::interop::into_copyable_cpp_obj(const CopyableType &copyable_c_obj)

Copy copyable zenoh-c struct into corresponding zenoh-cpp object.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(MatchingListener<Handler> &m)

Return a pair of pointers to owned zenoh-c representations of matching listener and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(const MatchingListener<Handler> &m)

Return a pair of pointers to owned zenoh-c representations of matching listener and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(MatchingListener<Handler> &m)

Return a pair of pointers to moved zenoh-c representations of matching listener and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(std::optional<MatchingListener<Handler>> &m) -> decltype(as_moved_c_ptr(m.value()))

Return a pair of pointers to moved zenoh-c representations of matching listener and its callback. Will return a pair of null pointers if option is empty.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::move_to_c_obj(MatchingListener<Handler> &&m)

Move matching listener and its handler to a pair containing corresponding zenoh-c structs.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(Queryable<Handler> &q)

Return a pair of pointers to owned zenoh-c representations of queryable and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(const Queryable<Handler> &q)

Return a pair of pointers to owned zenoh-c representations of queryable and its handler.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(Queryable<Handler> &q)

Return a pair of pointers to loaned zenoh-c representations of queryable and its handler.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(const Queryable<Handler> &q)

Return a pair of pointers to loaned zenoh-c representation of queryable and its handler.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(Queryable<Handler> &q)

Return a pair of pointers to moved zenoh-c representation of queryable and its handler.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(std::optional<Queryable<Handler>> &q) -> decltype(as_moved_c_ptr(q.value()))

Return a pair of pointers to moved zenoh-c representation of queryable and its handler. Will return a pair of null pointers if optional is empty.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::move_to_c_obj(Queryable<Handler> &&q)

Move queryable and its handler to a pair containing corresponding zenoh-c structs.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(Subscriber<Handler> &s)

Return a pair of pointers to owned zenoh-c representations of subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_owned_c_ptr(const Subscriber<Handler> &s)

Return a pair of pointers to owned zenoh-c representations of subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(Subscriber<Handler> &s)

Return a pair of pointers to loaned zenoh-c representations of subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_loaned_c_ptr(const Subscriber<Handler> &s)

Return a pair of pointers to loaned zenoh-c representations of subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(Subscriber<Handler> &s)

Return a pair of pointers to moved zenoh-c representations of subscriber and its callback.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::as_moved_c_ptr(std::optional<Subscriber<Handler>> &s) -> decltype(as_moved_c_ptr(s.value()))

Return a pair of pointers to moved zenoh-c representations of subscriber and its callback. Will return a pair of null pointers if option is empty.

template<class Handler, typename = std::enable_if_t<!std::is_same_v<Handler, void>>>
auto zenoh::interop::move_to_c_obj(Subscriber<Handler> &&s)

Move subscriber and its handler to a pair containing corresponding zenoh-c structs.