objc2_game_kit/generated/
GKMatch.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/gamekit/gkmatchsenddatamode?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct GKMatchSendDataMode(pub NSInteger);
15impl GKMatchSendDataMode {
16    #[doc(alias = "GKMatchSendDataReliable")]
17    pub const Reliable: Self = Self(0);
18    /// a.s.a.p. but requires fragmentation and reassembly for large messages, may stall if network congestion occurs
19    #[doc(alias = "GKMatchSendDataUnreliable")]
20    pub const Unreliable: Self = Self(1);
21}
22
23unsafe impl Encode for GKMatchSendDataMode {
24    const ENCODING: Encoding = NSInteger::ENCODING;
25}
26
27unsafe impl RefEncode for GKMatchSendDataMode {
28    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
29}
30
31/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkplayerconnectionstate?language=objc)
32// NS_ENUM
33#[repr(transparent)]
34#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
35pub struct GKPlayerConnectionState(pub NSInteger);
36impl GKPlayerConnectionState {
37    #[doc(alias = "GKPlayerStateUnknown")]
38    pub const StateUnknown: Self = Self(0);
39    /// initial player state
40    #[doc(alias = "GKPlayerStateConnected")]
41    pub const StateConnected: Self = Self(1);
42    /// connected to the match
43    #[doc(alias = "GKPlayerStateDisconnected")]
44    pub const StateDisconnected: Self = Self(2);
45}
46
47unsafe impl Encode for GKPlayerConnectionState {
48    const ENCODING: Encoding = NSInteger::ENCODING;
49}
50
51unsafe impl RefEncode for GKPlayerConnectionState {
52    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
53}
54
55extern_class!(
56    /// GKMatch represents an active networking sessions between players. It handles network communications and can report player connection status. All matches are created by a GKMatchmaker.
57    ///
58    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkmatch?language=objc)
59    #[unsafe(super(NSObject))]
60    #[derive(Debug, PartialEq, Eq, Hash)]
61    pub struct GKMatch;
62);
63
64extern_conformance!(
65    unsafe impl NSObjectProtocol for GKMatch {}
66);
67
68impl GKMatch {
69    extern_methods!(
70        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
71        #[unsafe(method(players))]
72        #[unsafe(method_family = none)]
73        pub unsafe fn players(&self) -> Retained<NSArray<GKPlayer>>;
74
75        /// all the GKPlayers in the match
76        #[unsafe(method(delegate))]
77        #[unsafe(method_family = none)]
78        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn GKMatchDelegate>>>;
79
80        /// Setter for [`delegate`][Self::delegate].
81        ///
82        /// This is a [weak property][objc2::topics::weak_property].
83        #[unsafe(method(setDelegate:))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn GKMatchDelegate>>);
86
87        #[unsafe(method(expectedPlayerCount))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn expectedPlayerCount(&self) -> NSUInteger;
90
91        #[cfg(feature = "GKDefines")]
92        #[unsafe(method(properties))]
93        #[unsafe(method_family = none)]
94        pub unsafe fn properties(&self) -> Option<Retained<GKMatchProperties>>;
95
96        #[cfg(all(feature = "GKBasePlayer", feature = "GKDefines", feature = "GKPlayer"))]
97        #[unsafe(method(playerProperties))]
98        #[unsafe(method_family = none)]
99        pub unsafe fn playerProperties(
100            &self,
101        ) -> Option<Retained<NSDictionary<GKPlayer, GKMatchProperties>>>;
102
103        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
104        /// Asynchronously send data to one or more GKPlayers. Returns YES if delivery started, NO if unable to start sending and error will be set.
105        #[unsafe(method(sendData:toPlayers:dataMode:error:_))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn sendData_toPlayers_dataMode_error(
108            &self,
109            data: &NSData,
110            players: &NSArray<GKPlayer>,
111            mode: GKMatchSendDataMode,
112        ) -> Result<(), Retained<NSError>>;
113
114        /// Asynchronously broadcasts data to all players. Returns YES if delivery started, NO if unable to start sending and error will be set.
115        #[unsafe(method(sendDataToAllPlayers:withDataMode:error:_))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn sendDataToAllPlayers_withDataMode_error(
118            &self,
119            data: &NSData,
120            mode: GKMatchSendDataMode,
121        ) -> Result<(), Retained<NSError>>;
122
123        /// Disconnect the match. This will show all other players in the match that the local player has disconnected. This should be called before releasing the match instance.
124        #[unsafe(method(disconnect))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn disconnect(&self);
127
128        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
129        /// Choose the best host from among the connected players using gathered estimates for bandwidth and packet loss. This is intended for applications that wish to implement a client-server model on top of the match. The returned player ID will be nil if the best host cannot currently be determined (e.g. players are still connecting).
130        #[unsafe(method(chooseBestHostingPlayerWithCompletionHandler:))]
131        #[unsafe(method_family = none)]
132        pub unsafe fn chooseBestHostingPlayerWithCompletionHandler(
133            &self,
134            completion_handler: &block2::DynBlock<dyn Fn(*mut GKPlayer)>,
135        );
136
137        #[cfg(feature = "block2")]
138        /// Automatching to recreate a previous peer-to-peer match that became disconnected. A new match with the same set of players will be returned by the completion handler. All players should perform this when the match has ended for automatching to succeed. Error will be nil on success.
139        /// Possible reasons for error:
140        /// 1. Communications failure
141        /// 2. Timeout
142        #[unsafe(method(rematchWithCompletionHandler:))]
143        #[unsafe(method_family = none)]
144        pub unsafe fn rematchWithCompletionHandler(
145            &self,
146            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut GKMatch, *mut NSError)>>,
147        );
148
149        #[cfg(feature = "GKVoiceChat")]
150        /// * This method is deprecated. GKVoiceChat is no longer supported. **
151        #[deprecated = "No longer supported"]
152        #[unsafe(method(voiceChatWithName:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn voiceChatWithName(&self, name: &NSString) -> Option<Retained<GKVoiceChat>>;
155    );
156}
157
158/// Methods declared on superclass `NSObject`.
159impl GKMatch {
160    extern_methods!(
161        #[unsafe(method(init))]
162        #[unsafe(method_family = init)]
163        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
164
165        #[unsafe(method(new))]
166        #[unsafe(method_family = new)]
167        pub unsafe fn new() -> Retained<Self>;
168    );
169}
170
171extern_protocol!(
172    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkmatchdelegate?language=objc)
173    pub unsafe trait GKMatchDelegate: NSObjectProtocol {
174        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
175        /// The match received data sent from the player.
176        #[optional]
177        #[unsafe(method(match:didReceiveData:fromRemotePlayer:))]
178        #[unsafe(method_family = none)]
179        unsafe fn match_didReceiveData_fromRemotePlayer(
180            &self,
181            r#match: &GKMatch,
182            data: &NSData,
183            player: &GKPlayer,
184        );
185
186        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
187        #[optional]
188        #[unsafe(method(match:didReceiveData:forRecipient:fromRemotePlayer:))]
189        #[unsafe(method_family = none)]
190        unsafe fn match_didReceiveData_forRecipient_fromRemotePlayer(
191            &self,
192            r#match: &GKMatch,
193            data: &NSData,
194            recipient: &GKPlayer,
195            player: &GKPlayer,
196        );
197
198        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
199        /// The player state changed (eg. connected or disconnected)
200        #[optional]
201        #[unsafe(method(match:player:didChangeConnectionState:))]
202        #[unsafe(method_family = none)]
203        unsafe fn match_player_didChangeConnectionState(
204            &self,
205            r#match: &GKMatch,
206            player: &GKPlayer,
207            state: GKPlayerConnectionState,
208        );
209
210        /// The match was unable to be established with any players due to an error.
211        #[optional]
212        #[unsafe(method(match:didFailWithError:))]
213        #[unsafe(method_family = none)]
214        unsafe fn match_didFailWithError(&self, r#match: &GKMatch, error: Option<&NSError>);
215
216        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
217        /// This method is called when the match is interrupted; if it returns YES, a new invite will be sent to attempt reconnection. This is supported only for 1v1 games
218        #[optional]
219        #[unsafe(method(match:shouldReinviteDisconnectedPlayer:))]
220        #[unsafe(method_family = none)]
221        unsafe fn match_shouldReinviteDisconnectedPlayer(
222            &self,
223            r#match: &GKMatch,
224            player: &GKPlayer,
225        ) -> bool;
226
227        /// * These protocol methods are obsoleted. They will never be invoked and their implementation does nothing**
228        #[deprecated]
229        #[optional]
230        #[unsafe(method(match:didReceiveData:fromPlayer:))]
231        #[unsafe(method_family = none)]
232        unsafe fn match_didReceiveData_fromPlayer(
233            &self,
234            r#match: &GKMatch,
235            data: &NSData,
236            player_id: &NSString,
237        );
238
239        #[deprecated]
240        #[optional]
241        #[unsafe(method(match:player:didChangeState:))]
242        #[unsafe(method_family = none)]
243        unsafe fn match_player_didChangeState(
244            &self,
245            r#match: &GKMatch,
246            player_id: &NSString,
247            state: GKPlayerConnectionState,
248        );
249
250        #[deprecated]
251        #[optional]
252        #[unsafe(method(match:shouldReinvitePlayer:))]
253        #[unsafe(method_family = none)]
254        unsafe fn match_shouldReinvitePlayer(
255            &self,
256            r#match: &GKMatch,
257            player_id: &NSString,
258        ) -> bool;
259    }
260);
261
262/// Obsoleted.
263impl GKMatch {
264    extern_methods!(
265        #[cfg(feature = "block2")]
266        /// * This method is obsolete. It will never be invoked and its implementation does nothing**
267        #[deprecated]
268        #[unsafe(method(chooseBestHostPlayerWithCompletionHandler:))]
269        #[unsafe(method_family = none)]
270        pub unsafe fn chooseBestHostPlayerWithCompletionHandler(
271            &self,
272            completion_handler: &block2::DynBlock<dyn Fn(*mut NSString)>,
273        );
274
275        /// * This method is obsolete. It will never be invoked and its implementation does nothing**
276        #[deprecated]
277        #[unsafe(method(sendData:toPlayers:withDataMode:error:_))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn sendData_toPlayers_withDataMode_error(
280            &self,
281            data: &NSData,
282            player_i_ds: &NSArray<NSString>,
283            mode: GKMatchSendDataMode,
284        ) -> Result<(), Retained<NSError>>;
285
286        /// * This property is obsolete.  **
287        #[deprecated]
288        #[unsafe(method(playerIDs))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn playerIDs(&self) -> Option<Retained<NSArray<NSString>>>;
291    );
292}