diff --git a/docs/api.rst b/docs/api.rst index dacbf7dee..a955768c7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -545,6 +545,7 @@ Functions --------- .. doxygenfunction:: zc_matching_listener_drop +.. doxygenfunction:: zc_matching_listener_undeclare .. doxygenfunction:: zc_closure_matching_status_drop .. doxygenfunction:: zc_closure_matching_status_loan .. doxygenfunction:: zc_closure_matching_status_call diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index d6dfc5672..6089e8709 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -5333,6 +5333,15 @@ void zc_stop_z_runtime(void); */ ZENOHC_API void zc_try_init_log_from_env(void); +/** + * @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. + * @brief Undeclares the given matching listener, droping and invalidating it. + * @return 0 in case of success, negative error code otherwise. + */ +#if defined(Z_FEATURE_UNSTABLE_API) +ZENOHC_API +z_result_t zc_undeclare_matching_listener(zc_moved_matching_listener_t *this_); +#endif /** * @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. * @brief Declares a background publication cache. It will function in background until the corresponding session is closed or dropped. diff --git a/src/matching.rs b/src/matching.rs index d66613ab6..7223d85bd 100644 --- a/src/matching.rs +++ b/src/matching.rs @@ -14,10 +14,13 @@ use std::mem::MaybeUninit; -use zenoh::matching::MatchingListener; +use zenoh::{matching::MatchingListener, Wait}; pub use crate::opaque_types::{zc_moved_matching_listener_t, zc_owned_matching_listener_t}; -use crate::transmute::{RustTypeRef, RustTypeRefUninit, TakeRustType}; +use crate::{ + result, + transmute::{RustTypeRef, RustTypeRefUninit, TakeRustType}, +}; decl_c_type!( owned(zc_owned_matching_listener_t, option MatchingListener<()>), ); @@ -56,3 +59,20 @@ pub struct zc_matching_status_t { pub extern "C" fn zc_matching_listener_drop(this: &mut zc_moved_matching_listener_t) { std::mem::drop(this.take_rust_type()) } + +/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release. +/// @brief Undeclares the given matching listener, droping and invalidating it. +/// @return 0 in case of success, negative error code otherwise. +#[no_mangle] +#[allow(clippy::missing_safety_doc)] +pub extern "C" fn zc_undeclare_matching_listener( + this: &mut zc_moved_matching_listener_t, +) -> result::z_result_t { + if let Some(m) = this.take_rust_type() { + if let Err(e) = m.undeclare().wait() { + tracing::error!("{}", e); + return result::Z_ENETWORK; + } + } + result::Z_OK +} diff --git a/src/querier.rs b/src/querier.rs index 7b0a8fe5d..df4c0a287 100644 --- a/src/querier.rs +++ b/src/querier.rs @@ -391,8 +391,8 @@ pub extern "C" fn z_querier_drop(this: &mut z_moved_querier_t) { /// /// @return 0 in case of success, negative error code otherwise. pub extern "C" fn z_undeclare_querier(this_: &mut z_moved_querier_t) -> result::z_result_t { - if let Some(p) = this_.take_rust_type() { - if let Err(e) = p.undeclare().wait() { + if let Some(q) = this_.take_rust_type() { + if let Err(e) = q.undeclare().wait() { tracing::error!("{}", e); return result::Z_ENETWORK; }