From 0b38e0f58686d1b592d2b7655f588ba5b65a37b0 Mon Sep 17 00:00:00 2001 From: DenisBiryukov91 <155981813+DenisBiryukov91@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:12:52 +0200 Subject: [PATCH] Fixes for Zenoh-cpp compatibility (#434) * fix z_owned_closure_hello_t to accept z_loaned_hello_t * remove unneeded NULLs * fix example * void unused arg * renamed value -> reply_err; updated macros for zenoh-cpp; * format * alignment test fixes * fixes * merge --- docs/api.rst | 15 +- 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 +- examples/zephyr/z_queryable.c | 2 +- include/zenoh-pico/api/macros.h | 487 +++++++++++++++------ include/zenoh-pico/api/primitives.h | 53 ++- include/zenoh-pico/api/types.h | 10 +- include/zenoh-pico/utils/result.h | 1 + src/api/api.c | 25 +- tests/z_api_alignment_test.c | 10 +- 17 files changed, 449 insertions(+), 172 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 60c969bd5..b0a076abf 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 @@ -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 @@ -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/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 851f6f525..d61e25f83 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,11 @@ 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_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, \ z_owned_hello_t : z_hello_clone, \ z_owned_string_t : z_string_clone, \ @@ -244,7 +256,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 +288,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 +367,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 +389,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 +407,274 @@ 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 1fb647705..2c3dcc285 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -375,6 +375,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`. * @@ -386,6 +388,17 @@ 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`. * @@ -409,15 +422,26 @@ 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 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. @@ -878,15 +902,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. @@ -1045,7 +1080,7 @@ _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_value_t, z_owned_value_t, value) +_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) @@ -1432,9 +1467,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 d5291de93..77b2b0195 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -184,14 +184,14 @@ _Z_OWNED_TYPE_PTR(_z_encoding_t, encoding) _Z_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. */ -_Z_OWNED_TYPE_PTR(_z_value_t, value) -_Z_LOANED_TYPE(_z_value_t, value) +_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`. 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 4d4820db3..07a781d0e 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -245,8 +245,19 @@ 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; } + // 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) { @@ -258,8 +269,6 @@ 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 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; } @@ -616,12 +625,13 @@ 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; } +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); @@ -678,7 +688,7 @@ static inline void _z_owner_noop_copy(void *dst, const void *src) { _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_config_t, config, _z_owner_noop_copy, _z_config_free) _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_scouting_config_t, scouting_config, _z_owner_noop_copy, _z_scouting_config_free) _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_string_t, string, _z_string_copy, _z_string_free) -_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_value_t, value, _z_value_copy, _z_value_free) +_Z_OWNED_FUNCTIONS_PTR_IMPL(_z_value_t, reply_err, _z_value_copy, _z_value_free) _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_keyexpr_t, keyexpr, _z_keyexpr_copy, _z_keyexpr_free) _Z_VIEW_FUNCTIONS_PTR_IMPL(_z_keyexpr_t, keyexpr) @@ -854,6 +864,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; } @@ -1081,7 +1094,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; } 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); } }