pubusecrate::sys::event_client_notify_handled; pubusecrate::sys::event_source_create; pubusecrate::sys::event_source_open; pubusecrate::sys::event_source_publish; pubusecrate::sys::event_source_signal; use alloc::ffi::CString; use alloc::vec::Vec; use core::ffi::CStr; use core::ptr::null; use core::ptr::null_mut; use peer_id::Uuid; use rust_support::handle::handle; use rust_support::handle::handle_close; use rust_support::Error as LkError;
type Result<T> = core::result::Result<T, LkError>;
mod sys { #![allow(unused)] #![allow(non_camel_case_types)] use peer_id::{uuid, uuid_t}; use rust_support::handle::handle;
include!(env!("BINDGEN_INC_FILE"));
}
/// An event source which owns the buffer for its name, the UUIDs allowed to access it and the /// backing event_source object. Dropping this closes the handle which destroys the backing /// event_source. #[derive(Debug)] pubstruct EventSource {
evt_handle: *mut handle, // The following are not accessed but need to be stored to ensure they live as long as the // event_source.
_evt_name: CString,
_uuids: Vec<Uuid>,
}
// SAFETY: Once created the only modifications to EventSource allowed are publishing and signaling // which may both happen concurrently from multiple threads since the backing event_source object // grabs locks for both these functions. unsafeimpl Sync for EventSource {}
// SAFETY: EventSource may be sent between threads since any thread is allowed to publish and signal // it, not just the thread that created it. unsafeimpl Send for EventSource {}
impl EventSource { /// Creates a new event_source object. /// /// The event name must be unique otherwise an error is returned. pubfn create(evt_name: CString, uuids: Vec<Uuid>) -> Result<Self> { letmut evt_handle = null_mut(); // SAFETY: The pointer to the name lives as long as needed since it's owned by the returned // Self and moving it in the return value does not change the address it points to. The // pointer to the UUIDs lives long enough since it is owned by the EventSource. The // reference to the event handle out parameter also lives as long as needed since it's a // local in this function. let rc = unsafe {
event_source_create(
evt_name.as_ptr(),
null(), /* event_source_ops */
null(), /* ops_arg */
uuids.as_ptr(),
uuids.len().try_into().unwrap(), /* usize to u32 conversion should not fail */ 0, /* reserved flag MBZ */
&mut evt_handle,
)
}; if rc < 0 {
LkError::from_lk(rc)?;
}
Ok(Self { evt_handle, _evt_name: evt_name, _uuids: uuids })
}
/// Publish the event source to allow clients to open it. pubfn publish(&self) -> Result<()> { // SAFETY: evt_handle is a handle pointer initialized by event_source_create. let rc = unsafe { event_source_publish(self.evt_handle) }; if rc < 0 {
LkError::from_lk(rc)?;
}
Ok(())
}
/// Signal an event. /// /// Signaling without publishing does nothing since clients cannot open the event_source before /// it's published. pubfn signal(&self) -> Result<()> { // SAFETY: evt_handle is a handle pointer initialized by event_source_create. let rc = unsafe { event_source_signal(self.evt_handle) }; if rc < 0 {
LkError::from_lk(rc)?;
}
Ok(())
}
impl Drop for EventSource { fn drop(&mutself) { // SAFETY: evt_handle is a handle pointer initialized by event_source_create. unsafe { handle_close(self.evt_handle) }
}
}
/// An event source client which owns the backing event_client object. /// Dropping this closes the handle which destroys the backing event_client. #[derive(Debug)] pubstruct EventClient {
evt_handle: *mut handle,
}
// SAFETY: Once created the only modification to EventClient allowed is notifying the source which // may both happen concurrently from multiple threads since the backing event_client object grabs // a lock for this function. unsafeimpl Sync for EventClient {}
// SAFETY: EventClient may be sent between threads since any thread is allowed to notify the source, // not just the thread that created it. unsafeimpl Send for EventClient {}
impl EventClient { /// Open a published event source. pubfn open(evt_name: &CStr, uuid: Uuid) -> Result<Self> { letmut evt_handle = null_mut(); // SAFETY: The pointers to the UUID and name only need to live for the lifetime of the call // to event_source_open since they are only used to lookup the existing event. The reference // to the event handle out parameter also lives as long as needed since it's a local in this // function. let rc = unsafe {
event_source_open(
&uuid as *const Uuid,
evt_name.as_ptr(),
evt_name.to_bytes_with_nul().len(), 0, /* reserved flag MBZ */
&mut evt_handle,
)
}; if rc < 0 {
LkError::from_lk(rc)?;
}
Ok(Self { evt_handle })
}
/// Notify the event source that the client has handled the signal. pubfn notify_handled(&self) -> Result<()> { // SAFETY: evt_handle is a handle pointer initialized by event_source_open. let rc = unsafe { event_client_notify_handled(self.evt_handle) }; if rc < 0 {
LkError::from_lk(rc)?;
}
Ok(())
}
impl Drop for EventClient { fn drop(&mutself) { // SAFETY: evt_handle is a handle pointer initialized by event_source_open. unsafe { handle_close(self.evt_handle) }
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.