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 z_liveliness_declare_background_subscriber #854

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
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
17 changes: 17 additions & 0 deletions include/zenoh-pico/api/liveliness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ****************/
Expand Down
9 changes: 9 additions & 0 deletions src/api/liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ****************/
Expand Down
3 changes: 1 addition & 2 deletions src/session/liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading