From e9fb8dcbddb2e7a8e36b4ad180cab29d536a89fc Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Fri, 10 Jan 2025 20:51:45 +0100 Subject: [PATCH] Fix tests and undeclaration --- include/zenoh-pico/net/matching.h | 1 + src/api/api.c | 4 +++- src/net/matching.c | 9 +++++---- tests/z_api_matching_test.c | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/zenoh-pico/net/matching.h b/include/zenoh-pico/net/matching.h index 3f1a56a91..7c3579c5f 100644 --- a/include/zenoh-pico/net/matching.h +++ b/include/zenoh-pico/net/matching.h @@ -30,6 +30,7 @@ typedef struct _z_matching_listener_t { } _z_matching_listener_t; _z_matching_listener_t _z_matching_listener_declare(const _z_publisher_t *pub, _z_closure_matching_status_t callback); +z_result_t _z_matching_listener_undeclare(_z_matching_listener_t *listener); // Warning: None of the sub-types require a non-0 initialization. Add a init function if it changes. static inline _z_matching_listener_t _z_matching_listener_null(void) { return (_z_matching_listener_t){0}; } static inline bool _z_matching_listener_check(const _z_matching_listener_t *matching_listener) { diff --git a/src/api/api.c b/src/api/api.c index 20220c899..adb18a94f 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1120,6 +1120,8 @@ z_result_t z_publisher_declare_matching_listener(const z_loaned_publisher_t *pub z_owned_matching_listener_t *matching_listener, z_moved_closure_matching_status_t *callback) { _z_matching_listener_t listener = _z_matching_listener_declare(publisher, callback->_this._val); + + z_internal_closure_matching_status_null(&callback->_this); matching_listener->_val = listener; return _z_matching_listener_check(&listener) ? _Z_RES_OK : _Z_ERR_GENERIC; } @@ -1557,7 +1559,7 @@ z_result_t zp_batch_stop(const z_loaned_session_t *zs) { #ifdef Z_FEATURE_MATCHING void _z_matching_listener_drop(_z_matching_listener_t *listener) { - //_z_undeclare_matching_listener(pub); + _z_matching_listener_undeclare(listener); _z_matching_listener_clear(listener); } diff --git a/src/net/matching.c b/src/net/matching.c index 7a59c1493..012f6256c 100644 --- a/src/net/matching.c +++ b/src/net/matching.c @@ -20,6 +20,7 @@ #include "zenoh-pico/api/types.h" #include "zenoh-pico/net/primitives.h" #include "zenoh-pico/utils/logging.h" +#include "zenoh-pico/utils/result.h" #if Z_FEATURE_MATCHING == 1 static void _z_matching_listener_callback(const _z_interest_msg_t *msg, void *arg) { @@ -68,11 +69,11 @@ _z_matching_listener_t _z_matching_listener_declare(const _z_publisher_t *pub, _ return ret; } +z_result_t _z_matching_listener_undeclare(_z_matching_listener_t *listener) { + return _z_remove_interest(_Z_RC_IN_VAL(&listener->_zn), listener->_interest_id); +} + void _z_matching_listener_clear(_z_matching_listener_t *listener) { - z_result_t res = _z_remove_interest(_Z_RC_IN_VAL(&listener->_zn), listener->_interest_id); - if (res != _Z_RES_OK) { - _Z_ERROR("Failed to remove interest: %i\n", res); - } _z_session_weak_drop(&listener->_zn); *listener = _z_matching_listener_null(); } diff --git a/tests/z_api_matching_test.c b/tests/z_api_matching_test.c index d4d1a9733..ad925854f 100644 --- a/tests/z_api_matching_test.c +++ b/tests/z_api_matching_test.c @@ -87,7 +87,7 @@ void test_matching_sub(void) { z_owned_subscriber_t sub; z_owned_closure_sample_t callback; z_closure_sample(&callback, NULL, NULL, NULL); - assert_ok(z_declare_subscriber(z_session_loan(&s1), &sub, z_view_keyexpr_loan(&k_sub), + assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub, z_view_keyexpr_loan(&k_sub), z_closure_sample_move(&callback), NULL)); z_sleep_s(5); @@ -136,7 +136,7 @@ void test_matching_get(void) { z_owned_subscriber_t sub; z_owned_closure_sample_t callback; z_closure_sample(&callback, NULL, NULL, NULL); - assert_ok(z_declare_subscriber(z_session_loan(&s1), &sub, z_view_keyexpr_loan(&k_sub), + assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub, z_view_keyexpr_loan(&k_sub), z_closure_sample_move(&callback), NULL)); z_sleep_s(3);