Skip to content
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 owned_query entity #327

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ typedef struct {
} z_queryable_t;
_OWNED_TYPE_PTR(_z_queryable_t, queryable)

/**
* Represents a Zenoh query entity, received by Zenoh Queryable entities.
*
*/
typedef struct z_query_t {
z_owned_query_t _val;
} z_query_t;

/**
* Represents the encoding of a payload, in a MIME-like format.
*
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 @@ -211,7 +211,7 @@ int8_t _z_undeclare_queryable(_z_queryable_t *qle);
* key: The resource key of this reply. The caller keeps the ownership.
* payload: The value of this reply, the caller keeps ownership.
*/
int8_t _z_send_reply(const z_query_t *query, const _z_keyexpr_t keyexpr, const _z_value_t payload);
int8_t _z_send_reply(const _z_query_t *query, const _z_keyexpr_t keyexpr, const _z_value_t payload);
#endif

#if Z_FEATURE_QUERY == 1
Expand Down
14 changes: 12 additions & 2 deletions include/zenoh-pico/net/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@
/**
* The query to be answered by a queryable.
*/
typedef struct z_query_t {
typedef struct _z_query_t {
_z_value_t _value;
_z_keyexpr_t _key;
uint32_t _request_id;
_z_session_t *_zn;
char *_parameters;
_Bool _anyke;
} z_query_t;
} _z_query_t;

void _z_query_clear(_z_query_t *q);
_Z_REFCOUNT_DEFINE(_z_query, _z_query)

Check warning

Code scanning / Cppcheck (reported by Codacy)

There is an unknown macro here somewhere. Configuration is required. If _Z_REFCOUNT_DEFINE is a macro then please configure it. Warning

There is an unknown macro here somewhere. Configuration is required. If _Z_REFCOUNT_DEFINE is a macro then please configure it.

/**
* Container for an owned query rc
*/
typedef struct {
_z_query_rc_t _rc;
} z_owned_query_t;

/**
* Return type when declaring a queryable.
Expand Down
9 changes: 5 additions & 4 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,14 @@
z_query_consolidation_t z_query_consolidation_default(void) { return z_query_consolidation_auto(); }

z_bytes_t z_query_parameters(const z_query_t *query) {
z_bytes_t parameters = _z_bytes_wrap((uint8_t *)query->_parameters, strlen(query->_parameters));
z_bytes_t parameters =
_z_bytes_wrap((uint8_t *)query->_val._rc.in->val._parameters, strlen(query->_val._rc.in->val._parameters));
return parameters;
}

z_value_t z_query_value(const z_query_t *query) { return query->_value; }
z_value_t z_query_value(const z_query_t *query) { return query->_val._rc.in->val._value; }

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

z_keyexpr_t z_query_keyexpr(const z_query_t *query) { return query->_key; }
z_keyexpr_t z_query_keyexpr(const z_query_t *query) { return query->_val._rc.in->val._key; }

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

_Bool z_value_is_initialized(z_value_t *value) {
_Bool ret = false;
Expand Down Expand Up @@ -917,7 +918,7 @@
.len = payload_len,
},
.encoding = {.prefix = opts.encoding.prefix, .suffix = opts.encoding.suffix}};
return _z_send_reply(query, keyexpr, value);
return _z_send_reply(&query->_val._rc.in->val, keyexpr, value);
return _Z_ERR_GENERIC;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
return _Z_RES_OK;
}

int8_t _z_send_reply(const z_query_t *query, _z_keyexpr_t keyexpr, const _z_value_t payload) {
int8_t _z_send_reply(const _z_query_t *query, _z_keyexpr_t keyexpr, const _z_value_t payload) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
int8_t ret = _Z_RES_OK;

_z_keyexpr_t q_ke;
Expand Down
4 changes: 4 additions & 0 deletions src/net/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include "zenoh-pico/net/query.h"

void _z_query_clear(_z_query_t *q) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
jean-roland marked this conversation as resolved.
Show resolved Hide resolved
_ZP_UNUSED(q); // Nothing to do
}

#if Z_FEATURE_QUERYABLE == 1
void _z_queryable_clear(_z_queryable_t *qbl) {
// Nothing to clear
Expand Down
13 changes: 9 additions & 4 deletions src/session/queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <stdint.h>
#include <string.h>

#include "zenoh-pico/api/types.h"
#include "zenoh-pico/config.h"
#include "zenoh-pico/net/query.h"
#include "zenoh-pico/protocol/core.h"
Expand Down Expand Up @@ -155,8 +156,8 @@
zp_mutex_unlock(&zn->_mutex_inner);
#endif // Z_FEATURE_MULTI_THREAD == 1

// Build the query
z_query_t q;
// Build the _z_query
_z_query_t q;
q._zn = zn;
q._request_id = qid;
q._key = key;
Expand All @@ -171,13 +172,17 @@
q._value.encoding = query->_ext_value.encoding;
q._value.payload = query->_ext_value.payload;
jean-roland marked this conversation as resolved.
Show resolved Hide resolved
q._anyke = (strstr(q._parameters, Z_SELECTOR_QUERY_MATCH) == NULL) ? false : true;

// Build the z_query
z_query_t query = {._val = {._rc = _z_query_rc_new_from_val(q)}};
Fixed Show fixed Hide fixed

_z_questionable_rc_list_t *xs = qles;
while (xs != NULL) {
_z_questionable_rc_t *qle = _z_questionable_rc_list_head(xs);
qle->in->val._callback(&q, qle->in->val._arg);
qle->in->val._callback(&query, qle->in->val._arg);
xs = _z_questionable_rc_list_tail(xs);
}

_z_query_rc_drop(&query._val._rc);
_z_keyexpr_clear(&key);
_z_questionable_rc_list_free(&qles);
#if defined(__STDC_NO_VLA__) || ((__STDC_VERSION__ < 201000L) && (defined(_WIN32) || defined(WIN32)))
Expand Down
Loading