diff --git a/CMakeLists.txt b/CMakeLists.txt index e504c60e0..04a5ecfee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,12 +117,14 @@ set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature") set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature") set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature") set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport feature") +set(Z_FEATURE_ATTACHMENT 1 CACHE STRING "Toggle attachment feature") add_definition(Z_FEATURE_MULTI_THREAD=${Z_FEATURE_MULTI_THREAD}) add_definition(Z_FEATURE_PUBLICATION=${Z_FEATURE_PUBLICATION}) add_definition(Z_FEATURE_SUBSCRIPTION=${Z_FEATURE_SUBSCRIPTION}) add_definition(Z_FEATURE_QUERY=${Z_FEATURE_QUERY}) add_definition(Z_FEATURE_QUERYABLE=${Z_FEATURE_QUERYABLE}) add_definition(Z_FEATURE_RAWETH_TRANSPORT=${Z_FEATURE_RAWETH_TRANSPORT}) +add_definition(Z_FEATURE_ATTACHMENT=${Z_FEATURE_ATTACHMENT}) add_compile_definitions("Z_BUILD_DEBUG=$") message(STATUS "Building with feature confing:\n\ * MULTI-THREAD: ${Z_FEATURE_MULTI_THREAD}\n\ @@ -130,6 +132,7 @@ message(STATUS "Building with feature confing:\n\ * SUBSCRIPTION: ${Z_FEATURE_SUBSCRIPTION}\n\ * QUERY: ${Z_FEATURE_QUERY}\n\ * QUERYABLE: ${Z_FEATURE_QUERYABLE}\n\ +* ATTACHMENT: ${Z_FEATURE_ATTACHMENT}\n\ * RAWETH: ${Z_FEATURE_RAWETH_TRANSPORT}") # Print summary of CMAKE configurations diff --git a/GNUmakefile b/GNUmakefile index eac55f32a..89b7c9334 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -56,6 +56,7 @@ Z_FEATURE_PUBLICATION?=1 Z_FEATURE_SUBSCRIPTION?=1 Z_FEATURE_QUERY?=1 Z_FEATURE_QUERYABLE?=1 +Z_FEATURE_ATTACHMENT?=1 Z_FEATURE_RAWETH_TRANSPORT?=0 # zenoh-pico/ directory @@ -74,7 +75,7 @@ CROSSIMG_PREFIX=zenoh-pico_ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST)\ -DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) \ -DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\ - -DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H. + -DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DZ_FEATURE_ATTACHMENT=$(Z_FEATURE_ATTACHMENT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H. ifeq ($(FORCE_C99), ON) CMAKE_OPT += -DCMAKE_C_STANDARD=99 diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index e79639f25..a542c26ac 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -93,14 +93,18 @@ int main(int argc, char **argv) { printf("Putting Data ('%s': '%s')...\n", keyexpr, value); z_put_options_t options = z_put_options_default(); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); +#if Z_FEATURE_ATTACHMENT == 1 z_owned_bytes_map_t map = z_bytes_map_new(); z_bytes_map_insert_by_alias(&map, _z_bytes_wrap((uint8_t *)"hi", 2), _z_bytes_wrap((uint8_t *)"there", 5)); options.attachment = z_bytes_map_as_attachment(&map); +#endif if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, strlen(value), &options) < 0) { printf("Oh no! Put has failed...\n"); } +#if Z_FEATURE_ATTACHMENT == 1 z_bytes_map_drop(&map); +#endif // z_undeclare_keyexpr(z_loan(s), z_move(ke)); // Stop read and lease tasks for zenoh-pico diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index c069960cb..99ea3e1d7 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -21,21 +21,26 @@ #include #if Z_FEATURE_SUBSCRIPTION == 1 + +#if Z_FEATURE_ATTACHMENT == 1 int8_t attachment_handler(z_bytes_t key, z_bytes_t value, void *ctx) { (void)ctx; printf(">>> %.*s: %.*s\n", (int)key.len, key.start, (int)value.len, value.start); return 0; } +#endif void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample->payload.len, sample->payload.start); +#if Z_FEATURE_ATTACHMENT == 1 if (z_attachment_check(&sample->attachment)) { printf("Attachement found\n"); z_attachment_iterate(sample->attachment, attachment_handler, NULL); } +#endif z_drop(z_move(keystr)); } diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index a672ff4e2..6b1d176ab 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -278,7 +278,9 @@ typedef struct { */ typedef struct { z_encoding_t encoding; - z_attachment_t attachment; +#if Z_FEATURE_ATTACHMENT == 1 + // TODO:ATT z_attachment_t attachment; +#endif } z_query_reply_options_t; /** @@ -294,7 +296,9 @@ typedef struct { z_encoding_t encoding; z_congestion_control_t congestion_control; z_priority_t priority; +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t attachment; +#endif } z_put_options_t; /** @@ -319,7 +323,9 @@ typedef struct { */ typedef struct { z_encoding_t encoding; +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t attachment; +#endif } z_publisher_put_options_t; /** @@ -343,7 +349,9 @@ typedef struct { z_value_t value; z_query_consolidation_t consolidation; z_query_target_t target; - z_attachment_t attachment; +#if Z_FEATURE_ATTACHMENT == 1 +// TODO:ATT z_attachment_t attachment; +#endif } z_get_options_t; /** @@ -553,7 +561,7 @@ typedef struct { } z_owned_closure_zid_t; void z_closure_zid_call(const z_owned_closure_zid_t *closure, const z_id_t *id); - +#if Z_FEATURE_ATTACHMENT == 1 struct _z_bytes_pair_t { _z_bytes_t key; _z_bytes_t value; @@ -645,6 +653,8 @@ z_owned_bytes_map_t z_bytes_map_new(void); * Constructs the gravestone value for `z_owned_bytes_map_t` */ z_owned_bytes_map_t z_bytes_map_null(void); +#endif + /** * Returns a view of `str` using `strlen`. * diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 0a253cc72..c1cf2a0da 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -11,8 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, -#ifndef ZENOH_PICO_PRIMITIVES_NETAPI_H -#define ZENOH_PICO_PRIMITIVES_NETAPI_H +#ifndef INCLUDE_ZENOH_PICO_NET_PRIMITIVES_H +#define INCLUDE_ZENOH_PICO_NET_PRIMITIVES_H #include @@ -119,7 +119,12 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub); */ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *payload, const size_t len, const _z_encoding_t encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, - z_priority_t priority, z_attachment_t attachment); + z_priority_t priority +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t attachment +#endif +); #endif #if Z_FEATURE_SUBSCRIPTION == 1 @@ -228,7 +233,12 @@ int8_t _z_send_reply(const z_query_t *query, const _z_keyexpr_t keyexpr, const _ */ 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, const _z_value_t value, _z_reply_handler_t callback, - void *arg_call, _z_drop_handler_t dropper, void *arg_drop, z_attachment_t attachment); + void *arg_call, _z_drop_handler_t dropper, void *arg_drop +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t attachment +#endif +); #endif -#endif /* ZENOH_PICO_PRIMITIVES_NETAPI_H */ +#endif /* INCLUDE_ZENOH_PICO_NET_PRIMITIVES_H */ diff --git a/include/zenoh-pico/protocol/core.h b/include/zenoh-pico/protocol/core.h index db56fe014..a60a12dc6 100644 --- a/include/zenoh-pico/protocol/core.h +++ b/include/zenoh-pico/protocol/core.h @@ -71,6 +71,7 @@ typedef struct { uint64_t time; } _z_timestamp_t; +#if Z_FEATURE_ATTACHMENT == 1 /** * The body of a loop over an attachment's key-value pairs. * @@ -127,6 +128,7 @@ typedef struct { size_t _z_attachment_estimate_length(z_attachment_t att); z_attachment_t _z_encoded_as_attachment(const _z_owned_encoded_attachment_t *att); void _z_encoded_attachment_drop(_z_owned_encoded_attachment_t *att); +#endif _z_timestamp_t _z_timestamp_duplicate(const _z_timestamp_t *tstamp); _z_timestamp_t _z_timestamp_null(void); @@ -225,7 +227,9 @@ typedef struct { _z_timestamp_t timestamp; _z_encoding_t encoding; z_sample_kind_t kind; +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t attachment; +#endif } _z_sample_t; /** diff --git a/include/zenoh-pico/protocol/definitions/message.h b/include/zenoh-pico/protocol/definitions/message.h index d143e5493..503483c89 100644 --- a/include/zenoh-pico/protocol/definitions/message.h +++ b/include/zenoh-pico/protocol/definitions/message.h @@ -69,7 +69,9 @@ typedef struct { _z_value_t _value; _z_source_info_t _ext_source_info; z_consolidation_mode_t _ext_consolidation; +#if Z_FEATURE_ATTACHMENT == 1 _z_owned_encoded_attachment_t _ext_attachment; +#endif } _z_msg_reply_t; void _z_msg_reply_clear(_z_msg_reply_t *msg); #define _Z_FLAG_Z_R_T 0x20 @@ -152,7 +154,9 @@ typedef struct { _z_m_push_commons_t _commons; _z_bytes_t _payload; _z_encoding_t _encoding; +#if Z_FEATURE_ATTACHMENT == 1 _z_owned_encoded_attachment_t _attachment; +#endif } _z_msg_put_t; void _z_msg_put_clear(_z_msg_put_t *); #define _Z_M_PUT_ID 0x01 @@ -176,7 +180,9 @@ typedef struct { _z_source_info_t _ext_info; _z_value_t _ext_value; z_consolidation_mode_t _ext_consolidation; +#if Z_FEATURE_ATTACHMENT == 1 _z_owned_encoded_attachment_t _ext_attachment; +#endif } _z_msg_query_t; typedef struct { _Bool info; diff --git a/include/zenoh-pico/protocol/definitions/network.h b/include/zenoh-pico/protocol/definitions/network.h index 14661adc0..5c09247d3 100644 --- a/include/zenoh-pico/protocol/definitions/network.h +++ b/include/zenoh-pico/protocol/definitions/network.h @@ -230,8 +230,12 @@ _Z_VEC_DEFINE(_z_network_message, _z_network_message_t) void _z_msg_fix_mapping(_z_zenoh_message_t *msg, uint16_t mapping); _z_network_message_t _z_msg_make_pull(_z_keyexpr_t key, _z_zint_t pull_id); _z_network_message_t _z_msg_make_query(_Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_bytes_t) parameters, _z_zint_t qid, - z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value, - z_attachment_t attachment); + z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t attachment +#endif +); _z_network_message_t _z_n_msg_make_reply(_z_zint_t rid, _Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_value_t) value); _z_network_message_t _z_n_msg_make_ack(_z_zint_t rid, _Z_MOVE(_z_keyexpr_t) key); _z_network_message_t _z_n_msg_make_response_final(_z_zint_t rid); diff --git a/include/zenoh-pico/session/subscription.h b/include/zenoh-pico/session/subscription.h index 1f1a1aca6..b6fcb2caa 100644 --- a/include/zenoh-pico/session/subscription.h +++ b/include/zenoh-pico/session/subscription.h @@ -25,10 +25,19 @@ _z_subscription_sptr_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8 _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_t *sub); void _z_trigger_local_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *payload, - _z_zint_t payload_len, z_attachment_t att); + _z_zint_t payload_len +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t att +#endif +); int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, - const _z_encoding_t encoding, const _z_zint_t kind, const _z_timestamp_t timestamp, - z_attachment_t att); + const _z_encoding_t encoding, const _z_zint_t kind, const _z_timestamp_t timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t att +#endif +); void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_sptr_t *sub); void _z_flush_subscriptions(_z_session_t *zn); diff --git a/src/api/api.c b/src/api/api.c index 8a4179973..e8ad13603 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -599,10 +599,13 @@ OWNED_FUNCTIONS_PTR_CLONE(z_publisher_t, z_owned_publisher_t, publisher, _z_owne void z_publisher_drop(z_owned_publisher_t *val) { z_undeclare_publisher(val); } z_put_options_t z_put_options_default(void) { - return (z_put_options_t){.encoding = z_encoding_default(), - .congestion_control = Z_CONGESTION_CONTROL_DEFAULT, - .priority = Z_PRIORITY_DEFAULT, - .attachment = z_attachment_null()}; + return (z_put_options_t) { + .encoding = z_encoding_default(), .congestion_control = Z_CONGESTION_CONTROL_DEFAULT, + .priority = Z_PRIORITY_DEFAULT, +#if Z_FEATURE_ATTACHMENT == 1 + .attachment = z_attachment_null() +#endif + }; } z_delete_options_t z_delete_options_default(void) { @@ -618,13 +621,25 @@ int8_t z_put(z_session_t zs, z_keyexpr_t keyexpr, const uint8_t *payload, z_zint opt.congestion_control = options->congestion_control; opt.encoding = options->encoding; opt.priority = options->priority; +#if Z_FEATURE_ATTACHMENT == 1 opt.attachment = options->attachment; +#endif } ret = _z_write(zs._val, keyexpr, (const uint8_t *)payload, payload_len, opt.encoding, Z_SAMPLE_KIND_PUT, - opt.congestion_control, opt.priority, opt.attachment); + opt.congestion_control, opt.priority +#if Z_FEATURE_ATTACHMENT == 1 + , + opt.attachment +#endif + ); // Trigger local subscriptions - _z_trigger_local_subscriptions(zs._val, keyexpr, payload, payload_len, opt.attachment); + _z_trigger_local_subscriptions(zs._val, keyexpr, payload, payload_len +#if Z_FEATURE_ATTACHMENT == 1 + , + opt.attachment +#endif + ); return ret; } @@ -638,7 +653,12 @@ int8_t z_delete(z_session_t zs, z_keyexpr_t keyexpr, const z_delete_options_t *o opt.priority = options->priority; } ret = _z_write(zs._val, keyexpr, NULL, 0, z_encoding_default(), Z_SAMPLE_KIND_DELETE, opt.congestion_control, - opt.priority, z_attachment_null()); + opt.priority +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_null() +#endif + ); return ret; } @@ -680,7 +700,12 @@ int8_t z_undeclare_publisher(z_owned_publisher_t *pub) { } z_publisher_put_options_t z_publisher_put_options_default(void) { - return (z_publisher_put_options_t){.encoding = z_encoding_default(), .attachment = z_attachment_null()}; + return (z_publisher_put_options_t) { + .encoding = z_encoding_default(), +#if Z_FEATURE_ATTACHMENT == 1 + .attachment = z_attachment_null() +#endif + }; } z_publisher_delete_options_t z_publisher_delete_options_default(void) { @@ -694,14 +719,26 @@ int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t l z_publisher_put_options_t opt = z_publisher_put_options_default(); if (options != NULL) { opt.encoding = options->encoding; +#if Z_FEATURE_ATTACHMENT == 1 opt.attachment = options->attachment; +#endif } ret = _z_write(pub._val->_zn, pub._val->_key, payload, len, opt.encoding, Z_SAMPLE_KIND_PUT, - pub._val->_congestion_control, pub._val->_priority, opt.attachment); + pub._val->_congestion_control, pub._val->_priority +#if Z_FEATURE_ATTACHMENT == 1 + , + opt.attachment +#endif + ); // Trigger local subscriptions - _z_trigger_local_subscriptions(pub._val->_zn, pub._val->_key, payload, len, opt.attachment); + _z_trigger_local_subscriptions(pub._val->_zn, pub._val->_key, payload, len +#if Z_FEATURE_ATTACHMENT == 1 + , + opt.attachment +#endif + ); return ret; } @@ -709,7 +746,12 @@ int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t l int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_options_t *options) { (void)(options); return _z_write(pub._val->_zn, pub._val->_key, NULL, 0, z_encoding_default(), Z_SAMPLE_KIND_DELETE, - pub._val->_congestion_control, pub._val->_priority, z_attachment_null()); + pub._val->_congestion_control, pub._val->_priority +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_null() +#endif + ); } z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) { @@ -725,10 +767,13 @@ z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) { OWNED_FUNCTIONS_PTR_INTERNAL(z_reply_t, z_owned_reply_t, reply, _z_reply_free, _z_owner_noop_copy) z_get_options_t z_get_options_default(void) { - return (z_get_options_t){.target = z_query_target_default(), - .consolidation = z_query_consolidation_default(), - .value = {.encoding = z_encoding_default(), .payload = _z_bytes_empty()}, - .attachment = z_attachment_null()}; + return (z_get_options_t) { + .target = z_query_target_default(), .consolidation = z_query_consolidation_default(), + .value = {.encoding = z_encoding_default(), .payload = _z_bytes_empty()}, +#if Z_FEATURE_ATTACHMENT == 1 + .attachment = z_attachment_null() +#endif + }; } typedef struct __z_reply_handler_wrapper_t { @@ -776,7 +821,13 @@ 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, opt.attachment); + wrapped_ctx, callback->drop, ctx + +#if Z_FEATURE_ATTACHMENT == 1 + , + opt.attachment +#endif + ); return ret; } @@ -1110,7 +1161,7 @@ int8_t zp_send_join(z_session_t zs, const zp_send_join_options_t *options) { (void)(options); return _zp_send_join(zs._val); } - +#if Z_FEATURE_ATTACHMENT == 1 void _z_bytes_pair_clear(struct _z_bytes_pair_t *this_) { _z_bytes_clear(&this_->key); _z_bytes_clear(&this_->value); @@ -1222,3 +1273,4 @@ z_bytes_t z_bytes_new(const char *str) { return (z_bytes_t){.len = strlen(str), ._is_alloc = false, .start = (unsigned char *)str}; } z_bytes_t z_bytes_null(void) { return (z_bytes_t){.len = 0, ._is_alloc = false, .start = NULL}; } +#endif \ No newline at end of file diff --git a/src/net/primitives.c b/src/net/primitives.c index 374083d63..13d51e0a5 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -128,7 +128,12 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub) { /*------------------ Write ------------------*/ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *payload, const size_t len, const _z_encoding_t encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, - z_priority_t priority, z_attachment_t attachment) { + z_priority_t priority +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t attachment +#endif +) { int8_t ret = _Z_RES_OK; _z_network_message_t msg; switch (kind) { @@ -146,7 +151,9 @@ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *pay ._commons = {._timestamp = _z_timestamp_null(), ._source_info = _z_source_info_null()}, ._payload = _z_bytes_wrap(payload, len), ._encoding = encoding, +#if Z_FEATURE_ATTACHMENT == 1 ._attachment = {.is_encoded = false, .body.decoded = attachment}, +#endif }, }, }; @@ -383,7 +390,12 @@ int8_t _z_send_reply(const z_query_t *query, _z_keyexpr_t keyexpr, const _z_valu /*------------------ 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, - void *arg_call, _z_drop_handler_t dropper, void *arg_drop, z_attachment_t attachment) { + void *arg_call, _z_drop_handler_t dropper, void *arg_drop +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t attachment +#endif +) { int8_t ret = _Z_RES_OK; // Create the pending query object @@ -404,8 +416,12 @@ int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, ret = _z_register_pending_query(zn, pq); // Add the pending query to the current session if (ret == _Z_RES_OK) { _z_bytes_t params = _z_bytes_wrap((uint8_t *)pq->_parameters, strlen(pq->_parameters)); - _z_zenoh_message_t z_msg = - _z_msg_make_query(&keyexpr, ¶ms, pq->_id, pq->_consolidation, &value, attachment); + _z_zenoh_message_t z_msg = _z_msg_make_query(&keyexpr, ¶ms, pq->_id, pq->_consolidation, &value +#if Z_FEATURE_ATTACHMENT == 1 + , + attachment +#endif + ); if (_z_send_n_msg(zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { _z_unregister_pending_query(zn, pq); diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 7060e638a..0f8438653 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -15,6 +15,7 @@ #include "zenoh-pico/protocol/definitions/message.h" #include +#include #include #include #include @@ -241,7 +242,7 @@ int8_t _z_source_info_encode_ext(_z_wbuf_t *wbf, const _z_source_info_t *info) { _Z_RETURN_IF_ERR(_z_zint_encode(wbf, info->_source_sn)); return ret; } - +#if Z_FEATURE_ATTACHMENT == 1 int8_t _z_attachment_encode_ext_kv(_z_bytes_t key, _z_bytes_t value, void *ctx) { _z_wbuf_t *wbf = (_z_wbuf_t *)ctx; _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &key)); @@ -254,7 +255,7 @@ int8_t _z_attachment_encode_ext(_z_wbuf_t *wbf, z_attachment_t att) { _Z_RETURN_IF_ERR(z_attachment_iterate(att, _z_attachment_encode_ext_kv, wbf)); return 0; } - +#endif /*------------------ Push Body Field ------------------*/ int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { (void)(wbf); @@ -263,8 +264,12 @@ int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { _Bool has_source_info = _z_id_check(pshb->_body._put._commons._source_info._id) || pshb->_body._put._commons._source_info._source_sn != 0 || pshb->_body._put._commons._source_info._entity_id != 0; +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t att = _z_encoded_as_attachment(&pshb->_body._put._attachment); _Bool has_attachment = pshb->_is_put && z_attachment_check(&att); +#else + _Bool has_attachment = false; +#endif _Bool has_timestamp = _z_timestamp_check(&pshb->_body._put._commons._timestamp); _Bool has_encoding = false; if (has_source_info || has_attachment) { @@ -298,12 +303,12 @@ int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZBUF | 0x01 | (has_attachment ? _Z_FLAG_Z_Z : 0))); _Z_RETURN_IF_ERR(_z_source_info_encode_ext(wbf, &pshb->_body._put._commons._source_info)); } - +#if Z_FEATURE_ATTACHMENT == 1 if (has_attachment) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZBUF | 0x03)); _Z_RETURN_IF_ERR(_z_attachment_encode_ext(wbf, att)); } - +#endif if (pshb->_is_put) { _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &pshb->_body._put._payload)); } @@ -319,6 +324,7 @@ int8_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) { ret = _z_source_info_decode(&pshb->_body._put._commons._source_info, &zbf); break; } +#if Z_FEATURE_ATTACHMENT == 1 case _Z_MSG_EXT_ENC_ZBUF | 0x03: { pshb->_body._put._attachment.is_encoded = true; pshb->_body._put._attachment.body.encoded = extension->_body._zbuf._val._is_alloc @@ -326,6 +332,7 @@ int8_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) { : _z_bytes_duplicate(&extension->_body._zbuf._val); break; } +#endif default: if (_Z_HAS_FLAG(extension->_header, _Z_MSG_EXT_FLAG_M)) { ret = _z_msg_ext_unknown_error(extension, 0x08); @@ -448,11 +455,13 @@ int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *msg) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); _Z_RETURN_IF_ERR(_z_source_info_encode_ext(wbf, &msg->_ext_info)); } +#if Z_FEATURE_ATTACHMENT == 1 if (required_exts.attachment) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZBUF | 0x05)); z_attachment_t att = _z_encoded_as_attachment(&msg->_ext_attachment); _Z_RETURN_IF_ERR(_z_attachment_encode_ext(wbf, att)); } +#endif return ret; } @@ -478,6 +487,7 @@ int8_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_bytes_copy(&msg->_ext_value.payload, &bytes); break; } +#if Z_FEATURE_ATTACHMENT == 1 case _Z_MSG_EXT_ENC_ZBUF | 0x05: { msg->_ext_attachment.is_encoded = true; msg->_ext_attachment.body.encoded = extension->_body._zbuf._val._is_alloc @@ -485,6 +495,7 @@ int8_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) { : _z_bytes_duplicate(&extension->_body._zbuf._val); break; } +#endif default: if (_Z_HAS_FLAG(extension->_header, _Z_MSG_EXT_FLAG_M)) { ret = _z_msg_ext_unknown_error(extension, 0x09); @@ -520,8 +531,12 @@ int8_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply) { !_z_bytes_is_empty(&reply->_value.encoding.suffix)) { header |= _Z_FLAG_Z_R_E; } +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t att = _z_encoded_as_attachment(&reply->_ext_attachment); _Bool has_attachment = z_attachment_check(&att); +#else + _Bool has_attachment = false; +#endif _Bool has_sourceinfo = _z_id_check(reply->_ext_source_info._id) || reply->_ext_source_info._source_sn != 0 || reply->_ext_source_info._entity_id != 0; _Bool has_consolidation_ext = reply->_ext_consolidation != Z_CONSOLIDATION_MODE_AUTO; @@ -555,10 +570,12 @@ int8_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); _Z_RETURN_IF_ERR(_z_zint_encode(wbf, reply->_ext_consolidation)); } +#if Z_FEATURE_ATTACHMENT == 1 if (has_attachment) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_MSG_EXT_ENC_ZBUF | 0x04)); _Z_RETURN_IF_ERR(_z_attachment_encode_ext(wbf, att)); } +#endif _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &reply->_value.payload)); return ret; } @@ -575,6 +592,7 @@ int8_t _z_reply_decode_extension(_z_msg_ext_t *extension, void *ctx) { reply->_ext_consolidation = extension->_body._zint._val; break; } +#if Z_FEATURE_ATTACHMENT == 1 case _Z_MSG_EXT_ENC_ZBUF | 0x04: { reply->_ext_attachment.is_encoded = true; reply->_ext_attachment.body.encoded = extension->_body._zbuf._val._is_alloc @@ -582,6 +600,7 @@ int8_t _z_reply_decode_extension(_z_msg_ext_t *extension, void *ctx) { : _z_bytes_duplicate(&extension->_body._zbuf._val); break; } +#endif default: if (_Z_HAS_FLAG(extension->_header, _Z_MSG_EXT_FLAG_M)) { ret = _z_msg_ext_unknown_error(extension, 0x0a); diff --git a/src/protocol/core.c b/src/protocol/core.c index b469f872c..29608735e 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -72,6 +72,8 @@ _z_value_t _z_value_steal(_z_value_t *value) { *value = _z_value_null(); return ret; } + +#if Z_FEATURE_ATTACHMENT == 1 struct _z_seeker_t { _z_bytes_t key; _z_bytes_t value; @@ -133,3 +135,4 @@ int8_t z_attachment_iterate(z_attachment_t this_, z_attachment_iter_body_t body, return this_.iteration_driver(this_.data, body, ctx); } z_attachment_t z_attachment_null(void) { return (z_attachment_t){.data = NULL, .iteration_driver = NULL}; } +#endif \ No newline at end of file diff --git a/src/protocol/definitions/message.c b/src/protocol/definitions/message.c index 10bd7b3ee..0fc391f62 100644 --- a/src/protocol/definitions/message.c +++ b/src/protocol/definitions/message.c @@ -14,6 +14,8 @@ #include "zenoh-pico/protocol/definitions/message.h" +#include + #include "zenoh-pico/collections/bytes.h" #include "zenoh-pico/protocol/core.h" @@ -26,13 +28,20 @@ void _z_msg_put_clear(_z_msg_put_t *msg) { } _z_msg_query_reqexts_t _z_msg_query_required_extensions(const _z_msg_query_t *msg) { +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t att = _z_encoded_as_attachment(&msg->_ext_attachment); - return (_z_msg_query_reqexts_t){ +#endif + return (_z_msg_query_reqexts_t) { .body = msg->_ext_value.payload.start != NULL || msg->_ext_value.encoding.prefix != 0 || !_z_bytes_is_empty(&msg->_ext_value.encoding.suffix), .info = _z_id_check(msg->_ext_info._id) || msg->_ext_info._entity_id != 0 || msg->_ext_info._source_sn != 0, .consolidation = msg->_ext_consolidation != Z_CONSOLIDATION_MODE_AUTO, - .attachment = z_attachment_check(&att)}; +#if Z_FEATURE_ATTACHMENT == 1 + .attachment = z_attachment_check(&att) +#else + .attachment = false +#endif + }; } void _z_msg_query_clear(_z_msg_query_t *msg) { diff --git a/src/protocol/definitions/network.c b/src/protocol/definitions/network.c index 922ba8cfd..af5192b14 100644 --- a/src/protocol/definitions/network.c +++ b/src/protocol/definitions/network.c @@ -168,8 +168,12 @@ _z_network_message_t _z_msg_make_pull(_z_keyexpr_t key, _z_zint_t pull_id) { return ret; } _z_zenoh_message_t _z_msg_make_query(_Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_bytes_t) parameters, _z_zint_t qid, - z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value, - z_attachment_t attachment) { + z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t attachment +#endif +) { return (_z_zenoh_message_t){ ._tag = _Z_N_REQUEST, ._body._request = @@ -181,7 +185,10 @@ _z_zenoh_message_t _z_msg_make_query(_Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_bytes ._ext_consolidation = consolidation, ._ext_value = _z_value_steal(value), ._ext_info = _z_source_info_null(), - ._ext_attachment = {.body.decoded = attachment, .is_encoded = false}}, +#if Z_FEATURE_ATTACHMENT == 1 + ._ext_attachment = {.body.decoded = attachment, .is_encoded = false} +#endif + }, ._ext_budget = 0, ._ext_qos = _Z_N_QOS_DEFAULT, ._ext_target = Z_QUERY_TARGET_BEST_MATCHING, diff --git a/src/session/push.c b/src/session/push.c index dae8f5823..55187bae7 100644 --- a/src/session/push.c +++ b/src/session/push.c @@ -29,8 +29,15 @@ int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push) { _z_encoding_t encoding = push->_body._is_put ? push->_body._body._put._encoding : z_encoding_default(); int kind = push->_body._is_put ? Z_SAMPLE_KIND_PUT : Z_SAMPLE_KIND_DELETE; #if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t att = _z_encoded_as_attachment(&push->_body._body._put._attachment); - ret = _z_trigger_subscriptions(zn, push->_key, payload, encoding, kind, push->_timestamp, att); +#endif + ret = _z_trigger_subscriptions(zn, push->_key, payload, encoding, kind, push->_timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + att +#endif + ); #endif return ret; } diff --git a/src/session/rx.c b/src/session/rx.c index e2336b481..9b27a9fbd 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -100,9 +100,16 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint case _Z_REQUEST_PUT: { _z_msg_put_t put = req._body._put; #if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_ATTACHMENT == 1 z_attachment_t att = _z_encoded_as_attachment(&put._attachment); +#endif ret = _z_trigger_subscriptions(zn, req._key, put._payload, put._encoding, Z_SAMPLE_KIND_PUT, - put._commons._timestamp, att); + put._commons._timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + att +#endif + ); #endif if (ret == _Z_RES_OK) { _z_network_message_t ack = _z_n_msg_make_ack(req._rid, &req._key); @@ -115,7 +122,12 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint _z_msg_del_t del = req._body._del; #if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, req._key, _z_bytes_empty(), z_encoding_default(), - Z_SAMPLE_KIND_DELETE, del._commons._timestamp, z_attachment_null()); + Z_SAMPLE_KIND_DELETE, del._commons._timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_null() +#endif + ); #endif if (ret == _Z_RES_OK) { _z_network_message_t ack = _z_n_msg_make_ack(req._rid, &req._key); @@ -149,17 +161,29 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } break; case _Z_RESPONSE_BODY_PUT: { _z_msg_put_t put = response._body._put; - z_attachment_t att = _z_encoded_as_attachment(&put._attachment); #if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_ATTACHMENT == 1 + z_attachment_t att = _z_encoded_as_attachment(&put._attachment); +#endif ret = _z_trigger_subscriptions(zn, response._key, put._payload, put._encoding, Z_SAMPLE_KIND_PUT, - put._commons._timestamp, att); + put._commons._timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + att +#endif + ); #endif } break; case _Z_RESPONSE_BODY_DEL: { _z_msg_del_t del = response._body._del; #if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, response._key, _z_bytes_empty(), z_encoding_default(), - Z_SAMPLE_KIND_DELETE, del._commons._timestamp, z_attachment_null()); + Z_SAMPLE_KIND_DELETE, del._commons._timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_null() +#endif + ); #endif } break; } diff --git a/src/session/subscription.c b/src/session/subscription.c index f585e9c23..435f2d682 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -153,16 +153,30 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo } void _z_trigger_local_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *payload, - _z_zint_t payload_len, z_attachment_t att) { + _z_zint_t payload_len +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t att +#endif +) { _z_encoding_t encoding = {.prefix = Z_ENCODING_PREFIX_DEFAULT, .suffix = _z_bytes_wrap(NULL, 0)}; int8_t ret = _z_trigger_subscriptions(zn, keyexpr, _z_bytes_wrap(payload, payload_len), encoding, Z_SAMPLE_KIND_PUT, - _z_timestamp_null(), att); + _z_timestamp_null() +#if Z_FEATURE_ATTACHMENT == 1 + , + att +#endif + ); (void)ret; } int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, - const _z_encoding_t encoding, const _z_zint_t kind, const _z_timestamp_t timestamp, - z_attachment_t att) { + const _z_encoding_t encoding, const _z_zint_t kind, const _z_timestamp_t timestamp +#if Z_FEATURE_ATTACHMENT == 1 + , + z_attachment_t att +#endif +) { int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 @@ -186,7 +200,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co s.encoding = encoding; s.kind = kind; s.timestamp = timestamp; +#if Z_FEATURE_ATTACHMENT == 1 s.attachment = att; +#endif _z_subscription_sptr_list_t *xs = subs; _Z_DEBUG("Triggering %ju subs", (uintmax_t)_z_subscription_sptr_list_len(xs)); while (xs != NULL) {