From 345e02aa338492f61f67e7bc3bef10ccee6c7332 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Wed, 13 Nov 2024 10:38:58 +0100 Subject: [PATCH] Fix review notes --- docs/api.rst | 4 ++-- include/zenoh-pico/api/liveliness.h | 11 +++++------ src/api/liveliness.c | 18 ++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index a6c4a2dd2..28d981f89 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1275,7 +1275,7 @@ Liveliness ======================== Types ----- -.. autoctype:: liveliness.h::z_liveliness_declaration_options_t +.. autoctype:: liveliness.h::z_liveliness_token_options_t_t .. autoctype:: liveliness.h::z_liveliness_subscriber_options_t .. autoctype:: liveliness.h::z_liveliness_get_options_t @@ -1289,7 +1289,7 @@ See details at :ref:`owned_types_concept` Functions --------- -.. autocfunction:: liveliness.h::z_liveliness_declaration_options_default +.. autocfunction:: liveliness.h::z_liveliness_token_options_t_default .. autocfunction:: liveliness.h::z_liveliness_declare_token .. autocfunction:: liveliness.h::z_liveliness_undeclare_token .. autocfunction:: liveliness.h::z_liveliness_subscriber_options_default diff --git a/include/zenoh-pico/api/liveliness.h b/include/zenoh-pico/api/liveliness.h index 18301458c..4fa62bb46 100644 --- a/include/zenoh-pico/api/liveliness.h +++ b/include/zenoh-pico/api/liveliness.h @@ -41,14 +41,14 @@ _Z_OWNED_FUNCTIONS_DEF(liveliness_token) /** * The options for :c:func:`z_liveliness_declare_token()`. */ -typedef struct z_liveliness_declaration_options_t { +typedef struct z_liveliness_token_options_t_t { uint8_t __dummy; -} z_liveliness_declaration_options_t; +} z_liveliness_token_options_t_t; /** - * Constructs default value for :c:type:`z_liveliness_declaration_options_t`. + * Constructs default value for :c:type:`z_liveliness_token_options_t_t`. */ -z_result_t z_liveliness_declaration_options_default(z_liveliness_declaration_options_t *options); +z_result_t z_liveliness_token_options_t_default(z_liveliness_token_options_t_t *options); /** * Constructs and declares a liveliness token on the network. @@ -66,8 +66,7 @@ z_result_t z_liveliness_declaration_options_default(z_liveliness_declaration_opt * ``0`` if put operation is successful, ``negative value`` otherwise. */ z_result_t z_liveliness_declare_token(const z_loaned_session_t *zs, z_owned_liveliness_token_t *token, - const z_loaned_keyexpr_t *keyexpr, - const z_liveliness_declaration_options_t *options); + const z_loaned_keyexpr_t *keyexpr, const z_liveliness_token_options_t_t *options); /** * Undeclare a liveliness token, notifying subscribers of its destruction. diff --git a/src/api/liveliness.c b/src/api/liveliness.c index 55a4cd035..3dcbac5f1 100644 --- a/src/api/liveliness.c +++ b/src/api/liveliness.c @@ -48,14 +48,14 @@ void _z_liveliness_token_clear(_z_liveliness_token_t *token) { _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_liveliness_token_t, liveliness_token, _z_liveliness_token_check, _z_liveliness_token_null, _z_liveliness_token_clear) -z_result_t z_liveliness_declaration_options_default(z_liveliness_declaration_options_t *options) { +z_result_t z_liveliness_token_options_t_default(z_liveliness_token_options_t_t *options) { options->__dummy = 0; return _Z_RES_OK; } z_result_t z_liveliness_declare_token(const z_loaned_session_t *zs, z_owned_liveliness_token_t *token, const z_loaned_keyexpr_t *keyexpr, - const z_liveliness_declaration_options_t *options) { + const z_liveliness_token_options_t_t *options) { (void)options; _z_keyexpr_t key = _z_update_keyexpr_to_declared(_Z_RC_IN_VAL(zs), *keyexpr); @@ -96,6 +96,10 @@ z_result_t z_liveliness_declare_subscriber(const z_loaned_session_t *zs, z_owned z_internal_closure_sample_null(&callback->_this); sub->_val = int_sub; + if (!_z_subscriber_check(&sub->_val)) { + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + if (opt.history) { z_result_t ret = _z_liveliness_subscription_trigger_history(_Z_RC_IN_VAL(zs), *keyexpr); if (ret != _Z_RES_OK) { @@ -103,11 +107,7 @@ z_result_t z_liveliness_declare_subscriber(const z_loaned_session_t *zs, z_owned } } - if (!_z_subscriber_check(&sub->_val)) { - return _Z_ERR_SYSTEM_OUT_OF_MEMORY; - } else { - return _Z_RES_OK; - } + return _Z_RES_OK; } #endif // Z_FEATURE_SUBSCRIPTION == 1 @@ -126,8 +126,6 @@ z_result_t z_liveliness_get(const z_loaned_session_t *zs, const z_loaned_keyexpr void *ctx = callback->_this._val.context; callback->_this._val.context = NULL; - _z_keyexpr_t key = _z_update_keyexpr_to_declared(_Z_RC_IN_VAL(zs), *keyexpr); - z_liveliness_get_options_t opt; if (options == NULL) { z_liveliness_get_options_default(&opt); @@ -135,7 +133,7 @@ z_result_t z_liveliness_get(const z_loaned_session_t *zs, const z_loaned_keyexpr opt = *options; } - ret = _z_liveliness_query(_Z_RC_IN_VAL(zs), key, callback->_this._val.call, callback->_this._val.drop, ctx, + ret = _z_liveliness_query(_Z_RC_IN_VAL(zs), *keyexpr, callback->_this._val.call, callback->_this._val.drop, ctx, opt.timeout_ms); z_internal_closure_reply_null(