IOPSNotificationCreateRunLoopSource

Function IOPSNotificationCreateRunLoopSource 

Source
pub unsafe extern "C-unwind" fn IOPSNotificationCreateRunLoopSource(
    callback: IOPowerSourceCallbackType,
    context: *mut c_void,
) -> Option<CFRetained<CFRunLoopSource>>
Available on crate feature ps only.
Expand description

Returns a CFRunLoopSourceRef that notifies the caller when power source information changes.

Returns a CFRunLoopSourceRef for scheduling with your CFRunLoop. If your project does not use a CFRunLoop, you can alternatively receive notifications via mach port, dispatch, or signal, via notify.h using the name

 kIOPSTimeRemainingNotificationKey
.

IOKit delivers this notification when percent remaining or time remaining changes. Thus it fires fairly frequently while discharging or charging the battery; please consider using:

 IOPSCreateLimitedPowerNotification
if you only require notifications when the power source type changes from limited to unlimited.

Parameter callback: A function to be called whenever any power source is added, removed, or changes.

Parameter context: Any user-defined pointer, passed to the IOPowerSource callback.

Returns: Returns NULL if an error was encountered, otherwise a CFRunLoopSource. Caller must release the CFRunLoopSource.

ยงSafety

  • callback must be implemented correctly.
  • context must be a valid pointer.