diff --git a/docs/api.rst b/docs/api.rst index b573396c1..b2ff6cf4a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -941,6 +941,7 @@ Functions .. autocfunction:: primitives.h::z_delete .. autocfunction:: primitives.h::z_declare_publisher +.. autocfunction:: primitives.h::z_undeclare_publisher .. autocfunction:: primitives.h::z_publisher_put .. autocfunction:: primitives.h::z_publisher_delete .. autocfunction:: primitives.h::z_publisher_keyexpr @@ -983,6 +984,7 @@ Functions --------- .. autocfunction:: primitives.h::z_declare_subscriber +.. autocfunction:: primitives.h::z_undeclare_subscriber .. autocfunction:: primitives.h::z_declare_background_subscriber .. autocfunction:: primitives.h::z_subscriber_options_default @@ -1028,6 +1030,7 @@ Option Types Functions --------- .. autocfunction:: primitives.h::z_declare_queryable +.. autocfunction:: primitives.h::z_undeclare_queryable .. autocfunction:: primitives.h::z_declare_background_queryable .. autocfunction:: primitives.h::z_queryable_options_default diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 4e4d84b87..b04c41912 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1580,6 +1580,17 @@ void z_publisher_options_default(z_publisher_options_t *options); z_result_t z_declare_publisher(const z_loaned_session_t *zs, z_owned_publisher_t *pub, const z_loaned_keyexpr_t *keyexpr, const z_publisher_options_t *options); +/** + * Undeclares the publisher. + * + * Parameters: + * pub: Moved :c:type:`z_owned_publisher_t` to undeclare. + * + * Return: + * ``0`` if undeclare is successful, ``negative value`` otherwise. + */ +z_result_t z_undeclare_publisher(z_moved_publisher_t *pub); + /** * Builds a :c:type:`z_publisher_put_options_t` with default values. * @@ -1734,6 +1745,17 @@ z_result_t z_declare_queryable(const z_loaned_session_t *zs, z_owned_queryable_t const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, const z_queryable_options_t *options); +/** + * Undeclares the queryable. + * + * Parameters: + * pub: Moved :c:type:`z_owned_queryable_t` to undeclare. + * + * Return: + * ``0`` if undeclare is successful, ``negative value`` otherwise. + */ +z_result_t z_undeclare_queryable(z_moved_queryable_t *pub); + /** * Declares a background queryable for a given keyexpr. The queryable callback will be called * to proccess incoming queries until the corresponding session is closed or dropped. @@ -1995,6 +2017,17 @@ z_result_t z_declare_subscriber(const z_loaned_session_t *zs, z_owned_subscriber const z_loaned_keyexpr_t *keyexpr, z_moved_closure_sample_t *callback, const z_subscriber_options_t *options); +/** + * Undeclares the subscriber. + * + * Parameters: + * pub: Moved :c:type:`z_owned_subscriber_t` to undeclare. + * + * Return: + * ``0`` if undeclare is successful, ``negative value`` otherwise. + */ +z_result_t z_undeclare_subscriber(z_moved_subscriber_t *pub); + /** * Declares a background subscriber for a given keyexpr. Subscriber callback will be called to process the messages, * until the corresponding session is closed or dropped. diff --git a/src/api/api.c b/src/api/api.c index 6abdb962b..489b78638 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -913,6 +913,12 @@ z_result_t z_declare_publisher(const z_loaned_session_t *zs, z_owned_publisher_t return _Z_RES_OK; } +z_result_t z_undeclare_publisher(z_moved_publisher_t *pub) { + z_result_t ret = _z_undeclare_publisher(&pub->_this._val); + _z_publisher_clear(&pub->_this._val); + return ret; +} + void z_publisher_put_options_default(z_publisher_put_options_t *options) { options->encoding = NULL; options->attachment = NULL; @@ -1144,6 +1150,12 @@ z_result_t z_declare_queryable(const z_loaned_session_t *zs, z_owned_queryable_t return _Z_RES_OK; } +z_result_t z_undeclare_queryable(z_moved_queryable_t *queryable) { + z_result_t ret = _z_undeclare_queryable(&queryable->_this._val); + _z_queryable_clear(&queryable->_this._val); + return ret; +} + void z_query_reply_options_default(z_query_reply_options_t *options) { options->encoding = NULL; options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; @@ -1375,6 +1387,12 @@ z_result_t z_declare_subscriber(const z_loaned_session_t *zs, z_owned_subscriber } } +z_result_t z_undeclare_subscriber(z_moved_subscriber_t *sub) { + z_result_t ret = _z_undeclare_subscriber(&sub->_this._val); + _z_subscriber_clear(&sub->_this._val); + return ret; +} + const z_loaned_keyexpr_t *z_subscriber_keyexpr(const z_loaned_subscriber_t *sub) { // Retrieve keyexpr from session uint32_t lookup = sub->_entity_id;