Skip to content

Commit

Permalink
make z_id_closure stable
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Oct 16, 2024
1 parent 26532cd commit 32643ed
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 50 deletions.
36 changes: 3 additions & 33 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,27 +346,21 @@ typedef struct z_moved_closure_sample_t {
struct z_owned_closure_sample_t _this;
} z_moved_closure_sample_t;
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief A zenoh id-processing closure.
*
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
*/
#if defined(Z_FEATURE_UNSTABLE_API)
typedef struct z_owned_closure_zid_t {
void *_context;
void (*_call)(const struct z_id_t *z_id, void *context);
void (*_drop)(void *context);
} z_owned_closure_zid_t;
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Moved closure.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
typedef struct z_moved_closure_zid_t {
struct z_owned_closure_zid_t _this;
} z_moved_closure_zid_t;
#endif
typedef struct z_moved_condvar_t {
struct z_owned_condvar_t _this;
} z_moved_condvar_t;
Expand Down Expand Up @@ -1568,38 +1562,27 @@ const struct z_loaned_closure_sample_t *z_closure_sample_loan(const struct z_own
* @param drop: an optional function to be called once on closure drop.
* @param context: closure context.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
void z_closure_zid(struct z_owned_closure_zid_t *this_,
void (*call)(const struct z_id_t *z_id, void *context),
void (*drop)(void *context),
void *context);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Calls the closure. Calling an uninitialized closure is a no-op.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
void z_closure_zid_call(const struct z_loaned_closure_zid_t *closure,
const struct z_id_t *z_id);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Drops the closure, resetting it to its gravestone state. Droping an uninitialized (null) closure is a no-op.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
void z_closure_zid_drop(struct z_moved_closure_zid_t *closure_);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Borrows closure.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
const struct z_loaned_closure_zid_t *z_closure_zid_loan(const struct z_owned_closure_zid_t *closure);
#endif
/**
* Drops conditional variable.
*/
Expand Down Expand Up @@ -2327,16 +2310,12 @@ ZENOHC_API enum z_whatami_t z_hello_whatami(const struct z_loaned_hello_t *this_
*/
ZENOHC_API struct z_id_t z_hello_zid(const struct z_loaned_hello_t *this_);
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Formats the `z_id_t` into 16-digit hex string (LSB-first order)
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
void z_id_to_string(const struct z_id_t *zid,
struct z_owned_string_t *dst);
ZENOHC_API void z_id_to_string(const struct z_id_t *zid, struct z_owned_string_t *dst);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Fetches the Zenoh IDs of all connected peers.
*
* `callback` will be called once for each ID, is guaranteed to never be called concurrently,
Expand All @@ -2350,7 +2329,6 @@ z_result_t z_info_peers_zid(const struct z_loaned_session_t *session,
struct z_moved_closure_zid_t *callback);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Fetches the Zenoh IDs of all connected routers.
*
* `callback` will be called once for each ID, is guaranteed to never be called concurrently,
Expand All @@ -2364,16 +2342,14 @@ z_result_t z_info_routers_zid(const struct z_loaned_session_t *session,
struct z_moved_closure_zid_t *callback);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Returns the session's Zenoh ID.
*
* Unless the `session` is invalid, that ID is guaranteed to be non-zero.
* In other words, this function returning an array of 16 zeros means you failed
* to pass it a valid session.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
struct z_id_t z_info_zid(const struct z_loaned_session_t *session);
ZENOHC_API struct z_id_t z_info_zid(const struct z_loaned_session_t *session);
#endif
/**
* Returns ``true`` if `this` is valid.
Expand Down Expand Up @@ -2452,21 +2428,15 @@ ZENOHC_API bool z_internal_closure_sample_check(const struct z_owned_closure_sam
*/
ZENOHC_API void z_internal_closure_sample_null(struct z_owned_closure_sample_t *this_);
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Returns ``true`` if closure is valid, ``false`` if it is in gravestone state.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
bool z_internal_closure_zid_check(const struct z_owned_closure_zid_t *this_);
#endif
ZENOHC_API bool z_internal_closure_zid_check(const struct z_owned_closure_zid_t *this_);
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Constructs a null closure.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
ZENOHC_API
void z_internal_closure_zid_null(struct z_owned_closure_zid_t *this_);
#endif
/**
* Returns ``true`` if conditional variable is valid, ``false`` otherwise.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/closures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ mod query_closure;
pub use reply_closure::*;
mod reply_closure;

#[cfg(feature = "unstable")]
pub use zenohid_closure::*;
#[cfg(feature = "unstable")]
mod zenohid_closure;

pub use response_channel::*;
Expand Down
7 changes: 0 additions & 7 deletions src/closures/zenohid_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
transmute::{LoanedCTypeRef, OwnedCTypeRef, TakeRustType},
z_id_t,
};
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief A zenoh id-processing closure.
///
/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
Expand All @@ -31,14 +30,12 @@ pub struct z_owned_closure_zid_t {
_drop: Option<extern "C" fn(context: *mut c_void)>,
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Loaned closure.
#[repr(C)]
pub struct z_loaned_closure_zid_t {
_0: [usize; 3],
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Moved closure.
#[repr(C)]
pub struct z_moved_closure_zid_t {
Expand Down Expand Up @@ -76,7 +73,6 @@ impl Drop for z_owned_closure_zid_t {
}
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Returns ``true`` if closure is valid, ``false`` if it is in gravestone state.
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
Expand All @@ -94,7 +90,6 @@ pub unsafe extern "C" fn z_internal_closure_zid_null(
this_.write(z_owned_closure_zid_t::default());
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Calls the closure. Calling an uninitialized closure is a no-op.
#[no_mangle]
pub extern "C" fn z_closure_zid_call(closure: &z_loaned_closure_zid_t, z_id: &z_id_t) {
Expand All @@ -107,7 +102,6 @@ pub extern "C" fn z_closure_zid_call(closure: &z_loaned_closure_zid_t, z_id: &z_
}
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Drops the closure, resetting it to its gravestone state. Droping an uninitialized (null) closure is a no-op.
#[no_mangle]
pub extern "C" fn z_closure_zid_drop(closure_: &mut z_moved_closure_zid_t) {
Expand All @@ -132,7 +126,6 @@ impl<F: Fn(&z_id_t)> From<F> for z_owned_closure_zid_t {
}
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Borrows closure.
#[no_mangle]
pub extern "C" fn z_closure_zid_loan(closure: &z_owned_closure_zid_t) -> &z_loaned_closure_zid_t {
Expand Down
4 changes: 0 additions & 4 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ impl From<[u8; 16]> for z_id_t {
}
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Formats the `z_id_t` into 16-digit hex string (LSB-first order)
#[no_mangle]
pub extern "C" fn z_id_to_string(zid: &z_id_t, dst: &mut MaybeUninit<z_owned_string_t>) {
let zid = zid.as_rust_type_ref();
dst.as_rust_type_mut_uninit().write(zid.to_string().into());
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Returns the session's Zenoh ID.
///
/// Unless the `session` is invalid, that ID is guaranteed to be non-zero.
Expand All @@ -51,7 +49,6 @@ pub unsafe extern "C" fn z_info_zid(session: &z_loaned_session_t) -> z_id_t {
session.info().zid().wait().into_c_type()
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Fetches the Zenoh IDs of all connected peers.
///
/// `callback` will be called once for each ID, is guaranteed to never be called concurrently,
Expand All @@ -72,7 +69,6 @@ pub unsafe extern "C" fn z_info_peers_zid(
result::Z_OK
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Fetches the Zenoh IDs of all connected routers.
///
/// `callback` will be called once for each ID, is guaranteed to never be called concurrently,
Expand Down
6 changes: 2 additions & 4 deletions src/scouting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ use zenoh::{
pub use crate::opaque_types::{z_loaned_hello_t, z_moved_hello_t, z_owned_hello_t};
use crate::{
result::{self, Z_OK},
transmute::{LoanedCTypeRef, RustTypeRef, RustTypeRefUninit, TakeRustType},
z_closure_hello_call, z_closure_hello_loan, z_moved_closure_hello_t, z_moved_config_t,
transmute::{IntoCType, LoanedCTypeRef, RustTypeRef, RustTypeRefUninit, TakeRustType},
z_closure_hello_call, z_closure_hello_loan, z_id_t, z_moved_closure_hello_t, z_moved_config_t,
z_owned_string_array_t, z_view_string_t, CString, CStringView, ZVector,
};
#[cfg(feature = "unstable")]
use crate::{transmute::IntoCType, z_id_t};
decl_c_type!(
owned(z_owned_hello_t, option Hello ),
loaned(z_loaned_hello_t),
Expand Down

0 comments on commit 32643ed

Please sign in to comment.