diff --git a/docs/api.rst b/docs/api.rst index bff46e12b..570a358a3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1299,6 +1299,7 @@ Functions .. autocfunction:: liveliness.h::z_liveliness_undeclare_token .. autocfunction:: liveliness.h::z_liveliness_subscriber_options_default .. autocfunction:: liveliness.h::z_liveliness_declare_subscriber +.. autocfunction:: liveliness.h::z_liveliness_declare_background_subscriber .. autocfunction:: liveliness.h::z_liveliness_get diff --git a/include/zenoh-pico/api/liveliness.h b/include/zenoh-pico/api/liveliness.h index 39c5bca6c..765a979ad 100644 --- a/include/zenoh-pico/api/liveliness.h +++ b/include/zenoh-pico/api/liveliness.h @@ -111,6 +111,23 @@ z_result_t z_liveliness_subscriber_options_default(z_liveliness_subscriber_optio z_result_t z_liveliness_declare_subscriber(const z_loaned_session_t *zs, z_owned_subscriber_t *sub, const z_loaned_keyexpr_t *keyexpr, z_moved_closure_sample_t *callback, z_liveliness_subscriber_options_t *options); +/** + * Declares a background subscriber on liveliness tokens that intersect `keyexpr`. + * Subscriber callback will be called to process the messages, until the corresponding session is closed or dropped. + * + * Parameters: + * zs: The Zenoh session. + * keyexpr: The key expression to subscribe to. + * callback: The callback function that will be called each time a liveliness token status is changed. + * options: The options to be passed to the liveliness subscriber declaration. + * + * Return: + * ``0`` if declare is successful, ``negative value`` otherwise. + */ +z_result_t z_liveliness_declare_background_subscriber(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, + z_moved_closure_sample_t *callback, + z_liveliness_subscriber_options_t *options); + #endif // Z_FEATURE_SUBSCRIPTION == 1 /**************** Liveliness Query ****************/ diff --git a/src/api/liveliness.c b/src/api/liveliness.c index 7c94f6fd2..793c5b318 100644 --- a/src/api/liveliness.c +++ b/src/api/liveliness.c @@ -116,6 +116,15 @@ z_result_t z_liveliness_declare_subscriber(const z_loaned_session_t *zs, z_owned return _Z_RES_OK; } + +z_result_t z_liveliness_declare_background_subscriber(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, + z_moved_closure_sample_t *callback, + z_liveliness_subscriber_options_t *options) { + z_owned_subscriber_t sub; + _Z_RETURN_IF_ERR(z_liveliness_declare_subscriber(zs, &sub, keyexpr, callback, options)); + _z_subscriber_clear(&sub._val); + return _Z_RES_OK; +} #endif // Z_FEATURE_SUBSCRIPTION == 1 /**************** Liveliness Query ****************/ diff --git a/src/session/liveliness.c b/src/session/liveliness.c index f3e7f0aa0..31a9d4b6b 100644 --- a/src/session/liveliness.c +++ b/src/session/liveliness.c @@ -244,9 +244,8 @@ z_result_t _z_liveliness_pending_query_drop(_z_session_t *zn, uint32_t interest_ ret = _Z_ERR_ENTITY_UNKNOWN; } - _Z_DEBUG("Liveliness pending query drop %i resolve result %i", (int)interest_id, ret); - if (ret == _Z_RES_OK) { + _Z_DEBUG("Liveliness pending query drop %i", (int)interest_id); _z_liveliness_pending_query_intmap_remove(&zn->_liveliness_pending_queries, interest_id); }