Skip to content

Commit

Permalink
Fix modular build
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Nov 5, 2024
1 parent 009fb00 commit 2080e3f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 26 deletions.
5 changes: 2 additions & 3 deletions examples/unix/c11/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_LIVELINESS == 1
#if Z_FEATURE_LIVELINESS == 1 && Z_FEATURE_QUERY == 1

int main(int argc, char **argv) {
const char *keyexpr = "group1/**";
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/api/liveliness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ****************/

/**
Expand Down
4 changes: 3 additions & 1 deletion include/zenoh-pico/net/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions include/zenoh-pico/session/liveliness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 0 additions & 15 deletions include/zenoh-pico/session/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 25 additions & 2 deletions src/session/liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,44 +237,67 @@ 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 ****************/

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

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

Expand Down
6 changes: 3 additions & 3 deletions tests/z_api_liveliness_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <assert.h>
Expand Down Expand Up @@ -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

0 comments on commit 2080e3f

Please sign in to comment.