objc2_system_configuration/generated/
SCNetworkReachability.rs1use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "dispatch2")]
8use dispatch2::*;
9#[cfg(feature = "objc2")]
10use objc2::__framework_prelude::*;
11use objc2_core_foundation::*;
12
13use crate::*;
14
15#[doc(alias = "SCNetworkReachabilityRef")]
19#[repr(C)]
20pub struct SCNetworkReachability {
21 inner: [u8; 0],
22 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
23}
24
25cf_type!(
26 unsafe impl SCNetworkReachability {}
27);
28#[cfg(feature = "objc2")]
29cf_objc2_type!(
30 unsafe impl RefEncode<"__SCNetworkReachability"> for SCNetworkReachability {}
31);
32
33#[repr(C)]
50#[allow(unpredictable_function_pointer_comparisons)]
51#[derive(Clone, Copy, Debug, PartialEq)]
52pub struct SCNetworkReachabilityContext {
53 pub version: CFIndex,
54 pub info: *mut c_void,
55 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
56 pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
57 pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
58}
59
60#[cfg(feature = "objc2")]
61unsafe impl Encode for SCNetworkReachabilityContext {
62 const ENCODING: Encoding = Encoding::Struct(
63 "?",
64 &[
65 <CFIndex>::ENCODING,
66 <*mut c_void>::ENCODING,
67 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
68 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
69 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
70 ],
71 );
72}
73
74#[cfg(feature = "objc2")]
75unsafe impl RefEncode for SCNetworkReachabilityContext {
76 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
77}
78
79#[repr(transparent)]
142#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
143pub struct SCNetworkReachabilityFlags(pub u32);
144bitflags::bitflags! {
145 impl SCNetworkReachabilityFlags: u32 {
146 #[doc(alias = "kSCNetworkReachabilityFlagsTransientConnection")]
147 const TransientConnection = 1<<0;
148 #[doc(alias = "kSCNetworkReachabilityFlagsReachable")]
149 const Reachable = 1<<1;
150 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionRequired")]
151 const ConnectionRequired = 1<<2;
152 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionOnTraffic")]
153 const ConnectionOnTraffic = 1<<3;
154 #[doc(alias = "kSCNetworkReachabilityFlagsInterventionRequired")]
155 const InterventionRequired = 1<<4;
156 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionOnDemand")]
157 const ConnectionOnDemand = 1<<5;
158 #[doc(alias = "kSCNetworkReachabilityFlagsIsLocalAddress")]
159 const IsLocalAddress = 1<<16;
160 #[doc(alias = "kSCNetworkReachabilityFlagsIsDirect")]
161 const IsDirect = 1<<17;
162 #[doc(alias = "kSCNetworkReachabilityFlagsIsWWAN")]
163 const IsWWAN = 1<<18;
164 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionAutomatic")]
165 const ConnectionAutomatic = SCNetworkReachabilityFlags::ConnectionOnTraffic.0;
166 }
167}
168
169#[cfg(feature = "objc2")]
170unsafe impl Encode for SCNetworkReachabilityFlags {
171 const ENCODING: Encoding = u32::ENCODING;
172}
173
174#[cfg(feature = "objc2")]
175unsafe impl RefEncode for SCNetworkReachabilityFlags {
176 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
177}
178
179pub type SCNetworkReachabilityCallBack = Option<
192 unsafe extern "C-unwind" fn(
193 NonNull<SCNetworkReachability>,
194 SCNetworkReachabilityFlags,
195 *mut c_void,
196 ),
197>;
198
199impl SCNetworkReachability {
200 #[doc(alias = "SCNetworkReachabilityCreateWithAddress")]
214 #[cfg(feature = "libc")]
215 #[deprecated]
216 #[inline]
217 pub unsafe fn with_address(
218 allocator: Option<&CFAllocator>,
219 address: NonNull<libc::sockaddr>,
220 ) -> Option<CFRetained<SCNetworkReachability>> {
221 extern "C-unwind" {
222 fn SCNetworkReachabilityCreateWithAddress(
223 allocator: Option<&CFAllocator>,
224 address: NonNull<libc::sockaddr>,
225 ) -> Option<NonNull<SCNetworkReachability>>;
226 }
227 let ret = unsafe { SCNetworkReachabilityCreateWithAddress(allocator, address) };
228 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
229 }
230
231 #[doc(alias = "SCNetworkReachabilityCreateWithAddressPair")]
250 #[cfg(feature = "libc")]
251 #[deprecated]
252 #[inline]
253 pub unsafe fn with_address_pair(
254 allocator: Option<&CFAllocator>,
255 local_address: *const libc::sockaddr,
256 remote_address: *const libc::sockaddr,
257 ) -> Option<CFRetained<SCNetworkReachability>> {
258 extern "C-unwind" {
259 fn SCNetworkReachabilityCreateWithAddressPair(
260 allocator: Option<&CFAllocator>,
261 local_address: *const libc::sockaddr,
262 remote_address: *const libc::sockaddr,
263 ) -> Option<NonNull<SCNetworkReachability>>;
264 }
265 let ret = unsafe {
266 SCNetworkReachabilityCreateWithAddressPair(allocator, local_address, remote_address)
267 };
268 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
269 }
270
271 #[doc(alias = "SCNetworkReachabilityCreateWithName")]
287 #[deprecated]
288 #[inline]
289 pub unsafe fn with_name(
290 allocator: Option<&CFAllocator>,
291 nodename: NonNull<c_char>,
292 ) -> Option<CFRetained<SCNetworkReachability>> {
293 extern "C-unwind" {
294 fn SCNetworkReachabilityCreateWithName(
295 allocator: Option<&CFAllocator>,
296 nodename: NonNull<c_char>,
297 ) -> Option<NonNull<SCNetworkReachability>>;
298 }
299 let ret = unsafe { SCNetworkReachabilityCreateWithName(allocator, nodename) };
300 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
301 }
302}
303
304unsafe impl ConcreteType for SCNetworkReachability {
305 #[doc(alias = "SCNetworkReachabilityGetTypeID")]
308 #[inline]
309 fn type_id() -> CFTypeID {
310 extern "C-unwind" {
311 fn SCNetworkReachabilityGetTypeID() -> CFTypeID;
312 }
313 unsafe { SCNetworkReachabilityGetTypeID() }
314 }
315}
316
317impl SCNetworkReachability {
318 #[doc(alias = "SCNetworkReachabilityGetFlags")]
335 #[deprecated]
336 #[inline]
337 pub unsafe fn flags(&self, flags: NonNull<SCNetworkReachabilityFlags>) -> bool {
338 extern "C-unwind" {
339 fn SCNetworkReachabilityGetFlags(
340 target: &SCNetworkReachability,
341 flags: NonNull<SCNetworkReachabilityFlags>,
342 ) -> Boolean;
343 }
344 let ret = unsafe { SCNetworkReachabilityGetFlags(self, flags) };
345 ret != 0
346 }
347
348 #[doc(alias = "SCNetworkReachabilitySetCallback")]
368 #[deprecated]
369 #[inline]
370 pub unsafe fn set_callback(
371 &self,
372 callout: SCNetworkReachabilityCallBack,
373 context: *mut SCNetworkReachabilityContext,
374 ) -> bool {
375 extern "C-unwind" {
376 fn SCNetworkReachabilitySetCallback(
377 target: &SCNetworkReachability,
378 callout: SCNetworkReachabilityCallBack,
379 context: *mut SCNetworkReachabilityContext,
380 ) -> Boolean;
381 }
382 let ret = unsafe { SCNetworkReachabilitySetCallback(self, callout, context) };
383 ret != 0
384 }
385
386 #[doc(alias = "SCNetworkReachabilityScheduleWithRunLoop")]
400 #[deprecated]
401 #[inline]
402 pub fn schedule_with_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
403 extern "C-unwind" {
404 fn SCNetworkReachabilityScheduleWithRunLoop(
405 target: &SCNetworkReachability,
406 run_loop: &CFRunLoop,
407 run_loop_mode: &CFString,
408 ) -> Boolean;
409 }
410 let ret =
411 unsafe { SCNetworkReachabilityScheduleWithRunLoop(self, run_loop, run_loop_mode) };
412 ret != 0
413 }
414
415 #[doc(alias = "SCNetworkReachabilityUnscheduleFromRunLoop")]
430 #[deprecated]
431 #[inline]
432 pub fn unschedule_from_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
433 extern "C-unwind" {
434 fn SCNetworkReachabilityUnscheduleFromRunLoop(
435 target: &SCNetworkReachability,
436 run_loop: &CFRunLoop,
437 run_loop_mode: &CFString,
438 ) -> Boolean;
439 }
440 let ret =
441 unsafe { SCNetworkReachabilityUnscheduleFromRunLoop(self, run_loop, run_loop_mode) };
442 ret != 0
443 }
444
445 #[doc(alias = "SCNetworkReachabilitySetDispatchQueue")]
461 #[cfg(feature = "dispatch2")]
462 #[deprecated]
463 #[inline]
464 pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool {
465 extern "C-unwind" {
466 fn SCNetworkReachabilitySetDispatchQueue(
467 target: &SCNetworkReachability,
468 queue: Option<&DispatchQueue>,
469 ) -> Boolean;
470 }
471 let ret = unsafe { SCNetworkReachabilitySetDispatchQueue(self, queue) };
472 ret != 0
473 }
474}
475
476#[cfg(feature = "libc")]
477#[deprecated = "renamed to `SCNetworkReachability::with_address`"]
478#[inline]
479pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithAddress(
480 allocator: Option<&CFAllocator>,
481 address: NonNull<libc::sockaddr>,
482) -> Option<CFRetained<SCNetworkReachability>> {
483 extern "C-unwind" {
484 fn SCNetworkReachabilityCreateWithAddress(
485 allocator: Option<&CFAllocator>,
486 address: NonNull<libc::sockaddr>,
487 ) -> Option<NonNull<SCNetworkReachability>>;
488 }
489 let ret = unsafe { SCNetworkReachabilityCreateWithAddress(allocator, address) };
490 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
491}
492
493#[cfg(feature = "libc")]
494#[deprecated = "renamed to `SCNetworkReachability::with_address_pair`"]
495#[inline]
496pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithAddressPair(
497 allocator: Option<&CFAllocator>,
498 local_address: *const libc::sockaddr,
499 remote_address: *const libc::sockaddr,
500) -> Option<CFRetained<SCNetworkReachability>> {
501 extern "C-unwind" {
502 fn SCNetworkReachabilityCreateWithAddressPair(
503 allocator: Option<&CFAllocator>,
504 local_address: *const libc::sockaddr,
505 remote_address: *const libc::sockaddr,
506 ) -> Option<NonNull<SCNetworkReachability>>;
507 }
508 let ret = unsafe {
509 SCNetworkReachabilityCreateWithAddressPair(allocator, local_address, remote_address)
510 };
511 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
512}
513
514#[deprecated = "renamed to `SCNetworkReachability::with_name`"]
515#[inline]
516pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithName(
517 allocator: Option<&CFAllocator>,
518 nodename: NonNull<c_char>,
519) -> Option<CFRetained<SCNetworkReachability>> {
520 extern "C-unwind" {
521 fn SCNetworkReachabilityCreateWithName(
522 allocator: Option<&CFAllocator>,
523 nodename: NonNull<c_char>,
524 ) -> Option<NonNull<SCNetworkReachability>>;
525 }
526 let ret = unsafe { SCNetworkReachabilityCreateWithName(allocator, nodename) };
527 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
528}
529
530#[deprecated = "renamed to `SCNetworkReachability::flags`"]
531#[inline]
532pub unsafe extern "C-unwind" fn SCNetworkReachabilityGetFlags(
533 target: &SCNetworkReachability,
534 flags: NonNull<SCNetworkReachabilityFlags>,
535) -> bool {
536 extern "C-unwind" {
537 fn SCNetworkReachabilityGetFlags(
538 target: &SCNetworkReachability,
539 flags: NonNull<SCNetworkReachabilityFlags>,
540 ) -> Boolean;
541 }
542 let ret = unsafe { SCNetworkReachabilityGetFlags(target, flags) };
543 ret != 0
544}
545
546#[deprecated = "renamed to `SCNetworkReachability::set_callback`"]
547#[inline]
548pub unsafe extern "C-unwind" fn SCNetworkReachabilitySetCallback(
549 target: &SCNetworkReachability,
550 callout: SCNetworkReachabilityCallBack,
551 context: *mut SCNetworkReachabilityContext,
552) -> bool {
553 extern "C-unwind" {
554 fn SCNetworkReachabilitySetCallback(
555 target: &SCNetworkReachability,
556 callout: SCNetworkReachabilityCallBack,
557 context: *mut SCNetworkReachabilityContext,
558 ) -> Boolean;
559 }
560 let ret = unsafe { SCNetworkReachabilitySetCallback(target, callout, context) };
561 ret != 0
562}
563
564#[deprecated = "renamed to `SCNetworkReachability::schedule_with_run_loop`"]
565#[inline]
566pub extern "C-unwind" fn SCNetworkReachabilityScheduleWithRunLoop(
567 target: &SCNetworkReachability,
568 run_loop: &CFRunLoop,
569 run_loop_mode: &CFString,
570) -> bool {
571 extern "C-unwind" {
572 fn SCNetworkReachabilityScheduleWithRunLoop(
573 target: &SCNetworkReachability,
574 run_loop: &CFRunLoop,
575 run_loop_mode: &CFString,
576 ) -> Boolean;
577 }
578 let ret = unsafe { SCNetworkReachabilityScheduleWithRunLoop(target, run_loop, run_loop_mode) };
579 ret != 0
580}
581
582#[deprecated = "renamed to `SCNetworkReachability::unschedule_from_run_loop`"]
583#[inline]
584pub extern "C-unwind" fn SCNetworkReachabilityUnscheduleFromRunLoop(
585 target: &SCNetworkReachability,
586 run_loop: &CFRunLoop,
587 run_loop_mode: &CFString,
588) -> bool {
589 extern "C-unwind" {
590 fn SCNetworkReachabilityUnscheduleFromRunLoop(
591 target: &SCNetworkReachability,
592 run_loop: &CFRunLoop,
593 run_loop_mode: &CFString,
594 ) -> Boolean;
595 }
596 let ret =
597 unsafe { SCNetworkReachabilityUnscheduleFromRunLoop(target, run_loop, run_loop_mode) };
598 ret != 0
599}
600
601#[cfg(feature = "dispatch2")]
602#[deprecated = "renamed to `SCNetworkReachability::set_dispatch_queue`"]
603#[inline]
604pub unsafe extern "C-unwind" fn SCNetworkReachabilitySetDispatchQueue(
605 target: &SCNetworkReachability,
606 queue: Option<&DispatchQueue>,
607) -> bool {
608 extern "C-unwind" {
609 fn SCNetworkReachabilitySetDispatchQueue(
610 target: &SCNetworkReachability,
611 queue: Option<&DispatchQueue>,
612 ) -> Boolean;
613 }
614 let ret = unsafe { SCNetworkReachabilitySetDispatchQueue(target, queue) };
615 ret != 0
616}