Skip to content

Commit

Permalink
add zc_undeclare_matching_listener
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Dec 2, 2024
1 parent 43b0b69 commit 1a9583d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 22 additions & 2 deletions src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>),
);
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1a9583d

Please sign in to comment.