objc2_system_configuration/generated/SCNetworkReachability.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// This is the handle to a network address or name.
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachability?language=objc)
16#[repr(C)]
17pub struct SCNetworkReachability {
18 inner: [u8; 0],
19 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
20}
21
22cf_type!(
23 #[encoding_name = "__SCNetworkReachability"]
24 unsafe impl SCNetworkReachability {}
25);
26
27/// Structure containing user-specified data and callbacks for SCNetworkReachability.
28/// Field: version The version number of the structure type being passed
29/// in as a parameter to the SCDynamicStore creation function.
30/// This structure is version 0.
31/// Field: info A C pointer to a user-specified block of data.
32/// Field: retain The callback used to add a retain for the info field.
33/// If this parameter is not a pointer to a function of the correct
34/// prototype, the behavior is undefined. The value may be NULL.
35/// Field: release The calllback used to remove a retain previously added
36/// for the info field. If this parameter is not a pointer to a
37/// function of the correct prototype, the behavior is undefined.
38/// The value may be NULL.
39/// Field: copyDescription The callback used to provide a description of
40/// the info field.
41///
42/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachabilitycontext?language=objc)
43#[repr(C)]
44#[derive(Clone, Copy, Debug, PartialEq)]
45pub struct SCNetworkReachabilityContext {
46 pub version: CFIndex,
47 pub info: *mut c_void,
48 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
49 pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
50 pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
51}
52
53#[cfg(feature = "objc2")]
54unsafe impl Encode for SCNetworkReachabilityContext {
55 const ENCODING: Encoding = Encoding::Struct(
56 "?",
57 &[
58 <CFIndex>::ENCODING,
59 <*mut c_void>::ENCODING,
60 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
61 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
62 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
63 ],
64 );
65}
66
67#[cfg(feature = "objc2")]
68unsafe impl RefEncode for SCNetworkReachabilityContext {
69 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
70}
71
72/// Flags that indicate whether the specified network
73/// nodename or address is reachable, whether a connection is
74/// required, and whether some user intervention may be required
75/// when establishing a connection.
76///
77/// This flag indicates that the specified nodename or address can
78/// be reached via a transient connection, such as PPP.
79///
80/// This flag indicates that the specified nodename or address can
81/// be reached using the current network configuration.
82///
83/// This flag indicates that the specified nodename or address can
84/// be reached using the current network configuration, but a
85/// connection must first be established.
86///
87/// As an example, this status would be returned for a dialup
88/// connection that was not currently active, but could handle
89/// network traffic for the target system.
90///
91/// This flag indicates that the specified nodename or address can
92/// be reached using the current network configuration, but a
93/// connection must first be established. Any traffic directed
94/// to the specified name or address will initiate the connection.
95///
96/// Note: this flag was previously named kSCNetworkReachabilityFlagsConnectionAutomatic
97///
98/// This flag indicates that the specified nodename or address can
99/// be reached using the current network configuration, but a
100/// connection must first be established. In addition, some
101/// form of user intervention will be required to establish this
102/// connection, such as providing a password, an authentication
103/// token, etc.
104///
105/// Note: At the present time, this flag will only be returned
106/// in the case where you have a dial-on-traffic configuration
107/// (ConnectionOnTraffic), where an attempt to connect has
108/// already been made, and where some error (e.g. no dial tone,
109/// no answer, bad password, ...) was encountered during the
110/// automatic connection attempt. In this case the PPP controller
111/// will stop attempting to establish a connection until the user
112/// has intervened.
113///
114/// This flag indicates that the specified nodename or address can
115/// be reached using the current network configuration, but a
116/// connection must first be established.
117/// The connection will be established "On Demand" by the
118/// CFSocketStream APIs.
119/// Other APIs will not establish the connection.
120///
121/// This flag indicates that the specified nodename or address
122/// is one associated with a network interface on the current
123/// system.
124///
125/// This flag indicates that network traffic to the specified
126/// nodename or address will not go through a gateway, but is
127/// routed directly to one of the interfaces in the system.
128///
129/// This flag indicates that the specified nodename or address can
130/// be reached via an EDGE, GPRS, or other "cell" connection.
131///
132/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachabilityflags?language=objc)
133// NS_OPTIONS
134#[repr(transparent)]
135#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
136pub struct SCNetworkReachabilityFlags(pub u32);
137bitflags::bitflags! {
138 impl SCNetworkReachabilityFlags: u32 {
139 #[doc(alias = "kSCNetworkReachabilityFlagsTransientConnection")]
140 const TransientConnection = 1<<0;
141 #[doc(alias = "kSCNetworkReachabilityFlagsReachable")]
142 const Reachable = 1<<1;
143 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionRequired")]
144 const ConnectionRequired = 1<<2;
145 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionOnTraffic")]
146 const ConnectionOnTraffic = 1<<3;
147 #[doc(alias = "kSCNetworkReachabilityFlagsInterventionRequired")]
148 const InterventionRequired = 1<<4;
149 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionOnDemand")]
150 const ConnectionOnDemand = 1<<5;
151 #[doc(alias = "kSCNetworkReachabilityFlagsIsLocalAddress")]
152 const IsLocalAddress = 1<<16;
153 #[doc(alias = "kSCNetworkReachabilityFlagsIsDirect")]
154 const IsDirect = 1<<17;
155 #[doc(alias = "kSCNetworkReachabilityFlagsIsWWAN")]
156 const IsWWAN = 1<<18;
157 #[doc(alias = "kSCNetworkReachabilityFlagsConnectionAutomatic")]
158 const ConnectionAutomatic = SCNetworkReachabilityFlags::ConnectionOnTraffic.0;
159 }
160}
161
162#[cfg(feature = "objc2")]
163unsafe impl Encode for SCNetworkReachabilityFlags {
164 const ENCODING: Encoding = u32::ENCODING;
165}
166
167#[cfg(feature = "objc2")]
168unsafe impl RefEncode for SCNetworkReachabilityFlags {
169 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
170}
171
172/// Type of the callback function used when the
173/// reachability of a network address or name changes.
174///
175/// Parameter `target`: The SCNetworkReachability reference being monitored
176/// for changes.
177///
178/// Parameter `flags`: The new SCNetworkReachabilityFlags representing the
179/// reachability status of the network address/name.
180///
181/// Parameter `info`: A C pointer to a user-specified block of data.
182///
183/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachabilitycallback?language=objc)
184pub type SCNetworkReachabilityCallBack = Option<
185 unsafe extern "C-unwind" fn(
186 NonNull<SCNetworkReachability>,
187 SCNetworkReachabilityFlags,
188 *mut c_void,
189 ),
190>;
191
192/// Creates a reference to the specified network
193/// address. This reference can be used later to monitor the
194/// reachability of the target host.
195///
196/// Parameter `address`: The address of the desired host.
197///
198/// Returns: Returns a reference to the new immutable SCNetworkReachabilityRef.
199///
200/// You must release the returned value.
201#[cfg(feature = "libc")]
202#[deprecated]
203#[inline]
204pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithAddress(
205 allocator: Option<&CFAllocator>,
206 address: NonNull<libc::sockaddr>,
207) -> Option<CFRetained<SCNetworkReachability>> {
208 extern "C-unwind" {
209 fn SCNetworkReachabilityCreateWithAddress(
210 allocator: Option<&CFAllocator>,
211 address: NonNull<libc::sockaddr>,
212 ) -> Option<NonNull<SCNetworkReachability>>;
213 }
214 let ret = unsafe { SCNetworkReachabilityCreateWithAddress(allocator, address) };
215 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
216}
217
218/// Creates a reference to the specified network
219/// address. This reference can be used later to monitor the
220/// reachability of the target host.
221///
222/// Parameter `localAddress`: The local address associated with a network
223/// connection. If NULL, only the remote address is of interest.
224///
225/// Parameter `remoteAddress`: The remote address associated with a network
226/// connection. If NULL, only the local address is of interest.
227///
228/// Returns: Returns a reference to the new immutable SCNetworkReachabilityRef.
229///
230/// You must release the returned value.
231#[cfg(feature = "libc")]
232#[deprecated]
233#[inline]
234pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithAddressPair(
235 allocator: Option<&CFAllocator>,
236 local_address: *const libc::sockaddr,
237 remote_address: *const libc::sockaddr,
238) -> Option<CFRetained<SCNetworkReachability>> {
239 extern "C-unwind" {
240 fn SCNetworkReachabilityCreateWithAddressPair(
241 allocator: Option<&CFAllocator>,
242 local_address: *const libc::sockaddr,
243 remote_address: *const libc::sockaddr,
244 ) -> Option<NonNull<SCNetworkReachability>>;
245 }
246 let ret = unsafe {
247 SCNetworkReachabilityCreateWithAddressPair(allocator, local_address, remote_address)
248 };
249 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
250}
251
252/// Creates a reference to the specified network host or node
253/// name. This reference can be used later to monitor the
254/// reachability of the target host.
255///
256/// Parameter `nodename`: The node name of the desired host.
257/// This name would be the same as that passed to the
258/// gethostbyname(3) or getaddrinfo(3) functions.
259///
260/// Returns: Returns a reference to the new immutable SCNetworkReachabilityRef.
261///
262/// You must release the returned value.
263#[deprecated]
264#[inline]
265pub unsafe extern "C-unwind" fn SCNetworkReachabilityCreateWithName(
266 allocator: Option<&CFAllocator>,
267 nodename: NonNull<c_char>,
268) -> Option<CFRetained<SCNetworkReachability>> {
269 extern "C-unwind" {
270 fn SCNetworkReachabilityCreateWithName(
271 allocator: Option<&CFAllocator>,
272 nodename: NonNull<c_char>,
273 ) -> Option<NonNull<SCNetworkReachability>>;
274 }
275 let ret = unsafe { SCNetworkReachabilityCreateWithName(allocator, nodename) };
276 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
277}
278
279unsafe impl ConcreteType for SCNetworkReachability {
280 /// Returns the type identifier of all SCNetworkReachability
281 /// instances.
282 #[doc(alias = "SCNetworkReachabilityGetTypeID")]
283 #[inline]
284 fn type_id() -> CFTypeID {
285 extern "C-unwind" {
286 fn SCNetworkReachabilityGetTypeID() -> CFTypeID;
287 }
288 unsafe { SCNetworkReachabilityGetTypeID() }
289 }
290}
291
292/// Determines if the given target is reachable using the
293/// current network configuration.
294///
295/// Parameter `target`: The network reference associated with the address or name
296/// to be checked for reachability.
297///
298/// Parameter `flags`: A pointer to memory that will be filled with the
299/// SCNetworkReachabilityFlags detailing the reachability
300/// of the specified target.
301///
302/// Returns: Returns TRUE if the network connection flags are valid;
303/// FALSE if the status could not be determined.
304#[deprecated]
305#[inline]
306pub unsafe extern "C-unwind" fn SCNetworkReachabilityGetFlags(
307 target: &SCNetworkReachability,
308 flags: NonNull<SCNetworkReachabilityFlags>,
309) -> bool {
310 extern "C-unwind" {
311 fn SCNetworkReachabilityGetFlags(
312 target: &SCNetworkReachability,
313 flags: NonNull<SCNetworkReachabilityFlags>,
314 ) -> Boolean;
315 }
316 let ret = unsafe { SCNetworkReachabilityGetFlags(target, flags) };
317 ret != 0
318}
319
320/// Assigns a client to a target, which receives callbacks
321/// when the reachability of the target changes.
322///
323/// Parameter `target`: The network reference associated with the address or
324/// name to be checked for reachability.
325///
326/// Parameter `callout`: The function to be called when the reachability of the
327/// target changes. If NULL, the current client for the target
328/// is removed.
329///
330/// Parameter `context`: The SCNetworkReachabilityContext associated with
331/// the callout. The value may be NULL.
332///
333/// Returns: Returns TRUE if the notification client was successfully set.
334#[deprecated]
335#[inline]
336pub unsafe extern "C-unwind" fn SCNetworkReachabilitySetCallback(
337 target: &SCNetworkReachability,
338 callout: SCNetworkReachabilityCallBack,
339 context: *mut SCNetworkReachabilityContext,
340) -> bool {
341 extern "C-unwind" {
342 fn SCNetworkReachabilitySetCallback(
343 target: &SCNetworkReachability,
344 callout: SCNetworkReachabilityCallBack,
345 context: *mut SCNetworkReachabilityContext,
346 ) -> Boolean;
347 }
348 let ret = unsafe { SCNetworkReachabilitySetCallback(target, callout, context) };
349 ret != 0
350}
351
352/// Schedules the given target with the given run loop and mode.
353///
354/// Parameter `target`: The address or name that is set up for asynchronous
355/// notifications. Must be non-NULL.
356///
357/// Parameter `runLoop`: A reference to a run loop on which the target should
358/// be scheduled. Must be non-NULL.
359///
360/// Parameter `runLoopMode`: The mode on which to schedule the target.
361/// Must be non-NULL.
362///
363/// Returns: Returns TRUE if the target is scheduled successfully;
364/// FALSE otherwise.
365#[deprecated]
366#[inline]
367pub unsafe extern "C-unwind" fn SCNetworkReachabilityScheduleWithRunLoop(
368 target: &SCNetworkReachability,
369 run_loop: &CFRunLoop,
370 run_loop_mode: &CFString,
371) -> bool {
372 extern "C-unwind" {
373 fn SCNetworkReachabilityScheduleWithRunLoop(
374 target: &SCNetworkReachability,
375 run_loop: &CFRunLoop,
376 run_loop_mode: &CFString,
377 ) -> Boolean;
378 }
379 let ret = unsafe { SCNetworkReachabilityScheduleWithRunLoop(target, run_loop, run_loop_mode) };
380 ret != 0
381}
382
383/// Unschedules the given target from the given run loop
384/// and mode.
385///
386/// Parameter `target`: The address or name that is set up for asynchronous
387/// notifications. Must be non-NULL.
388///
389/// Parameter `runLoop`: A reference to a run loop from which the target
390/// should be unscheduled. Must be non-NULL.
391///
392/// Parameter `runLoopMode`: The mode on which to unschedule the target.
393/// Must be non-NULL.
394///
395/// Returns: Returns TRUE if the target is unscheduled successfully;
396/// FALSE otherwise.
397#[deprecated]
398#[inline]
399pub unsafe extern "C-unwind" fn SCNetworkReachabilityUnscheduleFromRunLoop(
400 target: &SCNetworkReachability,
401 run_loop: &CFRunLoop,
402 run_loop_mode: &CFString,
403) -> bool {
404 extern "C-unwind" {
405 fn SCNetworkReachabilityUnscheduleFromRunLoop(
406 target: &SCNetworkReachability,
407 run_loop: &CFRunLoop,
408 run_loop_mode: &CFString,
409 ) -> Boolean;
410 }
411 let ret =
412 unsafe { SCNetworkReachabilityUnscheduleFromRunLoop(target, run_loop, run_loop_mode) };
413 ret != 0
414}