objc2_multipeer_connectivity/generated/
MCSession.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/// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/mcsessionsenddatamode?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct MCSessionSendDataMode(pub NSInteger);
15impl MCSessionSendDataMode {
16    #[doc(alias = "MCSessionSendDataReliable")]
17    pub const Reliable: Self = Self(0);
18    #[doc(alias = "MCSessionSendDataUnreliable")]
19    pub const Unreliable: Self = Self(1);
20}
21
22unsafe impl Encode for MCSessionSendDataMode {
23    const ENCODING: Encoding = NSInteger::ENCODING;
24}
25
26unsafe impl RefEncode for MCSessionSendDataMode {
27    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
28}
29
30/// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/mcsessionstate?language=objc)
31// NS_ENUM
32#[repr(transparent)]
33#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
34pub struct MCSessionState(pub NSInteger);
35impl MCSessionState {
36    #[doc(alias = "MCSessionStateNotConnected")]
37    pub const NotConnected: Self = Self(0);
38    #[doc(alias = "MCSessionStateConnecting")]
39    pub const Connecting: Self = Self(1);
40    #[doc(alias = "MCSessionStateConnected")]
41    pub const Connected: Self = Self(2);
42}
43
44unsafe impl Encode for MCSessionState {
45    const ENCODING: Encoding = NSInteger::ENCODING;
46}
47
48unsafe impl RefEncode for MCSessionState {
49    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
50}
51
52/// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/mcencryptionpreference?language=objc)
53// NS_ENUM
54#[repr(transparent)]
55#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
56pub struct MCEncryptionPreference(pub NSInteger);
57impl MCEncryptionPreference {
58    #[doc(alias = "MCEncryptionOptional")]
59    pub const Optional: Self = Self(0);
60    #[doc(alias = "MCEncryptionRequired")]
61    pub const Required: Self = Self(1);
62    #[doc(alias = "MCEncryptionNone")]
63    pub const None: Self = Self(2);
64}
65
66unsafe impl Encode for MCEncryptionPreference {
67    const ENCODING: Encoding = NSInteger::ENCODING;
68}
69
70unsafe impl RefEncode for MCEncryptionPreference {
71    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
72}
73
74extern "C" {
75    /// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/kmcsessionminimumnumberofpeers?language=objc)
76    pub static kMCSessionMinimumNumberOfPeers: NSUInteger;
77}
78
79extern "C" {
80    /// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/kmcsessionmaximumnumberofpeers?language=objc)
81    pub static kMCSessionMaximumNumberOfPeers: NSUInteger;
82}
83
84extern_class!(
85    /// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/mcsession?language=objc)
86    #[unsafe(super(NSObject))]
87    #[derive(Debug, PartialEq, Eq, Hash)]
88    pub struct MCSession;
89);
90
91extern_conformance!(
92    unsafe impl NSObjectProtocol for MCSession {}
93);
94
95impl MCSession {
96    extern_methods!(
97        #[cfg(feature = "MCPeerID")]
98        #[unsafe(method(initWithPeer:))]
99        #[unsafe(method_family = init)]
100        pub unsafe fn initWithPeer(this: Allocated<Self>, my_peer_id: &MCPeerID) -> Retained<Self>;
101
102        #[cfg(feature = "MCPeerID")]
103        /// # Safety
104        ///
105        /// `identity` generic should be of the correct type.
106        #[unsafe(method(initWithPeer:securityIdentity:encryptionPreference:))]
107        #[unsafe(method_family = init)]
108        pub unsafe fn initWithPeer_securityIdentity_encryptionPreference(
109            this: Allocated<Self>,
110            my_peer_id: &MCPeerID,
111            identity: Option<&NSArray>,
112            encryption_preference: MCEncryptionPreference,
113        ) -> Retained<Self>;
114
115        #[cfg(feature = "MCPeerID")]
116        #[unsafe(method(sendData:toPeers:withMode:error:_))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn sendData_toPeers_withMode_error(
119            &self,
120            data: &NSData,
121            peer_i_ds: &NSArray<MCPeerID>,
122            mode: MCSessionSendDataMode,
123        ) -> Result<(), Retained<NSError>>;
124
125        #[unsafe(method(disconnect))]
126        #[unsafe(method_family = none)]
127        pub unsafe fn disconnect(&self);
128
129        #[cfg(all(feature = "MCPeerID", feature = "block2"))]
130        #[unsafe(method(sendResourceAtURL:withName:toPeer:withCompletionHandler:))]
131        #[unsafe(method_family = none)]
132        pub unsafe fn sendResourceAtURL_withName_toPeer_withCompletionHandler(
133            &self,
134            resource_url: &NSURL,
135            resource_name: &NSString,
136            peer_id: &MCPeerID,
137            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
138        ) -> Option<Retained<NSProgress>>;
139
140        #[cfg(feature = "MCPeerID")]
141        #[unsafe(method(startStreamWithName:toPeer:error:_))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn startStreamWithName_toPeer_error(
144            &self,
145            stream_name: &NSString,
146            peer_id: &MCPeerID,
147        ) -> Result<Retained<NSOutputStream>, Retained<NSError>>;
148
149        #[unsafe(method(delegate))]
150        #[unsafe(method_family = none)]
151        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn MCSessionDelegate>>>;
152
153        /// Setter for [`delegate`][Self::delegate].
154        ///
155        /// This is a [weak property][objc2::topics::weak_property].
156        #[unsafe(method(setDelegate:))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn MCSessionDelegate>>);
159
160        #[cfg(feature = "MCPeerID")]
161        #[unsafe(method(myPeerID))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn myPeerID(&self) -> Retained<MCPeerID>;
164
165        #[unsafe(method(securityIdentity))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn securityIdentity(&self) -> Option<Retained<NSArray>>;
168
169        #[unsafe(method(encryptionPreference))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn encryptionPreference(&self) -> MCEncryptionPreference;
172
173        #[cfg(feature = "MCPeerID")]
174        #[unsafe(method(connectedPeers))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn connectedPeers(&self) -> Retained<NSArray<MCPeerID>>;
177    );
178}
179
180/// Methods declared on superclass `NSObject`.
181impl MCSession {
182    extern_methods!(
183        #[unsafe(method(init))]
184        #[unsafe(method_family = init)]
185        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
186
187        #[unsafe(method(new))]
188        #[unsafe(method_family = new)]
189        pub unsafe fn new() -> Retained<Self>;
190    );
191}
192
193extern_protocol!(
194    /// [Apple's documentation](https://developer.apple.com/documentation/multipeerconnectivity/mcsessiondelegate?language=objc)
195    pub unsafe trait MCSessionDelegate: NSObjectProtocol {
196        #[cfg(feature = "MCPeerID")]
197        #[unsafe(method(session:peer:didChangeState:))]
198        #[unsafe(method_family = none)]
199        unsafe fn session_peer_didChangeState(
200            &self,
201            session: &MCSession,
202            peer_id: &MCPeerID,
203            state: MCSessionState,
204        );
205
206        #[cfg(feature = "MCPeerID")]
207        #[unsafe(method(session:didReceiveData:fromPeer:))]
208        #[unsafe(method_family = none)]
209        unsafe fn session_didReceiveData_fromPeer(
210            &self,
211            session: &MCSession,
212            data: &NSData,
213            peer_id: &MCPeerID,
214        );
215
216        #[cfg(feature = "MCPeerID")]
217        #[unsafe(method(session:didReceiveStream:withName:fromPeer:))]
218        #[unsafe(method_family = none)]
219        unsafe fn session_didReceiveStream_withName_fromPeer(
220            &self,
221            session: &MCSession,
222            stream: &NSInputStream,
223            stream_name: &NSString,
224            peer_id: &MCPeerID,
225        );
226
227        #[cfg(feature = "MCPeerID")]
228        #[unsafe(method(session:didStartReceivingResourceWithName:fromPeer:withProgress:))]
229        #[unsafe(method_family = none)]
230        unsafe fn session_didStartReceivingResourceWithName_fromPeer_withProgress(
231            &self,
232            session: &MCSession,
233            resource_name: &NSString,
234            peer_id: &MCPeerID,
235            progress: &NSProgress,
236        );
237
238        #[cfg(feature = "MCPeerID")]
239        #[unsafe(method(session:didFinishReceivingResourceWithName:fromPeer:atURL:withError:))]
240        #[unsafe(method_family = none)]
241        unsafe fn session_didFinishReceivingResourceWithName_fromPeer_atURL_withError(
242            &self,
243            session: &MCSession,
244            resource_name: &NSString,
245            peer_id: &MCPeerID,
246            local_url: Option<&NSURL>,
247            error: Option<&NSError>,
248        );
249
250        #[cfg(all(feature = "MCPeerID", feature = "block2"))]
251        /// # Safety
252        ///
253        /// `certificate` generic should be of the correct type.
254        #[optional]
255        #[unsafe(method(session:didReceiveCertificate:fromPeer:certificateHandler:))]
256        #[unsafe(method_family = none)]
257        unsafe fn session_didReceiveCertificate_fromPeer_certificateHandler(
258            &self,
259            session: &MCSession,
260            certificate: Option<&NSArray>,
261            peer_id: &MCPeerID,
262            certificate_handler: &block2::DynBlock<dyn Fn(Bool)>,
263        );
264    }
265);
266
267/// MCSessionCustomDiscovery.
268impl MCSession {
269    extern_methods!(
270        #[cfg(all(feature = "MCPeerID", feature = "block2"))]
271        #[unsafe(method(nearbyConnectionDataForPeer:withCompletionHandler:))]
272        #[unsafe(method_family = none)]
273        pub unsafe fn nearbyConnectionDataForPeer_withCompletionHandler(
274            &self,
275            peer_id: &MCPeerID,
276            completion_handler: &block2::DynBlock<dyn Fn(*mut NSData, *mut NSError)>,
277        );
278
279        #[cfg(feature = "MCPeerID")]
280        #[unsafe(method(connectPeer:withNearbyConnectionData:))]
281        #[unsafe(method_family = none)]
282        pub unsafe fn connectPeer_withNearbyConnectionData(
283            &self,
284            peer_id: &MCPeerID,
285            data: &NSData,
286        );
287
288        #[cfg(feature = "MCPeerID")]
289        #[unsafe(method(cancelConnectPeer:))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn cancelConnectPeer(&self, peer_id: &MCPeerID);
292    );
293}