Skip to content

Commit

Permalink
Return undeclare for publisher/subscriber/queriable
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Oct 10, 2024
1 parent a90a3d8 commit 41c73f9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 41c73f9

Please sign in to comment.