-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add query & queryable token config #260
Changes from 12 commits
7f62365
88d9de6
b2ac6bc
9a7472d
45e80f7
d90526e
c84c092
28818df
fb4086c
abacd5e
e467205
9a8a84b
113b3ba
5838832
8a5ee92
d2297fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,9 +427,12 @@ void z_queryable_drop(z_owned_queryable_t *val) { z_undeclare_queryable(val); } | |
|
||
OWNED_FUNCTIONS_PTR_INTERNAL(z_keyexpr_t, z_owned_keyexpr_t, keyexpr, _z_keyexpr_free, _z_keyexpr_copy) | ||
OWNED_FUNCTIONS_PTR_INTERNAL(z_hello_t, z_owned_hello_t, hello, _z_hello_free, _z_owner_noop_copy) | ||
OWNED_FUNCTIONS_PTR_INTERNAL(z_reply_t, z_owned_reply_t, reply, _z_reply_free, _z_owner_noop_copy) | ||
OWNED_FUNCTIONS_PTR_INTERNAL(z_str_array_t, z_owned_str_array_t, str_array, _z_str_array_free, _z_owner_noop_copy) | ||
|
||
#if Z_FEATURE_QUERIES == 1 | ||
OWNED_FUNCTIONS_PTR_INTERNAL(z_reply_t, z_owned_reply_t, reply, _z_reply_free, _z_owner_noop_copy) | ||
#endif | ||
|
||
#define OWNED_FUNCTIONS_CLOSURE(ownedtype, name) \ | ||
_Bool z_##name##_check(const ownedtype *val) { return val->call != NULL; } \ | ||
ownedtype *z_##name##_move(ownedtype *val) { return val; } \ | ||
|
@@ -654,14 +657,17 @@ typedef struct __z_reply_handler_wrapper_t { | |
} __z_reply_handler_wrapper_t; | ||
|
||
void __z_reply_handler(_z_reply_t *reply, __z_reply_handler_wrapper_t *wrapped_ctx) { | ||
#if Z_FEATURE_QUERIES == 1 | ||
z_owned_reply_t oreply = {._value = reply}; | ||
|
||
wrapped_ctx->user_call(&oreply, wrapped_ctx->ctx); | ||
z_reply_drop(&oreply); // user_call is allowed to take ownership of the reply by setting oreply._value to NULL | ||
#endif | ||
} | ||
|
||
int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owned_closure_reply_t *callback, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If queries are disabled, I would completely omit any related APIs. In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior. Also, you can save some extra bytes in the final binary. |
||
const z_get_options_t *options) { | ||
#if Z_FEATURE_QUERIES == 1 | ||
int8_t ret = _Z_RES_OK; | ||
|
||
void *ctx = callback->context; | ||
|
@@ -694,6 +700,9 @@ int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owne | |
|
||
ret = _z_query(zs._val, keyexpr, parameters, opt.target, opt.consolidation.mode, opt.value, __z_reply_handler, | ||
wrapped_ctx, callback->drop, ctx); | ||
#else | ||
int8_t ret = _Z_ERR_GENERIC; // Not supported | ||
#endif | ||
return ret; | ||
} | ||
|
||
|
@@ -896,6 +905,7 @@ z_queryable_options_t z_queryable_options_default(void) { | |
|
||
z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If queryables are disabled, I would completely omit any related APIs. In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior. Also, you can save some extra bytes in the final binary. |
||
const z_queryable_options_t *options) { | ||
#if Z_FEATURE_QUERYABLES == 1 | ||
void *ctx = callback->context; | ||
callback->context = NULL; | ||
|
||
|
@@ -923,14 +933,20 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o | |
|
||
return (z_owned_queryable_t){ | ||
._value = _z_declare_queryable(zs._val, key, opt.complete, callback->call, callback->drop, ctx)}; | ||
#else | ||
return (z_owned_queryable_t){._value = NULL}; | ||
#endif | ||
} | ||
|
||
int8_t z_undeclare_queryable(z_owned_queryable_t *queryable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If queryables are disabled, I would completely omit any related APIs. In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior. Also, you can save some extra bytes in the final binary. |
||
#if Z_FEATURE_QUERYABLES == 1 | ||
int8_t ret = _Z_RES_OK; | ||
|
||
ret = _z_undeclare_queryable(queryable->_value); | ||
_z_queryable_free(&queryable->_value); | ||
|
||
#else | ||
int8_t ret = _Z_ERR_GENERIC; | ||
#endif | ||
return ret; | ||
} | ||
|
||
|
@@ -940,6 +956,7 @@ z_query_reply_options_t z_query_reply_options_default(void) { | |
|
||
int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len, | ||
const z_query_reply_options_t *options) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If queryables are disabled, I would completely omit any related APIs. In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior. Also, you can save some extra bytes in the final binary. |
||
#if Z_FEATURE_QUERYABLES == 1 | ||
z_query_reply_options_t opts = options == NULL ? z_query_reply_options_default() : *options; | ||
_z_value_t value = {.payload = | ||
{ | ||
|
@@ -949,6 +966,9 @@ int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const ui | |
}, | ||
.encoding = {.prefix = opts.encoding.prefix, .suffix = opts.encoding.suffix}}; | ||
return _z_send_reply(query, keyexpr, value); | ||
#else | ||
return _Z_ERR_GENERIC; | ||
#endif | ||
} | ||
|
||
_Bool z_reply_is_ok(const z_owned_reply_t *reply) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If queryables are disabled, I would completely omit any related APIs. In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior. Also, you can save some extra bytes in the final binary. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,8 +92,12 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint | |
_z_n_msg_request_t req = msg->_body._request; | ||
switch (req._tag) { | ||
case _Z_REQUEST_QUERY: { | ||
#if Z_FEATURE_QUERYABLES == 1 | ||
_z_msg_query_t *query = &req._body._query; | ||
ret = _z_trigger_queryables(zn, query, req._key, req._rid); | ||
#else | ||
_Z_DEBUG("_Z_REQUEST_QUERY dropped, queryables not supported\n"); | ||
#endif | ||
} break; | ||
case _Z_REQUEST_PUT: { | ||
_z_msg_put_t put = req._body._put; | ||
|
@@ -127,9 +131,13 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint | |
_z_n_msg_response_t response = msg->_body._response; | ||
switch (response._tag) { | ||
case _Z_RESPONSE_BODY_REPLY: { | ||
#if Z_FEATURE_QUERIES == 1 | ||
_z_msg_reply_t reply = response._body._reply; | ||
ret = _z_trigger_query_reply_partial(zn, response._request_id, response._key, reply._value.payload, | ||
reply._value.encoding, Z_SAMPLE_KIND_PUT, reply._timestamp); | ||
#else | ||
_Z_DEBUG("_Z_RESPONSE_BODY_REPLY dropped, queries not supported\n"); | ||
#endif | ||
} break; | ||
case _Z_RESPONSE_BODY_ERR: { | ||
// @TODO: expose errors to the user | ||
|
@@ -154,9 +162,13 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint | |
} | ||
} break; | ||
case _Z_N_RESPONSE_FINAL: { | ||
#if Z_FEATURE_QUERIES == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_Z_DEBUG("Handling _Z_N_RESPONSE_FINAL\n"); | ||
_z_zint_t id = msg->_body._response_final._request_id; | ||
_z_trigger_query_reply_final(zn, id); | ||
#else | ||
_Z_DEBUG("_Z_N_RESPONSE_FINAL dropped, queries not supported\n"); | ||
#endif | ||
} break; | ||
} | ||
_z_msg_clear(msg); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If queries are not supported, the entire reply handler can be ommitted.