Skip to content

Commit

Permalink
Merge branch 'master' into query-body
Browse files Browse the repository at this point in the history
  • Loading branch information
cguimaraes authored Dec 1, 2022
2 parents fb53aee + 05a9bc7 commit 036be9e
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 31 deletions.
4 changes: 1 addition & 3 deletions examples/arduino/z_get.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
4 changes: 1 addition & 3 deletions examples/espidf/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions examples/mbed/z_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ 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;
if (value != NULL) {
opts.with_value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value));
}
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;
}
Expand Down
4 changes: 1 addition & 3 deletions examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions include/zenoh-pico/api/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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 */
4 changes: 2 additions & 2 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,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;

/**
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/net/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
4 changes: 3 additions & 1 deletion include/zenoh-pico/session/queryable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#ifndef ZENOH_PICO_SESSION_QUERYABLE_H
#define ZENOH_PICO_SESSION_QUERYABLE_H

#include <stdbool.h>

#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 ------------------*/
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/session/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ 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_value_t z_value(const char *payload, size_t payload_len, z_encoding_t encoding) {
return (z_value_t){.payload = {.start = (const uint8_t *)payload, .len = payload_len}, .encoding = encoding};
}

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};
Expand Down Expand Up @@ -455,12 +455,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,
Expand Down Expand Up @@ -566,7 +567,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) {
Expand Down Expand Up @@ -635,11 +636,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,
Expand Down
3 changes: 1 addition & 2 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 036be9e

Please sign in to comment.