From 90c94ac87765700b7c0c858e7a43c1db389cfe42 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Mon, 1 Jul 2024 13:59:26 +0200 Subject: [PATCH] store value instead of ptr for z_owned_config, value, hello, encoding; remove z_scouting_config_t (since it corresponds exactly to z_config_t, and is also absent from zenoh-c) --- docs/api.rst | 12 --- examples/arduino/z_scout.ino | 6 +- examples/espidf/z_scout.c | 6 +- examples/freertos_plus_tcp/z_scout.c | 4 +- examples/unix/c11/z_scout.c | 4 +- examples/unix/c11/z_sub_attachment.c | 1 + examples/unix/c99/z_scout.c | 6 +- examples/windows/z_scout.c | 4 +- examples/zephyr/z_scout.c | 6 +- include/zenoh-pico/api/macros.h | 11 --- include/zenoh-pico/api/olv_macros.h | 18 +++++ include/zenoh-pico/api/primitives.h | 53 +------------ include/zenoh-pico/api/types.h | 21 +---- include/zenoh-pico/collections/vec.h | 6 +- include/zenoh-pico/net/config.h | 6 +- include/zenoh-pico/net/encoding.h | 2 +- include/zenoh-pico/protocol/core.h | 6 +- include/zenoh-pico/utils/config.h | 2 - src/api/api.c | 114 ++++++--------------------- src/collections/vec.c | 3 +- src/net/config.c | 34 ++++---- src/net/encoding.c | 6 +- src/net/memory.c | 8 +- src/protocol/core.c | 33 ++++++-- tests/z_api_alignment_test.c | 15 +--- tests/z_api_double_drop_test.c | 11 --- tests/z_api_null_drop_test.c | 8 -- 27 files changed, 136 insertions(+), 270 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index c51bb4e07..770905040 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -83,10 +83,6 @@ TODO: owned type description Represents a Zenoh configuration, used to configure Zenoh sessions upon opening. -.. c:type:: z_owned_scouting_config_t - - Represents a scouting configuration, used to configure a scouting procedure. - .. c:type:: z_owned_session_t Represents a Zenoh Session. @@ -160,10 +156,6 @@ TODO: loaned type description Represents a Zenoh configuration, used to configure Zenoh sessions upon opening. -.. c:type:: z_loaned_scouting_config_t - - Represents a scouting configuration, used to configure a scouting procedure. - .. c:type:: z_loaned_session_t Represents a Zenoh Session. @@ -288,10 +280,6 @@ Primitives .. autocfunction:: primitives.h::z_config_default .. autocfunction:: primitives.h::zp_config_get .. autocfunction:: primitives.h::zp_config_insert -.. autocfunction:: primitives.h::z_scouting_config_default -.. autocfunction:: primitives.h::z_scouting_config_from -.. autocfunction:: primitives.h::zp_scouting_config_get -.. autocfunction:: primitives.h::zp_scouting_config_insert .. autocfunction:: primitives.h::z_encoding_check .. autocfunction:: primitives.h::z_encoding_drop .. autocfunction:: primitives.h::z_encoding_loan diff --git a/examples/arduino/z_scout.ino b/examples/arduino/z_scout.ino index bd8f15836..2b72fb13c 100644 --- a/examples/arduino/z_scout.ino +++ b/examples/arduino/z_scout.ino @@ -115,10 +115,10 @@ void setup() { void loop() { int *context = (int *)malloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure_hello(&closure, callback, drop, context); printf("Scouting...\n"); - z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure)); + z_scout(z_config_move(&config), z_closure_hello_move(&closure)); } diff --git a/examples/espidf/z_scout.c b/examples/espidf/z_scout.c index e1ce7b9c7..462c70b25 100644 --- a/examples/espidf/z_scout.c +++ b/examples/espidf/z_scout.c @@ -168,10 +168,10 @@ void app_main() { int *context = (int *)malloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure_hello(&closure, callback, drop, context); printf("Scouting...\n"); - z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure)); + z_scout(z_config_move(&config), z_closure_hello_move(&closure)); } diff --git a/examples/freertos_plus_tcp/z_scout.c b/examples/freertos_plus_tcp/z_scout.c index 1d7ba13a3..9106f7380 100644 --- a/examples/freertos_plus_tcp/z_scout.c +++ b/examples/freertos_plus_tcp/z_scout.c @@ -86,8 +86,8 @@ void drop(void *context) { void app_main(void) { int *context = (int *)pvPortMalloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure(&closure, callback, drop, context); printf("Scouting...\n"); diff --git a/examples/unix/c11/z_scout.c b/examples/unix/c11/z_scout.c index be0be84fa..2b273648c 100644 --- a/examples/unix/c11/z_scout.c +++ b/examples/unix/c11/z_scout.c @@ -87,8 +87,8 @@ int main(int argc, char **argv) { int *context = (int *)malloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure(&closure, callback, drop, context); printf("Scouting...\n"); diff --git a/examples/unix/c11/z_sub_attachment.c b/examples/unix/c11/z_sub_attachment.c index 5038c2ae6..037037598 100644 --- a/examples/unix/c11/z_sub_attachment.c +++ b/examples/unix/c11/z_sub_attachment.c @@ -47,6 +47,7 @@ void parse_attachment(kv_pairs_t *kvp, const z_loaned_bytes_t *attachment) { z_bytes_deserialize_into_string(z_loan(second), &kvp->data[kvp->current_idx].value); z_bytes_drop(&first); z_bytes_drop(&second); + z_bytes_drop(&kv); kvp->current_idx++; } } diff --git a/examples/unix/c99/z_scout.c b/examples/unix/c99/z_scout.c index d383bc335..612a1fa28 100644 --- a/examples/unix/c99/z_scout.c +++ b/examples/unix/c99/z_scout.c @@ -86,12 +86,12 @@ int main(int argc, char **argv) { int *context = (int *)malloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure_hello(&closure, callback, drop, context); printf("Scouting...\n"); - z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure)); + z_scout(z_config_move(&config), z_closure_hello_move(&closure)); sleep(1); return 0; } diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index efffdc993..d1a4ae2d7 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -86,8 +86,8 @@ int main(int argc, char **argv) { int *context = (int *)malloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure(&closure, callback, drop, context); printf("Scouting...\n"); diff --git a/examples/zephyr/z_scout.c b/examples/zephyr/z_scout.c index 32c9a5660..ca371a632 100644 --- a/examples/zephyr/z_scout.c +++ b/examples/zephyr/z_scout.c @@ -82,12 +82,12 @@ int main(void) { int *context = (int *)malloc(sizeof(int)); *context = 0; - z_owned_scouting_config_t config; - z_scouting_config_default(&config); + z_owned_config_t config; + z_config_default(&config); z_owned_closure_hello_t closure; z_closure_hello(&closure, callback, drop, context); printf("Scouting...\n"); - z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure)); + z_scout(z_config_move(&config), z_closure_hello_move(&closure)); return 0; } diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index a17d40c41..68416d18a 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -38,7 +38,6 @@ z_owned_keyexpr_t : z_keyexpr_loan, \ z_view_keyexpr_t : z_view_keyexpr_loan, \ z_owned_config_t : z_config_loan, \ - z_owned_scouting_config_t : z_scouting_config_loan, \ z_owned_session_t : z_session_loan, \ z_owned_subscriber_t : z_subscriber_loan, \ z_owned_publisher_t : z_publisher_loan, \ @@ -65,7 +64,6 @@ #define z_loan_mut(x) _Generic((x), \ z_owned_keyexpr_t : z_keyexpr_loan_mut, \ z_owned_config_t : z_config_loan_mut, \ - z_owned_scouting_config_t : z_scouting_config_loan_mut, \ z_owned_session_t : z_session_loan_mut, \ z_owned_publisher_t : z_publisher_loan_mut, \ z_owned_queryable_t : z_queryable_loan_mut, \ @@ -89,7 +87,6 @@ #define z_drop(x) _Generic((x), \ z_owned_keyexpr_t * : z_keyexpr_drop, \ z_owned_config_t * : z_config_drop, \ - z_owned_scouting_config_t * : z_scouting_config_drop, \ z_owned_session_t * : z_session_drop, \ z_owned_subscriber_t * : z_subscriber_drop, \ z_owned_publisher_t * : z_publisher_drop, \ @@ -133,7 +130,6 @@ z_view_keyexpr_t : z_keyexpr_is_initialized, \ z_owned_reply_err_t : z_reply_err_check, \ z_owned_config_t : z_config_check, \ - z_owned_scouting_config_t : z_scouting_config_check, \ z_owned_session_t : z_session_check, \ z_owned_subscriber_t : z_subscriber_check, \ z_owned_publisher_t : z_publisher_check, \ @@ -198,7 +194,6 @@ #define z_move(x) _Generic((x), \ z_owned_keyexpr_t : z_keyexpr_move, \ z_owned_config_t : z_config_move, \ - z_owned_scouting_config_t : z_scouting_config_move, \ z_owned_session_t : z_session_move, \ z_owned_subscriber_t : z_subscriber_move, \ z_owned_publisher_t : z_publisher_move, \ @@ -266,7 +261,6 @@ z_owned_publisher_t * : z_publisher_null, \ z_owned_keyexpr_t * : z_keyexpr_null, \ z_owned_config_t * : z_config_null, \ - z_owned_scouting_config_t * : z_scouting_config_null, \ z_owned_subscriber_t * : z_subscriber_null, \ z_owned_queryable_t * : z_queryable_null, \ z_owned_query_t * : z_query_null, \ @@ -318,7 +312,6 @@ inline const z_loaned_keyexpr_t* z_loan(const z_owned_keyexpr_t& x) { return z_keyexpr_loan(&x); } inline const z_loaned_keyexpr_t* z_loan(const z_view_keyexpr_t& x) { return z_view_keyexpr_loan(&x); } inline const z_loaned_config_t* z_loan(const z_owned_config_t& x) { return z_config_loan(&x); } -inline const z_loaned_scouting_config_t* z_loan(const z_owned_scouting_config_t& x) { return z_scouting_config_loan(&x); } inline const z_loaned_session_t* z_loan(const z_owned_session_t& x) { return z_session_loan(&x); } inline const z_loaned_subscriber_t* z_loan(const z_owned_subscriber_t& x) { return z_subscriber_loan(&x); } inline const z_loaned_publisher_t* z_loan(const z_owned_publisher_t& x) { return z_publisher_loan(&x); } @@ -339,7 +332,6 @@ inline const z_loaned_reply_err_t* z_loan(const z_owned_reply_err_t& x) { return inline z_loaned_keyexpr_t* z_loan_mut(z_owned_keyexpr_t& x) { return z_keyexpr_loan_mut(&x); } inline z_loaned_keyexpr_t* z_loan_mut(z_view_keyexpr_t& x) { return z_view_keyexpr_loan_mut(&x); } inline z_loaned_config_t* z_loan_mut(z_owned_config_t& x) { return z_config_loan_mut(&x); } -inline z_loaned_scouting_config_t* z_loan_mut(z_owned_scouting_config_t& x) { return z_scouting_config_loan_mut(&x); } inline z_loaned_session_t* z_loan_mut(z_owned_session_t& x) { return z_session_loan_mut(&x); } inline z_loaned_publisher_t* z_loan_mut(z_owned_publisher_t& x) { return z_publisher_loan_mut(&x); } inline z_loaned_queryable_t* z_loan_mut(z_owned_queryable_t& x) { return z_queryable_loan_mut(&x); } @@ -360,7 +352,6 @@ inline int8_t z_drop(z_owned_session_t* v) { return z_close(v); } inline int8_t z_drop(z_owned_publisher_t* v) { return z_undeclare_publisher(v); } inline void z_drop(z_owned_keyexpr_t* v) { z_keyexpr_drop(v); } inline void z_drop(z_owned_config_t* v) { z_config_drop(v); } -inline void z_drop(z_owned_scouting_config_t* v) { z_scouting_config_drop(v); } inline int8_t z_drop(z_owned_subscriber_t* v) { return z_undeclare_subscriber(v); } inline int8_t z_drop(z_owned_queryable_t* v) { return z_undeclare_queryable(v); } inline void z_drop(z_owned_reply_t* v) { z_reply_drop(v); } @@ -391,7 +382,6 @@ inline void z_null(z_owned_session_t* v) { z_session_null(v); } inline void z_null(z_owned_publisher_t* v) { z_publisher_null(v); } inline void z_null(z_owned_keyexpr_t* v) { z_keyexpr_null(v); } inline void z_null(z_owned_config_t* v) { z_config_null(v); } -inline void z_null(z_owned_scouting_config_t* v) { z_scouting_config_null(v); } inline void z_null(z_owned_subscriber_t* v) { z_subscriber_null(v); } inline void z_null(z_owned_queryable_t* v) { z_queryable_null(v); } inline void z_null(z_owned_query_t* v) { z_query_null(v); } @@ -412,7 +402,6 @@ inline bool z_check(const z_owned_session_t& v) { return z_session_check(&v); } inline bool z_check(const z_owned_publisher_t& v) { return z_publisher_check(&v); } inline bool z_check(const z_owned_keyexpr_t& v) { return z_keyexpr_check(&v); } inline bool z_check(const z_owned_config_t& v) { return z_config_check(&v); } -inline bool z_check(const z_owned_scouting_config_t& v) { return z_scouting_config_check(&v); } inline bool z_check(const z_owned_subscriber_t& v) { return z_subscriber_check(&v); } inline bool z_check(const z_owned_queryable_t& v) { return z_queryable_check(&v); } inline bool z_check(const z_owned_reply_t& v) { return z_reply_check(&v); } diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index 8146af71c..1e480e50e 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -52,6 +52,14 @@ void z_##name##_drop(ownedtype *obj); \ void z_##name##_null(ownedtype *obj); +#define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(loanedtype, ownedtype, name) \ + _Bool z_##name##_check(const ownedtype *obj); \ + const loanedtype *z_##name##_loan(const ownedtype *obj); \ + loanedtype *z_##name##_loan_mut(ownedtype *obj); \ + ownedtype *z_##name##_move(ownedtype *obj); \ + void z_##name##_drop(ownedtype *obj); \ + void z_##name##_null(ownedtype *obj); + #define _Z_VIEW_FUNCTIONS_DEF(loanedtype, viewtype, name) \ const loanedtype *z_view_##name##_loan(const viewtype *name); \ loanedtype *z_view_##name##_loan_mut(viewtype *name); \ @@ -92,6 +100,16 @@ if (obj != NULL) f_drop((&obj->_val)); \ } +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(type, name, f_check, f_null, f_drop) \ + _Bool z_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ + const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \ + z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } \ + void z_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ + z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return obj; } \ + void z_##name##_drop(z_owned_##name##_t *obj) { \ + if (obj != NULL) f_drop((&obj->_val)); \ + } + #define _Z_OWNED_FUNCTIONS_RC_IMPL(name) \ _Bool z_##name##_check(const z_owned_##name##_t *val) { return val->_rc.in != NULL; } \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_rc; } \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 9d82a8c72..edc19fbcd 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -293,51 +293,6 @@ const char *zp_config_get(const z_loaned_config_t *config, uint8_t key); */ int8_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *value); -/** - * Builds a new :c:type:`z_owned_scouting_config_t` with a default set of properties for scouting configuration. - * - * Parameters: - * sc: Pointer to an uninitialized :c:type:`z_owned_scouting_config_t`. - */ -void z_scouting_config_default(z_owned_scouting_config_t *sc); - -/** - * Builds a new :c:type:`z_owned_scouting_config_t` with values from a :c:type:`z_loaned_config_t`. - * - * Parameters: - * config: Pointer to a :c:type:`z_owned_config_t` to get the values from. - * sc: Pointer to an uninitialized :c:type:`z_owned_scouting_config_t`. - * - * Return: - * ``0`` if build successful, ``negative value`` otherwise. - */ -int8_t z_scouting_config_from(z_owned_scouting_config_t *sc, const z_loaned_config_t *config); - -/** - * Gets the property with the given integer key from the configuration. - * - * Parameters: - * config: Pointer to a :c:type:`z_loaned_scouting_config_t` to get the property from. - * key: Integer key for the requested property. - * - * Return: - * The requested property value. - */ -const char *zp_scouting_config_get(const z_loaned_scouting_config_t *config, uint8_t key); - -/** - * Inserts or replace the property with the given integer key in the configuration. - * - * Parameters: - * config: Pointer to a :c:type:`z_loaned_scouting_config_t` to modify. - * key: Integer key for the property to be inserted. - * value: Property value to be inserted. - * - * Return: - * ``0`` if insertion successful, ``negative value`` otherwise. - */ -int8_t zp_scouting_config_insert(z_loaned_scouting_config_t *config, uint8_t key, const char *value); - /** * Checks if a :c:type:`z_owned_encoding_t` has non-default values. * @@ -1181,8 +1136,7 @@ int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_drop /**************** Loans ****************/ _Z_OWNED_FUNCTIONS_DEF(z_loaned_string_t, z_owned_string_t, string) _Z_OWNED_FUNCTIONS_DEF(z_loaned_keyexpr_t, z_owned_keyexpr_t, keyexpr) -_Z_OWNED_FUNCTIONS_DEF(z_loaned_config_t, z_owned_config_t, config) -_Z_OWNED_FUNCTIONS_DEF(z_loaned_scouting_config_t, z_owned_scouting_config_t, scouting_config) +_Z_OWNED_FUNCTIONS_NO_COPY_DEF(z_loaned_config_t, z_owned_config_t, config) _Z_OWNED_FUNCTIONS_DEF(z_loaned_session_t, z_owned_session_t, session) _Z_OWNED_FUNCTIONS_DEF(z_loaned_subscriber_t, z_owned_subscriber_t, subscriber) _Z_OWNED_FUNCTIONS_DEF(z_loaned_publisher_t, z_owned_publisher_t, publisher) @@ -1196,6 +1150,7 @@ _Z_OWNED_FUNCTIONS_DEF(z_loaned_slice_t, z_owned_slice_t, slice) _Z_OWNED_FUNCTIONS_DEF(z_loaned_bytes_t, z_owned_bytes_t, bytes) _Z_OWNED_FUNCTIONS_DEF(z_loaned_bytes_writer_t, z_owned_bytes_writer_t, bytes_writer) _Z_OWNED_FUNCTIONS_DEF(z_loaned_reply_err_t, z_owned_reply_err_t, reply_err) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_encoding_t, z_owned_encoding_t, encoding) _Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_sample_t, closure_sample) _Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_sample_t, closure_owned_sample) @@ -1247,13 +1202,13 @@ size_t z_string_len(const z_loaned_string_t *str); * Scouts for other Zenoh entities like routers and/or peers. * * Parameters: - * config: Pointer to a moved :c:type:`z_owned_scouting_config_t` to configure the scouting with. + * config: Pointer to a moved :c:type:`z_owned_config_t` to configure the scouting with. * callback: Pointer to a moved :c:type:`z_owned_closure_hello_t` callback. * * Return: * ``0`` if scouting successfully triggered, ``negative value`` otherwise. */ -int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callback); +int8_t z_scout(z_owned_config_t *config, z_owned_closure_hello_t *callback); /** * Opens a Zenoh session. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index 2c99949b6..8626b1c8b 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -123,22 +123,9 @@ _Z_VIEW_TYPE(_z_keyexpr_t, keyexpr) * - :c:func:`zp_config_get` * - :c:func:`zp_config_insert` */ -_Z_OWNED_TYPE_PTR(_z_config_t, config) +_Z_OWNED_TYPE_VALUE(_z_config_t, config) _Z_LOANED_TYPE(_z_config_t, config) -/** - * Represents a scouting configuration, used to configure a scouting procedure. - * - * Members are private and operations must be done using the provided functions: - * - * - :c:func:`z_scouting_config_default` - * - :c:func:`z_scouting_config_from` - * - :c:func:`zp_scouting_config_get` - * - :c:func:`zp_scouting_config_insert` - */ -_Z_OWNED_TYPE_PTR(_z_scouting_config_t, scouting_config) -_Z_LOANED_TYPE(_z_scouting_config_t, scouting_config) - /** * Represents a Zenoh Session. */ @@ -194,7 +181,7 @@ _Z_LOANED_TYPE(_z_query_rc_t, query) * uint16_t prefix: The integer prefix of this encoding. * z_loaned_slice_t* suffix: The suffix of this encoding. It MUST be a valid UTF-8 string. */ -_Z_OWNED_TYPE_PTR(_z_encoding_t, encoding) +_Z_OWNED_TYPE_VALUE(_z_encoding_t, encoding) _Z_LOANED_TYPE(_z_encoding_t, encoding) /** @@ -204,7 +191,7 @@ _Z_LOANED_TYPE(_z_encoding_t, encoding) * z_loaned_encoding_t encoding: The encoding of the error `payload`. * z_loaned_bytes_t* payload: The payload of this zenoh reply error. */ -_Z_OWNED_TYPE_PTR(_z_value_t, reply_err) +_Z_OWNED_TYPE_VALUE(_z_value_t, reply_err) _Z_LOANED_TYPE(_z_value_t, reply_err) /** @@ -427,7 +414,7 @@ _Z_LOANED_TYPE(_z_sample_rc_t, sample) * z_loaned_slice_t* zid: The Zenoh ID of the scouted entity (empty if absent). * z_loaned_string_array_t locators: The locators of the scouted entity. */ -_Z_OWNED_TYPE_PTR(_z_hello_t, hello) +_Z_OWNED_TYPE_VALUE(_z_hello_t, hello) _Z_LOANED_TYPE(_z_hello_t, hello) /** diff --git a/include/zenoh-pico/collections/vec.h b/include/zenoh-pico/collections/vec.h index cc1790fe7..001e36fd4 100644 --- a/include/zenoh-pico/collections/vec.h +++ b/include/zenoh-pico/collections/vec.h @@ -75,7 +75,7 @@ typedef struct { } _z_svec_t; _z_svec_t _z_svec_make(size_t capacity, size_t element_size); -void _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, size_t element_size); +_Bool _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, size_t element_size); size_t _z_svec_len(const _z_svec_t *v); _Bool _z_svec_is_empty(const _z_svec_t *v); @@ -107,8 +107,8 @@ void _z_svec_release(_z_svec_t *v); static inline void name##_svec_remove(name##_svec_t *v, size_t pos) { \ _z_svec_remove(v, pos, name##_elem_clear, name##_elem_move, sizeof(type)); \ } \ - static inline void name##_svec_copy(name##_svec_t *dst, const name##_svec_t *src) { \ - _z_svec_copy(dst, src, name##_elem_copy, sizeof(type)); \ + static inline _Bool name##_svec_copy(name##_svec_t *dst, const name##_svec_t *src) { \ + return _z_svec_copy(dst, src, name##_elem_copy, sizeof(type)); \ } \ static inline void name##_svec_reset(name##_svec_t *v) { _z_svec_reset(v, name##_elem_clear, sizeof(type)); } \ static inline void name##_svec_clear(name##_svec_t *v) { _z_svec_clear(v, name##_elem_clear, sizeof(type)); } \ diff --git a/include/zenoh-pico/net/config.h b/include/zenoh-pico/net/config.h index ba94a122e..c54d7b5b2 100644 --- a/include/zenoh-pico/net/config.h +++ b/include/zenoh-pico/net/config.h @@ -24,7 +24,7 @@ * Returns: * A :c:type:`_z_config_t` containing an empty configuration. */ -_z_config_t *_z_config_empty(void); +_z_config_t _z_config_empty(void); /** * Create a default set of properties for zenoh-net session configuration. @@ -32,7 +32,7 @@ _z_config_t *_z_config_empty(void); * Returns: * A :c:type:`_z_config_t` containing a default configuration. */ -_z_config_t *_z_config_default(void); +_z_config_t _z_config_default(void); /** * Create a default set of properties for client mode zenoh-net session configuration. @@ -43,6 +43,6 @@ _z_config_t *_z_config_default(void); * Returns: * A :c:type:`_z_config_t` containing a default configuration for client mode. */ -_z_config_t *_z_config_client(const char *locator); +_z_config_t _z_config_client(const char *locator); #endif /* ZENOH_PICO_CONFIG_NETAPI_H */ diff --git a/include/zenoh-pico/net/encoding.h b/include/zenoh-pico/net/encoding.h index 25e6c6260..9235d45b3 100644 --- a/include/zenoh-pico/net/encoding.h +++ b/include/zenoh-pico/net/encoding.h @@ -32,7 +32,7 @@ _z_encoding_t _z_encoding_wrap(uint16_t id, const char *schema); _z_encoding_t _z_encoding_null(void); void _z_encoding_clear(_z_encoding_t *encoding); _Bool _z_encoding_check(const _z_encoding_t *encoding); -void _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src); +int8_t _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src); void _z_encoding_move(_z_encoding_t *dst, _z_encoding_t *src); #endif /* ZENOH_PICO_ENCODING_NETAPI_H */ diff --git a/include/zenoh-pico/protocol/core.h b/include/zenoh-pico/protocol/core.h index 552fdc513..7fea4833e 100644 --- a/include/zenoh-pico/protocol/core.h +++ b/include/zenoh-pico/protocol/core.h @@ -167,7 +167,7 @@ typedef struct { } _z_value_t; _z_value_t _z_value_null(void); _z_value_t _z_value_steal(_z_value_t *value); -void _z_value_copy(_z_value_t *dst, const _z_value_t *src); +int8_t _z_value_copy(_z_value_t *dst, const _z_value_t *src); void _z_value_clear(_z_value_t *src); void _z_value_free(_z_value_t **hello); @@ -187,6 +187,10 @@ typedef struct { } _z_hello_t; void _z_hello_clear(_z_hello_t *src); void _z_hello_free(_z_hello_t **hello); +int8_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t* src); +_z_hello_t _z_hello_null(void); +_Bool _z_hello_check(const _z_hello_t* hello); + _Z_ELEM_DEFINE(_z_hello, _z_hello_t, _z_noop_size, _z_hello_clear, _z_noop_copy) _Z_LIST_DEFINE(_z_hello, _z_hello_t) diff --git a/include/zenoh-pico/utils/config.h b/include/zenoh-pico/utils/config.h index c7d49188a..6c587370d 100644 --- a/include/zenoh-pico/utils/config.h +++ b/include/zenoh-pico/utils/config.h @@ -30,7 +30,6 @@ * Zenoh-net properties are represented as int-string map. */ typedef _z_str_intmap_t _z_config_t; -typedef _z_str_intmap_t _z_scouting_config_t; /** * Initialize a new empty map of properties. @@ -98,6 +97,5 @@ char *_z_config_get(const _z_config_t *ps, uint8_t key); * */ #define _z_config_free _z_str_intmap_free -#define _z_scouting_config_free _z_str_intmap_free #endif /* ZENOH_PICO_UTILS_PROPERTY_H */ diff --git a/src/api/api.c b/src/api/api.c index a66b55825..9f77dbc4c 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -177,48 +177,6 @@ int8_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *valu return _zp_config_insert(config, key, value); } -void z_scouting_config_default(z_owned_scouting_config_t *sc) { - sc->_val = _z_config_empty(); - - _zp_config_insert(sc->_val, Z_CONFIG_MULTICAST_LOCATOR_KEY, Z_CONFIG_MULTICAST_LOCATOR_DEFAULT); - _zp_config_insert(sc->_val, Z_CONFIG_SCOUTING_TIMEOUT_KEY, Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT); - _zp_config_insert(sc->_val, Z_CONFIG_SCOUTING_WHAT_KEY, Z_CONFIG_SCOUTING_WHAT_DEFAULT); -} - -int8_t z_scouting_config_from(z_owned_scouting_config_t *sc, const z_loaned_config_t *c) { - sc->_val = _z_config_empty(); - - char *opt; - opt = _z_config_get(c, Z_CONFIG_MULTICAST_LOCATOR_KEY); - if (opt == NULL) { - _zp_config_insert(sc->_val, Z_CONFIG_MULTICAST_LOCATOR_KEY, Z_CONFIG_MULTICAST_LOCATOR_DEFAULT); - } else { - _zp_config_insert(sc->_val, Z_CONFIG_MULTICAST_LOCATOR_KEY, opt); - } - - opt = _z_config_get(c, Z_CONFIG_SCOUTING_TIMEOUT_KEY); - if (opt == NULL) { - _zp_config_insert(sc->_val, Z_CONFIG_SCOUTING_TIMEOUT_KEY, Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT); - } else { - _zp_config_insert(sc->_val, Z_CONFIG_SCOUTING_TIMEOUT_KEY, opt); - } - - opt = _z_config_get(c, Z_CONFIG_SCOUTING_WHAT_KEY); - if (opt == NULL) { - _zp_config_insert(sc->_val, Z_CONFIG_SCOUTING_WHAT_KEY, Z_CONFIG_SCOUTING_WHAT_DEFAULT); - } else { - _zp_config_insert(sc->_val, Z_CONFIG_SCOUTING_WHAT_KEY, opt); - } - - return _Z_RES_OK; -} - -const char *zp_scouting_config_get(const z_loaned_scouting_config_t *sc, uint8_t key) { return _z_config_get(sc, key); } - -int8_t zp_scouting_config_insert(z_loaned_scouting_config_t *sc, uint8_t key, const char *value) { - return _zp_config_insert(sc, key, value); -} - #if Z_FEATURE_ENCODING_VALUES == 1 #define ENCODING_SCHEMA_SEPARATOR ';' @@ -309,11 +267,11 @@ static int8_t _z_encoding_convert_from_string(z_owned_encoding_t *encoding, cons uint16_t id = _z_encoding_values_str_to_int(s, len); // Check id if (id != UINT16_MAX) { - return _z_encoding_make(encoding->_val, id, (id_end[1] == '\0') ? NULL : ++id_end); + return _z_encoding_make(&encoding->_val, id, (id_end[1] == '\0') ? NULL : ++id_end); } } // By default store the string as schema - return _z_encoding_make(encoding->_val, _Z_ENCODING_ID_DEFAULT, s); + return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s); } static int8_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { @@ -361,42 +319,9 @@ static int8_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encodin #endif -z_owned_encoding_t *z_encoding_move(z_owned_encoding_t *encoding) { return encoding; } - -void z_encoding_null(z_owned_encoding_t *encoding) { encoding->_val = NULL; } - -_Bool z_encoding_check(const z_owned_encoding_t *encoding) { return _z_encoding_check(encoding->_val); } - -void z_encoding_drop(z_owned_encoding_t *encoding) { - if (encoding == NULL) { - return; - } - if (_z_string_check(&encoding->_val->schema)) { - _z_string_clear(&encoding->_val->schema); - } - z_free(encoding->_val); -} - -int8_t z_encoding_clone(z_owned_encoding_t *dst, const z_loaned_encoding_t *src) { - dst->_val = (_z_encoding_t *)z_malloc(sizeof(_z_encoding_t)); - if (dst->_val == NULL) { - return _Z_ERR_SYSTEM_OUT_OF_MEMORY; - } - _z_encoding_copy(dst->_val, src); - return _Z_RES_OK; -} - -const z_loaned_encoding_t *z_encoding_loan(const z_owned_encoding_t *encoding) { return encoding->_val; } - -z_loaned_encoding_t *z_encoding_loan_mut(z_owned_encoding_t *encoding) { return encoding->_val; } - int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { // Init owned encoding z_encoding_null(encoding); - encoding->_val = (_z_encoding_t *)z_malloc(sizeof(_z_encoding_t)); - if (encoding->_val == NULL) { - return _Z_ERR_SYSTEM_OUT_OF_MEMORY; - } // Convert string to encoding if (s != NULL) { return _z_encoding_convert_from_string(encoding, s); @@ -694,17 +619,23 @@ static inline void _z_owner_noop_copy(void *dst, const void *src) { (void)(src); } -_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_config_t, config, _z_owner_noop_copy, _z_config_free) -_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_scouting_config_t, scouting_config, _z_owner_noop_copy, _z_scouting_config_free) +_Bool _z_config_check(const _z_config_t *config) { return !_z_str_intmap_is_empty(config); } +_z_config_t _z_config_null(void) { return _z_str_intmap_make(); } +void _z_config_drop(_z_config_t *config) { _z_str_intmap_clear(config); } +_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_config_t, config, _z_config_check, _z_config_null, _z_config_drop) _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_string_t, string, _z_string_check, _z_string_null, _z_string_copy, _z_string_clear) -_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_value_t, reply_err, _z_value_copy, _z_value_free) + +_Bool _z_value_check(const _z_value_t *value) { + return _z_string_check(&value->encoding.schema) && value->encoding.id == _Z_ENCODING_ID_DEFAULT; +} +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_value_t, reply_err, _z_value_check, _z_value_null, _z_value_copy, _z_value_clear) _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_keyexpr_t, keyexpr, _z_keyexpr_copy, _z_keyexpr_free) _Z_VIEW_FUNCTIONS_IMPL(_z_keyexpr_t, keyexpr) _Z_VIEW_FUNCTIONS_IMPL(_z_string_t, string) -_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_hello_t, hello, _z_owner_noop_copy, _z_hello_free) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_hello_t, hello, _z_hello_check, _z_hello_null, _z_hello_copy, _z_hello_clear) _Bool _z_string_array_check(const _z_string_svec_t *val) { return !_z_string_svec_is_empty(val); } int8_t _z_string_array_copy(_z_string_svec_t *dst, const _z_string_svec_t *src) { @@ -740,15 +671,14 @@ static _z_bytes_t _z_bytes_from_owned_bytes(z_owned_bytes_t *bytes) { } } +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_encoding_t, encoding, _z_encoding_check, _z_encoding_null, _z_encoding_copy, _z_encoding_clear) + // Convert a user owned encoding to an internal encoding, return default encoding if value invalid static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) { if (encoding == NULL) { return _z_encoding_null(); } - if (encoding->_val == NULL) { - return _z_encoding_null(); - } - return *encoding->_val; + return encoding->_val; } #endif @@ -777,7 +707,7 @@ void __z_hello_handler(_z_hello_t *hello, __z_hello_handler_wrapper_t *wrapped_c wrapped_ctx->user_call(hello, wrapped_ctx->ctx); } -int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callback) { +int8_t z_scout(z_owned_config_t *config, z_owned_closure_hello_t *callback) { int8_t ret = _Z_RES_OK; void *ctx = callback->context; @@ -791,26 +721,26 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb wrapped_ctx->user_call = callback->call; wrapped_ctx->ctx = ctx; - char *opt_as_str = _z_config_get(config->_val, Z_CONFIG_SCOUTING_WHAT_KEY); + char *opt_as_str = _z_config_get(&config->_val, Z_CONFIG_SCOUTING_WHAT_KEY); if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_SCOUTING_WHAT_DEFAULT; } z_what_t what = strtol(opt_as_str, NULL, 10); - opt_as_str = _z_config_get(config->_val, Z_CONFIG_MULTICAST_LOCATOR_KEY); + opt_as_str = _z_config_get(&config->_val, Z_CONFIG_MULTICAST_LOCATOR_KEY); if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_MULTICAST_LOCATOR_DEFAULT; } char *mcast_locator = opt_as_str; - opt_as_str = _z_config_get(config->_val, Z_CONFIG_SCOUTING_TIMEOUT_KEY); + opt_as_str = _z_config_get(&config->_val, Z_CONFIG_SCOUTING_TIMEOUT_KEY); if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT; } uint32_t timeout = (uint32_t)strtoul(opt_as_str, NULL, 10); _z_id_t zid = _z_id_empty(); - char *zid_str = _z_config_get(config->_val, Z_CONFIG_SESSION_ZID_KEY); + char *zid_str = _z_config_get(&config->_val, Z_CONFIG_SESSION_ZID_KEY); if (zid_str != NULL) { _z_uuid_to_bytes(zid.id, zid_str); } @@ -818,7 +748,7 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb _z_scout(what, zid, mcast_locator, timeout, __z_hello_handler, wrapped_ctx, callback->drop, ctx); z_free(wrapped_ctx); - z_scouting_config_drop(config); + z_config_drop(config); } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; } @@ -836,7 +766,7 @@ int8_t z_open(z_owned_session_t *zs, z_owned_config_t *config) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; } // Open session - int8_t ret = _z_open(&zsrc.in->val, config->_val); + int8_t ret = _z_open(&zsrc.in->val, &config->_val); if (ret != _Z_RES_OK) { _z_session_rc_drop(&zsrc); z_config_drop(config); diff --git a/src/collections/vec.c b/src/collections/vec.c index 9acd13f85..e33034fd2 100644 --- a/src/collections/vec.c +++ b/src/collections/vec.c @@ -164,7 +164,7 @@ void __z_svec_move_inner(void *dst, void *src, z_element_move_f move, size_t num } } -void _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, size_t element_size) { +_Bool _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, size_t element_size) { dst->_capacity = 0; dst->_len = 0; dst->_val = z_malloc(element_size * src->_capacity); @@ -173,6 +173,7 @@ void _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, s dst->_len = src->_len; __z_svec_copy_inner(dst->_val, src->_val, copy, src->_len, element_size); } + return dst->_len == src->_len; } void _z_svec_reset(_z_svec_t *v, z_element_clear_f clear, size_t element_size) { diff --git a/src/net/config.c b/src/net/config.c index d8ab54459..9f2969702 100644 --- a/src/net/config.c +++ b/src/net/config.c @@ -17,29 +17,25 @@ #include "zenoh-pico/net/config.h" -_z_config_t *_z_config_empty(void) { - _z_config_t *config = (_z_config_t *)z_malloc(sizeof(_z_config_t)); - if (config != NULL) { - _z_config_init(config); - } +_z_config_t _z_config_empty(void) { + _z_config_t config; + _z_config_init(&config); return config; } -_z_config_t *_z_config_default(void) { return _z_config_client(NULL); } +_z_config_t _z_config_default(void) { return _z_config_client(NULL); } -_z_config_t *_z_config_client(const char *locator) { - _z_config_t *ps = _z_config_empty(); - if (ps != NULL) { - _zp_config_insert(ps, Z_CONFIG_MODE_KEY, Z_CONFIG_MODE_CLIENT); - if (locator != NULL) { - // Connect only to the provided locator - _zp_config_insert(ps, Z_CONFIG_CONNECT_KEY, locator); - } else { - // The locator is not provided, we should perform scouting - _zp_config_insert(ps, Z_CONFIG_MULTICAST_SCOUTING_KEY, Z_CONFIG_MULTICAST_SCOUTING_DEFAULT); - _zp_config_insert(ps, Z_CONFIG_MULTICAST_LOCATOR_KEY, Z_CONFIG_MULTICAST_LOCATOR_DEFAULT); - _zp_config_insert(ps, Z_CONFIG_SCOUTING_TIMEOUT_KEY, Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT); - } +_z_config_t _z_config_client(const char *locator) { + _z_config_t ps = _z_config_empty(); + _zp_config_insert(&ps, Z_CONFIG_MODE_KEY, Z_CONFIG_MODE_CLIENT); + if (locator != NULL) { + // Connect only to the provided locator + _zp_config_insert(&ps, Z_CONFIG_CONNECT_KEY, locator); + } else { + // The locator is not provided, we should perform scouting + _zp_config_insert(&ps, Z_CONFIG_MULTICAST_SCOUTING_KEY, Z_CONFIG_MULTICAST_SCOUTING_DEFAULT); + _zp_config_insert(&ps, Z_CONFIG_MULTICAST_LOCATOR_KEY, Z_CONFIG_MULTICAST_LOCATOR_DEFAULT); + _zp_config_insert(&ps, Z_CONFIG_SCOUTING_TIMEOUT_KEY, Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT); } return ps; } diff --git a/src/net/encoding.c b/src/net/encoding.c index 07db554bd..c4fd5e50b 100644 --- a/src/net/encoding.c +++ b/src/net/encoding.c @@ -45,9 +45,11 @@ _Bool _z_encoding_check(const _z_encoding_t *encoding) { return ((encoding->id != _Z_ENCODING_ID_DEFAULT) || _z_string_check(&encoding->schema)); } -void _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src) { +int8_t _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src) { + *dst = _z_encoding_null(); + _Z_RETURN_IF_ERR(_z_string_copy(&dst->schema, &src->schema)); dst->id = src->id; - _z_string_copy(&dst->schema, &src->schema); + return _Z_RES_OK; } void _z_encoding_move(_z_encoding_t *dst, _z_encoding_t *src) { diff --git a/src/net/memory.c b/src/net/memory.c index ef9a03804..e6f9d573a 100644 --- a/src/net/memory.c +++ b/src/net/memory.c @@ -17,9 +17,7 @@ #include "zenoh-pico/protocol/core.h" void _z_hello_clear(_z_hello_t *hello) { - if (!_z_string_svec_is_empty(&hello->locators)) { - _z_string_svec_clear(&hello->locators); - } + _z_string_svec_clear(&hello->locators); } void _z_hello_free(_z_hello_t **hello) { @@ -48,3 +46,7 @@ void _z_value_free(_z_value_t **value) { *value = NULL; } } + +_Bool _z_hello_check(const _z_hello_t* hello) { + return _z_id_check(hello->zid); +} diff --git a/src/protocol/core.c b/src/protocol/core.c index 08cc542c4..7e25f127c 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -24,8 +24,10 @@ #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/utils/logging.h" +#define _Z_ID_LEN (16) + uint8_t _z_id_len(_z_id_t id) { - uint8_t len = 16; + uint8_t len = _Z_ID_LEN; while (len > 0) { --len; if (id.id[len] != 0) { @@ -37,7 +39,7 @@ uint8_t _z_id_len(_z_id_t id) { } _Bool _z_id_check(_z_id_t id) { _Bool ret = false; - for (int i = 0; !ret && i < 16; i++) { + for (int i = 0; !ret && i < _Z_ID_LEN; i++) { ret |= id.id[i] != 0; } return ret; @@ -62,6 +64,7 @@ _z_id_t _z_id_empty(void) { 0, }}; } + _z_source_info_t _z_source_info_null(void) { return (_z_source_info_t){._source_sn = 0, ._entity_id = 0, ._id = _z_id_empty()}; } @@ -72,7 +75,27 @@ _z_value_t _z_value_steal(_z_value_t *value) { *value = _z_value_null(); return ret; } -void _z_value_copy(_z_value_t *dst, const _z_value_t *src) { - _z_encoding_copy(&dst->encoding, &src->encoding); - _z_bytes_copy(&dst->payload, &src->payload); +int8_t _z_value_copy(_z_value_t *dst, const _z_value_t *src) { + *dst = _z_value_null(); + _Z_RETURN_IF_ERR(_z_encoding_copy(&dst->encoding, &src->encoding)); + _Z_CLEAN_RETURN_IF_ERR(_z_bytes_copy(&dst->payload, &src->payload), _z_encoding_clear(&dst->encoding)); + return _Z_RES_OK; +} + +int8_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t* src) { + *dst = _z_hello_null(); + _Z_RETURN_IF_ERR(_z_string_svec_copy(&dst->locators, &src->locators) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY); + dst->version = src->version; + dst->whatami = src->whatami; + memcpy(&dst->zid.id, &src->zid.id, _Z_ID_LEN); + return _Z_RES_OK; +} + +_z_hello_t _z_hello_null(void) { + return (_z_hello_t) { + .zid = _z_id_empty(), + .version = 0, + .whatami = 0x0, + .locators = _z_string_svec_make(0) + }; } diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 21c9087d7..d045641b5 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -188,7 +188,7 @@ int main(int argc, char **argv) { printf("Testing Configs..."); z_owned_config_t _ret_config; z_config_new(&_ret_config); - assert(z_check(_ret_config)); + assert(!z_check(_ret_config)); // null config corresponds to empty one z_drop(z_move(_ret_config)); z_config_default(&_ret_config); assert(z_check(_ret_config)); @@ -200,23 +200,14 @@ int main(int argc, char **argv) { assert_eq(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)), 0); #endif - z_owned_scouting_config_t _ret_sconfig; - z_scouting_config_default(&_ret_sconfig); + z_owned_config_t _ret_sconfig; + z_config_default(&_ret_sconfig); assert(z_check(_ret_sconfig)); -#ifdef ZENOH_PICO - _ret_int8 = zp_scouting_config_insert(z_loan_mut(_ret_sconfig), Z_CONFIG_SCOUTING_TIMEOUT_KEY, SCOUTING_TIMEOUT); - assert_eq(_ret_int8, 0); - _ret_cstr = zp_scouting_config_get(z_loan(_ret_sconfig), Z_CONFIG_SCOUTING_TIMEOUT_KEY); - assert_eq(strlen(_ret_cstr), strlen(SCOUTING_TIMEOUT)); - assert_eq(strncmp(_ret_cstr, SCOUTING_TIMEOUT, strlen(_ret_cstr)), 0); -#endif - z_drop(z_move(_ret_sconfig)); printf("Ok\n"); z_sleep_s(SLEEP); printf("Testing Scouting..."); - z_scouting_config_from(&_ret_sconfig, z_loan(_ret_config)); z_owned_closure_hello_t _ret_closure_hello; z_closure(&_ret_closure_hello, hello_handler, NULL, NULL); _ret_int8 = z_scout(z_move(_ret_sconfig), z_move(_ret_closure_hello)); diff --git a/tests/z_api_double_drop_test.c b/tests/z_api_double_drop_test.c index 48cd41e4b..5d5823493 100644 --- a/tests/z_api_double_drop_test.c +++ b/tests/z_api_double_drop_test.c @@ -42,19 +42,8 @@ void test_config(void) { assert(!z_check(config)); } -void test_scouting_config(void) { - z_owned_scouting_config_t config; - z_scouting_config_default(&config); - assert(z_check(config)); - z_drop(z_move(config)); - assert(!z_check(config)); - z_drop(z_move(config)); - assert(!z_check(config)); -} - int main(void) { test_keyexpr(); test_config(); - test_scouting_config(); return 0; } diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index 5494e283f..bb3bf6bc2 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -30,8 +30,6 @@ int main(void) { z_keyexpr_null(&keyexpr_null_1); z_owned_config_t config_null_1; z_config_null(&config_null_1); - z_owned_scouting_config_t scouting_config_null_1; - z_scouting_config_null(&scouting_config_null_1); z_owned_hello_t hello_null_1; z_hello_null(&hello_null_1); z_owned_closure_sample_t closure_sample_null_1; @@ -53,7 +51,6 @@ int main(void) { assert(!z_check(session_null_1)); assert(!z_check(keyexpr_null_1)); assert(!z_check(config_null_1)); - assert(!z_check(scouting_config_null_1)); assert(!z_check(hello_null_1)); assert(!z_check(str_null_1)); @@ -63,7 +60,6 @@ int main(void) { z_owned_session_t session_null_2; z_owned_keyexpr_t keyexpr_null_2; z_owned_config_t config_null_2; - z_owned_scouting_config_t scouting_config_null_2; z_owned_hello_t hello_null_2; z_owned_closure_sample_t closure_sample_null_2; z_owned_closure_query_t closure_query_null_2; @@ -75,7 +71,6 @@ int main(void) { z_null(&session_null_2); z_null(&keyexpr_null_2); z_null(&config_null_2); - z_null(&scouting_config_null_2); z_null(&hello_null_2); z_null(&closure_sample_null_2); z_null(&closure_query_null_2); @@ -123,7 +118,6 @@ int main(void) { assert(!z_check(session_null_2)); assert(!z_check(keyexpr_null_2)); assert(!z_check(config_null_2)); - assert(!z_check(scouting_config_null_2)); assert(!z_check(hello_null_2)); assert(!z_check(str_null_2)); @@ -134,7 +128,6 @@ int main(void) { z_drop(z_move(session_null_1)); z_drop(z_move(keyexpr_null_1)); z_drop(z_move(config_null_1)); - z_drop(z_move(scouting_config_null_1)); z_drop(z_move(hello_null_1)); z_drop(z_move(closure_sample_null_1)); z_drop(z_move(closure_query_null_1)); @@ -146,7 +139,6 @@ int main(void) { z_drop(z_move(session_null_2)); z_drop(z_move(keyexpr_null_2)); z_drop(z_move(config_null_2)); - z_drop(z_move(scouting_config_null_2)); z_drop(z_move(hello_null_2)); z_drop(z_move(closure_sample_null_2)); z_drop(z_move(closure_query_null_2));