use crate::{arc, blocks, define_cls, define_mtl, define_obj_type, mtl, ns, objc};
#[cfg(feature = "dispatch")]
use crate::dispatch;
define_obj_type!(
#[doc(alias = "MTLEvent")]
pub Event(ns::Id)
);
impl Event {
define_mtl!(set_label);
#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;
#[objc::msg_send(label)]
pub fn label(&self) -> Option<&ns::String>;
}
define_obj_type!(
#[doc(alias = "MTLSharedEventListener")]
pub SharedEventListener(ns::Id)
);
impl arc::A<SharedEventListener> {
#[cfg(feature = "dispatch")]
#[objc::msg_send(initWithDispatchQueue:)]
pub fn init_with_dispatch_queue(self, queue: &dispatch::Queue) -> arc::R<SharedEventListener>;
}
pub type SharedEventNotificationBlock =
blocks::EscBlock<fn(event: &mut mtl::SharedEvent, value: u64)>;
impl SharedEventListener {
define_cls!(MTL_SHARED_EVENT_LISTENER);
#[inline]
#[cfg(feature = "dispatch")]
pub fn with_dispatch_queue(queue: &dispatch::Queue) -> arc::R<Self> {
Self::alloc().init_with_dispatch_queue(queue)
}
#[cfg(feature = "dispatch")]
#[objc::msg_send(dispatchQueue)]
pub fn dispatch_queue(&self) -> arc::R<dispatch::Queue>;
}
define_obj_type!(
#[doc(alias = "MTLSharedEventHandle")]
pub SharedEventHandle(ns::Id)
);
impl SharedEventHandle {
#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}
define_obj_type!(
#[doc(alias = "MTLSharedEvent")]
pub SharedEvent(Event)
);
impl SharedEvent {
#[objc::msg_send(notifyListener:atValue:block:)]
pub fn notify_listener_at_block(
&self,
listener: &mtl::SharedEventListener,
at_value: u64,
block: &mut SharedEventNotificationBlock,
);
pub fn notify_listener_at(
&self,
listener: &mtl::SharedEventListener,
at_value: u64,
block: impl FnMut(&mut mtl::SharedEvent, u64) + Send + 'static,
) {
let mut block = SharedEventNotificationBlock::new2(block);
self.notify_listener_at_block(listener, at_value, &mut block);
}
#[objc::msg_send(newSharedEventHandle)]
pub fn new_shared_event_handle(&self) -> arc::R<mtl::SharedEventHandle>;
#[objc::msg_send(waitUntilSignaledValue:timeoutMS:)]
pub fn wait_until_signaled_value(&self, value: u64, timeout_ms: u64) -> bool;
#[objc::msg_send(signaledValue)]
pub fn signaled_value(&self) -> u64;
#[objc::msg_send(setSignaledValue:)]
pub fn set_signaled_value(&self, val: u64);
}
unsafe extern "C" {
static MTL_SHARED_EVENT_LISTENER: &'static objc::Class<SharedEventListener>;
}