From 68eca1f238fdb49c789dd78011211075127fd79a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 20 Feb 2024 11:57:24 +0100 Subject: [PATCH] fix: fuse identical functions --- include/zenoh-pico/session/interest.h | 1 - src/session/interest.c | 34 ++------------------------- src/session/rx.c | 4 ++-- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/include/zenoh-pico/session/interest.h b/include/zenoh-pico/session/interest.h index d1e7b900a..3ff41c908 100644 --- a/include/zenoh-pico/session/interest.h +++ b/include/zenoh-pico/session/interest.h @@ -28,7 +28,6 @@ void _z_flush_interest(_z_session_t *zn); #endif // Z_FEATURE_INTEREST == 1 int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl); -int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl); int8_t _z_interest_process_final_interest(_z_session_t *zn, uint32_t id); int8_t _z_interest_process_undeclare_interest(_z_session_t *zn, uint32_t id); int8_t _z_interest_process_declare_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags); diff --git a/src/session/interest.c b/src/session/interest.c index 515b15b21..1e6cfd16a 100644 --- a/src/session/interest.c +++ b/src/session/interest.c @@ -127,37 +127,6 @@ int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *de msg.id = decl->_body._decl_queryable._id; decl_key = &decl->_body._decl_queryable._keyexpr; break; - default: - return _Z_ERR_MESSAGE_ZENOH_DECLARATION_UNKNOWN; - } - _zp_session_lock_mutex(zn); - _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, decl_key); - if (key._suffix == NULL) { - _zp_session_unlock_mutex(zn); - return _Z_ERR_KEYEXPR_UNKNOWN; - } - _z_session_interest_rc_list_t *intrs = __unsafe_z_get_interest_by_key(zn, key); - _zp_session_unlock_mutex(zn); - - // Parse session_interest list - _z_session_interest_rc_list_t *xs = intrs; - while (xs != NULL) { - _z_session_interest_rc_t *intr = _z_session_interest_rc_list_head(xs); - if (intr->in->val._callback != NULL) { - intr->in->val._callback(&msg, intr->in->val._arg); - } - xs = _z_session_interest_rc_list_tail(xs); - } - // Clean up - _z_keyexpr_clear(&key); - _z_session_interest_rc_list_free(&intrs); - return _Z_RES_OK; -} - -int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl) { - const _z_keyexpr_t *decl_key = NULL; - _z_interest_msg_t msg; - switch (decl->_tag) { case _Z_UNDECL_SUBSCRIBER: msg.type = _Z_INTEREST_MSG_TYPE_UNDECL_SUBSCRIBER; msg.id = decl->_body._undecl_subscriber._id; @@ -173,7 +142,8 @@ int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t * } _zp_session_lock_mutex(zn); _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, decl_key); - if (key._suffix != NULL) { + if (key._suffix == NULL) { + _z_keyexpr_clear(&key); _zp_session_unlock_mutex(zn); return _Z_ERR_KEYEXPR_UNKNOWN; } diff --git a/src/session/rx.c b/src/session/rx.c index bdbe96be1..087f21628 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -70,10 +70,10 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint _z_interest_process_declares(zn, &decl._decl); } break; case _Z_UNDECL_SUBSCRIBER: { - _z_interest_process_undeclares(zn, &decl._decl); + _z_interest_process_declares(zn, &decl._decl); } break; case _Z_UNDECL_QUERYABLE: { - _z_interest_process_undeclares(zn, &decl._decl); + _z_interest_process_declares(zn, &decl._decl); } break; case _Z_DECL_TOKEN: { // TODO: add support or explicitly discard