From 2080e3fcf06a1dfdd78a0876cd166aef79e70f1f Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Tue, 5 Nov 2024 16:32:15 +0100 Subject: [PATCH] Fix modular build --- examples/unix/c11/z_get_liveliness.c | 5 ++--- include/zenoh-pico/api/liveliness.h | 4 ++-- include/zenoh-pico/net/session.h | 4 +++- include/zenoh-pico/session/liveliness.h | 15 ++++++++++++++ include/zenoh-pico/session/session.h | 15 -------------- src/session/liveliness.c | 27 +++++++++++++++++++++++-- tests/z_api_liveliness_test.c | 6 +++--- 7 files changed, 50 insertions(+), 26 deletions(-) diff --git a/examples/unix/c11/z_get_liveliness.c b/examples/unix/c11/z_get_liveliness.c index 32fea41a7..cefa20175 100644 --- a/examples/unix/c11/z_get_liveliness.c +++ b/examples/unix/c11/z_get_liveliness.c @@ -13,11 +13,10 @@ #include #include -#include #include #include -#if Z_FEATURE_LIVELINESS == 1 +#if Z_FEATURE_LIVELINESS == 1 && Z_FEATURE_QUERY == 1 int main(int argc, char **argv) { const char *keyexpr = "group1/**"; @@ -110,7 +109,7 @@ int main(int argc, char **argv) { #else int main(void) { printf( - "ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY or Z_FEATURE_MULTI_THREAD but this example requires " + "ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY or Z_FEATURE_LIVELINESS but this example requires " "them.\n"); return -2; } diff --git a/include/zenoh-pico/api/liveliness.h b/include/zenoh-pico/api/liveliness.h index 4453fdafb..89848eb96 100644 --- a/include/zenoh-pico/api/liveliness.h +++ b/include/zenoh-pico/api/liveliness.h @@ -21,8 +21,6 @@ #include "zenoh-pico/api/types.h" #include "zenoh-pico/protocol/core.h" -#if Z_FEATURE_LIVELINESS == 1 - typedef struct { uint32_t _id; _z_keyexpr_t _key; @@ -32,6 +30,8 @@ typedef struct { _Z_OWNED_TYPE_VALUE(_z_liveliness_token_t, liveliness_token) _Z_OWNED_FUNCTIONS_DEF(liveliness_token) +#if Z_FEATURE_LIVELINESS == 1 + /**************** Liveliness Token ****************/ /** diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index d252d493c..f47428aaa 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -59,10 +59,12 @@ typedef struct _z_session_t { #endif #if Z_FEATURE_LIVELINESS == 1 - uint32_t _liveliness_query_id; _z_keyexpr_intmap_t _local_tokens; _z_keyexpr_intmap_t _remote_tokens; +#if Z_FEATURE_QUERY == 1 + uint32_t _liveliness_query_id; _z_liveliness_pending_query_intmap_t _liveliness_pending_queries; +#endif #endif // Session queryables diff --git a/include/zenoh-pico/session/liveliness.h b/include/zenoh-pico/session/liveliness.h index cfa31594e..6c64be399 100644 --- a/include/zenoh-pico/session/liveliness.h +++ b/include/zenoh-pico/session/liveliness.h @@ -16,6 +16,21 @@ #define ZENOH_PICO_SESSION_LIVELINESS_H #if Z_FEATURE_LIVELINESS == 1 +typedef struct { + _z_keyexpr_t _key; + _z_closure_reply_callback_t _callback; + _z_drop_handler_t _dropper; + void *_arg; +} _z_liveliness_pending_query_t; + +void _z_liveliness_pending_query_clear(_z_liveliness_pending_query_t *res); +void _z_liveliness_pending_query_copy(_z_liveliness_pending_query_t *dst, const _z_liveliness_pending_query_t *src); +_z_liveliness_pending_query_t *_z_liveliness_pending_query_clone(const _z_liveliness_pending_query_t *src); + +_Z_ELEM_DEFINE(_z_liveliness_pending_query, _z_liveliness_pending_query_t, _z_noop_size, + _z_liveliness_pending_query_clear, _z_liveliness_pending_query_copy) +_Z_INT_MAP_DEFINE(_z_liveliness_pending_query, _z_liveliness_pending_query_t) + uint32_t _z_liveliness_get_query_id(_z_session_t *zn); z_result_t _z_liveliness_register_token(_z_session_t *zn, uint32_t id, const _z_keyexpr_t keyexpr); diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index 18b2c4508..d096daf94 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -143,21 +143,6 @@ void _z_pending_query_clear(_z_pending_query_t *res); _Z_ELEM_DEFINE(_z_pending_query, _z_pending_query_t, _z_noop_size, _z_pending_query_clear, _z_noop_copy) _Z_LIST_DEFINE(_z_pending_query, _z_pending_query_t) -typedef struct { - _z_keyexpr_t _key; - _z_closure_reply_callback_t _callback; - _z_drop_handler_t _dropper; - void *_arg; -} _z_liveliness_pending_query_t; - -void _z_liveliness_pending_query_clear(_z_liveliness_pending_query_t *res); -void _z_liveliness_pending_query_copy(_z_liveliness_pending_query_t *dst, const _z_liveliness_pending_query_t *src); -_z_liveliness_pending_query_t *_z_liveliness_pending_query_clone(const _z_liveliness_pending_query_t *src); - -_Z_ELEM_DEFINE(_z_liveliness_pending_query, _z_liveliness_pending_query_t, _z_noop_size, - _z_liveliness_pending_query_clear, _z_liveliness_pending_query_copy) -_Z_INT_MAP_DEFINE(_z_liveliness_pending_query, _z_liveliness_pending_query_t) - typedef struct { #if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_t _mutex; diff --git a/src/session/liveliness.c b/src/session/liveliness.c index 92f952cd7..f3ddb383b 100644 --- a/src/session/liveliness.c +++ b/src/session/liveliness.c @@ -237,25 +237,44 @@ void _z_liveliness_unregister_pending_query(_z_session_t *zn, uint32_t id) { /**************** Interest processing ****************/ z_result_t _z_liveliness_process_token_declare(_z_session_t *zn, const _z_n_msg_declare_t *decl) { +#if Z_FEATURE_QUERY == 1 if (decl->has_interest_id) { _z_liveliness_pending_query_reply(zn, decl->_interest_id, decl->_decl._body._decl_token._keyexpr, &decl->_ext_timestamp); } +#endif +#if Z_FEATURE_SUBSCRIPTION == 1 return _z_liveliness_subscription_declare(zn, decl->_decl._body._decl_token._id, decl->_decl._body._decl_token._keyexpr, &decl->_ext_timestamp); +#else + _ZP_UNUSED(zn); + _ZP_UNUSED(decl); + return _Z_RES_OK; +#endif } z_result_t _z_liveliness_process_token_undeclare(_z_session_t *zn, const _z_n_msg_declare_t *decl) { +#if Z_FEATURE_SUBSCRIPTION == 1 return _z_liveliness_subscription_undeclare(zn, decl->_decl._body._undecl_token._id, &decl->_ext_timestamp); +#else + _ZP_UNUSED(zn); + _ZP_UNUSED(decl); + return _Z_RES_OK; +#endif } z_result_t _z_liveliness_process_declare_final(_z_session_t *zn, const _z_n_msg_declare_t *decl) { +#if Z_FEATURE_QUERY == 1 if (decl->has_interest_id) { _z_liveliness_pending_query_drop(zn, decl->_interest_id); } - return _Z_RES_OK; +#else + _ZP_UNUSED(zn); + _ZP_UNUSED(decl); + return _Z_RES_OK; +#endif } /**************** Init/Clear ****************/ @@ -263,10 +282,12 @@ z_result_t _z_liveliness_process_declare_final(_z_session_t *zn, const _z_n_msg_ void _z_liveliness_init(_z_session_t *zn) { _zp_session_lock_mutex(zn); - zn->_liveliness_query_id = 1; zn->_remote_tokens = _z_keyexpr_intmap_make(); zn->_local_tokens = _z_keyexpr_intmap_make(); +#if Z_FEATURE_QUERY == 1 + zn->_liveliness_query_id = 1; zn->_liveliness_pending_queries = _z_liveliness_pending_query_intmap_make(); +#endif _zp_session_unlock_mutex(zn); } @@ -274,7 +295,9 @@ void _z_liveliness_init(_z_session_t *zn) { void _z_liveliness_clear(_z_session_t *zn) { _zp_session_lock_mutex(zn); +#if Z_FEATURE_QUERY == 1 _z_liveliness_pending_query_intmap_clear(&zn->_liveliness_pending_queries); +#endif _z_keyexpr_intmap_clear(&zn->_local_tokens); _z_keyexpr_intmap_clear(&zn->_remote_tokens); diff --git a/tests/z_api_liveliness_test.c b/tests/z_api_liveliness_test.c index 623494cc5..8c31d315f 100644 --- a/tests/z_api_liveliness_test.c +++ b/tests/z_api_liveliness_test.c @@ -24,7 +24,7 @@ #include "zenoh-pico/api/primitives.h" #include "zenoh-pico/api/types.h" -#if Z_FEATURE_QUERY == 1 +#if Z_FEATURE_LIVELINESS == 1 && Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_QUERY == 1 #undef NDEBUG #include @@ -195,9 +195,9 @@ int main(int argc, char** argv) { test_liveliness_get(); } -#else // Z_FEATURE_QUERY == 1 +#else int main(int argc, char** argv) { (void)argc; (void)argv; } -#endif // Z_FEATURE_QUERY == 1 +#endif