From 188d3243363d7e23626e090867437501935cbf80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Wed, 30 Nov 2022 16:53:00 +0100 Subject: [PATCH 1/4] Use _Bool instead of bool --- include/zenoh-pico/api/types.h | 4 ++-- include/zenoh-pico/net/primitives.h | 2 +- include/zenoh-pico/session/session.h | 2 +- src/net/primitives.c | 3 +-- src/utils/string.c | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index aaf0e3162..7b8c0898b 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -245,10 +245,10 @@ typedef struct { * upon its declaration via :c:func:`z_declare_queryable`. * * Members: - * bool complete: The completeness of the queryable. + * _Bool complete: The completeness of the queryable. */ typedef struct { - bool complete; + _Bool complete; } z_queryable_options_t; /** diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 3eb0b953b..ab9ee9241 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -138,7 +138,7 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub); * Returns: * The created :c:type:`_z_queryable_t` or null if the declaration failed. */ -_z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, bool complete, +_z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, _Bool complete, _z_questionable_handler_t callback, _z_drop_handler_t dropper, void *arg); /** diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index 183ef3241..de8402531 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -115,7 +115,7 @@ typedef void (*_z_questionable_handler_t)(const z_query_t *query, void *arg); typedef struct { _z_zint_t _id; _z_keyexpr_t _key; - bool _complete; + _Bool _complete; _z_questionable_handler_t _callback; _z_drop_handler_t _dropper; void *_arg; diff --git a/src/net/primitives.c b/src/net/primitives.c index b52666481..ba4229d74 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -186,7 +186,6 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { ret = _Z_ERR_TRANSPORT_TX_FAILED; } _z_msg_clear(&z_msg); - } else { ret = _Z_ERR_SUBSCRIPTION_UNKNOWN; } @@ -195,7 +194,7 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { } /*------------------ Queryable Declaration ------------------*/ -_z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, bool complete, +_z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, _Bool complete, _z_questionable_handler_t callback, _z_drop_handler_t dropper, void *arg) { _z_queryable_t *ret = NULL; diff --git a/src/utils/string.c b/src/utils/string.c index f00c79358..ee0bf975b 100644 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -40,7 +40,7 @@ char const *_z_bstrstr(_z_str_t haystack, _z_str_t needle) { char const *result = NULL; for (; (result == false) && (haystack.start <= haystack.end); haystack.start = _z_cptr_char_offset(haystack.start, 1)) { - bool found = true; + _Bool found = true; char const *n = needle.start; char const *h = haystack.start; while (_z_ptr_char_diff(needle.end, n) > 0) { From 96b8275a69495ea108cd39a8281b294c6a1d0168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Wed, 30 Nov 2022 17:29:49 +0100 Subject: [PATCH 2/4] Explicitly have defines for defaults --- include/zenoh-pico/api/constants.h | 9 +++++++++ src/api/api.c | 17 +++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/zenoh-pico/api/constants.h b/include/zenoh-pico/api/constants.h index a8cbd03c7..4b2327c42 100644 --- a/include/zenoh-pico/api/constants.h +++ b/include/zenoh-pico/api/constants.h @@ -30,6 +30,7 @@ typedef enum { Z_WHATAMI_PEER = 0x02, // 1 << 1 Z_WHATAMI_CLIENT = 0x04 // 1 << 2 } z_whatami_t; +#define Z_WHATAMI_DEFAULT Z_WHATAMI_ROUTER /** * Status values for keyexpr canonization operation. @@ -68,6 +69,7 @@ typedef enum { * Z_SAMPLE_KIND_DELETE: The Sample was issued by a ``delete`` operation. */ typedef enum { Z_SAMPLE_KIND_PUT = 0, Z_SAMPLE_KIND_DELETE = 1 } z_sample_kind_t; +#define Z_SAMPLE_KIND_DEFAULT Z_SAMPLE_KIND_PUT /** * Zenoh encoding values. @@ -118,6 +120,7 @@ typedef enum { Z_ENCODING_PREFIX_IMAGE_PNG = 19, Z_ENCODING_PREFIX_IMAGE_GIF = 20 } z_encoding_prefix_t; +#define Z_ENCODING_PREFIX_DEFAULT Z_ENCODING_PREFIX_EMPTY /** * Consolidation mode values. @@ -138,6 +141,7 @@ typedef enum { Z_CONSOLIDATION_MODE_MONOTONIC = 1, Z_CONSOLIDATION_MODE_LATEST = 2, } z_consolidation_mode_t; +#define Z_CONSOLIDATION_MODE_DEFAULT Z_CONSOLIDATION_MODE_AUTO /** * Reliability values. @@ -147,6 +151,7 @@ typedef enum { * Z_RELIABILITY_RELIABLE: Defines reliability as ``RELIABLE`` */ typedef enum { Z_RELIABILITY_BEST_EFFORT = 0, Z_RELIABILITY_RELIABLE = 1 } z_reliability_t; +#define Z_RELIABILITY_DEFAULT Z_RELIABILITY_RELIABLE /** * Reply tag values. @@ -168,6 +173,7 @@ typedef enum { Z_REPLY_TAG_DATA = 0, Z_REPLY_TAG_FINAL = 1 } z_reply_tag_t; * of congestion control. */ typedef enum { Z_CONGESTION_CONTROL_BLOCK = 0, Z_CONGESTION_CONTROL_DROP = 1 } z_congestion_control_t; +#define Z_CONGESTION_CONTROL_DEFAULT Z_CONGESTION_CONTROL_BLOCK /** * Priority of Zenoh messages values. @@ -192,6 +198,7 @@ typedef enum { Z_PRIORITY_DATA_LOW = 6, Z_PRIORITY_BACKGROUND = 7 } z_priority_t; +#define Z_PRIORITY_DEFAULT Z_PRIORITY_DATA /** * Subscription mode values. @@ -201,6 +208,7 @@ typedef enum { * Z_SUBMODE_PULL: Defines the subscription with a pull paradigm. */ typedef enum { Z_SUBMODE_PUSH = 0, Z_SUBMODE_PULL = 1 } z_submode_t; +#define Z_SUBMODE_DEFAULT Z_SUBMODE_PUSH /** * Query target values. @@ -215,5 +223,6 @@ typedef enum { Z_QUERY_TARGET_ALL = 1, Z_QUERY_TARGET_ALL_COMPLETE = 2 } z_query_target_t; +#define Z_QUERY_TARGET_DEFAULT Z_QUERY_TARGET_BEST_MATCHING #endif /* ZENOH_PICO_API_CONSTANTS_H */ diff --git a/src/api/api.c b/src/api/api.c index b4a93d7de..be147d0f5 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -200,9 +200,9 @@ z_encoding_t z_encoding(z_encoding_prefix_t prefix, const char *suffix) { .suffix = _z_bytes_wrap((const uint8_t *)suffix, (suffix == NULL) ? (size_t)0 : strlen(suffix))}; } -z_encoding_t z_encoding_default(void) { return z_encoding(Z_ENCODING_PREFIX_EMPTY, NULL); } +z_encoding_t z_encoding_default(void) { return z_encoding(Z_ENCODING_PREFIX_DEFAULT, NULL); } -z_query_target_t z_query_target_default(void) { return Z_QUERY_TARGET_BEST_MATCHING; } +z_query_target_t z_query_target_default(void) { return Z_QUERY_TARGET_DEFAULT; } z_query_consolidation_t z_query_consolidation_auto(void) { return (z_query_consolidation_t){.mode = Z_CONSOLIDATION_MODE_AUTO}; @@ -439,12 +439,13 @@ z_id_t z_info_zid(const z_session_t zs) { } z_put_options_t z_put_options_default(void) { - return (z_put_options_t){ - .encoding = z_encoding_default(), .congestion_control = Z_CONGESTION_CONTROL_DROP, .priority = Z_PRIORITY_DATA}; + return (z_put_options_t){.encoding = z_encoding_default(), + .congestion_control = Z_CONGESTION_CONTROL_DEFAULT, + .priority = Z_PRIORITY_DEFAULT}; } z_delete_options_t z_delete_options_default(void) { - return (z_delete_options_t){.congestion_control = Z_CONGESTION_CONTROL_DROP, .priority = Z_PRIORITY_DATA}; + return (z_delete_options_t){.congestion_control = Z_CONGESTION_CONTROL_DEFAULT, .priority = Z_PRIORITY_DEFAULT}; } int8_t z_put(z_session_t zs, z_keyexpr_t keyexpr, const uint8_t *payload, z_zint_t payload_len, @@ -547,7 +548,7 @@ int8_t z_undeclare_keyexpr(z_session_t zs, z_owned_keyexpr_t *keyexpr) { } z_publisher_options_t z_publisher_options_default(void) { - return (z_publisher_options_t){.congestion_control = Z_CONGESTION_CONTROL_DROP, .priority = Z_PRIORITY_DATA_HIGH}; + return (z_publisher_options_t){.congestion_control = Z_CONGESTION_CONTROL_DEFAULT, .priority = Z_PRIORITY_DEFAULT}; } z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, z_publisher_options_t *options) { @@ -616,11 +617,11 @@ int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_opti } z_subscriber_options_t z_subscriber_options_default(void) { - return (z_subscriber_options_t){.reliability = Z_RELIABILITY_RELIABLE}; + return (z_subscriber_options_t){.reliability = Z_RELIABILITY_DEFAULT}; } z_pull_subscriber_options_t z_pull_subscriber_options_default(void) { - return (z_pull_subscriber_options_t){.reliability = Z_RELIABILITY_RELIABLE}; + return (z_pull_subscriber_options_t){.reliability = Z_RELIABILITY_DEFAULT}; } z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_sample_t *callback, From 4ce5edc7fd529526ba16a30c21678c7add971563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Wed, 30 Nov 2022 17:30:14 +0100 Subject: [PATCH 3/4] Change queryable complete default --- include/zenoh-pico/session/queryable.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/zenoh-pico/session/queryable.h b/include/zenoh-pico/session/queryable.h index c7c79746f..a86c3248a 100644 --- a/include/zenoh-pico/session/queryable.h +++ b/include/zenoh-pico/session/queryable.h @@ -15,9 +15,11 @@ #ifndef ZENOH_PICO_SESSION_QUERYABLE_H #define ZENOH_PICO_SESSION_QUERYABLE_H +#include + #include "zenoh-pico/net/session.h" -#define _Z_QUERYABLE_COMPLETE_DEFAULT 1 +#define _Z_QUERYABLE_COMPLETE_DEFAULT false #define _Z_QUERYABLE_DISTANCE_DEFAULT 0 /*------------------ Queryable ------------------*/ From 493bb4310a13713c5c5fa2293630660f2b3bd339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Thu, 1 Dec 2022 16:40:43 +0100 Subject: [PATCH 4/4] Use default get options on examples --- examples/arduino/z_get.ino | 4 +--- examples/espidf/z_get.c | 4 +--- examples/mbed/z_get.cpp | 4 +--- examples/unix/c11/z_get.c | 4 +--- examples/unix/c99/z_get.c | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/examples/arduino/z_get.ino b/examples/arduino/z_get.ino index 3a876fe01..a45c75838 100644 --- a/examples/arduino/z_get.ino +++ b/examples/arduino/z_get.ino @@ -108,10 +108,8 @@ void loop() { Serial.print("Sending Query "); Serial.print(KEYEXPR); Serial.println(" ..."); - z_get_options_t opts = z_get_options_default(); - opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback = z_closure_reply(reply_handler, reply_dropper, NULL); - if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) { + if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), NULL) < 0) { Serial.println("Unable to send query."); } } diff --git a/examples/espidf/z_get.c b/examples/espidf/z_get.c index 95edd3724..5ab2c0b3d 100644 --- a/examples/espidf/z_get.c +++ b/examples/espidf/z_get.c @@ -151,10 +151,8 @@ void app_main() { while (1) { sleep(5); printf("Sending Query '%s'...\n", KEYEXPR); - z_get_options_t opts = z_get_options_default(); - opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback = z_closure(reply_handler, reply_dropper); - if (z_get(z_loan(s), z_keyexpr(KEYEXPR), "", z_move(callback), &opts) < 0) { + if (z_get(z_loan(s), z_keyexpr(KEYEXPR), "", z_move(callback), NULL) < 0) { printf("Unable to send query.\n"); exit(-1); } diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index d891d1546..90342a7d6 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -74,10 +74,8 @@ int main(int argc, char **argv) { while (1) { z_sleep_s(5); printf("Sending Query '%s'...\n", KEYEXPR); - z_get_options_t opts = z_get_options_default(); - opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback = z_closure_reply(reply_handler, reply_dropper, NULL); - if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) { + if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), NULL) < 0) { printf("Unable to send query.\n"); exit(-1); } diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index 447dcd44c..3688ea123 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -94,10 +94,8 @@ int main(int argc, char **argv) { } printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); - opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback = z_closure(reply_handler, reply_dropper); - if (z_get(z_loan(s), ke, "", z_move(callback), &opts) < 0) { + if (z_get(z_loan(s), ke, "", z_move(callback), NULL) < 0) { printf("Unable to send query.\n"); return -1; } diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 72bb45af0..880880838 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -94,10 +94,8 @@ int main(int argc, char **argv) { } printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); - opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback = z_closure_reply(reply_handler, reply_dropper, NULL); - if (z_get(z_session_loan(&s), ke, "", z_closure_reply_move(&callback), &opts) < 0) { + if (z_get(z_session_loan(&s), ke, "", z_closure_reply_move(&callback), NULL) < 0) { printf("Unable to send query.\n"); return -1; }