Skip to content

Commit

Permalink
Fix tests and undeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jan 10, 2025
1 parent 5d3bc7c commit e9fb8dc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/zenoh-pico/net/matching.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions src/net/matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/z_api_matching_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e9fb8dc

Please sign in to comment.