objc2_system_configuration/generated/SCNetworkConnection.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 = "dispatch2")]
8use dispatch2::*;
9#[cfg(feature = "objc2")]
10use objc2::__framework_prelude::*;
11use objc2_core_foundation::*;
12
13use crate::*;
14
15/// This is the handle to manage a connection-oriented service.
16///
17/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkconnection?language=objc)
18#[doc(alias = "SCNetworkConnectionRef")]
19#[repr(C)]
20pub struct SCNetworkConnection {
21 inner: [u8; 0],
22 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
23}
24
25cf_type!(
26 unsafe impl SCNetworkConnection {}
27);
28#[cfg(feature = "objc2")]
29cf_objc2_type!(
30 unsafe impl RefEncode<"__SCNetworkConnection"> for SCNetworkConnection {}
31);
32
33/// Structure containing user-specified data and callbacks
34/// for a SCNetworkConnection.
35/// Field: version The version number of the structure type being passed
36/// in as a parameter to the SCNetworkConnectionCreateWithServiceID
37/// function. This structure is version 0.
38/// Field: info A C pointer to a user-specified block of data.
39/// Field: retain The callback used to add a retain for the info field.
40/// If this parameter is not a pointer to a function of the correct
41/// prototype, the behavior is undefined. The value may be NULL.
42/// Field: release The calllback used to remove a retain previously added
43/// for the info field. If this parameter is not a pointer to a
44/// function of the correct prototype, the behavior is undefined.
45/// The value may be NULL.
46/// Field: copyDescription The callback used to provide a description of
47/// the info field.
48///
49/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkconnectioncontext?language=objc)
50#[repr(C)]
51#[allow(unpredictable_function_pointer_comparisons)]
52#[derive(Clone, Copy, Debug, PartialEq)]
53pub struct SCNetworkConnectionContext {
54 pub version: CFIndex,
55 pub info: *mut c_void,
56 pub retain: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>,
57 pub release: Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>,
58 pub copyDescription: Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>,
59}
60
61#[cfg(feature = "objc2")]
62unsafe impl Encode for SCNetworkConnectionContext {
63 const ENCODING: Encoding = Encoding::Struct(
64 "?",
65 &[
66 <CFIndex>::ENCODING,
67 <*mut c_void>::ENCODING,
68 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<c_void>>>::ENCODING,
69 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>>::ENCODING,
70 <Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> NonNull<CFString>>>::ENCODING,
71 ],
72 );
73}
74
75#[cfg(feature = "objc2")]
76unsafe impl RefEncode for SCNetworkConnectionContext {
77 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
78}
79
80/// Status of the network connection.
81/// This status is intended to be generic and high level.
82/// An extended status, specific to the type of network
83/// connection is also available for applications that
84/// need additonal information.
85///
86/// The network connection refers to an invalid service.
87///
88/// The network connection is disconnected.
89///
90/// The network connection is connecting.
91///
92/// The network connection is connected.
93///
94/// The network connection is disconnecting.
95///
96/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkconnectionstatus?language=objc)
97// NS_ENUM
98#[repr(transparent)]
99#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
100pub struct SCNetworkConnectionStatus(pub i32);
101impl SCNetworkConnectionStatus {
102 #[doc(alias = "kSCNetworkConnectionInvalid")]
103 pub const Invalid: Self = Self(-1);
104 #[doc(alias = "kSCNetworkConnectionDisconnected")]
105 pub const Disconnected: Self = Self(0);
106 #[doc(alias = "kSCNetworkConnectionConnecting")]
107 pub const Connecting: Self = Self(1);
108 #[doc(alias = "kSCNetworkConnectionConnected")]
109 pub const Connected: Self = Self(2);
110 #[doc(alias = "kSCNetworkConnectionDisconnecting")]
111 pub const Disconnecting: Self = Self(3);
112}
113
114#[cfg(feature = "objc2")]
115unsafe impl Encode for SCNetworkConnectionStatus {
116 const ENCODING: Encoding = i32::ENCODING;
117}
118
119#[cfg(feature = "objc2")]
120unsafe impl RefEncode for SCNetworkConnectionStatus {
121 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
122}
123
124/// PPP-specific status of the network connection.
125/// This status is returned as part of the extended information
126/// for a PPP service.
127/// Note: additional status might be returned in the future.
128/// Your application should be prepared to receive an unknown value.
129///
130/// PPP is disconnected.
131///
132/// PPP is initializing.
133///
134/// PPP is connecting the lower connection layer (for example,
135/// the modem is dialing out).
136///
137/// PPP is waiting for networking traffic to automatically
138/// establish the connection.
139///
140/// The PPP lower layer is connected and PPP is negotiating the
141/// link layer (LCP protocol).
142///
143/// PPP is authenticating to the server (PAP, CHAP, MS-CHAP or
144/// EAP protocols).
145///
146/// PPP is waiting for the server to call back.
147///
148/// PPP is now authenticated and negotiating the networking
149/// layer (IPCP or IPv6CP protocols)
150///
151/// PPP is now fully connected for at least one networking layer.
152/// Additional networking protocol might still be negotiating.
153///
154/// PPP networking and link protocols are terminating.
155///
156/// PPP is disconnecting the lower level (for example, the modem
157/// is hanging up).
158///
159/// PPP is disconnected and maintaining the link temporarily off.
160///
161/// PPP is suspended as a result of the suspend command (for
162/// example, when a V.92 Modem is On Hold).
163///
164/// PPP has found a busy server and is waiting for redial.
165///
166/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkconnectionpppstatus?language=objc)
167// NS_ENUM
168#[repr(transparent)]
169#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
170pub struct SCNetworkConnectionPPPStatus(pub i32);
171impl SCNetworkConnectionPPPStatus {
172 #[doc(alias = "kSCNetworkConnectionPPPDisconnected")]
173 pub const Disconnected: Self = Self(0);
174 #[doc(alias = "kSCNetworkConnectionPPPInitializing")]
175 pub const Initializing: Self = Self(1);
176 #[doc(alias = "kSCNetworkConnectionPPPConnectingLink")]
177 pub const ConnectingLink: Self = Self(2);
178 #[doc(alias = "kSCNetworkConnectionPPPDialOnTraffic")]
179 pub const DialOnTraffic: Self = Self(3);
180 #[doc(alias = "kSCNetworkConnectionPPPNegotiatingLink")]
181 pub const NegotiatingLink: Self = Self(4);
182 #[doc(alias = "kSCNetworkConnectionPPPAuthenticating")]
183 pub const Authenticating: Self = Self(5);
184 #[doc(alias = "kSCNetworkConnectionPPPWaitingForCallBack")]
185 pub const WaitingForCallBack: Self = Self(6);
186 #[doc(alias = "kSCNetworkConnectionPPPNegotiatingNetwork")]
187 pub const NegotiatingNetwork: Self = Self(7);
188 #[doc(alias = "kSCNetworkConnectionPPPConnected")]
189 pub const Connected: Self = Self(8);
190 #[doc(alias = "kSCNetworkConnectionPPPTerminating")]
191 pub const Terminating: Self = Self(9);
192 #[doc(alias = "kSCNetworkConnectionPPPDisconnectingLink")]
193 pub const DisconnectingLink: Self = Self(10);
194 #[doc(alias = "kSCNetworkConnectionPPPHoldingLinkOff")]
195 pub const HoldingLinkOff: Self = Self(11);
196 #[doc(alias = "kSCNetworkConnectionPPPSuspended")]
197 pub const Suspended: Self = Self(12);
198 #[doc(alias = "kSCNetworkConnectionPPPWaitingForRedial")]
199 pub const WaitingForRedial: Self = Self(13);
200}
201
202#[cfg(feature = "objc2")]
203unsafe impl Encode for SCNetworkConnectionPPPStatus {
204 const ENCODING: Encoding = i32::ENCODING;
205}
206
207#[cfg(feature = "objc2")]
208unsafe impl RefEncode for SCNetworkConnectionPPPStatus {
209 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
210}
211
212/// Type of the callback function used when a
213/// status event is delivered.
214///
215/// Parameter `status`: The connection status.
216///
217/// Parameter `connection`: The connection reference.
218///
219/// Parameter `info`: Application-specific information.
220///
221/// See also [Apple's documentation](https://developer.apple.com/documentation/systemconfiguration/scnetworkconnectioncallback?language=objc)
222pub type SCNetworkConnectionCallBack = Option<
223 unsafe extern "C-unwind" fn(
224 NonNull<SCNetworkConnection>,
225 SCNetworkConnectionStatus,
226 *mut c_void,
227 ),
228>;
229
230unsafe impl ConcreteType for SCNetworkConnection {
231 /// Returns the type identifier of all SCNetworkConnection
232 /// instances.
233 #[doc(alias = "SCNetworkConnectionGetTypeID")]
234 #[inline]
235 fn type_id() -> CFTypeID {
236 extern "C-unwind" {
237 fn SCNetworkConnectionGetTypeID() -> CFTypeID;
238 }
239 unsafe { SCNetworkConnectionGetTypeID() }
240 }
241}
242
243impl SCNetworkConnection {
244 /// Provides the default service ID and a dictionary of user
245 /// options for the connection. Applications can use the
246 /// returned serviceID and userOptions values to open a
247 /// connection on the fly.
248 ///
249 /// Parameter `selectionOptions`: Currently unimplemented. Pass NULL for this
250 /// version.
251 ///
252 /// Parameter `serviceID`: Reference to the default serviceID for starting
253 /// connections, this value will be returned by the function.
254 ///
255 /// Parameter `userOptions`: Reference to default userOptions for starting
256 /// connections, this will be returned by the function.
257 ///
258 /// Returns: Returns TRUE if there is a valid service to dial;
259 /// FALSE if the function was unable to retrieve a service to dial.
260 ///
261 /// # Safety
262 ///
263 /// - `selection_options` generics must be of the correct type.
264 /// - `service_id` must be a valid pointer.
265 /// - `user_options` must be a valid pointer.
266 #[doc(alias = "SCNetworkConnectionCopyUserPreferences")]
267 #[inline]
268 pub unsafe fn user_preferences(
269 selection_options: Option<&CFDictionary>,
270 service_id: NonNull<*const CFString>,
271 user_options: NonNull<*const CFDictionary>,
272 ) -> bool {
273 extern "C-unwind" {
274 fn SCNetworkConnectionCopyUserPreferences(
275 selection_options: Option<&CFDictionary>,
276 service_id: NonNull<*const CFString>,
277 user_options: NonNull<*const CFDictionary>,
278 ) -> Boolean;
279 }
280 let ret = unsafe {
281 SCNetworkConnectionCopyUserPreferences(selection_options, service_id, user_options)
282 };
283 ret != 0
284 }
285
286 /// Creates a new connection reference to use for getting
287 /// the status or for connecting or disconnecting the associated
288 /// service.
289 ///
290 /// Parameter `allocator`: The CFAllocator that should be used to allocate
291 /// memory for the connection structure. This parameter may be
292 /// NULL in which case the current default CFAllocator is used.
293 /// If this reference is not a valid CFAllocator, the behavior
294 /// is undefined.
295 ///
296 /// Parameter `serviceID`: A string that defines the service identifier
297 /// of the connection. Service identifiers uniquely identify
298 /// services in the system configuration database.
299 ///
300 /// Parameter `callout`: The function to be called when the status
301 /// of the connection changes. If this parameter is NULL, the
302 /// application will not receive notifications of status change
303 /// and will need to poll for updates.
304 ///
305 /// Parameter `context`: The SCNetworkConnectionContext associated with the
306 /// callout.
307 ///
308 /// Returns: Returns a reference to the new SCNetworkConnection.
309 ///
310 /// # Safety
311 ///
312 /// - `callout` must be implemented correctly.
313 /// - `context` must be a valid pointer or null.
314 #[doc(alias = "SCNetworkConnectionCreateWithServiceID")]
315 #[inline]
316 pub unsafe fn with_service_id(
317 allocator: Option<&CFAllocator>,
318 service_id: &CFString,
319 callout: SCNetworkConnectionCallBack,
320 context: *mut SCNetworkConnectionContext,
321 ) -> Option<CFRetained<SCNetworkConnection>> {
322 extern "C-unwind" {
323 fn SCNetworkConnectionCreateWithServiceID(
324 allocator: Option<&CFAllocator>,
325 service_id: &CFString,
326 callout: SCNetworkConnectionCallBack,
327 context: *mut SCNetworkConnectionContext,
328 ) -> Option<NonNull<SCNetworkConnection>>;
329 }
330 let ret = unsafe {
331 SCNetworkConnectionCreateWithServiceID(allocator, service_id, callout, context)
332 };
333 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
334 }
335
336 /// Returns the service ID associated with the SCNetworkConnection.
337 ///
338 /// Parameter `connection`: The SCNetworkConnection to obtain status from.
339 ///
340 /// Returns: Returns the service ID associated with the SCNetworkConnection.
341 #[doc(alias = "SCNetworkConnectionCopyServiceID")]
342 #[inline]
343 pub fn service_id(&self) -> Option<CFRetained<CFString>> {
344 extern "C-unwind" {
345 fn SCNetworkConnectionCopyServiceID(
346 connection: &SCNetworkConnection,
347 ) -> Option<NonNull<CFString>>;
348 }
349 let ret = unsafe { SCNetworkConnectionCopyServiceID(self) };
350 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
351 }
352
353 /// Returns the status of the SCNetworkConnection.
354 /// A status is one of the following values:
355 /// <pre>
356 ///
357 /// ```text
358 ///  
359 /// kSCNetworkConnectionInvalid
360 /// kSCNetworkConnectionDisconnected
361 /// kSCNetworkConnectionConnecting
362 /// kSCNetworkConnectionDisconnecting
363 /// kSCNetworkConnectionConnected
364 /// ```
365 ///
366 /// </pre>
367 ///
368 /// Parameter `connection`: The SCNetworkConnection to obtain status from.
369 ///
370 /// Returns: Returns the status value.
371 #[doc(alias = "SCNetworkConnectionGetStatus")]
372 #[inline]
373 pub fn status(&self) -> SCNetworkConnectionStatus {
374 extern "C-unwind" {
375 fn SCNetworkConnectionGetStatus(
376 connection: &SCNetworkConnection,
377 ) -> SCNetworkConnectionStatus;
378 }
379 unsafe { SCNetworkConnectionGetStatus(self) }
380 }
381
382 /// Returns the extended status of the connection.
383 /// An extended status dictionary contains specific dictionaries
384 /// describing the status for each subcomponent of the service.
385 ///
386 /// For example, a status dictionary will contain the following
387 /// sub-dictionaries, keys, and values:
388 /// <pre>
389 ///
390 /// ```text
391 ///  
392 /// IPv4 : Addresses : the assigned IP address.
393 ///  
394 /// PPP : Status : the PPP-specific status of type
395 /// SCNetworkConnectionPPPStatus.
396 ///  
397 /// LastCause : Available when the status is "Disconnected"
398 /// and contains the last error associated with
399 /// connecting or disconnecting.
400 ///  
401 /// ConnectTime : the time when the connection was
402 /// established.
403 ///  
404 /// Modem : ConnectSpeed : the speed of the modem connection
405 /// in bits/second.
406 ///  
407 /// IPSec : Status : the IPSec-specific status of type
408 /// SCNetworkConnectionIPSecStatus
409 ///  
410 /// ConnectTime : the time when the connection was
411 /// established.
412 ///
413 /// ```
414 ///
415 /// </pre>
416 /// Other dictionaries could be present for PPPoE, PPTP, and L2TP.
417 ///
418 /// The status dictionary may be extended in the future to contain
419 /// additional information.
420 ///
421 /// Parameter `connection`: The SCNetworkConnection to obtain status from.
422 ///
423 /// Returns: Returns the status dictionary.
424 /// If NULL is returned, the error can be retrieved using the SCError function.
425 #[doc(alias = "SCNetworkConnectionCopyExtendedStatus")]
426 #[inline]
427 pub fn extended_status(&self) -> Option<CFRetained<CFDictionary>> {
428 extern "C-unwind" {
429 fn SCNetworkConnectionCopyExtendedStatus(
430 connection: &SCNetworkConnection,
431 ) -> Option<NonNull<CFDictionary>>;
432 }
433 let ret = unsafe { SCNetworkConnectionCopyExtendedStatus(self) };
434 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
435 }
436
437 /// Returns the statistics of the SCNetworkConnection.
438 /// A statistic dictionary contains specific dictionaries
439 /// with statistics for each subcomponent of the service.
440 ///
441 /// For example, a statistics dictionary will contain the following
442 /// sub-dictionaries, keys, and values:
443 /// <pre>
444 ///
445 /// ```text
446 ///  
447 /// PPP : BytesIn :
448 /// PPP : BytesOut : Contains the number of bytes going up into
449 /// (or coming out of) the network stack for
450 /// any networking protocol without the PPP
451 /// headers and trailers.
452 ///  
453 /// PPP : PacketsIn :
454 /// PPP : PacketsOut : Contains the number of packets going up into
455 /// (or coming out of) the network stack for
456 /// any networking protocol without the PPP
457 /// headers and trailers.
458 ///  
459 /// PPP : ErrorsIn :
460 /// PPP : ErrorsOut : Contains the number of errors going up into
461 /// (or coming out of) the network stack for
462 /// any networking protocol without the PPP
463 /// headers and trailers.
464 /// ```
465 ///
466 /// </pre>
467 /// The statistics dictionary may be extended in the future to
468 /// contain additional information.
469 ///
470 /// Parameter `connection`: The SCNetworkConnection to obtained statistics from.
471 ///
472 /// Returns: Returns the statistics dictionary.
473 /// If NULL is returned, the error can be retrieved using the SCError function.
474 #[doc(alias = "SCNetworkConnectionCopyStatistics")]
475 #[inline]
476 pub fn statistics(&self) -> Option<CFRetained<CFDictionary>> {
477 extern "C-unwind" {
478 fn SCNetworkConnectionCopyStatistics(
479 connection: &SCNetworkConnection,
480 ) -> Option<NonNull<CFDictionary>>;
481 }
482 let ret = unsafe { SCNetworkConnectionCopyStatistics(self) };
483 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
484 }
485
486 /// Starts the connection for the SCNetworkConnection.
487 /// The connection process is asynchronous and the function will
488 /// return immediately. The connection status can be obtained
489 /// by polling or by callback. The connection is made with the
490 /// default settings from the administrator. Some of the settings
491 /// can be overridden for the duration of the connection. These
492 /// are specified in an options dictionary. The options dictionary
493 /// uses the same format as a network service defined in the system
494 /// configuration preferences schema.
495 ///
496 /// Note: Starting and stopping of connections is implicitly
497 /// arbitrated. Calling SCNetworkConnectionStart on a connection
498 /// already started will indicate that the application has
499 /// interest in the connection and it shouldn't be stopped by
500 /// anyone else.
501 ///
502 /// Parameter `connection`: The SCNetworkConnection to start.
503 ///
504 /// Parameter `userOptions`: The options dictionary to start the connection with.
505 /// If userOptions is NULL, the default settings will be used.
506 /// If userOptions are specified, they must be in the same format
507 /// as network services stored in the system configuration
508 /// preferences schema. The options will override the default
509 /// settings defined for the service.
510 ///
511 /// For security reasons, not all options can be overridden; the
512 /// appropriate merging of all settings will be done before the
513 /// connection is established, and inappropriate options will be
514 /// ignored.
515 ///
516 /// Parameter `linger`: This parameter indicates whether or not the connection
517 /// can stay around when the application no longer has interest
518 /// in it. A typical application should pass FALSE, and the
519 /// connection will be automatically stopped when the reference
520 /// is released or if the application quits. If the application
521 /// passes TRUE, the application can release the reference or
522 /// exit and the connection will be maintained until a timeout
523 /// event, until a specific stop request occurs, or until an
524 /// error is encountered.
525 ///
526 /// Returns: Returns TRUE if the connection was correctly started (the
527 /// actual connection is not established yet, and the connection
528 /// status needs to be periodically checked); FALSE if the
529 /// connection request was not started. The error must be
530 /// retrieved from the SCError function.
531 ///
532 /// # Safety
533 ///
534 /// `user_options` generics must be of the correct type.
535 #[doc(alias = "SCNetworkConnectionStart")]
536 #[inline]
537 pub unsafe fn start(&self, user_options: Option<&CFDictionary>, linger: bool) -> bool {
538 extern "C-unwind" {
539 fn SCNetworkConnectionStart(
540 connection: &SCNetworkConnection,
541 user_options: Option<&CFDictionary>,
542 linger: Boolean,
543 ) -> Boolean;
544 }
545 let ret = unsafe { SCNetworkConnectionStart(self, user_options, linger as _) };
546 ret != 0
547 }
548
549 /// Stops the connection for the SCNetworkConnection.
550 /// The disconnection process is asynchronous and the function
551 /// will return immediately. The connection status can be
552 /// obtained by polling or by callback. This function performs
553 /// an arbitrated stop of the connection. If several applications
554 /// have marked their interest in the connection, by calling
555 /// SCNetworkConnectionStart, the call will succeed but the
556 /// actual connection will be maintained until the last interested
557 /// application calls SCNetworkConnectionStop.
558 ///
559 /// In certain cases, you might want to stop the connection anyway.
560 /// In these cases, you set the forceDisconnect argument to TRUE.
561 ///
562 /// Parameter `connection`: The SCNetworkConnection to stop.
563 ///
564 /// Returns: Returns TRUE if the disconnection request succeeded;
565 /// FALSE if the disconnection request failed.
566 /// The error must be retrieved from the SCError function.
567 #[doc(alias = "SCNetworkConnectionStop")]
568 #[inline]
569 pub fn stop(&self, force_disconnect: bool) -> bool {
570 extern "C-unwind" {
571 fn SCNetworkConnectionStop(
572 connection: &SCNetworkConnection,
573 force_disconnect: Boolean,
574 ) -> Boolean;
575 }
576 let ret = unsafe { SCNetworkConnectionStop(self, force_disconnect as _) };
577 ret != 0
578 }
579
580 /// Copies the user options used to start the connection.
581 /// This is a mechanism a client can use to retrieve the user options
582 /// previously passed to the SCNetworkConnectionStart function.
583 ///
584 /// Parameter `connection`: The SCNetworkConnection to obtain options from.
585 ///
586 /// Returns: Returns the service dictionary containing the connection options.
587 /// The dictionary can be empty if no user options were used.
588 /// If NULL is returned, the error can be retrieved using the SCError function.
589 #[doc(alias = "SCNetworkConnectionCopyUserOptions")]
590 #[inline]
591 pub fn user_options(&self) -> Option<CFRetained<CFDictionary>> {
592 extern "C-unwind" {
593 fn SCNetworkConnectionCopyUserOptions(
594 connection: &SCNetworkConnection,
595 ) -> Option<NonNull<CFDictionary>>;
596 }
597 let ret = unsafe { SCNetworkConnectionCopyUserOptions(self) };
598 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
599 }
600
601 /// Schedules a connection with the run loop.
602 ///
603 /// Parameter `connection`: The SCNetworkConnection to schedule.
604 ///
605 /// Parameter `runLoop`: The run loop to schedule with.
606 ///
607 /// Parameter `runLoopMode`: The run loop mode.
608 ///
609 /// Returns: Returns TRUE if the connection is scheduled successfully;
610 /// FALSE if the scheduling failed.
611 /// The error can be retrieved using the SCError function.
612 #[doc(alias = "SCNetworkConnectionScheduleWithRunLoop")]
613 #[inline]
614 pub fn schedule_with_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
615 extern "C-unwind" {
616 fn SCNetworkConnectionScheduleWithRunLoop(
617 connection: &SCNetworkConnection,
618 run_loop: &CFRunLoop,
619 run_loop_mode: &CFString,
620 ) -> Boolean;
621 }
622 let ret = unsafe { SCNetworkConnectionScheduleWithRunLoop(self, run_loop, run_loop_mode) };
623 ret != 0
624 }
625
626 /// Unschedules a connection from the run loop.
627 ///
628 /// Parameter `connection`: The SCNetworkConnection to unschedule.
629 ///
630 /// Parameter `runLoop`: The run loop to unschedule from.
631 ///
632 /// Parameter `runLoopMode`: The run loop mode.
633 ///
634 /// Returns: Returns TRUE if the connection is unscheduled successfully;
635 /// FALSE if the unscheduling failed.
636 /// The error can be retrieved using the SCError function.
637 #[doc(alias = "SCNetworkConnectionUnscheduleFromRunLoop")]
638 #[inline]
639 pub fn unschedule_from_run_loop(&self, run_loop: &CFRunLoop, run_loop_mode: &CFString) -> bool {
640 extern "C-unwind" {
641 fn SCNetworkConnectionUnscheduleFromRunLoop(
642 connection: &SCNetworkConnection,
643 run_loop: &CFRunLoop,
644 run_loop_mode: &CFString,
645 ) -> Boolean;
646 }
647 let ret =
648 unsafe { SCNetworkConnectionUnscheduleFromRunLoop(self, run_loop, run_loop_mode) };
649 ret != 0
650 }
651
652 /// Caller provides a dispatch queue on which the callback contained in connection will run.
653 ///
654 /// Parameter `connection`: The SCNetworkConnection to notify.
655 ///
656 /// Parameter `queue`: The libdispatch queue to run the callback on.
657 /// Pass NULL to disable notifications, and release queue.
658 ///
659 /// Returns: Returns TRUE if the notifications have been enabled/disabled as desired;
660 /// FALSE if not.
661 /// The error can be retrieved using the SCError function.
662 ///
663 /// # Safety
664 ///
665 /// `queue` possibly has additional threading requirements.
666 #[doc(alias = "SCNetworkConnectionSetDispatchQueue")]
667 #[cfg(feature = "dispatch2")]
668 #[inline]
669 pub unsafe fn set_dispatch_queue(&self, queue: Option<&DispatchQueue>) -> bool {
670 extern "C-unwind" {
671 fn SCNetworkConnectionSetDispatchQueue(
672 connection: &SCNetworkConnection,
673 queue: Option<&DispatchQueue>,
674 ) -> Boolean;
675 }
676 let ret = unsafe { SCNetworkConnectionSetDispatchQueue(self, queue) };
677 ret != 0
678 }
679}
680
681#[deprecated = "renamed to `SCNetworkConnection::user_preferences`"]
682#[inline]
683pub unsafe extern "C-unwind" fn SCNetworkConnectionCopyUserPreferences(
684 selection_options: Option<&CFDictionary>,
685 service_id: NonNull<*const CFString>,
686 user_options: NonNull<*const CFDictionary>,
687) -> bool {
688 extern "C-unwind" {
689 fn SCNetworkConnectionCopyUserPreferences(
690 selection_options: Option<&CFDictionary>,
691 service_id: NonNull<*const CFString>,
692 user_options: NonNull<*const CFDictionary>,
693 ) -> Boolean;
694 }
695 let ret = unsafe {
696 SCNetworkConnectionCopyUserPreferences(selection_options, service_id, user_options)
697 };
698 ret != 0
699}
700
701#[deprecated = "renamed to `SCNetworkConnection::with_service_id`"]
702#[inline]
703pub unsafe extern "C-unwind" fn SCNetworkConnectionCreateWithServiceID(
704 allocator: Option<&CFAllocator>,
705 service_id: &CFString,
706 callout: SCNetworkConnectionCallBack,
707 context: *mut SCNetworkConnectionContext,
708) -> Option<CFRetained<SCNetworkConnection>> {
709 extern "C-unwind" {
710 fn SCNetworkConnectionCreateWithServiceID(
711 allocator: Option<&CFAllocator>,
712 service_id: &CFString,
713 callout: SCNetworkConnectionCallBack,
714 context: *mut SCNetworkConnectionContext,
715 ) -> Option<NonNull<SCNetworkConnection>>;
716 }
717 let ret =
718 unsafe { SCNetworkConnectionCreateWithServiceID(allocator, service_id, callout, context) };
719 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
720}
721
722#[deprecated = "renamed to `SCNetworkConnection::service_id`"]
723#[inline]
724pub extern "C-unwind" fn SCNetworkConnectionCopyServiceID(
725 connection: &SCNetworkConnection,
726) -> Option<CFRetained<CFString>> {
727 extern "C-unwind" {
728 fn SCNetworkConnectionCopyServiceID(
729 connection: &SCNetworkConnection,
730 ) -> Option<NonNull<CFString>>;
731 }
732 let ret = unsafe { SCNetworkConnectionCopyServiceID(connection) };
733 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
734}
735
736#[deprecated = "renamed to `SCNetworkConnection::status`"]
737#[inline]
738pub extern "C-unwind" fn SCNetworkConnectionGetStatus(
739 connection: &SCNetworkConnection,
740) -> SCNetworkConnectionStatus {
741 extern "C-unwind" {
742 fn SCNetworkConnectionGetStatus(
743 connection: &SCNetworkConnection,
744 ) -> SCNetworkConnectionStatus;
745 }
746 unsafe { SCNetworkConnectionGetStatus(connection) }
747}
748
749#[deprecated = "renamed to `SCNetworkConnection::extended_status`"]
750#[inline]
751pub extern "C-unwind" fn SCNetworkConnectionCopyExtendedStatus(
752 connection: &SCNetworkConnection,
753) -> Option<CFRetained<CFDictionary>> {
754 extern "C-unwind" {
755 fn SCNetworkConnectionCopyExtendedStatus(
756 connection: &SCNetworkConnection,
757 ) -> Option<NonNull<CFDictionary>>;
758 }
759 let ret = unsafe { SCNetworkConnectionCopyExtendedStatus(connection) };
760 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
761}
762
763#[deprecated = "renamed to `SCNetworkConnection::statistics`"]
764#[inline]
765pub extern "C-unwind" fn SCNetworkConnectionCopyStatistics(
766 connection: &SCNetworkConnection,
767) -> Option<CFRetained<CFDictionary>> {
768 extern "C-unwind" {
769 fn SCNetworkConnectionCopyStatistics(
770 connection: &SCNetworkConnection,
771 ) -> Option<NonNull<CFDictionary>>;
772 }
773 let ret = unsafe { SCNetworkConnectionCopyStatistics(connection) };
774 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
775}
776
777#[deprecated = "renamed to `SCNetworkConnection::start`"]
778#[inline]
779pub unsafe extern "C-unwind" fn SCNetworkConnectionStart(
780 connection: &SCNetworkConnection,
781 user_options: Option<&CFDictionary>,
782 linger: bool,
783) -> bool {
784 extern "C-unwind" {
785 fn SCNetworkConnectionStart(
786 connection: &SCNetworkConnection,
787 user_options: Option<&CFDictionary>,
788 linger: Boolean,
789 ) -> Boolean;
790 }
791 let ret = unsafe { SCNetworkConnectionStart(connection, user_options, linger as _) };
792 ret != 0
793}
794
795#[deprecated = "renamed to `SCNetworkConnection::stop`"]
796#[inline]
797pub extern "C-unwind" fn SCNetworkConnectionStop(
798 connection: &SCNetworkConnection,
799 force_disconnect: bool,
800) -> bool {
801 extern "C-unwind" {
802 fn SCNetworkConnectionStop(
803 connection: &SCNetworkConnection,
804 force_disconnect: Boolean,
805 ) -> Boolean;
806 }
807 let ret = unsafe { SCNetworkConnectionStop(connection, force_disconnect as _) };
808 ret != 0
809}
810
811#[deprecated = "renamed to `SCNetworkConnection::user_options`"]
812#[inline]
813pub extern "C-unwind" fn SCNetworkConnectionCopyUserOptions(
814 connection: &SCNetworkConnection,
815) -> Option<CFRetained<CFDictionary>> {
816 extern "C-unwind" {
817 fn SCNetworkConnectionCopyUserOptions(
818 connection: &SCNetworkConnection,
819 ) -> Option<NonNull<CFDictionary>>;
820 }
821 let ret = unsafe { SCNetworkConnectionCopyUserOptions(connection) };
822 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
823}
824
825#[deprecated = "renamed to `SCNetworkConnection::schedule_with_run_loop`"]
826#[inline]
827pub extern "C-unwind" fn SCNetworkConnectionScheduleWithRunLoop(
828 connection: &SCNetworkConnection,
829 run_loop: &CFRunLoop,
830 run_loop_mode: &CFString,
831) -> bool {
832 extern "C-unwind" {
833 fn SCNetworkConnectionScheduleWithRunLoop(
834 connection: &SCNetworkConnection,
835 run_loop: &CFRunLoop,
836 run_loop_mode: &CFString,
837 ) -> Boolean;
838 }
839 let ret =
840 unsafe { SCNetworkConnectionScheduleWithRunLoop(connection, run_loop, run_loop_mode) };
841 ret != 0
842}
843
844#[deprecated = "renamed to `SCNetworkConnection::unschedule_from_run_loop`"]
845#[inline]
846pub extern "C-unwind" fn SCNetworkConnectionUnscheduleFromRunLoop(
847 connection: &SCNetworkConnection,
848 run_loop: &CFRunLoop,
849 run_loop_mode: &CFString,
850) -> bool {
851 extern "C-unwind" {
852 fn SCNetworkConnectionUnscheduleFromRunLoop(
853 connection: &SCNetworkConnection,
854 run_loop: &CFRunLoop,
855 run_loop_mode: &CFString,
856 ) -> Boolean;
857 }
858 let ret =
859 unsafe { SCNetworkConnectionUnscheduleFromRunLoop(connection, run_loop, run_loop_mode) };
860 ret != 0
861}
862
863#[cfg(feature = "dispatch2")]
864#[deprecated = "renamed to `SCNetworkConnection::set_dispatch_queue`"]
865#[inline]
866pub unsafe extern "C-unwind" fn SCNetworkConnectionSetDispatchQueue(
867 connection: &SCNetworkConnection,
868 queue: Option<&DispatchQueue>,
869) -> bool {
870 extern "C-unwind" {
871 fn SCNetworkConnectionSetDispatchQueue(
872 connection: &SCNetworkConnection,
873 queue: Option<&DispatchQueue>,
874 ) -> Boolean;
875 }
876 let ret = unsafe { SCNetworkConnectionSetDispatchQueue(connection, queue) };
877 ret != 0
878}