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

stabilize liveliness API #314

Merged
merged 5 commits into from
Dec 11, 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
3 changes: 0 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ function(add_examples glob mode lib)
endif()

if(("${mode}" STREQUAL "zenohc") AND (NOT(ZENOHC_BUILD_WITH_UNSTABLE_API)))
if(${file} MATCHES ".*liveliness.*$")
continue()
endif()
if(${file} MATCHES ".*querier.*$")
continue()
endif()
Expand Down
2 changes: 2 additions & 0 deletions include/zenoh/api.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "api/hello.hxx"
#include "api/id.hxx"
#include "api/keyexpr.hxx"
#if defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1
#include "api/liveliness.hxx"
#endif
#include "api/logging.hxx"
#include "api/publisher.hxx"
#include "api/query.hxx"
Expand Down
6 changes: 1 addition & 5 deletions include/zenoh/api/liveliness.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@

#pragma once

#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1)
milyin marked this conversation as resolved.
Show resolved Hide resolved
#include "base.hxx"
#include "interop.hxx"

namespace zenoh {

class Session;

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief A liveliness token that can be used to provide the network with information about connectivity to its
/// declarer.
///
/// When constructed, a PUT sample will be received by liveliness subscribers on intersecting key expressions.
///
/// A DELETE on the token's key expression will be received by subscribers if the token is destroyed, or if connectivity
/// between the subscriber and the token's creator is lost.
/// @note Zenoh-c only.
class LivelinessToken : public Owned<::z_owned_liveliness_token_t> {
LivelinessToken(zenoh::detail::null_object_t) : Owned(nullptr){};
friend struct interop::detail::Converter;
Expand All @@ -44,5 +41,4 @@ class LivelinessToken : public Owned<::z_owned_liveliness_token_t> {
}
};

} // namespace zenoh
#endif
} // namespace zenoh
30 changes: 3 additions & 27 deletions include/zenoh/api/session.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,8 @@ class Session : public Owned<::z_owned_session_t> {
}
#endif

#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1)
milyin marked this conversation as resolved.
Show resolved Hide resolved
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
#if defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1
/// @brief Options to pass to ``Session::liveliness_declare_token``.
/// @note Zenoh-c only.
struct LivelinessDeclarationOptions {
protected:
uint8_t _dummy = 0;
Expand All @@ -876,8 +873,6 @@ class Session : public Owned<::z_owned_session_t> {
static LivelinessDeclarationOptions create_default() { return {}; }
};

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Declares a liveliness token on the network.
///
/// Liveliness token subscribers on an intersecting key expression will receive a PUT sample when connectivity
Expand All @@ -888,7 +883,6 @@ class Session : public Owned<::z_owned_session_t> {
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
/// @return a ``LivelinessToken``.
/// @note Zenoh-c only.
LivelinessToken liveliness_declare_token(
const KeyExpr& key_expr,
LivelinessDeclarationOptions&& options = LivelinessDeclarationOptions::create_default(),
Expand All @@ -903,19 +897,14 @@ class Session : public Owned<::z_owned_session_t> {
return t;
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Options to pass to ``Session::liveliness_declare_subscriber``.
/// @note Zenoh-c only.
struct LivelinessSubscriberOptions {
public:
bool history = false;

static LivelinessSubscriberOptions create_default() { return {}; }
};

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Declares a subscriber on liveliness tokens that intersect `key_expr`.
/// @param key_expr the key expression to subscribe to.
/// @param on_sample the callable that will be called each time a liveliness token status is changed.
Expand All @@ -924,7 +913,6 @@ class Session : public Owned<::z_owned_session_t> {
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
/// @return a ``Subscriber`` object.
/// @note Zenoh-c only.
template <class C, class D>
[[nodiscard]] Subscriber<void> liveliness_declare_subscriber(
const KeyExpr& key_expr, C&& on_sample, D&& on_drop,
Expand Down Expand Up @@ -989,9 +977,7 @@ class Session : public Owned<::z_owned_session_t> {
}
#endif

#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1)
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
#if defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1
/// @brief Declare a subscriber on liveliness tokens that intersect `key_expr`.
/// @tparam Channel the type of channel used to create stream of data (see ``zenoh::channels::FifoChannel`` or
/// ``zenoh::channels::RingChannel``).
Expand All @@ -1001,7 +987,6 @@ class Session : public Owned<::z_owned_session_t> {
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
/// @return a ``Subscriber`` object.
/// @note Zenoh-c only.
template <class Channel>
[[nodiscard]] Subscriber<typename Channel::template HandlerType<Sample>> liveliness_declare_subscriber(
const KeyExpr& key_expr, Channel channel,
Expand All @@ -1021,10 +1006,7 @@ class Session : public Owned<::z_owned_session_t> {
std::move(cb_handler_pair.second));
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Options to pass to ``Session::liveliness_get``.
/// @note Zenoh-c only.
struct LivelinessGetOptions {
/// @name Fields

Expand All @@ -1037,8 +1019,6 @@ class Session : public Owned<::z_owned_session_t> {
static LivelinessGetOptions create_default() { return {}; }
};

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Query liveliness tokens currently on the network with a key expression intersecting with `key_expr`.
///
/// @param key_expr: the key expression to query liveliness tokens for.
Expand All @@ -1047,7 +1027,6 @@ class Session : public Owned<::z_owned_session_t> {
/// @param options: additional options for the liveliness get operation.
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
/// @note Zenoh-c only.
template <class C, class D>
void liveliness_get(const KeyExpr& key_expr, C&& on_reply, D&& on_drop,
LivelinessGetOptions&& options = LivelinessGetOptions::create_default(),
Expand All @@ -1071,8 +1050,6 @@ class Session : public Owned<::z_owned_session_t> {
err, "Failed to perform liveliness_get operation");
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
/// release.
/// @brief Query liveliness tokens currently on the network with a key expression intersecting with `key_expr`.
/// @tparam Channel the type of channel used to create stream of data (see ``zenoh::channels::FifoChannel`` or
/// ``zenoh::channels::RingChannel``).
Expand All @@ -1082,7 +1059,6 @@ class Session : public Owned<::z_owned_session_t> {
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
/// @return reply handler.
/// @note Zenoh-c only.
template <class Channel>
typename Channel::template HandlerType<Reply> liveliness_get(
const KeyExpr& key_expr, Channel channel,
Expand All @@ -1099,7 +1075,6 @@ class Session : public Owned<::z_owned_session_t> {
return std::move(cb_handler_pair.second);
}

#endif
/// @brief Create Timestamp from session id.
/// @param err if not null, the result code will be written to this location, otherwise ZException exception will be
/// thrown in case of error.
Expand All @@ -1120,6 +1095,7 @@ class Session : public Owned<::z_owned_session_t> {
(void)options;
__ZENOH_RESULT_CHECK(::z_close(interop::as_loaned_c_ptr(*this), nullptr), err, "Failed to close the session");
}
#endif

#if defined(ZENOHCXX_ZENOHC) && defined(Z_FEATURE_UNSTABLE_API)
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_from_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ absolute_install_location=$(cd $1; pwd)
bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-c $absolute_install_location -DZENOHC_BUILD_WITH_UNSTABLE_API=$USE_UNSTABLE -DZENOHC_BUILD_WITH_SHARED_MEMORY=$USE_SHARED_MEMORY
if [ "$BUILD_PICO" == "ON" ]; then
#build zenoh-pico
bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-pico $absolute_install_location -DZ_FEATURE_UNSTABLE_API=$USE_UNSTABLE_PICO -DZ_FEATURE_LIVELINESS=$USE_UNSTABLE_PICO
bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-pico $absolute_install_location -DZ_FEATURE_UNSTABLE_API=$USE_UNSTABLE_PICO
fi

rm -rf ./build
Expand Down
5 changes: 0 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ endforeach()
if(ZENOHCXX_ZENOHC)
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/zenohc/*.cxx")
foreach(file ${files})
if(NOT(ZENOHC_BUILD_WITH_UNSTABLE_API))
if(${file} MATCHES ".*liveliness.*$")
continue()
endif()
endif()
add_test_instance(${file} zenohc zenohcxx::zenohc "")
endforeach()
endif()
Expand Down
6 changes: 0 additions & 6 deletions tests/universal/network/liveliness.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ using namespace std::chrono_literals;
#undef NDEBUG
#include <assert.h>

#if defined(Z_FEATURE_UNSTABLE_API) && (defined(ZENOHCXX_ZENOHC) || Z_FEATURE_LIVELINESS == 1)

void test_liveliness_get() {
KeyExpr ke("zenoh/liveliness/test/*");
KeyExpr token_ke("zenoh/liveliness/test/1");
Expand Down Expand Up @@ -92,11 +90,7 @@ void test_liveliness_subscriber() {
assert(delete_tokens.count("zenoh/liveliness/test/2") == 1);
}

#endif

int main(int argc, char** argv) {
#if defined Z_FEATURE_UNSTABLE_API
test_liveliness_get();
test_liveliness_subscriber();
#endif
};
2 changes: 1 addition & 1 deletion zenoh-pico
Submodule zenoh-pico updated 183 files
Loading