diff --git a/cidre/pomace/ns/ns.h b/cidre/pomace/ns/ns.h index 5b4f4e89..6e386f4e 100644 --- a/cidre/pomace/ns/ns.h +++ b/cidre/pomace/ns/ns.h @@ -62,6 +62,8 @@ Class NS_UUID; Class NS_VALUE; Class NS_FILE_MANAGER; +Class NS_NOTIFICATION; +Class NS_CODER; __attribute__((constructor)) static void common_initializer(void) @@ -99,6 +101,8 @@ static void common_initializer(void) NS_VALUE = [NSValue class]; NS_FILE_MANAGER = [NSFileManager class]; + NS_NOTIFICATION = [NSNotification class]; + NS_CODER = [NSCoder class]; initialized = 1; } diff --git a/cidre/pomace/sc/sc.h b/cidre/pomace/sc/sc.h index f663535c..e28eadbd 100644 --- a/cidre/pomace/sc/sc.h +++ b/cidre/pomace/sc/sc.h @@ -21,14 +21,11 @@ static void mtl_initializer(void) { static int initialized = 0; if (!initialized) { - if (@available(macOS 12.3, *)) { - SC_STREAM_CONFIGURATION = [SCStreamConfiguration class]; - SC_CONTENT_FILTER = [SCContentFilter class]; - SC_STREAM = [SCStream class]; - SC_SHAREABLE_CONTENT = [SCShareableContent class]; - } else { - // Fallback on earlier versions - } + + SC_STREAM_CONFIGURATION = [SCStreamConfiguration class]; + SC_CONTENT_FILTER = [SCContentFilter class]; + SC_STREAM = [SCStream class]; + SC_SHAREABLE_CONTENT = [SCShareableContent class]; initialized = 1; } diff --git a/cidre/src/ca/renderer.rs b/cidre/src/ca/renderer.rs index 5f40478f..b435bc26 100644 --- a/cidre/src/ca/renderer.rs +++ b/cidre/src/ca/renderer.rs @@ -1,4 +1,4 @@ -use crate::{arc, cf, cv, define_cls, define_obj_type, ns, objc}; +use crate::{arc, ca, cf, cg, cv, define_cls, define_obj_type, mtl, ns, objc}; define_obj_type!(OptionKey(ns::String)); @@ -24,7 +24,7 @@ impl Renderer { options: Option<&ns::Dictionary>, ) -> &'ar Self; - #[objc::rar_retain] + #[objc::cls_rar_retain] pub fn with_mtl_texture( texture: &mtl::Texture, options: Option<&ns::Dictionary>, @@ -46,7 +46,7 @@ impl Renderer { #[objc::msg_send(beginFrameAtTime:timeStamp:)] pub fn begin_frame_at(&mut self, time_stamp: cf::TimeInterval, ts: Option<&cv::TimeStamp>); - #[objc::msg_send(updateBounds)] + #[objc::msg_send(updateBounds:)] pub fn update_bounds(&mut self, bounds: cg::Rect); #[objc::msg_send(addUpdateRect:)] diff --git a/cidre/src/ns.rs b/cidre/src/ns.rs index 6b75cc86..29a7161e 100644 --- a/cidre/src/ns.rs +++ b/cidre/src/ns.rs @@ -147,3 +147,10 @@ pub use path_utilities::temporary_directory; pub use path_utilities::user_name; pub use path_utilities::SearchPathDirectory; pub use path_utilities::SearchPathDomainMask; + +mod notification; +pub use notification::Notification; +pub use notification::NotificationName; + +mod coder; +pub use coder::Coder; diff --git a/cidre/src/ns/coder.rs b/cidre/src/ns/coder.rs new file mode 100644 index 00000000..95180bb7 --- /dev/null +++ b/cidre/src/ns/coder.rs @@ -0,0 +1,38 @@ +use crate::{arc, define_obj_type, ns, objc}; + +/// Describes the action an ns::Coder should take when it encounters decode failures (e.g. corrupt data) +/// for non-TopLevel decodes. +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +#[repr(isize)] +pub enum DecodingFailurePolicy { + /// On decode failure, the ns::Coder will raise an exception internally + /// to propagate failure messages (and unwind the stack). This exception can be transformed + /// into an ns::Error via any of the TopLevel decode APIs. + RaiseException, + + /// On decode failure, the NSCoder will capture the failure as an ns::Error, + /// and prevent further decodes (by returning 0 / None equivalent as appropriate). + /// Clients should consider using this policy if they know that all encoded objects behave correctly + /// in the presence of decode failures (e.g. they use fail_with_error to communicate decode failures + /// and don't raise exceptions for error propagation) + SetErrorAndReturn, +} + +define_obj_type!(Coder(ns::Id), NS_CODER); +impl Coder {} + +#[link(name = "ns", kind = "static")] +extern "C" { + static NS_CODER: &'static objc::Class; +} + +#[cfg(test)] +mod tests { + use crate::ns; + + #[test] + fn basics() { + let coder = ns::Coder::new(); + println!("{coder:?}"); + } +} diff --git a/cidre/src/ns/notification.rs b/cidre/src/ns/notification.rs new file mode 100644 index 00000000..54ca7bd5 --- /dev/null +++ b/cidre/src/ns/notification.rs @@ -0,0 +1,48 @@ +use crate::{arc, define_cls, define_obj_type, ns, objc}; + +define_obj_type!(NotificationName(ns::String)); + +define_obj_type!(Notification(ns::Id)); + +impl arc::A { + #[objc::msg_send(initWithName:object:userInfo:)] + pub fn init_with_name( + self, + name: &ns::NotificationName, + object: Option<&ns::Id>, + user_info: Option<&ns::Dictionary>, + ) -> arc::R; + + #[objc::msg_send(initWithCoder:)] + pub fn init_with_coder(self, coder: &ns::Coder) -> arc::R; +} + +impl Notification { + define_cls!(NS_NOTIFICATION); + + #[objc::msg_send(name)] + pub fn name(&self) -> &ns::NotificationName; + + #[objc::msg_send(object)] + pub fn id(&self) -> Option<&ns::Id>; + + #[objc::msg_send(userInfo)] + pub fn user_info(&self) -> Option<&ns::Dictionary>; + + pub fn with_name( + name: &ns::NotificationName, + object: Option<&ns::Id>, + user_info: Option<&ns::Dictionary>, + ) -> arc::R { + Self::alloc().init_with_name(name, object, user_info) + } + + pub fn with_coder(coder: &ns::Coder) -> arc::R { + Self::alloc().init_with_coder(coder) + } +} + +#[link(name = "ns", kind = "static")] +extern "C" { + static NS_NOTIFICATION: &'static objc::Class; +}