diff --git a/include/zenoh-pico/net/query.h b/include/zenoh-pico/net/query.h index ee774b27e..4cf60a4f7 100644 --- a/include/zenoh-pico/net/query.h +++ b/include/zenoh-pico/net/query.h @@ -25,8 +25,8 @@ * The query to be answered by a queryable. */ typedef struct _z_query_t { - _z_value_t _value; _z_keyexpr_t _key; + _z_value_t _value; uint32_t _request_id; _z_session_rc_t _zn; _z_bytes_t _attachment; @@ -60,13 +60,13 @@ static inline _z_query_t _z_query_alias(_z_value_t *value, _z_keyexpr_t *key, co _z_session_rc_t *zn, uint32_t request_id, const _z_bytes_t *attachment, bool anyke) { return (_z_query_t){ + ._key = *key, + ._value = *value, ._request_id = request_id, ._zn = *zn, + ._attachment = *attachment, ._parameters = _z_string_alias_slice(parameters), ._anyke = anyke, - ._key = *key, - ._attachment = *attachment, - ._value = *value, }; } void _z_queryable_clear(_z_queryable_t *qbl); diff --git a/include/zenoh-pico/net/reply.h b/include/zenoh-pico/net/reply.h index 48c4e2e52..f352be9a1 100644 --- a/include/zenoh-pico/net/reply.h +++ b/include/zenoh-pico/net/reply.h @@ -83,24 +83,18 @@ static inline _z_reply_t _z_reply_null(void) { return (_z_reply_t){0}; } static inline _z_reply_t _z_reply_alias(_z_keyexpr_t *keyexpr, _z_id_t id, const _z_bytes_t *payload, const _z_timestamp_t *timestamp, _z_encoding_t *encoding, z_sample_kind_t kind, const _z_bytes_t *attachment) { - _z_reply_t r = { - .data.replier_id = id, - .data._tag = _Z_REPLY_TAG_DATA, - .data._result.sample.keyexpr = *keyexpr, - .data._result.sample.kind = kind, - .data._result.sample.timestamp = *timestamp, - .data._result.sample.payload = *payload, - .data._result.sample.attachment = *attachment, - .data._result.sample.encoding = *encoding, - }; + _z_reply_t r; + r.data.replier_id = id; + r.data._tag = _Z_REPLY_TAG_DATA; + r.data._result.sample = _z_sample_alias(keyexpr, payload, timestamp, encoding, kind, _Z_N_QOS_DEFAULT, attachment, + Z_RELIABILITY_DEFAULT); return r; } static inline _z_reply_t _z_reply_err_alias(const _z_bytes_t *payload, _z_encoding_t *encoding) { - _z_reply_t r = { - .data._tag = _Z_REPLY_TAG_ERROR, - .data._result.error.payload = *payload, - .data._result.error.encoding = *encoding, - }; + _z_reply_t r; + r.data._tag = _Z_REPLY_TAG_ERROR; + r.data._result.error.payload = *payload; + r.data._result.error.encoding = *encoding; return r; } _z_reply_t _z_reply_move(_z_reply_t *src_reply); diff --git a/include/zenoh-pico/net/sample.h b/include/zenoh-pico/net/sample.h index 374241808..718fe95da 100644 --- a/include/zenoh-pico/net/sample.h +++ b/include/zenoh-pico/net/sample.h @@ -46,18 +46,19 @@ static inline bool _z_sample_check(const _z_sample_t *sample) { return _z_keyexpr_check(&sample->keyexpr) || _z_encoding_check(&sample->encoding) || _z_bytes_check(&sample->payload) || _z_bytes_check(&sample->attachment); } -static inline _z_sample_t _z_sample_alias(_z_keyexpr_t *key, _z_bytes_t *payload, const _z_timestamp_t *timestamp, - _z_encoding_t *encoding, const z_sample_kind_t kind, const _z_qos_t qos, - _z_bytes_t *attachment, z_reliability_t reliability) { +static inline _z_sample_t _z_sample_alias(const _z_keyexpr_t *key, const _z_bytes_t *payload, + const _z_timestamp_t *timestamp, const _z_encoding_t *encoding, + const z_sample_kind_t kind, const _z_qos_t qos, const _z_bytes_t *attachment, + z_reliability_t reliability) { return (_z_sample_t){ - .kind = kind, - .qos = qos, - .reliability = reliability, .keyexpr = *key, - .encoding = *encoding, - .attachment = *attachment, .payload = *payload, .timestamp = *timestamp, + .encoding = *encoding, + .kind = kind, + .qos = qos, + .attachment = *attachment, + .reliability = reliability, }; } void _z_sample_move(_z_sample_t *dst, _z_sample_t *src); diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index 6f2eae321..5362c1921 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -56,13 +56,15 @@ typedef struct _z_session_t { _z_subscription_rc_list_t *_remote_subscriptions; #if Z_FEATURE_RX_CACHE == 1 _z_subscription_cache_t _subscription_cache; - _z_queryable_cache_t _queryable_cache; #endif #endif // Session queryables #if Z_FEATURE_QUERYABLE == 1 _z_session_queryable_rc_list_t *_local_queryable; +#if Z_FEATURE_RX_CACHE == 1 + _z_queryable_cache_t _queryable_cache; +#endif #endif #if Z_FEATURE_QUERY == 1 _z_pending_query_list_t *_pending_queries; diff --git a/include/zenoh-pico/protocol/definitions/network.h b/include/zenoh-pico/protocol/definitions/network.h index bae5c47c1..24d86102c 100644 --- a/include/zenoh-pico/protocol/definitions/network.h +++ b/include/zenoh-pico/protocol/definitions/network.h @@ -91,7 +91,7 @@ static inline bool _z_n_qos_get_express(_z_n_qos_t n_qos) { return (bool)(n_qos. #define _z_n_qos_make(express, nodrop, priority) \ _z_n_qos_create((bool)express, nodrop ? Z_CONGESTION_CONTROL_BLOCK : Z_CONGESTION_CONTROL_DROP, \ (z_priority_t)priority) -#define _Z_N_QOS_DEFAULT _z_n_qos_make(0, 0, 5) +#define _Z_N_QOS_DEFAULT ((_z_qos_t){._val = 5}) // RESPONSE FINAL message flags: // Z Extensions if Z==1 then Zenoh extensions are present diff --git a/src/session/utils.c b/src/session/utils.c index ca80d4e94..84ad8793e 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -64,11 +64,13 @@ z_result_t _z_session_init(_z_session_rc_t *zsrc, _z_id_t *zid) { zn->_remote_subscriptions = NULL; #if Z_FEATURE_RX_CACHE == 1 memset(&zn->_subscription_cache, 0, sizeof(zn->_subscription_cache)); - memset(&zn->_queryable_cache, 0, sizeof(zn->_queryable_cache)); #endif #endif #if Z_FEATURE_QUERYABLE == 1 zn->_local_queryable = NULL; +#if Z_FEATURE_RX_CACHE == 1 + memset(&zn->_queryable_cache, 0, sizeof(zn->_queryable_cache)); +#endif #endif #if Z_FEATURE_QUERY == 1 zn->_pending_queries = NULL; @@ -119,11 +121,13 @@ void _z_session_clear(_z_session_t *zn) { _z_flush_subscriptions(zn); #if Z_FEATURE_RX_CACHE == 1 _z_subscription_cache_clear(&zn->_subscription_cache); - _z_queryable_cache_clear(&zn->_queryable_cache); #endif #endif #if Z_FEATURE_QUERYABLE == 1 _z_flush_session_queryable(zn); +#if Z_FEATURE_RX_CACHE == 1 + _z_queryable_cache_clear(&zn->_queryable_cache); +#endif #endif #if Z_FEATURE_QUERY == 1 _z_flush_pending_queries(zn); diff --git a/tests/modularity.py b/tests/modularity.py index 7350ae70a..c268e5756 100644 --- a/tests/modularity.py +++ b/tests/modularity.py @@ -47,8 +47,8 @@ def pub_and_sub(args): # Expected z_sub output & status if args.sub == 1: - z_sub_expected_status = -2 if args.pub == 1: + z_sub_expected_status = 0 z_sub_expected_output = """Opening session... Declaring Subscriber on 'demo/example/**'... Press CTRL-C to quit... @@ -63,6 +63,7 @@ def pub_and_sub(args): >> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 8] Pub from Pico!') >> [Subscriber] Received ('demo/example/zenoh-pico-pub': '[ 9] Pub from Pico!')""" else: + z_sub_expected_status = -2 z_sub_expected_output = """Opening session... Declaring Subscriber on 'demo/example/**'... Press CTRL-C to quit...""" @@ -72,7 +73,7 @@ def pub_and_sub(args): print("Start subscriber") # Start z_sub in the background - z_sub_command = f"stdbuf -oL -eL ./{DIR_EXAMPLES}/z_sub" + z_sub_command = f"stdbuf -oL -eL ./{DIR_EXAMPLES}/z_sub -n 10" z_sub_process = subprocess.Popen( z_sub_command, shell=True, @@ -175,14 +176,15 @@ def query_and_queryable(args): # Expected z_queryable output & status if args.queryable == 1: - z_queryable_expected_status = -2 if args.query == 1: + z_queryable_expected_status = 0 z_queryable_expected_output = """Opening session... Creating Queryable on 'demo/example/zenoh-pico-queryable'... Press CTRL-C to quit... >> [Queryable handler] Received Query 'demo/example/**' """ else: + z_queryable_expected_status = -2 z_queryable_expected_output = """Opening session... Creating Queryable on 'demo/example/zenoh-pico-queryable'... Press CTRL-C to quit...""" @@ -192,7 +194,7 @@ def query_and_queryable(args): print("Start queryable") # Start z_queryable in the background - z_queryable_command = f"stdbuf -oL -eL ./{DIR_EXAMPLES}/z_queryable" + z_queryable_command = f"stdbuf -oL -eL ./{DIR_EXAMPLES}/z_queryable -n 1" z_queryable_process = subprocess.Popen( z_queryable_command, shell=True,