use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
use crate::*;
#[doc(alias = "SCNetworkReachabilityRef")]
#[repr(C)]
pub struct SCNetworkReachability {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl SCNetworkReachability {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__SCNetworkReachability"> for SCNetworkReachability {}
);
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SCNetworkReachabilityContext {
pub version: CFIndex,
pub info: *mut c_void,
pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for SCNetworkReachabilityContext {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<*mut c_void>::ENCODING,
<Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
<Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for SCNetworkReachabilityContext {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SCNetworkReachabilityFlags(pub u32);
bitflags::bitflags! {
impl SCNetworkReachabilityFlags: u32 {
#[doc(alias = "kSCNetworkReachabilityFlagsTransientConnection")]
const TransientConnection = 1<<0;
#[doc(alias = "kSCNetworkReachabilityFlagsReachable")]
const Reachable = 1<<1;
#[doc(alias = "kSCNetworkReachabilityFlagsConnectionRequired")]
const ConnectionRequired = 1<<2;
#[doc(alias = "kSCNetworkReachabilityFlagsConnectionOnTraffic")]
const ConnectionOnTraffic = 1<<3;
#[doc(alias = "kSCNetworkReachabilityFlagsInterventionRequired")]
const InterventionRequired = 1<<4;
#[doc(alias = "kSCNetworkReachabilityFlagsConnectionOnDemand")]
const ConnectionOnDemand = 1<<5;
#[doc(alias = "kSCNetworkReachabilityFlagsIsLocalAddress")]
const IsLocalAddress = 1<<16;
#[doc(alias = "kSCNetworkReachabilityFlagsIsDirect")]
const IsDirect = 1<<17;
#[doc(alias = "kSCNetworkReachabilityFlagsIsWWAN")]
const IsWWAN = 1<<18;
#[doc(alias = "kSCNetworkReachabilityFlagsConnectionAutomatic")]
const ConnectionAutomatic = SCNetworkReachabilityFlags::ConnectionOnTraffic.0;
}
}
#[cfg(feature = "objc2")]
unsafe impl Encode for SCNetworkReachabilityFlags {
const ENCODING: Encoding = u32::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for SCNetworkReachabilityFlags {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
pub type SCNetworkReachabilityCallBack = Option<
unsafe extern "C-unwind" fn(
NonNull<SCNetworkReachability>,
SCNetworkReachabilityFlags,
*mut c_void,
),
>;
impl SCNetworkReachability {
#[doc(alias = "SCNetworkReachabilityCreateWithAddress")]
#[cfg(feature = "libc")]
#[deprecated]
#[inline]
pub unsafe fn with_address(
allocator: Option<&CFAllocator>,
address: NonNull<libc::sockaddr>,
) -> Option<CFRetained<SCNetworkReachability>> {
extern "C-unwind" {
fn SCNetworkReachabilityCreateWithAddress(
allocator: Option<&CFAllocator>,
address: NonNull<libc::sockaddr>,
) -> Option<NonNull<SCNetworkReachability>>;
}
let ret = unsafe { SCNetworkReachabilityCreateWithAddress(allocator, address) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "SCNetworkReachabilityCreateWithAddressPair")]
#[cfg(feature = "libc")]
#[deprecated]
#[inline]
pub unsafe fn with_address_pair(
allocator: Option<&CFAllocator>,
local_address: *const libc::sockaddr,
remote_address: *const libc::sockaddr,
) -> Option<CFRetained<SCNetworkReachability>> {
extern "C-unwind" {
fn SCNetworkReachabilityCreateWithAddressPair(
allocator: Option<&CFAllocator>,
local_address: *const libc::sockaddr,
remote_address: *const libc::sockaddr,
) -> Option<NonNull<SCNetworkReachability>>;
}
let ret = unsafe {
SCNetworkReachabilityCreateWithAddressPair(allocator, local_address, remote_address)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "SCNetworkReachabilityCreateWithName")]
#[deprecated]
#[inline]
pub unsafe fn with_name(
allocator: Option<&CFAllocator>,
nodename: NonNull<c_char>,
) -> Option<CFRetained<SCNetworkReachability>> {
extern "C-unwind" {
fn SCNetworkReachabilityCreateWithName(
allocator: Option<&CFAllocator>,
nodename: NonNull<c_char>,
) -> Option<NonNull<SCNetworkReachability>>;
}
let ret = unsafe { SCNetworkReachabilityCreateWithName(allocator, nodename) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
unsafe impl ConcreteType for SCNetworkReachability {
#[doc(alias = "SCNetworkReachabilityGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn SCNetworkReachabilityGetTypeID() -> CFTypeID;
}
unsafe { SCNetworkReachabilityGetTypeID() }
}
}
impl SCNetworkReachability {
#[doc(alias = "SCNetworkReachabilityGetFlags")]
#[deprecated]
#[inline]
pub unsafe fn flags(&self, flags: NonNull<SCNetworkReachabilityFlags>) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilityGetFlags(
target: &SCNetworkReachability,
flags: NonNull<SCNetworkReachabilityFlags>,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilityGetFlags(self, flags) };
ret != 0
}
#[doc(alias = "SCNetworkReachabilitySetCallback")]
#[deprecated]
#[inline]
pub unsafe fn set_callback(
&self,
callout: SCNetworkReachabilityCallBack,
context: *mut SCNetworkReachabilityContext,
) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilitySetCallback(
target: &SCNetworkReachability,
callout: SCNetworkReachabilityCallBack,
context: *mut SCNetworkReachabilityContext,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilitySetCallback(self, callout, context) };
ret != 0
}
#[doc(alias = "SCNetworkReachabilityScheduleWithRunLoop")]
#[deprecated]
#[inline]
pub fn schedule_with_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilityScheduleWithRunLoop(
target: &SCNetworkReachability,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> Boolean;
}
let ret =
unsafe { SCNetworkReachabilityScheduleWithRunLoop(self, run_loop, run_loop_mode) };
ret != 0
}
#[doc(alias = "SCNetworkReachabilityUnscheduleFromRunLoop")]
#[deprecated]
#[inline]
pub fn unschedule_from_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilityUnscheduleFromRunLoop(
target: &SCNetworkReachability,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> Boolean;
}
let ret =
unsafe { SCNetworkReachabilityUnscheduleFromRunLoop(self, run_loop, run_loop_mode) };
ret != 0
}
#[doc(alias = "SCNetworkReachabilitySetDispatchQueue")]
#[cfg(feature = "dispatch2")]
#[deprecated]
#[inline]
pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilitySetDispatchQueue(
target: &SCNetworkReachability,
queue: Option<&DispatchQueue>,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilitySetDispatchQueue(self, queue) };
ret != 0
}
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `SCNetworkReachability::with_address`"]
#[inline]
pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithAddress(
allocator: Option<&CFAllocator>,
address: NonNull<libc::sockaddr>,
) -> Option<CFRetained<SCNetworkReachability>> {
extern "C-unwind" {
fn SCNetworkReachabilityCreateWithAddress(
allocator: Option<&CFAllocator>,
address: NonNull<libc::sockaddr>,
) -> Option<NonNull<SCNetworkReachability>>;
}
let ret = unsafe { SCNetworkReachabilityCreateWithAddress(allocator, address) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(feature = "libc")]
#[deprecated = "renamed to `SCNetworkReachability::with_address_pair`"]
#[inline]
pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithAddressPair(
allocator: Option<&CFAllocator>,
local_address: *const libc::sockaddr,
remote_address: *const libc::sockaddr,
) -> Option<CFRetained<SCNetworkReachability>> {
extern "C-unwind" {
fn SCNetworkReachabilityCreateWithAddressPair(
allocator: Option<&CFAllocator>,
local_address: *const libc::sockaddr,
remote_address: *const libc::sockaddr,
) -> Option<NonNull<SCNetworkReachability>>;
}
let ret = unsafe {
SCNetworkReachabilityCreateWithAddressPair(allocator, local_address, remote_address)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `SCNetworkReachability::with_name`"]
#[inline]
pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithName(
allocator: Option<&CFAllocator>,
nodename: NonNull<c_char>,
) -> Option<CFRetained<SCNetworkReachability>> {
extern "C-unwind" {
fn SCNetworkReachabilityCreateWithName(
allocator: Option<&CFAllocator>,
nodename: NonNull<c_char>,
) -> Option<NonNull<SCNetworkReachability>>;
}
let ret = unsafe { SCNetworkReachabilityCreateWithName(allocator, nodename) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `SCNetworkReachability::flags`"]
#[inline]
pub unsafe extern "C-unwind" fn SCNetworkReachabilityGetFlags(
target: &SCNetworkReachability,
flags: NonNull<SCNetworkReachabilityFlags>,
) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilityGetFlags(
target: &SCNetworkReachability,
flags: NonNull<SCNetworkReachabilityFlags>,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilityGetFlags(target, flags) };
ret != 0
}
#[deprecated = "renamed to `SCNetworkReachability::set_callback`"]
#[inline]
pub unsafe extern "C-unwind" fn SCNetworkReachabilitySetCallback(
target: &SCNetworkReachability,
callout: SCNetworkReachabilityCallBack,
context: *mut SCNetworkReachabilityContext,
) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilitySetCallback(
target: &SCNetworkReachability,
callout: SCNetworkReachabilityCallBack,
context: *mut SCNetworkReachabilityContext,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilitySetCallback(target, callout, context) };
ret != 0
}
#[deprecated = "renamed to `SCNetworkReachability::schedule_with_run_loop`"]
#[inline]
pub extern "C-unwind" fn SCNetworkReachabilityScheduleWithRunLoop(
target: &SCNetworkReachability,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilityScheduleWithRunLoop(
target: &SCNetworkReachability,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilityScheduleWithRunLoop(target, run_loop, run_loop_mode) };
ret != 0
}
#[deprecated = "renamed to `SCNetworkReachability::unschedule_from_run_loop`"]
#[inline]
pub extern "C-unwind" fn SCNetworkReachabilityUnscheduleFromRunLoop(
target: &SCNetworkReachability,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilityUnscheduleFromRunLoop(
target: &SCNetworkReachability,
run_loop: &CFRunLoop,
run_loop_mode: &CFString,
) -> Boolean;
}
let ret =
unsafe { SCNetworkReachabilityUnscheduleFromRunLoop(target, run_loop, run_loop_mode) };
ret != 0
}
#[cfg(feature = "dispatch2")]
#[deprecated = "renamed to `SCNetworkReachability::set_dispatch_queue`"]
#[inline]
pub unsafe extern "C-unwind" fn SCNetworkReachabilitySetDispatchQueue(
target: &SCNetworkReachability,
queue: Option<&DispatchQueue>,
) -> bool {
extern "C-unwind" {
fn SCNetworkReachabilitySetDispatchQueue(
target: &SCNetworkReachability,
queue: Option<&DispatchQueue>,
) -> Boolean;
}
let ret = unsafe { SCNetworkReachabilitySetDispatchQueue(target, queue) };
ret != 0
}