-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ns::Notification and fixes for ca::Renderer
- Loading branch information
Showing
6 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Coder>; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::ns; | ||
|
||
#[test] | ||
fn basics() { | ||
let coder = ns::Coder::new(); | ||
println!("{coder:?}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Notification> { | ||
#[objc::msg_send(initWithName:object:userInfo:)] | ||
pub fn init_with_name( | ||
self, | ||
name: &ns::NotificationName, | ||
object: Option<&ns::Id>, | ||
user_info: Option<&ns::Dictionary<ns::Id, ns::Id>>, | ||
) -> arc::R<Notification>; | ||
|
||
#[objc::msg_send(initWithCoder:)] | ||
pub fn init_with_coder(self, coder: &ns::Coder) -> arc::R<Notification>; | ||
} | ||
|
||
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<ns::Id, ns::Id>>; | ||
|
||
pub fn with_name( | ||
name: &ns::NotificationName, | ||
object: Option<&ns::Id>, | ||
user_info: Option<&ns::Dictionary<ns::Id, ns::Id>>, | ||
) -> arc::R<Self> { | ||
Self::alloc().init_with_name(name, object, user_info) | ||
} | ||
|
||
pub fn with_coder(coder: &ns::Coder) -> arc::R<Self> { | ||
Self::alloc().init_with_coder(coder) | ||
} | ||
} | ||
|
||
#[link(name = "ns", kind = "static")] | ||
extern "C" { | ||
static NS_NOTIFICATION: &'static objc::Class<Notification>; | ||
} |