From fec347dd35dc752bfaecc61ad8d9b071b3e3ba43 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 15:21:50 +0200 Subject: [PATCH 1/9] fix z_owned_closure_hello_t to accept z_loaned_hello_t --- examples/arduino/z_scout.ino | 4 ++-- examples/espidf/z_scout.c | 4 ++-- examples/freertos_plus_tcp/z_scout.c | 4 ++-- examples/mbed/z_scout.cpp | 4 ++-- examples/unix/c11/z_scout.c | 5 ++--- examples/unix/c99/z_scout.c | 5 ++--- examples/windows/z_scout.c | 4 ++-- examples/zephyr/z_scout.c | 2 +- include/zenoh-pico/api/primitives.h | 2 +- include/zenoh-pico/api/types.h | 8 ++++---- src/api/api.c | 9 ++++----- src/net/primitives.c | 3 ++- tests/z_api_alignment_test.c | 3 +-- tests/z_test_fragment_rx.c | 2 +- 14 files changed, 28 insertions(+), 31 deletions(-) diff --git a/examples/arduino/z_scout.ino b/examples/arduino/z_scout.ino index 2d168225c..bd8f15836 100644 --- a/examples/arduino/z_scout.ino +++ b/examples/arduino/z_scout.ino @@ -79,8 +79,8 @@ void fprinthello(const z_loaned_hello_t *hello) { Serial.println(" }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(z_hello_loan(hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(hello); Serial.println(""); (*(int *)context)++; } diff --git a/examples/espidf/z_scout.c b/examples/espidf/z_scout.c index e569d81ea..e1ce7b9c7 100644 --- a/examples/espidf/z_scout.c +++ b/examples/espidf/z_scout.c @@ -133,8 +133,8 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(stdout, z_hello_loan(hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; } diff --git a/examples/freertos_plus_tcp/z_scout.c b/examples/freertos_plus_tcp/z_scout.c index 4b62c1301..1d7ba13a3 100644 --- a/examples/freertos_plus_tcp/z_scout.c +++ b/examples/freertos_plus_tcp/z_scout.c @@ -67,8 +67,8 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(stdout, z_loan(*hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; } diff --git a/examples/mbed/z_scout.cpp b/examples/mbed/z_scout.cpp index 9f78c6be4..a8d305a22 100644 --- a/examples/mbed/z_scout.cpp +++ b/examples/mbed/z_scout.cpp @@ -75,8 +75,8 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(stdout, z_hello_loan(hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; } diff --git a/examples/unix/c11/z_scout.c b/examples/unix/c11/z_scout.c index a39bd2226..be0be84fa 100644 --- a/examples/unix/c11/z_scout.c +++ b/examples/unix/c11/z_scout.c @@ -65,11 +65,10 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(stdout, z_loan(*hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; - z_drop(hello); } void drop(void *context) { diff --git a/examples/unix/c99/z_scout.c b/examples/unix/c99/z_scout.c index d94c278f4..d383bc335 100644 --- a/examples/unix/c99/z_scout.c +++ b/examples/unix/c99/z_scout.c @@ -64,11 +64,10 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(stdout, z_hello_loan(hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; - z_hello_drop(hello); } void drop(void *context) { diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index dfd993637..efffdc993 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -64,8 +64,8 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { - fprinthello(stdout, z_loan(*hello)); +void callback(const z_loaned_hello_t *hello, void *context) { + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; } diff --git a/examples/zephyr/z_scout.c b/examples/zephyr/z_scout.c index 06c8277b5..7872e73ba 100644 --- a/examples/zephyr/z_scout.c +++ b/examples/zephyr/z_scout.c @@ -61,7 +61,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, " }"); } -void callback(z_owned_hello_t *hello, void *context) { +void callback(const z_loaned_hello_t *hello, void *context) { fprinthello(stdout, z_hello_loan(hello)); fprintf(stdout, "\n"); (*(int *)context)++; diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 97b1debf4..bae7ab894 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1011,7 +1011,7 @@ int8_t z_closure_owned_reply(z_owned_closure_owned_reply_t *closure, z_owned_rep * Return: * The hello closure. */ -int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_owned_hello_handler_t call, z_dropper_handler_t drop, +int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_loaned_hello_handler_t call, z_dropper_handler_t drop, void *context); /** diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index b5a0b617e..ac4797f1f 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -588,7 +588,7 @@ typedef struct { void z_closure_owned_reply_call(const z_owned_closure_owned_reply_t *closure, z_owned_reply_t *reply); -typedef void (*z_owned_hello_handler_t)(z_owned_hello_t *hello, void *arg); +typedef void (*z_loaned_hello_handler_t)(const z_loaned_hello_t *hello, void *arg); /** * Represents the Zenoh ID callback closure. @@ -597,18 +597,18 @@ typedef void (*z_owned_hello_handler_t)(z_owned_hello_t *hello, void *arg); * * Members: * void *context: a pointer to an arbitrary state. - * z_owned_hello_handler_t call: `void (*z_owned_hello_handler_t)(const z_owned_hello_t *hello, void *arg)` is the + * z_loaned_hello_handler_t call: `void (*z_loaned_hello_handler_t)(const z_loaned_hello_t *hello, void *arg)` is the * callback function. * z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed. * void *context: a pointer to an arbitrary state. */ typedef struct { void *context; - z_owned_hello_handler_t call; + z_loaned_hello_handler_t call; z_dropper_handler_t drop; } z_owned_closure_hello_t; -void z_closure_hello_call(const z_owned_closure_hello_t *closure, z_owned_hello_t *hello); +void z_closure_hello_call(const z_owned_closure_hello_t *closure, const z_loaned_hello_t *hello); typedef void (*z_id_handler_t)(const z_id_t *id, void *arg); diff --git a/src/api/api.c b/src/api/api.c index 1072c95b9..c439ed142 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -657,7 +657,7 @@ void z_closure_owned_reply_call(const z_owned_closure_owned_reply_t *closure, z_ } } -void z_closure_hello_call(const z_owned_closure_hello_t *closure, z_owned_hello_t *hello) { +void z_closure_hello_call(const z_owned_closure_hello_t *closure, const z_loaned_hello_t *hello) { if (closure->call != NULL) { (closure->call)(hello, closure->context); } @@ -781,18 +781,17 @@ OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_query_t, closure_owned_query, z_ow OWNED_FUNCTIONS_CLOSURE(z_owned_closure_reply_t, closure_reply, _z_reply_handler_t, z_dropper_handler_t) OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_reply_t, closure_owned_reply, z_owned_reply_handler_t, z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello, z_owned_hello_handler_t, z_dropper_handler_t) +OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello, z_loaned_hello_handler_t, z_dropper_handler_t) OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid, z_id_handler_t, z_dropper_handler_t) /************* Primitives **************/ typedef struct __z_hello_handler_wrapper_t { - z_owned_hello_handler_t user_call; + z_loaned_hello_handler_t user_call; void *ctx; } __z_hello_handler_wrapper_t; void __z_hello_handler(_z_hello_t *hello, __z_hello_handler_wrapper_t *wrapped_ctx) { - z_owned_hello_t ohello = {._val = hello}; - wrapped_ctx->user_call(&ohello, wrapped_ctx->ctx); + wrapped_ctx->user_call(hello, wrapped_ctx->ctx); } int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callback) { diff --git a/src/net/primitives.c b/src/net/primitives.c index c0392e806..35476ccf0 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -44,7 +44,8 @@ void _z_scout(const z_what_t what, const _z_id_t zid, const char *locator, const while (hellos != NULL) { _z_hello_t *hello = NULL; hellos = _z_hello_list_pop(hellos, &hello); - (*callback)(hello, arg_call); // callback takes ownership of hello + (*callback)(hello, arg_call); + _z_hello_free(&hello); } if (dropper != NULL) { diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index c63dce561..79ba3add4 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -53,11 +53,10 @@ void zid_handler(const z_id_t *id, void *arg) { } volatile unsigned int hellos = 0; -void hello_handler(z_owned_hello_t *hello, void *arg) { +void hello_handler(const z_loaned_hello_t *hello, void *arg) { (void)(arg); printf("%s\n", __func__); hellos++; - z_drop(hello); } volatile unsigned int queries = 0; diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index 155e2894c..438694414 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) { } // Declare subscriber z_owned_closure_sample_t callback; - z_closure(&callback, data_handler); + z_closure(&callback, data_handler, NULL, NULL); z_owned_subscriber_t sub; z_view_keyexpr_t ke; z_view_keyexpr_from_string(&ke, keyexpr); From 99c24db34ec3d22bf3c83d016fd69788a32ad6d3 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 15:32:16 +0200 Subject: [PATCH 2/9] remove unneeded NULLs --- tests/z_test_fragment_rx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index 438694414..155e2894c 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) { } // Declare subscriber z_owned_closure_sample_t callback; - z_closure(&callback, data_handler, NULL, NULL); + z_closure(&callback, data_handler); z_owned_subscriber_t sub; z_view_keyexpr_t ke; z_view_keyexpr_from_string(&ke, keyexpr); From ae8db8bd3e3a4c0f7555b15071db6dbbeaf395fd Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 15:34:23 +0200 Subject: [PATCH 3/9] fix example --- examples/zephyr/z_scout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/zephyr/z_scout.c b/examples/zephyr/z_scout.c index 7872e73ba..32c9a5660 100644 --- a/examples/zephyr/z_scout.c +++ b/examples/zephyr/z_scout.c @@ -62,7 +62,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { } void callback(const z_loaned_hello_t *hello, void *context) { - fprinthello(stdout, z_hello_loan(hello)); + fprinthello(stdout, hello); fprintf(stdout, "\n"); (*(int *)context)++; } From 713fdb1ac4475b51f2d93dc3a077387149d5762e Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 15:37:46 +0200 Subject: [PATCH 4/9] void unused arg --- tests/z_api_alignment_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 79ba3add4..8ed72b264 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -54,6 +54,7 @@ void zid_handler(const z_id_t *id, void *arg) { volatile unsigned int hellos = 0; void hello_handler(const z_loaned_hello_t *hello, void *arg) { + (void)hello; (void)(arg); printf("%s\n", __func__); hellos++; From 2b6dede1929ca83e360fab5005cf25c56e5feb3f Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 16:55:47 +0200 Subject: [PATCH 5/9] renamed value -> reply_err; updated macros for zenoh-cpp; --- docs/api.rst | 11 +- examples/arduino/z_queryable.ino | 2 +- examples/espidf/z_queryable.c | 2 +- examples/freertos_plus_tcp/z_queryable.c | 2 +- examples/mbed/z_queryable.cpp | 2 +- examples/unix/c11/z_queryable.c | 2 +- examples/unix/c11/z_queryable_attachment.c | 2 +- examples/unix/c11/z_queryable_channel.c | 2 +- examples/unix/c99/z_queryable.c | 2 +- examples/windows/z_queryable.c | 2 +- include/zenoh-pico/api/macros.h | 349 +++++++++++++-------- include/zenoh-pico/api/primitives.h | 41 ++- include/zenoh-pico/api/types.h | 10 +- include/zenoh-pico/utils/result.h | 1 + src/api/api.c | 11 +- 15 files changed, 277 insertions(+), 164 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 60c969bd5..22e560c91 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -109,9 +109,9 @@ TODO: owned type description Represents the encoding of a payload, in a MIME-like format. -.. c:type:: z_owned_value_t +.. c:type:: z_owned_reply_err_t - Represents a Zenoh value. + Represents a Zenoh reply error value. .. c:type:: z_owned_sample_t @@ -287,9 +287,11 @@ Primitives .. autocfunction:: primitives.h::z_encoding_check .. autocfunction:: primitives.h::z_encoding_drop .. autocfunction:: primitives.h::z_encoding_loan +.. autocfunction:: primitives.h::z_encoding_loan_mut .. autocfunction:: primitives.h::z_encoding_move .. autocfunction:: primitives.h::z_encoding_null -.. autocfunction:: primitives.h::z_value_payload +.. autocfunction:: primitives.h::z_reply_err_payload +.. autocfunction:: primitives.h::z_reply_err_encoding .. autocfunction:: primitives.h::z_slice_data .. autocfunction:: primitives.h::z_slice_len .. autocfunction:: primitives.h::z_bytes_deserialize_into_int8 @@ -326,7 +328,8 @@ Primitives .. autocfunction:: primitives.h::z_query_consolidation_monotonic .. autocfunction:: primitives.h::z_query_consolidation_none .. autocfunction:: primitives.h::z_query_parameters -.. autocfunction:: primitives.h::z_query_value +.. autocfunction:: primitives.h::z_query_payload +.. autocfunction:: primitives.h::z_query_encoding .. autocfunction:: primitives.h::z_query_attachment .. autocfunction:: primitives.h::z_query_keyexpr .. autocfunction:: primitives.h::z_closure_sample diff --git a/examples/arduino/z_queryable.ino b/examples/arduino/z_queryable.ino index f3d8161c6..b9086e8fc 100644 --- a/examples/arduino/z_queryable.ino +++ b/examples/arduino/z_queryable.ino @@ -44,7 +44,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) { // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_string_loan(&payload_string)) > 1) { Serial.print(" with value '"); Serial.print(z_string_data(z_string_loan(&payload_string))); diff --git a/examples/espidf/z_queryable.c b/examples/espidf/z_queryable.c index 6d08dc624..bd16db8e0 100644 --- a/examples/espidf/z_queryable.c +++ b/examples/espidf/z_queryable.c @@ -111,7 +111,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index 9110eb380..185cabdc5 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -39,7 +39,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index d00cee73d..8262829cf 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -41,7 +41,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (int)z_view_string_loan(&pred)->len, z_view_string_loan(&pred)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_string_loan(&payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_string_loan(&payload_string))); } diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 3e7a273f9..394b6cd0e 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -33,7 +33,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/examples/unix/c11/z_queryable_attachment.c b/examples/unix/c11/z_queryable_attachment.c index a000a58c0..ad3d7f693 100644 --- a/examples/unix/c11/z_queryable_attachment.c +++ b/examples/unix/c11/z_queryable_attachment.c @@ -111,7 +111,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/examples/unix/c11/z_queryable_channel.c b/examples/unix/c11/z_queryable_channel.c index 181e32661..42c36f62e 100644 --- a/examples/unix/c11/z_queryable_channel.c +++ b/examples/unix/c11/z_queryable_channel.c @@ -108,7 +108,7 @@ int main(int argc, char **argv) { (int)z_loan(params)->len, z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(z_loan(query))), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(z_loan(query)), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index 88e2ae92b..22f1e4cd3 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -32,7 +32,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { (int)z_view_string_loan(¶ms)->len, z_view_string_loan(¶ms)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_string_loan(&payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_string_loan(&payload_string))); } diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index 98d84b108..294afd37e 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -32,7 +32,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 851f6f525..31df88947 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -39,7 +39,9 @@ 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, \ + z_owned_queryable_t : z_queryable_loan, \ z_owned_reply_t : z_reply_loan, \ z_owned_hello_t : z_hello_loan, \ z_owned_string_t : z_string_loan, \ @@ -49,7 +51,8 @@ z_owned_query_t : z_query_loan, \ z_owned_slice_t : z_slice_loan, \ z_owned_bytes_t : z_bytes_loan, \ - z_owned_encoding_t : z_encoding_loan \ + z_owned_encoding_t : z_encoding_loan, \ + z_owned_reply_err_t : z_reply_err_loan \ )(&x) #define z_loan_mut(x) _Generic((x), \ @@ -58,6 +61,7 @@ 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, \ z_owned_reply_t : z_reply_loan_mut, \ z_owned_hello_t : z_hello_loan_mut, \ z_owned_string_t : z_string_loan_mut, \ @@ -66,7 +70,8 @@ z_owned_sample_t : z_sample_loan_mut, \ z_owned_query_t : z_query_loan_mut, \ z_owned_slice_t : z_slice_loan_mut, \ - z_owned_bytes_t : z_bytes_loan_mut \ + z_owned_bytes_t : z_bytes_loan_mut, \ + z_owned_reply_err_t : z_reply_err_loan_mut \ )(&x) /** * Defines a generic function for dropping any of the ``z_owned_X_t`` types. @@ -102,7 +107,8 @@ z_owned_query_ring_channel_t * : z_query_ring_channel_drop, \ z_owned_query_fifo_channel_t * : z_query_fifo_channel_drop, \ z_owned_reply_ring_channel_t * : z_reply_ring_channel_drop, \ - z_owned_reply_fifo_channel_t * : z_reply_fifo_channel_drop \ + z_owned_reply_fifo_channel_t * : z_reply_fifo_channel_drop, \ + z_owned_reply_err_t : z_reply_err_drop \ )(x) /** @@ -118,7 +124,7 @@ #define z_check(x) _Generic((x), \ z_owned_keyexpr_t : z_keyexpr_check, \ z_view_keyexpr_t : z_keyexpr_is_initialized, \ - z_owned_value_t : z_value_check, \ + 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, \ @@ -191,7 +197,8 @@ z_owned_query_ring_channel_t : z_query_ring_channel_move, \ z_owned_query_fifo_channel_t : z_query_fifo_channel_move, \ z_owned_reply_ring_channel_t : z_reply_ring_channel_move, \ - z_owned_reply_fifo_channel_t : z_reply_fifo_channel_move \ + z_owned_reply_fifo_channel_t : z_reply_fifo_channel_move, \ + z_owned_reply_err_t : z_reply_err_move \ )(&x) /** @@ -210,6 +217,10 @@ z_owned_subscriber_t : z_subscriber_clone, \ z_owned_publisher_t : z_publisher_clone, \ z_owned_queryable_t : z_queryable_clone, \ + z_owned_query_t : z_query_clone, \ + z_owned_sample_t : z_sample_clone, \ + z_owned_encoding_t : z_encoding_clone, \ + z_owned_reply_err_t : z_reply_err_clone, \ z_owned_reply_t : z_reply_clone, \ z_owned_hello_t : z_hello_clone, \ z_owned_string_t : z_string_clone, \ @@ -244,7 +255,8 @@ z_owned_closure_hello_t * : z_closure_hello_null, \ z_owned_closure_zid_t * : z_closure_zid_null, \ z_owned_sample_t * : z_sample_null, \ - z_owned_encoding_t * : z_encoding_null \ + z_owned_encoding_t * : z_encoding_null, \ + z_owned_reply_err_t * : z_reply_err_null \ )(x) // clang-format on @@ -275,126 +287,75 @@ // z_loan definition -template struct zenoh_loan_type { typedef T type; }; -template inline typename zenoh_loan_type::type z_loan(const T&); - -template <> struct zenoh_loan_type { typedef const z_loaned_keyexpr_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_keyexpr_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_config_t* type; }; -template <> struct zenoh_loan_type { const typedef z_loaned_scouting_config_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_session_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_publisher_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_reply_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_hello_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_string_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_string_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_string_array_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_sample_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_query_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_slice_t* type; }; -template <> struct zenoh_loan_type { typedef const z_loaned_bytes_t* type; }; - -template <> inline const z_loaned_keyexpr_t* z_loan(const z_owned_keyexpr_t& x) { return z_keyexpr_loan(&x); } -template <> inline const z_loaned_keyexpr_t* z_loan(const z_view_keyexpr_t& x) { return z_view_keyexpr_loan(&x); } -template <> inline const z_loaned_config_t* z_loan(const z_owned_config_t& x) { return z_config_loan(&x); } -template <> inline const z_loaned_scouting_config_t* z_loan(const z_owned_scouting_config_t& x) { return z_scouting_config_loan(&x); } -template <> inline const z_loaned_session_t* z_loan(const z_owned_session_t& x) { return z_session_loan(&x); } -template <> inline const z_loaned_publisher_t* z_loan(const z_owned_publisher_t& x) { return z_publisher_loan(&x); } -template <> inline const z_loaned_reply_t* z_loan(const z_owned_reply_t& x) { return z_reply_loan(&x); } -template <> inline const z_loaned_hello_t* z_loan(const z_owned_hello_t& x) { return z_hello_loan(&x); } -template <> inline const z_loaned_string_t* z_loan(const z_owned_string_t& x) { return z_string_loan(&x); } -template <> inline const z_loaned_string_t* z_loan(const z_view_string_t& x) { return z_view_string_loan(&x); } -template <> inline const z_loaned_string_array_t* z_loan(const z_owned_string_array_t& x) { return z_string_array_loan(&x); } -template <> inline const z_loaned_sample_t* z_loan(const z_owned_sample_t& x) { return z_sample_loan(&x); } -template <> inline const z_loaned_query_t* z_loan(const z_owned_query_t& x) { return z_query_loan(&x); } -template <> inline const z_loaned_slice_t* z_loan(const z_owned_slice_t& x) { return z_slice_loan(&x); } -template <> inline const z_loaned_bytes_t* z_loan(const z_owned_bytes_t& x) { return z_bytes_loan(&x); } +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); } +inline const z_loaned_queryable_t* z_loan(const z_owned_queryable_t& x) { return z_queryable_loan(&x); } +inline const z_loaned_reply_t* z_loan(const z_owned_reply_t& x) { return z_reply_loan(&x); } +inline const z_loaned_hello_t* z_loan(const z_owned_hello_t& x) { return z_hello_loan(&x); } +inline const z_loaned_string_t* z_loan(const z_owned_string_t& x) { return z_string_loan(&x); } +inline const z_loaned_string_t* z_loan(const z_view_string_t& x) { return z_view_string_loan(&x); } +inline const z_loaned_string_array_t* z_loan(const z_owned_string_array_t& x) { return z_string_array_loan(&x); } +inline const z_loaned_sample_t* z_loan(const z_owned_sample_t& x) { return z_sample_loan(&x); } +inline const z_loaned_query_t* z_loan(const z_owned_query_t& x) { return z_query_loan(&x); } +inline const z_loaned_slice_t* z_loan(const z_owned_slice_t& x) { return z_slice_loan(&x); } +inline const z_loaned_bytes_t* z_loan(const z_owned_bytes_t& x) { return z_bytes_loan(&x); } +inline const z_loaned_encoding_t* z_loan(const z_owned_encoding_t& x) { return z_encoding_loan(&x); } +inline const z_loaned_reply_err_t* z_loan(const z_owned_reply_err_t& x) { return z_reply_err_loan(&x); } // z_loan_mut definition - -template struct zenoh_loan_mut_type { typedef T type; }; -template inline typename zenoh_loan_mut_type::type z_loan_mut(T&); - -template <> struct zenoh_loan_mut_type { typedef z_loaned_keyexpr_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_keyexpr_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_config_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_scouting_config_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_session_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_publisher_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_reply_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_hello_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_string_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_string_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_string_array_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_sample_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_query_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_slice_t* type; }; -template <> struct zenoh_loan_mut_type { typedef z_loaned_bytes_t* type; }; - -template <> inline z_loaned_keyexpr_t* z_loan_mut(z_owned_keyexpr_t& x) { return z_keyexpr_loan_mut(&x); } -template <> inline z_loaned_keyexpr_t* z_loan_mut(z_view_keyexpr_t& x) { return z_view_keyexpr_loan_mut(&x); } -template <> inline z_loaned_config_t* z_loan_mut(z_owned_config_t& x) { return z_config_loan_mut(&x); } -template <> inline z_loaned_scouting_config_t* z_loan_mut(z_owned_scouting_config_t& x) { return z_scouting_config_loan_mut(&x); } -template <> inline z_loaned_session_t* z_loan_mut(z_owned_session_t& x) { return z_session_loan_mut(&x); } -template <> inline z_loaned_publisher_t* z_loan_mut(z_owned_publisher_t& x) { return z_publisher_loan_mut(&x); } -template <> inline z_loaned_reply_t* z_loan_mut(z_owned_reply_t& x) { return z_reply_loan_mut(&x); } -template <> inline z_loaned_hello_t* z_loan_mut(z_owned_hello_t& x) { return z_hello_loan_mut(&x); } -template <> inline z_loaned_string_t* z_loan_mut(z_owned_string_t& x) { return z_string_loan_mut(&x); } -template <> inline z_loaned_string_t* z_loan_mut(z_view_string_t& x) { return z_view_string_loan_mut(&x); } -template <> inline z_loaned_string_array_t* z_loan_mut(z_owned_string_array_t& x) { return z_string_array_loan_mut(&x); } -template <> inline z_loaned_sample_t* z_loan_mut(z_owned_sample_t& x) { return z_sample_loan_mut(&x); } -template <> inline z_loaned_query_t* z_loan_mut(z_owned_query_t& x) { return z_query_loan_mut(&x); } -template <> inline z_loaned_slice_t* z_loan_mut(z_owned_slice_t& x) { return z_slice_loan_mut(&x); } -template <> inline z_loaned_bytes_t* z_loan_mut(z_owned_bytes_t& x) { return z_bytes_loan_mut(&x); } +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); } +inline z_loaned_reply_t* z_loan_mut(z_owned_reply_t& x) { return z_reply_loan_mut(&x); } +inline z_loaned_hello_t* z_loan_mut(z_owned_hello_t& x) { return z_hello_loan_mut(&x); } +inline z_loaned_string_t* z_loan_mut(z_owned_string_t& x) { return z_string_loan_mut(&x); } +inline z_loaned_string_t* z_loan_mut(z_view_string_t& x) { return z_view_string_loan_mut(&x); } +inline z_loaned_string_array_t* z_loan_mut(z_owned_string_array_t& x) { return z_string_array_loan_mut(&x); } +inline z_loaned_sample_t* z_loan_mut(z_owned_sample_t& x) { return z_sample_loan_mut(&x); } +inline z_loaned_query_t* z_loan_mut(z_owned_query_t& x) { return z_query_loan_mut(&x); } +inline z_loaned_slice_t* z_loan_mut(z_owned_slice_t& x) { return z_slice_loan_mut(&x); } +inline z_loaned_bytes_t* z_loan_mut(z_owned_bytes_t& x) { return z_bytes_loan_mut(&x); } +inline z_loaned_encoding_t* z_loan(z_owned_encoding_t& x) { return z_encoding_loan_mut(&x); } +inline z_loaned_reply_err_t* z_loan_mut(z_owned_reply_err_t& x) { return z_reply_err_loan_mut(&x); } // z_drop definition - -template struct zenoh_drop_type { typedef T type; }; -template inline typename zenoh_drop_type::type z_drop(T*); - -template<> struct zenoh_drop_type { typedef int8_t type; }; -template<> struct zenoh_drop_type { typedef int8_t type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef int8_t type; }; -template<> struct zenoh_drop_type { typedef int8_t type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef void type; }; - -template<> inline int8_t z_drop(z_owned_session_t* v) { return z_close(v); } -template<> inline int8_t z_drop(z_owned_publisher_t* v) { return z_undeclare_publisher(v); } -template<> inline void z_drop(z_owned_keyexpr_t* v) { z_keyexpr_drop(v); } -template<> inline void z_drop(z_owned_config_t* v) { z_config_drop(v); } -template<> inline void z_drop(z_owned_scouting_config_t* v) { z_scouting_config_drop(v); } -template<> inline int8_t z_drop(z_owned_subscriber_t* v) { return z_undeclare_subscriber(v); } -template<> inline int8_t z_drop(z_owned_queryable_t* v) { return z_undeclare_queryable(v); } -template<> inline void z_drop(z_owned_reply_t* v) { z_reply_drop(v); } -template<> inline void z_drop(z_owned_hello_t* v) { z_hello_drop(v); } -template<> inline void z_drop(z_owned_string_t* v) { z_string_drop(v); } -template<> inline void z_drop(z_owned_closure_sample_t* v) { z_closure_sample_drop(v); } -template<> inline void z_drop(z_owned_closure_query_t* v) { z_closure_query_drop(v); } -template<> inline void z_drop(z_owned_closure_reply_t* v) { z_closure_reply_drop(v); } -template<> inline void z_drop(z_owned_closure_hello_t* v) { z_closure_hello_drop(v); } -template<> inline void z_drop(z_owned_closure_zid_t* v) { z_closure_zid_drop(v); } -template<> inline void z_drop(z_owned_sample_ring_channel_t* v) { z_sample_ring_channel_drop(v); } -template<> inline void z_drop(z_owned_sample_fifo_channel_t* v) { z_sample_fifo_channel_drop(v); } -template<> inline void z_drop(z_owned_query_ring_channel_t* v) { z_query_ring_channel_drop(v); } -template<> inline void z_drop(z_owned_query_fifo_channel_t* v) { z_query_fifo_channel_drop(v); } -template<> inline void z_drop(z_owned_reply_ring_channel_t* v) { z_reply_ring_channel_drop(v); } -template<> inline void z_drop(z_owned_reply_fifo_channel_t* v) { z_reply_fifo_channel_drop(v); } +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); } +inline void z_drop(z_owned_hello_t* v) { z_hello_drop(v); } +inline void z_drop(z_owned_string_t* v) { z_string_drop(v); } +inline void z_drop(z_owned_slice_t* v) { z_slice_drop(v); } +inline void z_drop(z_owned_string_array_t* v) { z_string_array_drop(v); } +inline void z_drop(z_owned_sample_t* v) { z_sample_drop(v); } +inline void z_drop(z_owned_query_t* v) { z_query_drop(v); } +inline void z_drop(z_owned_bytes_t* v) { z_bytes_drop(v); } +inline void z_drop(z_owned_encoding_t* v) { z_encoding_drop(v); } +inline void z_drop(z_owned_reply_err_t* v) { z_reply_err_drop(v); } +inline void z_drop(z_owned_closure_sample_t* v) { z_closure_sample_drop(v); } +inline void z_drop(z_owned_closure_query_t* v) { z_closure_query_drop(v); } +inline void z_drop(z_owned_closure_reply_t* v) { z_closure_reply_drop(v); } +inline void z_drop(z_owned_closure_hello_t* v) { z_closure_hello_drop(v); } +inline void z_drop(z_owned_closure_zid_t* v) { z_closure_zid_drop(v); } +inline void z_drop(z_owned_sample_ring_channel_t* v) { z_sample_ring_channel_drop(v); } +inline void z_drop(z_owned_sample_fifo_channel_t* v) { z_sample_fifo_channel_drop(v); } +inline void z_drop(z_owned_query_ring_channel_t* v) { z_query_ring_channel_drop(v); } +inline void z_drop(z_owned_query_fifo_channel_t* v) { z_query_fifo_channel_drop(v); } +inline void z_drop(z_owned_reply_ring_channel_t* v) { z_reply_ring_channel_drop(v); } +inline void z_drop(z_owned_reply_fifo_channel_t* v) { z_reply_fifo_channel_drop(v); } // z_null definition @@ -405,9 +366,14 @@ 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); } +inline void z_null(z_owned_sample_t* v) { z_sample_null(v); } inline void z_null(z_owned_reply_t* v) { z_reply_null(v); } inline void z_null(z_owned_hello_t* v) { z_hello_null(v); } inline void z_null(z_owned_string_t* v) { z_string_null(v); } +inline void z_null(z_owned_bytes_t* v) { z_bytes_null(v); } +inline void z_null(z_owned_encoding_t* v) { z_encoding_null(v); } +inline void z_null(z_owned_reply_err_t* v) { z_reply_err_null(v); } inline void z_null(z_owned_closure_sample_t* v) { z_closure_sample_null(v); } inline void z_null(z_owned_closure_query_t* v) { z_closure_query_null(v); } inline void z_null(z_owned_closure_reply_t* v) { z_closure_reply_null(v); } @@ -422,9 +388,13 @@ inline bool z_check(const z_owned_scouting_config_t& v) { return z_scouting_conf 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); } +inline bool z_check(const z_owned_query_t& v) { return z_query_check(&v); } inline bool z_check(const z_owned_hello_t& v) { return z_hello_check(&v); } inline bool z_check(const z_owned_string_t& v) { return z_string_check(&v); } inline bool z_check(const z_owned_sample_t& v) { return z_sample_check(&v); } +inline bool z_check(const z_owned_bytes_t& v) { return z_bytes_check(&v); } +inline bool z_check(const z_owned_encoding_t& v) { return z_encoding_check(&v); } +inline bool z_check(const z_owned_reply_err_t& v) { return z_reply_err_check(&v); } // z_call definition @@ -436,22 +406,137 @@ inline void z_call(const z_owned_closure_reply_t &closure, const z_loaned_reply_ { z_closure_reply_call(&closure, reply); } inline void z_call(const z_owned_closure_owned_reply_t &closure, z_owned_reply_t *reply) { z_closure_owned_reply_call(&closure, reply); } -inline void z_call(const z_owned_closure_hello_t &closure, z_owned_hello_t *hello) +inline void z_call(const z_owned_closure_hello_t &closure, const z_loaned_hello_t *hello) { z_closure_hello_call(&closure, hello); } inline void z_call(const z_owned_closure_zid_t &closure, const z_id_t *zid) { z_closure_zid_call(&closure, zid); } -// clang-format on -#define _z_closure_overloader(closure, callback, dropper, ctx, ...) \ - do { \ - (closure)->call = callback; \ - (closure)->drop = dropper; \ - (closure)->context = const_cast(static_cast(ctx)); \ - } while (0); +inline void z_closure( + z_owned_closure_hello_t* closure, + void (*call)(const z_loaned_hello_t*, void*), + void (*drop)(void*) = NULL, + void *context = NULL) { + closure->context = context; + closure->drop = drop; + closure->call = call; +}; +inline void z_closure( + z_owned_closure_owned_query_t* closure, + void (*call)(z_owned_query_t*, void*), + void (*drop)(void*) = NULL, + void *context = NULL) { + closure->context = context; + closure->drop = drop; + closure->call = call; +}; +inline void z_closure( + z_owned_closure_query_t* closure, + void (*call)(const z_loaned_query_t*, void*), + void (*drop)(void*) = NULL, + void *context = NULL) { + closure->context = context; + closure->drop = drop; + closure->call = call; +}; +inline void z_closure( + z_owned_closure_reply_t* closure, + void (*call)(const z_loaned_reply_t*, void*), + void (*drop)(void*) = NULL, + void *context = NULL) { + closure->context = context; + closure->drop = drop; + closure->call = call; +}; +inline void z_closure( + z_owned_closure_sample_t* closure, + void (*call)(const z_loaned_sample_t*, void*), + void (*drop)(void*) = NULL, + void *context = NULL) { + closure->context = context; + closure->drop = drop; + closure->call = call; +}; +inline void z_closure( + z_owned_closure_zid_t* closure, + void (*call)(const z_id_t*, void*), + void (*drop)(void*) = NULL, + void *context = NULL) { + closure->context = context; + closure->drop = drop; + closure->call = call; +}; -#define z_closure(...) _z_closure_overloader(__VA_ARGS__, NULL, NULL) +// clang-format on -#define z_move(x) (&x) +inline z_owned_bytes_t* z_move(z_owned_bytes_t& x) { return z_bytes_move(&x); }; +inline z_owned_closure_hello_t* z_move(z_owned_closure_hello_t& closure) { return z_closure_hello_move(&closure); }; +inline z_owned_closure_owned_query_t* z_move(z_owned_closure_owned_query_t& closure) { return z_closure_owned_query_move(&closure); }; +inline z_owned_closure_query_t* z_move(z_owned_closure_query_t& closure) { return z_closure_query_move(&closure); }; +inline z_owned_closure_reply_t* z_move(z_owned_closure_reply_t& closure) { return z_closure_reply_move(&closure); }; +inline z_owned_closure_sample_t* z_move(z_owned_closure_sample_t& closure) { return z_closure_sample_move(&closure); }; +inline z_owned_closure_zid_t* z_move(z_owned_closure_zid_t& closure) { return z_closure_zid_move(&closure); }; +inline z_owned_config_t* z_move(z_owned_config_t& x) { return z_config_move(&x); }; +inline z_owned_encoding_t* z_move(z_owned_encoding_t& x) { return z_encoding_move(&x); }; +inline z_owned_reply_err_t* z_move(z_owned_reply_err_t& x) { return z_reply_err_move(&x); }; +inline z_owned_hello_t* z_move(z_owned_hello_t& x) { return z_hello_move(&x); }; +inline z_owned_keyexpr_t* z_move(z_owned_keyexpr_t& x) { return z_keyexpr_move(&x); }; +inline z_owned_publisher_t* z_move(z_owned_publisher_t& x) { return z_publisher_move(&x); }; +inline z_owned_query_t* z_move(z_owned_query_t& x) { return z_query_move(&x); }; +inline z_owned_queryable_t* z_move(z_owned_queryable_t& x) { return z_queryable_move(&x); }; +inline z_owned_reply_t* z_move(z_owned_reply_t& x) { return z_reply_move(&x); }; +inline z_owned_sample_t* z_move(z_owned_sample_t& x) { return z_sample_move(&x); }; +inline z_owned_session_t* z_move(z_owned_session_t& x) { return z_session_move(&x); }; +inline z_owned_slice_t* z_move(z_owned_slice_t& x) { return z_slice_move(&x); }; +inline z_owned_string_array_t* z_move(z_owned_string_array_t& x) { return z_string_array_move(&x); }; +inline z_owned_string_t* z_move(z_owned_string_t& x) { return z_string_move(&x); }; +inline z_owned_subscriber_t* z_move(z_owned_subscriber_t& x) { return z_subscriber_move(&x); }; + +template struct z_loaned_to_owned_type_t {}; +template struct z_owned_to_loaned_type_t {}; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_bytes_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_bytes_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_hello_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_hello_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_owned_query_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_owned_query_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_query_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_query_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_reply_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_reply_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_sample_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_sample_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_zid_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_zid_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_config_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_config_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_encoding_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_encoding_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_reply_err_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_reply_err_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_hello_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_hello_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_keyexpr_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_keyexpr_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_publisher_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_publisher_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_query_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_query_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_queryable_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_queryable_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_reply_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_reply_t type; };; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_sample_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_sample_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_session_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_session_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_slice_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_slice_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_string_array_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_string_array_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_string_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_string_t type; }; +template<> struct z_loaned_to_owned_type_t { typedef z_owned_subscriber_t type; }; +template<> struct z_owned_to_loaned_type_t { typedef z_loaned_subscriber_t type; }; #endif diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index bae7ab894..b433a697a 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -385,6 +385,18 @@ void z_encoding_drop(z_owned_encoding_t *encoding); */ const z_loaned_encoding_t *z_encoding_loan(const z_owned_encoding_t *encoding); + +/** + * Gets a loaned version of a :c:type:`z_owned_encoding_t`. + * + * Parameters: + * encoding: Pointer to a :c:type:`z_owned_encoding_t` to loan. + * + * Return: + * Pointer to the loaned version. + */ +z_loaned_encoding_t *z_encoding_loan_mut(z_owned_encoding_t *encoding); + /** * Gets a moved version of a :c:type:`z_owned_encoding_t`. * @@ -408,15 +420,15 @@ z_owned_encoding_t *z_encoding_move(z_owned_encoding_t *encoding); int8_t z_encoding_null(z_owned_encoding_t *encoding); /** - * Gets the bytes data from a value payload by aliasing it. + * Gets the bytes data from a reply error payload by aliasing it. * * Parameters: - * value: Pointer to a :c:type:`z_loaned_value_t` to get data from. + * reply_err: Pointer to a :c:type:`z_loaned_reply_err_t` to get data from. * * Return: * Pointer to the data as a :c:type:`z_loaned_bytes_t`. */ -const z_loaned_bytes_t *z_value_payload(const z_loaned_value_t *value); +const z_loaned_bytes_t *z_reply_err_payload(const z_loaned_reply_err_t *reply_err); /** * Gets date pointer of a bytes array. @@ -877,15 +889,26 @@ z_query_consolidation_t z_query_consolidation_none(void); void z_query_parameters(const z_loaned_query_t *query, z_view_string_t *parameters); /** - * Gets a query value payload by aliasing it. + * Gets a query payload by aliasing it. + * + * Parameters: + * query: Pointer to the :c:type:`z_loaned_query_t` to get the value from. + * + * Return: + * Pointer to the payload as a :c:type:`z_loaned_bytes_t`. + */ +const z_loaned_bytes_t *z_query_payload(const z_loaned_query_t *query); + +/** + * Gets a query encoding by aliasing it. * * Parameters: * query: Pointer to the :c:type:`z_loaned_query_t` to get the value from. * * Return: - * Pointer to the value payload as a :c:type:`z_loaned_value_t`. + * Pointer to the encoding as a :c:type:`z_loaned_encoding_t`. */ -const z_loaned_value_t *z_query_value(const z_loaned_query_t *query); +const z_loaned_encoding_t *z_query_encoding(const z_loaned_query_t *query); /** * Gets a query attachment value by aliasing it. @@ -1053,7 +1076,7 @@ _OWNED_FUNCTIONS(z_loaned_sample_t, z_owned_sample_t, sample) _OWNED_FUNCTIONS(z_loaned_query_t, z_owned_query_t, query) _OWNED_FUNCTIONS(z_loaned_slice_t, z_owned_slice_t, slice) _OWNED_FUNCTIONS(z_loaned_bytes_t, z_owned_bytes_t, bytes) -_OWNED_FUNCTIONS(z_loaned_value_t, z_owned_value_t, value) +_OWNED_FUNCTIONS(z_loaned_reply_err_t, z_owned_reply_err_t, reply_err) #define _OWNED_FUNCTIONS_CLOSURE(ownedtype, name) \ _Bool z_##name##_check(const ownedtype *val); \ @@ -1457,9 +1480,9 @@ const z_loaned_sample_t *z_reply_ok(const z_loaned_reply_t *reply); * reply: Pointer to a :c:type:`z_loaned_reply_t` to get content from. * * Return: - * The error reply content wrapped as a :c:type:`z_loaned_value_t`. + * The error reply content wrapped as a :c:type:`z_loaned_reply_err_t`. */ -const z_loaned_value_t *z_reply_err(const z_loaned_reply_t *reply); +const z_loaned_reply_err_t *z_reply_err(const z_loaned_reply_t *reply); #endif #if Z_FEATURE_QUERYABLE == 1 diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index ac4797f1f..99cbf0f58 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -204,14 +204,14 @@ _OWNED_TYPE_PTR(_z_encoding_t, encoding) _LOANED_TYPE(_z_encoding_t, encoding) /** - * Represents a Zenoh value. + * Represents a Zenoh reply error. * * Members: - * z_loaned_encoding_t encoding: The encoding of the `payload`. - * z_loaned_bytes_t* payload: The payload of this zenoh value. + * z_loaned_encoding_t encoding: The encoding of the error `payload`. + * z_loaned_bytes_t* payload: The payload of this zenoh reply error. */ -_OWNED_TYPE_PTR(_z_value_t, value) -_LOANED_TYPE(_z_value_t, value) +_OWNED_TYPE_PTR(_z_value_t, reply_err) +_LOANED_TYPE(_z_value_t, reply_err) /** * Represents the configuration used to configure a subscriber upon declaration :c:func:`z_declare_subscriber`. diff --git a/include/zenoh-pico/utils/result.h b/include/zenoh-pico/utils/result.h index a3ff7c1d6..68d735dc3 100644 --- a/include/zenoh-pico/utils/result.h +++ b/include/zenoh-pico/utils/result.h @@ -26,6 +26,7 @@ #define _Z_ERR_SYSTEM_MASK 0xb0 #define _Z_ERR_GENERIC_MASK 0xb8 +typedef int8_t z_error_t; /*------------------ Result Enums ------------------*/ typedef enum { _Z_RES_OK = 0, diff --git a/src/api/api.c b/src/api/api.c index c439ed142..052333d6c 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -246,6 +246,8 @@ void z_encoding_drop(z_owned_encoding_t *encoding) { 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; } + // 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) { @@ -257,7 +259,8 @@ static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) return *encoding->_val; } -const z_loaned_bytes_t *z_value_payload(const z_loaned_value_t *value) { return &value->payload; } +const z_loaned_bytes_t *z_query_payload(const z_loaned_query_t *query) { return &query->in->val._value.payload; } +const z_loaned_encoding_t *z_query_encoding(const z_loaned_query_t *query) { return &query->in->val._value.encoding; } const uint8_t *z_slice_data(const z_loaned_slice_t *slice) { return slice->start; } @@ -615,8 +618,6 @@ void z_query_parameters(const z_loaned_query_t *query, z_view_string_t *paramete parameters->_val.len = strlen(query->in->val._parameters); } -const z_loaned_value_t *z_query_value(const z_loaned_query_t *query) { return &query->in->val._value; } - const z_loaned_bytes_t *z_query_attachment(const z_loaned_query_t *query) { return &query->in->val.attachment; } const z_loaned_keyexpr_t *z_query_keyexpr(const z_loaned_query_t *query) { return &query->in->val._key; } @@ -725,7 +726,7 @@ static inline void _z_owner_noop_copy(void *dst, const void *src) { OWNED_FUNCTIONS_PTR(_z_config_t, config, _z_owner_noop_copy, _z_config_free) OWNED_FUNCTIONS_PTR(_z_scouting_config_t, scouting_config, _z_owner_noop_copy, _z_scouting_config_free) OWNED_FUNCTIONS_PTR(_z_string_t, string, _z_string_copy, _z_string_free) -OWNED_FUNCTIONS_PTR(_z_value_t, value, _z_value_copy, _z_value_free) +OWNED_FUNCTIONS_PTR(_z_value_t, reply_err, _z_value_copy, _z_value_free) OWNED_FUNCTIONS_PTR(_z_keyexpr_t, keyexpr, _z_keyexpr_copy, _z_keyexpr_free) VIEW_FUNCTIONS_PTR(_z_keyexpr_t, keyexpr) @@ -1152,7 +1153,7 @@ _Bool z_reply_is_ok(const z_loaned_reply_t *reply) { const z_loaned_sample_t *z_reply_ok(const z_loaned_reply_t *reply) { return &reply->in->val.data.sample; } -const z_loaned_value_t *z_reply_err(const z_loaned_reply_t *reply) { +const z_loaned_reply_err_t *z_reply_err(const z_loaned_reply_t *reply) { _ZP_UNUSED(reply); return NULL; } From 228908ffe2fd5c0a1b1bf0a4a1fcf20f644870eb Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 16:57:45 +0200 Subject: [PATCH 6/9] format --- include/zenoh-pico/api/macros.h | 231 ++++++++++++++++++++++------ include/zenoh-pico/api/primitives.h | 1 - 2 files changed, 184 insertions(+), 48 deletions(-) diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 31df88947..1bb7562f4 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -470,7 +470,9 @@ inline void z_closure( inline z_owned_bytes_t* z_move(z_owned_bytes_t& x) { return z_bytes_move(&x); }; inline z_owned_closure_hello_t* z_move(z_owned_closure_hello_t& closure) { return z_closure_hello_move(&closure); }; -inline z_owned_closure_owned_query_t* z_move(z_owned_closure_owned_query_t& closure) { return z_closure_owned_query_move(&closure); }; +inline z_owned_closure_owned_query_t* z_move(z_owned_closure_owned_query_t& closure) { + return z_closure_owned_query_move(&closure); +}; inline z_owned_closure_query_t* z_move(z_owned_closure_query_t& closure) { return z_closure_query_move(&closure); }; inline z_owned_closure_reply_t* z_move(z_owned_closure_reply_t& closure) { return z_closure_reply_move(&closure); }; inline z_owned_closure_sample_t* z_move(z_owned_closure_sample_t& closure) { return z_closure_sample_move(&closure); }; @@ -491,52 +493,187 @@ inline z_owned_string_array_t* z_move(z_owned_string_array_t& x) { return z_stri inline z_owned_string_t* z_move(z_owned_string_t& x) { return z_string_move(&x); }; inline z_owned_subscriber_t* z_move(z_owned_subscriber_t& x) { return z_subscriber_move(&x); }; -template struct z_loaned_to_owned_type_t {}; -template struct z_owned_to_loaned_type_t {}; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_bytes_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_bytes_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_hello_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_hello_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_owned_query_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_owned_query_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_query_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_query_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_reply_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_reply_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_sample_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_sample_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_closure_zid_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_closure_zid_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_config_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_config_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_encoding_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_encoding_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_reply_err_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_reply_err_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_hello_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_hello_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_keyexpr_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_keyexpr_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_publisher_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_publisher_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_query_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_query_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_queryable_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_queryable_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_reply_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_reply_t type; };; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_sample_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_sample_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_session_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_session_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_slice_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_slice_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_string_array_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_string_array_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_string_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_string_t type; }; -template<> struct z_loaned_to_owned_type_t { typedef z_owned_subscriber_t type; }; -template<> struct z_owned_to_loaned_type_t { typedef z_loaned_subscriber_t type; }; +template +struct z_loaned_to_owned_type_t {}; +template +struct z_owned_to_loaned_type_t {}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_bytes_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_bytes_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_closure_hello_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_closure_hello_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_closure_owned_query_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_closure_owned_query_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_closure_query_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_closure_query_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_closure_reply_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_closure_reply_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_closure_sample_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_closure_sample_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_closure_zid_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_closure_zid_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_config_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_config_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_encoding_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_encoding_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_reply_err_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_reply_err_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_hello_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_hello_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_keyexpr_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_keyexpr_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_publisher_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_publisher_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_query_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_query_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_queryable_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_queryable_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_reply_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_reply_t type; +}; +; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_sample_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_sample_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_session_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_session_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_slice_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_slice_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_string_array_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_string_array_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_string_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_string_t type; +}; +template <> +struct z_loaned_to_owned_type_t { + typedef z_owned_subscriber_t type; +}; +template <> +struct z_owned_to_loaned_type_t { + typedef z_loaned_subscriber_t type; +}; #endif diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index b433a697a..63fee4bfb 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -385,7 +385,6 @@ void z_encoding_drop(z_owned_encoding_t *encoding); */ const z_loaned_encoding_t *z_encoding_loan(const z_owned_encoding_t *encoding); - /** * Gets a loaned version of a :c:type:`z_owned_encoding_t`. * From 1aea57171fbc18e7462473519d47a2025bc998bd Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 17:03:01 +0200 Subject: [PATCH 7/9] alignment test fixes --- tests/z_api_alignment_test.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 8ed72b264..aa5f634ae 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -77,8 +77,10 @@ void query_handler(const z_loaned_query_t *query, void *arg) { z_view_string_t pred; z_query_parameters(query, &pred); (void)(pred); - const z_loaned_value_t *payload_value = z_query_value(query); - (void)(payload_value); + const z_loaned_bytes_t *payload = z_query_payload(query); + const z_loaned_encoding_t *encoding = z_query_encoding(query); + (void)(payload); + (void)(encoding); z_query_reply_options_t _ret_qreply_opt; z_query_reply_options_default(&_ret_qreply_opt); @@ -108,8 +110,8 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { #endif z_drop(z_move(k_str)); } else { - const z_loaned_value_t *_ret_zvalue = z_reply_err(reply); - (void)(_ret_zvalue); + const z_loaned_reply_err_t *_ret_zerr = z_reply_err(reply); + (void)(_ret_zerr); } } From 6e94220667756e9190b3ef35ac2abb2dbf3a75eb Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 17:57:08 +0200 Subject: [PATCH 8/9] fixes --- docs/api.rst | 4 ++-- examples/zephyr/z_queryable.c | 2 +- include/zenoh-pico/api/macros.h | 1 + include/zenoh-pico/api/primitives.h | 13 +++++++++++++ src/api/api.c | 18 +++++++++++++++--- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 22e560c91..b0a076abf 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -182,9 +182,9 @@ TODO: loaned type description Represents the encoding of a payload, in a MIME-like format. -.. c:type:: z_loaned_value_t +.. c:type:: z_loaned_reply_err_t - Represents a Zenoh value. + Represents a Zenoh reply error. .. c:type:: z_loaned_sample_t diff --git a/examples/zephyr/z_queryable.c b/examples/zephyr/z_queryable.c index 679493eb7..89cccb54a 100644 --- a/examples/zephyr/z_queryable.c +++ b/examples/zephyr/z_queryable.c @@ -41,7 +41,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) { z_loan(params)->val); // Process value z_owned_string_t payload_string; - z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string); + z_bytes_deserialize_into_string(z_query_payload(query), &payload_string); if (z_string_len(z_loan(payload_string)) > 1) { printf(" with value '%s'\n", z_string_data(z_loan(payload_string))); } diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 1bb7562f4..d61e25f83 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -219,6 +219,7 @@ z_owned_queryable_t : z_queryable_clone, \ z_owned_query_t : z_query_clone, \ z_owned_sample_t : z_sample_clone, \ + z_owned_bytes_t : z_bytes_clone, \ z_owned_encoding_t : z_encoding_clone, \ z_owned_reply_err_t : z_reply_err_clone, \ z_owned_reply_t : z_reply_clone, \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 63fee4bfb..585ff4986 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -374,6 +374,8 @@ _Bool z_encoding_check(const z_owned_encoding_t *encoding); */ void z_encoding_drop(z_owned_encoding_t *encoding); +int8_t z_encoding_clone(z_owned_encoding_t *dst, const z_loaned_encoding_t *src); + /** * Gets a loaned version of a :c:type:`z_owned_encoding_t`. * @@ -429,6 +431,17 @@ int8_t z_encoding_null(z_owned_encoding_t *encoding); */ const z_loaned_bytes_t *z_reply_err_payload(const z_loaned_reply_err_t *reply_err); +/** + * Gets a reply error encoding by aliasing it. + * + * Parameters: + * query: Pointer to the :c:type:`z_loaned_reply_err_t` to get the encoding from. + * + * Return: + * Pointer to the encoding as a :c:type:`z_loaned_encoding_t`. + */ +const z_loaned_encoding_t *z_reply_err_encoding(const z_loaned_reply_err_t *reply_err); + /** * Gets date pointer of a bytes array. * diff --git a/src/api/api.c b/src/api/api.c index 052333d6c..a7bdaa572 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -244,6 +244,15 @@ void z_encoding_drop(z_owned_encoding_t *encoding) { 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; } @@ -259,9 +268,6 @@ static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) return *encoding->_val; } -const z_loaned_bytes_t *z_query_payload(const z_loaned_query_t *query) { return &query->in->val._value.payload; } -const z_loaned_encoding_t *z_query_encoding(const z_loaned_query_t *query) { return &query->in->val._value.encoding; } - const uint8_t *z_slice_data(const z_loaned_slice_t *slice) { return slice->start; } size_t z_slice_len(const z_loaned_slice_t *slice) { return slice->len; } @@ -622,6 +628,9 @@ const z_loaned_bytes_t *z_query_attachment(const z_loaned_query_t *query) { retu const z_loaned_keyexpr_t *z_query_keyexpr(const z_loaned_query_t *query) { return &query->in->val._key; } +const z_loaned_bytes_t *z_query_payload(const z_loaned_query_t *query) { return &query->in->val._value.payload; } +const z_loaned_encoding_t *z_query_encoding(const z_loaned_query_t *query) { return &query->in->val._value.encoding; } + void z_closure_sample_call(const z_owned_closure_sample_t *closure, const z_loaned_sample_t *sample) { if (closure->call != NULL) { (closure->call)(sample, closure->context); @@ -926,6 +935,9 @@ const z_loaned_bytes_t *z_sample_attachment(const z_loaned_sample_t *sample) { return &_Z_RC_IN_VAL(sample).attachment; } +const z_loaned_bytes_t *z_reply_err_payload(const z_loaned_reply_err_t *reply_err) { return &reply_err->payload; } +const z_loaned_encoding_t *z_reply_err_encoding(const z_loaned_reply_err_t *reply_err) { return &reply_err->encoding; } + const char *z_string_data(const z_loaned_string_t *str) { return str->val; } size_t z_string_len(const z_loaned_string_t *str) { return str->len; } From 1dd3f5b6cf33c0d3af3db9051d5d0051a1c6712c Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 18 Jun 2024 18:23:39 +0200 Subject: [PATCH 9/9] merge --- include/zenoh-pico/api/olv_macros.h | 138 ++++++++++++++++++++++++++++ include/zenoh-pico/api/primitives.h | 83 ++++++----------- include/zenoh-pico/api/types.h | 96 ++++++++----------- src/api/api.c | 135 +++++++-------------------- 4 files changed, 237 insertions(+), 215 deletions(-) create mode 100644 include/zenoh-pico/api/olv_macros.h diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h new file mode 100644 index 000000000..bae04c382 --- /dev/null +++ b/include/zenoh-pico/api/olv_macros.h @@ -0,0 +1,138 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +#ifndef INCLUDE_ZENOH_PICO_API_OLV_MACROS_H +#define INCLUDE_ZENOH_PICO_API_OLV_MACROS_H + +// Owned/Loaned/View type macros +// +// !!! FOR INTERNAL USAGE ONLY !!! + +// For pointer types +#define _Z_OWNED_TYPE_PTR(type, name) \ + typedef struct { \ + type *_val; \ + } z_owned_##name##_t; + +// For refcounted types +#define _Z_OWNED_TYPE_RC(type, name) \ + typedef struct { \ + type _rc; \ + } z_owned_##name##_t; + +#define _Z_LOANED_TYPE(type, name) typedef type z_loaned_##name##_t; + +#define _Z_VIEW_TYPE(type, name) \ + typedef struct { \ + type _val; \ + } z_view_##name##_t; + +#define _Z_OWNED_FUNCTIONS_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); \ + int8_t z_##name##_clone(ownedtype *obj, const loanedtype *src); \ + 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); \ + void z_view_##name##_null(viewtype *name); + +#define _Z_OWNED_FUNCTIONS_PTR_IMPL(type, name, f_copy, f_free) \ + _Bool z_##name##_check(const z_owned_##name##_t *obj) { return obj->_val != NULL; } \ + 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 = NULL; } \ + z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return obj; } \ + int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ + int8_t ret = _Z_RES_OK; \ + obj->_val = (type *)z_malloc(sizeof(type)); \ + if (obj->_val != NULL) { \ + f_copy(obj->_val, src); \ + } else { \ + ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \ + } \ + return ret; \ + } \ + void z_##name##_drop(z_owned_##name##_t *obj) { \ + if ((obj != NULL) && (obj->_val != NULL)) { \ + f_free(&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; } \ + z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *val) { return &val->_rc; } \ + void z_##name##_null(z_owned_##name##_t *val) { val->_rc.in = NULL; } \ + z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *val) { return val; } \ + int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ + int8_t ret = _Z_RES_OK; \ + obj->_rc = _z_##name##_rc_clone((z_loaned_##name##_t *)src); \ + if (obj->_rc.in == NULL) { \ + ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \ + } \ + return ret; \ + } \ + void z_##name##_drop(z_owned_##name##_t *val) { \ + if (val->_rc.in != NULL) { \ + if (_z_##name##_rc_drop(&val->_rc)) { \ + val->_rc.in = NULL; \ + } \ + } \ + } + +#define _Z_VIEW_FUNCTIONS_PTR_IMPL(type, name) \ + const z_loaned_##name##_t *z_view_##name##_loan(const z_view_##name##_t *obj) { return &obj->_val; } \ + z_loaned_##name##_t *z_view_##name##_loan_mut(z_view_##name##_t *obj) { return &obj->_val; } + +#define _Z_OWNED_FUNCTIONS_CLOSURE_DEF(ownedtype, name) \ + _Bool z_##name##_check(const ownedtype *val); \ + ownedtype *z_##name##_move(ownedtype *val); \ + void z_##name##_drop(ownedtype *val); \ + void z_##name##_null(ownedtype *name); + +#define _Z_OWNED_FUNCTIONS_CLOSURE_IMPL(ownedtype, name, f_call, f_drop) \ + _Bool z_##name##_check(const ownedtype *val) { return val->call != NULL; } \ + ownedtype *z_##name##_move(ownedtype *val) { return val; } \ + void z_##name##_drop(ownedtype *val) { \ + if (val->drop != NULL) { \ + (val->drop)(val->context); \ + val->drop = NULL; \ + } \ + val->call = NULL; \ + val->context = NULL; \ + } \ + void z_##name##_null(ownedtype *val) { \ + val->call = NULL; \ + val->drop = NULL; \ + val->context = NULL; \ + } \ + int8_t z_##name(ownedtype *closure, f_call call, f_drop drop, void *context) { \ + closure->call = call; \ + closure->drop = drop; \ + closure->context = context; \ + \ + return _Z_RES_OK; \ + } + +// Gets internal value from refcounted type (e.g. z_loaned_session_t, z_query_t) +#define _Z_RC_IN_VAL(arg) ((arg)->in->val) + +// Gets internal value from refcounted owned type (e.g. z_owned_session_t, z_owned_query_t) +#define _Z_OWNED_RC_IN_VAL(arg) ((arg)->_rc.in->val) + +#endif /* INCLUDE_ZENOH_PICO_API_OLV_MACROS_H */ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 585ff4986..2c3dcc285 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -18,6 +18,7 @@ #include #include +#include "olv_macros.h" #include "zenoh-pico/api/types.h" #include "zenoh-pico/net/query.h" #include "zenoh-pico/net/session.h" @@ -1064,60 +1065,34 @@ int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_loaned_hello_handler_ int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_dropper_handler_t drop, void *context); /**************** Loans ****************/ -#define _OWNED_FUNCTIONS(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); \ - int8_t z_##name##_clone(ownedtype *obj, const loanedtype *src); \ - void z_##name##_drop(ownedtype *obj); \ - void z_##name##_null(ownedtype *obj); - -_OWNED_FUNCTIONS(z_loaned_string_t, z_owned_string_t, string) -_OWNED_FUNCTIONS(z_loaned_keyexpr_t, z_owned_keyexpr_t, keyexpr) -_OWNED_FUNCTIONS(z_loaned_config_t, z_owned_config_t, config) -_OWNED_FUNCTIONS(z_loaned_scouting_config_t, z_owned_scouting_config_t, scouting_config) -_OWNED_FUNCTIONS(z_loaned_session_t, z_owned_session_t, session) -_OWNED_FUNCTIONS(z_loaned_subscriber_t, z_owned_subscriber_t, subscriber) -_OWNED_FUNCTIONS(z_loaned_publisher_t, z_owned_publisher_t, publisher) -_OWNED_FUNCTIONS(z_loaned_queryable_t, z_owned_queryable_t, queryable) -_OWNED_FUNCTIONS(z_loaned_hello_t, z_owned_hello_t, hello) -_OWNED_FUNCTIONS(z_loaned_reply_t, z_owned_reply_t, reply) -_OWNED_FUNCTIONS(z_loaned_string_array_t, z_owned_string_array_t, string_array) -_OWNED_FUNCTIONS(z_loaned_sample_t, z_owned_sample_t, sample) -_OWNED_FUNCTIONS(z_loaned_query_t, z_owned_query_t, query) -_OWNED_FUNCTIONS(z_loaned_slice_t, z_owned_slice_t, slice) -_OWNED_FUNCTIONS(z_loaned_bytes_t, z_owned_bytes_t, bytes) -_OWNED_FUNCTIONS(z_loaned_reply_err_t, z_owned_reply_err_t, reply_err) - -#define _OWNED_FUNCTIONS_CLOSURE(ownedtype, name) \ - _Bool z_##name##_check(const ownedtype *val); \ - ownedtype *z_##name##_move(ownedtype *val); \ - void z_##name##_drop(ownedtype *val); \ - void z_##name##_null(ownedtype *name); - -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_sample_t, closure_sample) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_sample_t, closure_owned_sample) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_query_t, closure_query) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_query_t, closure_owned_query) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_reply_t, closure_reply) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_reply_t, closure_owned_reply) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello) -_OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid) - -#define _VIEW_FUNCTIONS(loanedtype, viewtype, name) \ - const loanedtype *z_view_##name##_loan(const viewtype *name); \ - loanedtype *z_view_##name##_loan_mut(viewtype *name); \ - void z_view_##name##_null(viewtype *name); - -_VIEW_FUNCTIONS(z_loaned_keyexpr_t, z_view_keyexpr_t, keyexpr) -_VIEW_FUNCTIONS(z_loaned_string_t, z_view_string_t, string) - -// Gets internal value from refcounted type (e.g. z_loaned_session_t, z_query_t) -#define _Z_RC_IN_VAL(arg) ((arg)->in->val) - -// Gets internal value from refcounted owned type (e.g. z_owned_session_t, z_owned_query_t) -#define _Z_OWNED_RC_IN_VAL(arg) ((arg)->_rc.in->val) +_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_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) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_queryable_t, z_owned_queryable_t, queryable) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_hello_t, z_owned_hello_t, hello) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_reply_t, z_owned_reply_t, reply) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_string_array_t, z_owned_string_array_t, string_array) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_sample_t, z_owned_sample_t, sample) +_Z_OWNED_FUNCTIONS_DEF(z_loaned_query_t, z_owned_query_t, query) +_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_reply_err_t, z_owned_reply_err_t, reply_err) + +_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) +_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_query_t, closure_query) +_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_query_t, closure_owned_query) +_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_reply_t, closure_reply) +_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_reply_t, closure_owned_reply) +_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_hello_t, closure_hello) +_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_zid_t, closure_zid) + +_Z_VIEW_FUNCTIONS_DEF(z_loaned_keyexpr_t, z_view_keyexpr_t, keyexpr) +_Z_VIEW_FUNCTIONS_DEF(z_loaned_string_t, z_view_string_t, string) /** * Loans a :c:type:`z_owned_sample_t`. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index 99cbf0f58..77b2b0195 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -15,6 +15,7 @@ #ifndef INCLUDE_ZENOH_PICO_API_TYPES_H #define INCLUDE_ZENOH_PICO_API_TYPES_H +#include "olv_macros.h" #include "zenoh-pico/collections/element.h" #include "zenoh-pico/collections/list.h" #include "zenoh-pico/collections/slice.h" @@ -32,27 +33,6 @@ extern "C" { #endif -/* Owned/Loaned types */ - -// For pointer types -#define _OWNED_TYPE_PTR(type, name) \ - typedef struct { \ - type *_val; \ - } z_owned_##name##_t; - -// For refcounted types -#define _OWNED_TYPE_RC(type, name) \ - typedef struct { \ - type _rc; \ - } z_owned_##name##_t; - -#define _LOANED_TYPE(type, name) typedef type z_loaned_##name##_t; - -#define _VIEW_TYPE(type, name) \ - typedef struct { \ - type _val; \ - } z_view_##name##_t; - /** * Represents a variable-length encoding unsigned integer. * @@ -82,8 +62,8 @@ typedef _z_timestamp_t z_timestamp_t; * size_t len: The length of the bytes array. * uint8_t *start: A pointer to the bytes array. */ -_OWNED_TYPE_PTR(_z_slice_t, slice) -_LOANED_TYPE(_z_slice_t, slice) +_Z_OWNED_TYPE_PTR(_z_slice_t, slice) +_Z_LOANED_TYPE(_z_slice_t, slice) /** * Represents a container for slices. @@ -91,8 +71,8 @@ _LOANED_TYPE(_z_slice_t, slice) * Members: * _z_slice_t slice: content of the container. */ -_OWNED_TYPE_PTR(_z_bytes_t, bytes) -_LOANED_TYPE(_z_bytes_t, bytes) +_Z_OWNED_TYPE_PTR(_z_bytes_t, bytes) +_Z_LOANED_TYPE(_z_bytes_t, bytes) /** * Represents a string without null-terminator. @@ -101,9 +81,9 @@ _LOANED_TYPE(_z_bytes_t, bytes) * size_t len: The length of the string. * const char *val: A pointer to the string. */ -_OWNED_TYPE_PTR(_z_string_t, string) -_LOANED_TYPE(_z_string_t, string) -_VIEW_TYPE(_z_string_t, string) +_Z_OWNED_TYPE_PTR(_z_string_t, string) +_Z_LOANED_TYPE(_z_string_t, string) +_Z_VIEW_TYPE(_z_string_t, string) /** * Represents a key expression in Zenoh. @@ -115,9 +95,9 @@ _VIEW_TYPE(_z_string_t, string) * - :c:func:`z_keyexpr_to_string` * - :c:func:`zp_keyexpr_resolve` */ -_OWNED_TYPE_PTR(_z_keyexpr_t, keyexpr) -_LOANED_TYPE(_z_keyexpr_t, keyexpr) -_VIEW_TYPE(_z_keyexpr_t, keyexpr) +_Z_OWNED_TYPE_PTR(_z_keyexpr_t, keyexpr) +_Z_LOANED_TYPE(_z_keyexpr_t, keyexpr) +_Z_VIEW_TYPE(_z_keyexpr_t, keyexpr) /** * Represents a Zenoh configuration, used to configure Zenoh sessions upon opening. @@ -129,8 +109,8 @@ _VIEW_TYPE(_z_keyexpr_t, keyexpr) * - :c:func:`zp_config_get` * - :c:func:`zp_config_insert` */ -_OWNED_TYPE_PTR(_z_config_t, config) -_LOANED_TYPE(_z_config_t, config) +_Z_OWNED_TYPE_PTR(_z_config_t, config) +_Z_LOANED_TYPE(_z_config_t, config) /** * Represents a scouting configuration, used to configure a scouting procedure. @@ -142,14 +122,14 @@ _LOANED_TYPE(_z_config_t, config) * - :c:func:`zp_scouting_config_get` * - :c:func:`zp_scouting_config_insert` */ -_OWNED_TYPE_PTR(_z_scouting_config_t, scouting_config) -_LOANED_TYPE(_z_scouting_config_t, scouting_config) +_Z_OWNED_TYPE_PTR(_z_scouting_config_t, scouting_config) +_Z_LOANED_TYPE(_z_scouting_config_t, scouting_config) /** * Represents a Zenoh Session. */ -_OWNED_TYPE_RC(_z_session_rc_t, session) -_LOANED_TYPE(_z_session_rc_t, session) +_Z_OWNED_TYPE_RC(_z_session_rc_t, session) +_Z_LOANED_TYPE(_z_session_rc_t, session) /** * Represents a Zenoh Subscriber entity. @@ -159,8 +139,8 @@ _LOANED_TYPE(_z_session_rc_t, session) * - :c:func:`z_declare_subscriber` * - :c:func:`z_undeclare_subscriber` */ -_OWNED_TYPE_PTR(_z_subscriber_t, subscriber) -_LOANED_TYPE(_z_subscriber_t, subscriber) +_Z_OWNED_TYPE_PTR(_z_subscriber_t, subscriber) +_Z_LOANED_TYPE(_z_subscriber_t, subscriber) /** * Represents a Zenoh Publisher entity. @@ -172,8 +152,8 @@ _LOANED_TYPE(_z_subscriber_t, subscriber) * - :c:func:`z_publisher_put` * - :c:func:`z_publisher_delete` */ -_OWNED_TYPE_PTR(_z_publisher_t, publisher) -_LOANED_TYPE(_z_publisher_t, publisher) +_Z_OWNED_TYPE_PTR(_z_publisher_t, publisher) +_Z_LOANED_TYPE(_z_publisher_t, publisher) /** * Represents a Zenoh Queryable entity. @@ -183,15 +163,15 @@ _LOANED_TYPE(_z_publisher_t, publisher) * - :c:func:`z_declare_queryable` * - :c:func:`z_undeclare_queryable` */ -_OWNED_TYPE_PTR(_z_queryable_t, queryable) -_LOANED_TYPE(_z_queryable_t, queryable) +_Z_OWNED_TYPE_PTR(_z_queryable_t, queryable) +_Z_LOANED_TYPE(_z_queryable_t, queryable) /** * Represents a Zenoh Query entity, received by Zenoh Queryable entities. * */ -_OWNED_TYPE_RC(_z_query_rc_t, query) -_LOANED_TYPE(_z_query_rc_t, query) +_Z_OWNED_TYPE_RC(_z_query_rc_t, query) +_Z_LOANED_TYPE(_z_query_rc_t, query) /** * Represents the encoding of a payload, in a MIME-like format. @@ -200,8 +180,8 @@ _LOANED_TYPE(_z_query_rc_t, query) * z_encoding_id_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. */ -_OWNED_TYPE_PTR(_z_encoding_t, encoding) -_LOANED_TYPE(_z_encoding_t, encoding) +_Z_OWNED_TYPE_PTR(_z_encoding_t, encoding) +_Z_LOANED_TYPE(_z_encoding_t, encoding) /** * Represents a Zenoh reply error. @@ -210,8 +190,8 @@ _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. */ -_OWNED_TYPE_PTR(_z_value_t, reply_err) -_LOANED_TYPE(_z_value_t, reply_err) +_Z_OWNED_TYPE_PTR(_z_value_t, reply_err) +_Z_LOANED_TYPE(_z_value_t, reply_err) /** * Represents the configuration used to configure a subscriber upon declaration :c:func:`z_declare_subscriber`. @@ -422,8 +402,8 @@ static inline z_qos_t z_qos_default(void) { return _Z_N_QOS_DEFAULT; } * z_timestamp_t timestamp: The timestamp of this data sample. * z_qos_t qos: Quality of service settings used to deliver this sample. */ -_OWNED_TYPE_RC(_z_sample_rc_t, sample) -_LOANED_TYPE(_z_sample_rc_t, sample) +_Z_OWNED_TYPE_RC(_z_sample_rc_t, sample) +_Z_LOANED_TYPE(_z_sample_rc_t, sample) /** * Represents the content of a `hello` message returned by a zenoh entity as a reply to a `scout` message. @@ -433,14 +413,14 @@ _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. */ -_OWNED_TYPE_PTR(_z_hello_t, hello) -_LOANED_TYPE(_z_hello_t, hello) +_Z_OWNED_TYPE_PTR(_z_hello_t, hello) +_Z_LOANED_TYPE(_z_hello_t, hello) /** * Represents the reply to a query. */ -_OWNED_TYPE_RC(_z_reply_rc_t, reply) -_LOANED_TYPE(_z_reply_rc_t, reply) +_Z_OWNED_TYPE_RC(_z_reply_rc_t, reply) +_Z_LOANED_TYPE(_z_reply_rc_t, reply) /** * Represents an array of non null-terminated string. @@ -451,9 +431,9 @@ _LOANED_TYPE(_z_reply_rc_t, reply) * - :c:func:`z_string_array_len` * - :c:func:`z_str_array_array_is_empty` */ -_OWNED_TYPE_PTR(_z_string_vec_t, string_array) -_LOANED_TYPE(_z_string_vec_t, string_array) -_VIEW_TYPE(_z_string_vec_t, string_array) +_Z_OWNED_TYPE_PTR(_z_string_vec_t, string_array) +_Z_LOANED_TYPE(_z_string_vec_t, string_array) +_Z_VIEW_TYPE(_z_string_vec_t, string_array) const z_loaned_string_t *z_string_array_get(const z_loaned_string_array_t *a, size_t k); size_t z_string_array_len(const z_loaned_string_array_t *a); diff --git a/src/api/api.c b/src/api/api.c index a7bdaa572..07a781d0e 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -18,6 +18,7 @@ #include #include +#include "zenoh-pico/api/olv_macros.h" #include "zenoh-pico/api/primitives.h" #include "zenoh-pico/api/types.h" #include "zenoh-pico/collections/slice.h" @@ -679,73 +680,25 @@ void z_closure_zid_call(const z_owned_closure_zid_t *closure, const z_id_t *id) } } -#define OWNED_FUNCTIONS_PTR(type, name, f_copy, f_free) \ - _Bool z_##name##_check(const z_owned_##name##_t *obj) { return obj->_val != NULL; } \ - 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 = NULL; } \ - z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return obj; } \ - int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ - int8_t ret = _Z_RES_OK; \ - obj->_val = (type *)z_malloc(sizeof(type)); \ - if (obj->_val != NULL) { \ - f_copy(obj->_val, src); \ - } else { \ - ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \ - } \ - return ret; \ - } \ - void z_##name##_drop(z_owned_##name##_t *obj) { \ - if ((obj != NULL) && (obj->_val != NULL)) { \ - f_free(&obj->_val); \ - } \ - } - -#define OWNED_FUNCTIONS_RC(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; } \ - z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *val) { return &val->_rc; } \ - void z_##name##_null(z_owned_##name##_t *val) { val->_rc.in = NULL; } \ - z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *val) { return val; } \ - int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ - int8_t ret = _Z_RES_OK; \ - obj->_rc = _z_##name##_rc_clone((z_loaned_##name##_t *)src); \ - if (obj->_rc.in == NULL) { \ - ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \ - } \ - return ret; \ - } \ - void z_##name##_drop(z_owned_##name##_t *val) { \ - if (val->_rc.in != NULL) { \ - if (_z_##name##_rc_drop(&val->_rc)) { \ - val->_rc.in = NULL; \ - } \ - } \ - } - -#define VIEW_FUNCTIONS_PTR(type, name) \ - const z_loaned_##name##_t *z_view_##name##_loan(const z_view_##name##_t *obj) { return &obj->_val; } \ - z_loaned_##name##_t *z_view_##name##_loan_mut(z_view_##name##_t *obj) { return &obj->_val; } - static inline void _z_owner_noop_copy(void *dst, const void *src) { (void)(dst); (void)(src); } -OWNED_FUNCTIONS_PTR(_z_config_t, config, _z_owner_noop_copy, _z_config_free) -OWNED_FUNCTIONS_PTR(_z_scouting_config_t, scouting_config, _z_owner_noop_copy, _z_scouting_config_free) -OWNED_FUNCTIONS_PTR(_z_string_t, string, _z_string_copy, _z_string_free) -OWNED_FUNCTIONS_PTR(_z_value_t, reply_err, _z_value_copy, _z_value_free) +_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) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_string_t, string, _z_string_copy, _z_string_free) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_value_t, reply_err, _z_value_copy, _z_value_free) -OWNED_FUNCTIONS_PTR(_z_keyexpr_t, keyexpr, _z_keyexpr_copy, _z_keyexpr_free) -VIEW_FUNCTIONS_PTR(_z_keyexpr_t, keyexpr) -VIEW_FUNCTIONS_PTR(_z_string_t, string) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_keyexpr_t, keyexpr, _z_keyexpr_copy, _z_keyexpr_free) +_Z_VIEW_FUNCTIONS_PTR_IMPL(_z_keyexpr_t, keyexpr) +_Z_VIEW_FUNCTIONS_PTR_IMPL(_z_string_t, string) -OWNED_FUNCTIONS_PTR(_z_hello_t, hello, _z_owner_noop_copy, _z_hello_free) -OWNED_FUNCTIONS_PTR(_z_string_vec_t, string_array, _z_owner_noop_copy, _z_string_vec_free) -VIEW_FUNCTIONS_PTR(_z_string_vec_t, string_array) -OWNED_FUNCTIONS_PTR(_z_slice_t, slice, _z_slice_copy, _z_slice_free) -OWNED_FUNCTIONS_PTR(_z_bytes_t, bytes, _z_bytes_copy, _z_bytes_free) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_hello_t, hello, _z_owner_noop_copy, _z_hello_free) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_string_vec_t, string_array, _z_owner_noop_copy, _z_string_vec_free) +_Z_VIEW_FUNCTIONS_PTR_IMPL(_z_string_vec_t, string_array) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_slice_t, slice, _z_slice_copy, _z_slice_free) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_bytes_t, bytes, _z_bytes_copy, _z_bytes_free) static _z_bytes_t _z_bytes_from_owned_bytes(z_owned_bytes_t *bytes) { _z_bytes_t b = _z_bytes_null(); @@ -755,44 +708,20 @@ static _z_bytes_t _z_bytes_from_owned_bytes(z_owned_bytes_t *bytes) { return b; } -OWNED_FUNCTIONS_RC(sample) -OWNED_FUNCTIONS_RC(session) - -#define OWNED_FUNCTIONS_CLOSURE(ownedtype, name, f_call, f_drop) \ - _Bool z_##name##_check(const ownedtype *val) { return val->call != NULL; } \ - ownedtype *z_##name##_move(ownedtype *val) { return val; } \ - void z_##name##_drop(ownedtype *val) { \ - if (val->drop != NULL) { \ - (val->drop)(val->context); \ - val->drop = NULL; \ - } \ - val->call = NULL; \ - val->context = NULL; \ - } \ - void z_##name##_null(ownedtype *val) { \ - val->call = NULL; \ - val->drop = NULL; \ - val->context = NULL; \ - } \ - int8_t z_##name(ownedtype *closure, f_call call, f_drop drop, void *context) { \ - closure->call = call; \ - closure->drop = drop; \ - closure->context = context; \ - \ - return _Z_RES_OK; \ - } - -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_sample_t, closure_sample, _z_data_handler_t, z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_sample_t, closure_owned_sample, z_owned_sample_handler_t, - z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_query_t, closure_query, _z_queryable_handler_t, z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_query_t, closure_owned_query, z_owned_query_handler_t, - z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_reply_t, closure_reply, _z_reply_handler_t, z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_reply_t, closure_owned_reply, z_owned_reply_handler_t, - z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello, z_loaned_hello_handler_t, z_dropper_handler_t) -OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid, z_id_handler_t, z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_RC_IMPL(sample) +_Z_OWNED_FUNCTIONS_RC_IMPL(session) + +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_sample_t, closure_sample, _z_data_handler_t, z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_owned_sample_t, closure_owned_sample, z_owned_sample_handler_t, + z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_query_t, closure_query, _z_queryable_handler_t, z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_owned_query_t, closure_owned_query, z_owned_query_handler_t, + z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_reply_t, closure_reply, _z_reply_handler_t, z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_owned_reply_t, closure_owned_reply, z_owned_reply_handler_t, + z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_hello_t, closure_hello, z_loaned_hello_handler_t, z_dropper_handler_t) +_Z_OWNED_FUNCTIONS_CLOSURE_IMPL(z_owned_closure_zid_t, closure_zid, z_id_handler_t, z_dropper_handler_t) /************* Primitives **************/ typedef struct __z_hello_handler_wrapper_t { @@ -951,7 +880,7 @@ int8_t _z_publisher_drop(_z_publisher_t **pub) { return ret; } -OWNED_FUNCTIONS_PTR(_z_publisher_t, publisher, _z_owner_noop_copy, _z_publisher_drop) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_publisher_t, publisher, _z_owner_noop_copy, _z_publisher_drop) void z_put_options_default(z_put_options_t *options) { options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; @@ -1105,7 +1034,7 @@ z_owned_keyexpr_t z_publisher_keyexpr(z_loaned_publisher_t *publisher) { #endif #if Z_FEATURE_QUERY == 1 -OWNED_FUNCTIONS_RC(reply) +_Z_OWNED_FUNCTIONS_RC_IMPL(reply) void z_get_options_default(z_get_options_t *options) { options->target = z_query_target_default(); @@ -1180,8 +1109,8 @@ int8_t _z_queryable_drop(_z_queryable_t **queryable) { return ret; } -OWNED_FUNCTIONS_RC(query) -OWNED_FUNCTIONS_PTR(_z_queryable_t, queryable, _z_owner_noop_copy, _z_queryable_drop) +_Z_OWNED_FUNCTIONS_RC_IMPL(query) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_queryable_t, queryable, _z_owner_noop_copy, _z_queryable_drop) void z_queryable_options_default(z_queryable_options_t *options) { options->complete = _Z_QUERYABLE_COMPLETE_DEFAULT; } @@ -1292,7 +1221,7 @@ int8_t _z_subscriber_drop(_z_subscriber_t **sub) { return ret; } -OWNED_FUNCTIONS_PTR(_z_subscriber_t, subscriber, _z_owner_noop_copy, _z_subscriber_drop) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_subscriber_t, subscriber, _z_owner_noop_copy, _z_subscriber_drop) void z_subscriber_options_default(z_subscriber_options_t *options) { options->reliability = Z_RELIABILITY_DEFAULT; }