Skip to content

Commit

Permalink
make attachments optional
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Jan 18, 2024
1 parent 20de28f commit a1e5db7
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ 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=$<CONFIG:Debug>")
message(STATUS "Building with feature confing:\n\
* MULTI-THREAD: ${Z_FEATURE_MULTI_THREAD}\n\
* PUBLICATION: ${Z_FEATURE_PUBLICATION}\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
Expand Down
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
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));

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 11.8 rule Note

MISRA 11.8 rule
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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
z_bytes_map_drop(&map);
#endif
// z_undeclare_keyexpr(z_loan(s), z_move(ke));

// Stop read and lease tasks for zenoh-pico
Expand Down
5 changes: 5 additions & 0 deletions examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@
#include <zenoh-pico.h>

#if Z_FEATURE_SUBSCRIPTION == 1

#if Z_FEATURE_ATTACHMENT == 1
int8_t attachment_handler(z_bytes_t key, z_bytes_t value, void *ctx) {

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
(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));
}

Expand Down
16 changes: 13 additions & 3 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ typedef struct {
*/
typedef struct {
z_encoding_t encoding;
z_attachment_t attachment;
#if Z_FEATURE_ATTACHMENT == 1

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
// TODO:ATT z_attachment_t attachment;
#endif
} z_query_reply_options_t;

/**
Expand All @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
z_attachment_t attachment;
#endif
} z_put_options_t;

/**
Expand All @@ -319,7 +323,9 @@ typedef struct {
*/
typedef struct {
z_encoding_t encoding;
#if Z_FEATURE_ATTACHMENT == 1

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
z_attachment_t attachment;
#endif
} z_publisher_put_options_t;

/**
Expand All @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
// TODO:ATT z_attachment_t attachment;
#endif
} z_get_options_t;

/**
Expand Down Expand Up @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
struct _z_bytes_pair_t {
_z_bytes_t key;
_z_bytes_t value;
Expand Down Expand Up @@ -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`.
*
Expand Down
20 changes: 15 additions & 5 deletions include/zenoh-pico/net/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>

#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 <stdint.h>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
4 changes: 4 additions & 0 deletions include/zenoh-pico/protocol/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

/**
Expand Down
6 changes: 6 additions & 0 deletions include/zenoh-pico/protocol/definitions/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
_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
Expand Down Expand Up @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
_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
Expand All @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
_z_owned_encoded_attachment_t _ext_attachment;
#endif
} _z_msg_query_t;
typedef struct {
_Bool info;
Expand Down
8 changes: 6 additions & 2 deletions include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 12 additions & 3 deletions include/zenoh-pico/session/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
,
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

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
,
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);

Expand Down
Loading

0 comments on commit a1e5db7

Please sign in to comment.