objc2_device_discovery_extension/generated/
DDEvent.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Type of event.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/devicediscoveryextension/ddeventtype?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct DDEventType(pub NSInteger);
17impl DDEventType {
18    #[doc(alias = "DDEventTypeUnknown")]
19    pub const Unknown: Self = Self(0);
20    /// Unknown event. Placeholder for initializing event types.
21    #[doc(alias = "DDEventTypeDeviceFound")]
22    pub const DeviceFound: Self = Self(40);
23    /// [DDDeviceEvent] Device found.
24    #[doc(alias = "DDEventTypeDeviceLost")]
25    pub const DeviceLost: Self = Self(41);
26    /// [DDDeviceEvent] Device lost.
27    #[doc(alias = "DDEventTypeDeviceChanged")]
28    pub const DeviceChanged: Self = Self(42);
29}
30
31unsafe impl Encode for DDEventType {
32    const ENCODING: Encoding = NSInteger::ENCODING;
33}
34
35unsafe impl RefEncode for DDEventType {
36    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
37}
38
39impl DDEventType {
40    /// Converts an event to a string for logging, etc.
41    #[doc(alias = "DDEventTypeToString")]
42    #[inline]
43    pub unsafe fn to_string(self) -> Retained<NSString> {
44        extern "C-unwind" {
45            fn DDEventTypeToString(in_value: DDEventType) -> *mut NSString;
46        }
47        let ret = unsafe { DDEventTypeToString(self) };
48        unsafe { Retained::retain_autoreleased(ret) }
49            .expect("function was marked as returning non-null, but actually returned NULL")
50    }
51}
52
53/// Invoked when an event occurs.
54///
55/// See also [Apple's documentation](https://developer.apple.com/documentation/devicediscoveryextension/ddeventhandler?language=objc)
56#[cfg(feature = "block2")]
57pub type DDEventHandler = *mut block2::DynBlock<dyn Fn(NonNull<DDDeviceEvent>)>;
58
59extern_class!(
60    /// Device-related event (e.g. found, lost).
61    ///
62    /// See also [Apple's documentation](https://developer.apple.com/documentation/devicediscoveryextension/dddeviceevent?language=objc)
63    #[unsafe(super(NSObject))]
64    #[derive(Debug, PartialEq, Eq, Hash)]
65    pub struct DDDeviceEvent;
66);
67
68extern_conformance!(
69    unsafe impl NSObjectProtocol for DDDeviceEvent {}
70);
71
72impl DDDeviceEvent {
73    extern_methods!(
74        #[cfg(feature = "DDDevice")]
75        /// Initializes a device event.
76        #[unsafe(method(initWithEventType:device:))]
77        #[unsafe(method_family = init)]
78        pub unsafe fn initWithEventType_device(
79            this: Allocated<Self>,
80            r#type: DDEventType,
81            device: &DDDevice,
82        ) -> Retained<Self>;
83
84        #[cfg(feature = "DDDevice")]
85        /// Device found or lost.
86        #[unsafe(method(device))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn device(&self) -> Retained<DDDevice>;
89
90        /// Type of event.
91        #[unsafe(method(eventType))]
92        #[unsafe(method_family = none)]
93        pub unsafe fn eventType(&self) -> DDEventType;
94    );
95}
96
97/// Methods declared on superclass `NSObject`.
98impl DDDeviceEvent {
99    extern_methods!(
100        #[unsafe(method(init))]
101        #[unsafe(method_family = init)]
102        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
103
104        #[unsafe(method(new))]
105        #[unsafe(method_family = new)]
106        pub unsafe fn new() -> Retained<Self>;
107    );
108}
109
110#[deprecated = "renamed to `DDEventType::to_string`"]
111#[inline]
112pub unsafe extern "C-unwind" fn DDEventTypeToString(in_value: DDEventType) -> Retained<NSString> {
113    extern "C-unwind" {
114        fn DDEventTypeToString(in_value: DDEventType) -> *mut NSString;
115    }
116    let ret = unsafe { DDEventTypeToString(in_value) };
117    unsafe { Retained::retain_autoreleased(ret) }
118        .expect("function was marked as returning non-null, but actually returned NULL")
119}