use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKMatchSendDataMode(pub NSInteger);
impl GKMatchSendDataMode {
#[doc(alias = "GKMatchSendDataReliable")]
pub const Reliable: Self = Self(0);
#[doc(alias = "GKMatchSendDataUnreliable")]
pub const Unreliable: Self = Self(1);
}
unsafe impl Encode for GKMatchSendDataMode {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for GKMatchSendDataMode {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKPlayerConnectionState(pub NSInteger);
impl GKPlayerConnectionState {
#[doc(alias = "GKPlayerStateUnknown")]
pub const StateUnknown: Self = Self(0);
#[doc(alias = "GKPlayerStateConnected")]
pub const StateConnected: Self = Self(1);
#[doc(alias = "GKPlayerStateDisconnected")]
pub const StateDisconnected: Self = Self(2);
}
unsafe impl Encode for GKPlayerConnectionState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for GKPlayerConnectionState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct GKMatch;
);
extern_conformance!(
unsafe impl NSObjectProtocol for GKMatch {}
);
impl GKMatch {
extern_methods!(
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
#[unsafe(method(players))]
#[unsafe(method_family = none)]
pub unsafe fn players(&self) -> Retained<NSArray<GKPlayer>>;
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn GKMatchDelegate>>>;
#[unsafe(method(setDelegate:))]
#[unsafe(method_family = none)]
pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn GKMatchDelegate>>);
#[unsafe(method(expectedPlayerCount))]
#[unsafe(method_family = none)]
pub unsafe fn expectedPlayerCount(&self) -> NSUInteger;
#[cfg(feature = "GKDefines")]
#[unsafe(method(properties))]
#[unsafe(method_family = none)]
pub unsafe fn properties(&self) -> Option<Retained<GKMatchProperties>>;
#[cfg(all(feature = "GKBasePlayer", feature = "GKDefines", feature = "GKPlayer"))]
#[unsafe(method(playerProperties))]
#[unsafe(method_family = none)]
pub unsafe fn playerProperties(
&self,
) -> Option<Retained<NSDictionary<GKPlayer, GKMatchProperties>>>;
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
#[unsafe(method(sendData:toPlayers:dataMode:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn sendData_toPlayers_dataMode_error(
&self,
data: &NSData,
players: &NSArray<GKPlayer>,
mode: GKMatchSendDataMode,
) -> Result<(), Retained<NSError>>;
#[unsafe(method(sendDataToAllPlayers:withDataMode:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn sendDataToAllPlayers_withDataMode_error(
&self,
data: &NSData,
mode: GKMatchSendDataMode,
) -> Result<(), Retained<NSError>>;
#[unsafe(method(disconnect))]
#[unsafe(method_family = none)]
pub unsafe fn disconnect(&self);
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
#[unsafe(method(chooseBestHostingPlayerWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn chooseBestHostingPlayerWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(*mut GKPlayer)>,
);
#[cfg(feature = "block2")]
#[unsafe(method(rematchWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn rematchWithCompletionHandler(
&self,
completion_handler: Option<&block2::DynBlock<dyn Fn(*mut GKMatch, *mut NSError)>>,
);
#[cfg(feature = "GKVoiceChat")]
#[deprecated = "No longer supported"]
#[unsafe(method(voiceChatWithName:))]
#[unsafe(method_family = none)]
pub unsafe fn voiceChatWithName(&self, name: &NSString) -> Option<Retained<GKVoiceChat>>;
);
}
impl GKMatch {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}
extern_protocol!(
pub unsafe trait GKMatchDelegate: NSObjectProtocol {
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
#[optional]
#[unsafe(method(match:didReceiveData:fromRemotePlayer:))]
#[unsafe(method_family = none)]
unsafe fn match_didReceiveData_fromRemotePlayer(
&self,
r#match: &GKMatch,
data: &NSData,
player: &GKPlayer,
);
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
#[optional]
#[unsafe(method(match:didReceiveData:forRecipient:fromRemotePlayer:))]
#[unsafe(method_family = none)]
unsafe fn match_didReceiveData_forRecipient_fromRemotePlayer(
&self,
r#match: &GKMatch,
data: &NSData,
recipient: &GKPlayer,
player: &GKPlayer,
);
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
#[optional]
#[unsafe(method(match:player:didChangeConnectionState:))]
#[unsafe(method_family = none)]
unsafe fn match_player_didChangeConnectionState(
&self,
r#match: &GKMatch,
player: &GKPlayer,
state: GKPlayerConnectionState,
);
#[optional]
#[unsafe(method(match:didFailWithError:))]
#[unsafe(method_family = none)]
unsafe fn match_didFailWithError(&self, r#match: &GKMatch, error: Option<&NSError>);
#[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
#[optional]
#[unsafe(method(match:shouldReinviteDisconnectedPlayer:))]
#[unsafe(method_family = none)]
unsafe fn match_shouldReinviteDisconnectedPlayer(
&self,
r#match: &GKMatch,
player: &GKPlayer,
) -> bool;
#[deprecated]
#[optional]
#[unsafe(method(match:didReceiveData:fromPlayer:))]
#[unsafe(method_family = none)]
unsafe fn match_didReceiveData_fromPlayer(
&self,
r#match: &GKMatch,
data: &NSData,
player_id: &NSString,
);
#[deprecated]
#[optional]
#[unsafe(method(match:player:didChangeState:))]
#[unsafe(method_family = none)]
unsafe fn match_player_didChangeState(
&self,
r#match: &GKMatch,
player_id: &NSString,
state: GKPlayerConnectionState,
);
#[deprecated]
#[optional]
#[unsafe(method(match:shouldReinvitePlayer:))]
#[unsafe(method_family = none)]
unsafe fn match_shouldReinvitePlayer(
&self,
r#match: &GKMatch,
player_id: &NSString,
) -> bool;
}
);
impl GKMatch {
extern_methods!(
#[cfg(feature = "block2")]
#[deprecated]
#[unsafe(method(chooseBestHostPlayerWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn chooseBestHostPlayerWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<dyn Fn(*mut NSString)>,
);
#[deprecated]
#[unsafe(method(sendData:toPlayers:withDataMode:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn sendData_toPlayers_withDataMode_error(
&self,
data: &NSData,
player_i_ds: &NSArray<NSString>,
mode: GKMatchSendDataMode,
) -> Result<(), Retained<NSError>>;
#[deprecated]
#[unsafe(method(playerIDs))]
#[unsafe(method_family = none)]
pub unsafe fn playerIDs(&self) -> Option<Retained<NSArray<NSString>>>;
);
}