From 10d2f2e36e70e8fc762e47df82a6ed6c8405f026 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 9 Jan 2024 14:28:05 +0100 Subject: [PATCH 1/2] feat: add keyexpr_was_declared api function --- include/zenoh-pico/api/primitives.h | 12 ++++++++++++ src/api/api.c | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index c96937518..57fc6fc5d 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -97,6 +97,18 @@ z_owned_str_t z_keyexpr_to_string(z_keyexpr_t keyexpr); */ z_bytes_t z_keyexpr_as_bytes(z_keyexpr_t keyexpr); +/** + * Indicates if the key expression has been declared but don't guarantee it's still in session. + * + * Parameters: + * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` + * + * Returns: + * Returns ``true`` if the keyexpr was declared or ``false`` otherwise. + + */ +_Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr); + /** * Constructs a null-terminated string departing from a :c:type:`z_keyexpr_t` for a given :c:type:`z_session_t`. * The user is responsible of dropping the returned string using ``z_free``. diff --git a/src/api/api.c b/src/api/api.c index 9455a6a2e..430aa0c3e 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -77,6 +77,14 @@ z_bytes_t z_keyexpr_as_bytes(z_keyexpr_t keyexpr) { } } +_Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr) { + _Bool ret = false; + if (keyexpr->_id != Z_RESOURCE_ID_NONE) { + ret = true; + } + return ret; +} + z_owned_str_t zp_keyexpr_resolve(z_session_t zs, z_keyexpr_t keyexpr) { z_owned_str_t ret = {._value = NULL}; From f32cccdd5bca906bb0c956e108af8b6e79f3fc6b Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 11 Jan 2024 17:10:37 +0100 Subject: [PATCH 2/2] doc: clarify function use --- include/zenoh-pico/api/primitives.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 57fc6fc5d..8df6ba1c0 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -93,19 +93,20 @@ z_owned_str_t z_keyexpr_to_string(z_keyexpr_t keyexpr); * * Returns: * The :c:type:`z_bytes_t` pointing to key expression string representation if it's possible - */ z_bytes_t z_keyexpr_as_bytes(z_keyexpr_t keyexpr); /** * Indicates if the key expression has been declared but don't guarantee it's still in session. * + * If given keyexpr was declared, to retrieve the keyexpr string representation the user must use + * :c:func:zp_keyexpr_resolve + * * Parameters: * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` * * Returns: * Returns ``true`` if the keyexpr was declared or ``false`` otherwise. - */ _Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr);