Skip to content

Commit

Permalink
feat: split into query and queryable tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Oct 11, 2023
1 parent abacd5e commit e467205
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 17 deletions.
9 changes: 8 additions & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@
#endif

/**
* Enable queries and queryables
* Enable queryables
*/
#ifndef Z_FEATURE_QUERYABLES
#define Z_FEATURE_QUERYABLES 1
#endif

/**
* Enable queries
*/
#ifndef Z_FEATURE_QUERIES
#define Z_FEATURE_QUERIES 1
#endif

/**
* Enable TCP links.
*/
Expand Down
2 changes: 2 additions & 0 deletions include/zenoh-pico/net/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ typedef struct {
void *_zn; // FIXME: _z_session_t *zn;
} _z_queryable_t;

#if Z_FEATURE_QUERYABLES == 1
void _z_queryable_clear(_z_queryable_t *qbl);
void _z_queryable_free(_z_queryable_t **qbl);
#endif

#endif /* ZENOH_PICO_QUERY_NETAPI_H */
4 changes: 3 additions & 1 deletion include/zenoh-pico/net/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ typedef struct {
_z_subscription_sptr_list_t *_local_subscriptions;
_z_subscription_sptr_list_t *_remote_subscriptions;

#if Z_FEATURE_QUERYABLES == 1
// Session queryables
#if Z_FEATURE_QUERYABLES == 1
_z_questionable_sptr_list_t *_local_questionable;
#endif
#if Z_FEATURE_QUERIES == 1
_z_pending_query_list_t *_pending_queries;
#endif
} _z_session_t;
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/session/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "zenoh-pico/net/session.h"
#include "zenoh-pico/protocol/core.h"

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
/*------------------ Query ------------------*/
_z_zint_t _z_get_query_id(_z_session_t *zn);

Expand Down
6 changes: 3 additions & 3 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ OWNED_FUNCTIONS_PTR_INTERNAL(z_keyexpr_t, z_owned_keyexpr_t, keyexpr, _z_keyexpr
OWNED_FUNCTIONS_PTR_INTERNAL(z_hello_t, z_owned_hello_t, hello, _z_hello_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_QUERYABLES == 1
#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

Expand Down Expand Up @@ -657,7 +657,7 @@ 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_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
z_owned_reply_t oreply = {._value = reply};

wrapped_ctx->user_call(&oreply, wrapped_ctx->ctx);
Expand All @@ -667,7 +667,7 @@ void __z_reply_handler(_z_reply_t *reply, __z_reply_handler_wrapper_t *wrapped_c

int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owned_closure_reply_t *callback,
const z_get_options_t *options) {
#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
int8_t ret = _Z_RES_OK;

void *ctx = callback->context;
Expand Down
2 changes: 2 additions & 0 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ int8_t _z_send_reply(const z_query_t *query, _z_keyexpr_t keyexpr, const _z_valu

return ret;
}
#endif

#if Z_FEATURE_QUERIES == 1
/*------------------ Query ------------------*/
int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target,
const z_consolidation_mode_t consolidation, _z_value_t value, _z_reply_handler_t callback,
Expand Down
2 changes: 1 addition & 1 deletion src/session/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "zenoh-pico/session/resource.h"
#include "zenoh-pico/utils/logging.h"

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
_z_reply_t *_z_reply_alloc_and_move(_z_reply_t *_reply) {
_z_reply_t *reply = (_z_reply_t *)z_malloc(sizeof(_z_reply_t));
if (reply != NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/session/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint
_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, queries not supported\n");
_Z_DEBUG("_Z_REQUEST_QUERY dropped, queryables not supported\n");
#endif
} break;
case _Z_REQUEST_PUT: {
Expand Down Expand Up @@ -131,7 +131,7 @@ 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_QUERYABLES == 1
#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);
Expand Down Expand Up @@ -162,7 +162,7 @@ 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_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
_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);
Expand Down
4 changes: 4 additions & 0 deletions src/session/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) {
zn->_remote_subscriptions = NULL;
#if Z_FEATURE_QUERYABLES == 1
zn->_local_questionable = NULL;
#endif
#if Z_FEATURE_QUERIES == 1
zn->_pending_queries = NULL;
#endif

Expand Down Expand Up @@ -105,6 +107,8 @@ void _z_session_clear(_z_session_t *zn) {

#if Z_FEATURE_QUERYABLES == 1
_z_flush_questionables(zn);
#endif
#if Z_FEATURE_QUERIES == 1
_z_flush_pending_queries(zn);
#endif

Expand Down
14 changes: 7 additions & 7 deletions tests/z_api_null_drop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(void) {
z_owned_closure_zid_t closure_zid_null_1 = z_closure_zid_null();
z_owned_str_t str_null_1 = z_str_null();

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
z_owned_reply_t reply_null_1 = z_reply_null();
#endif

Expand All @@ -58,7 +58,7 @@ int main(void) {
assert(!z_check(hello_null_1));
assert(!z_check(str_null_1));

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
assert(!z_check(reply_null_1));
#endif

Expand All @@ -81,7 +81,7 @@ int main(void) {
z_owned_closure_zid_t closure_zid_null_2;
z_owned_str_t str_null_2;

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
z_owned_reply_t reply_null_2;
#endif

Expand All @@ -101,7 +101,7 @@ int main(void) {
z_null(&closure_zid_null_2);
z_null(&str_null_2);

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
z_null(&reply_null_2);
#endif

Expand All @@ -119,7 +119,7 @@ int main(void) {
assert(!z_check(hello_null_2));
assert(!z_check(str_null_2));

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
assert(!z_check(reply_null_2));
#endif

Expand All @@ -143,7 +143,7 @@ int main(void) {
z_drop(z_move(closure_zid_null_1));
z_drop(z_move(str_null_1));

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
z_drop(z_move(reply_null_1));
#endif

Expand All @@ -163,7 +163,7 @@ int main(void) {
z_drop(z_move(closure_zid_null_2));
z_drop(z_move(str_null_2));

#if Z_FEATURE_QUERYABLES == 1
#if Z_FEATURE_QUERIES == 1
z_drop(z_move(reply_null_2));
#endif
}
Expand Down

0 comments on commit e467205

Please sign in to comment.