Mac Developer Library

Developer

IOPMLib.h Reference

Options
Deployment Target:

On This Page

IOPMLib.h Reference

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Not Applicable

Objective-C

@import IOKit;

IOPMLib provides access to common power management facilities, like initiating system sleep, getting current idle timer values, registering for sleep/wake notifications, and preventing system sleep.

Included Headers

  • <CoreFoundation/CFArray.h>

  • <IOKit/IOKitLib.h>

  • <IOKit/pwr_mgt/IOPMLibDefs.h>

  • <IOKit/pwr_mgt/IOPMKeys.h>

  • <Availability.h>

Functions

  • Cancel a previously scheduled power event.

    Declaration

    Objective-C

    IOReturn IOPMCancelScheduledPowerEvent ( CFDateRef time_to_wake, CFStringRef my_id, CFStringRef type );

    Parameters

    time_to_wake

    Cancel entry with this date and time.

    my_id

    Cancel entry with this name.

    type

    Type to cancel

    Return Value

    kIOReturnSuccess on success, otherwise on failure

    Discussion

    Arguments mirror those to IOPMSchedulePowerEvent. All arguments must match the original arguments from when the power on was scheduled. Must be called as root.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.3 and later.

  • List all scheduled system power events

    Declaration

    Objective-C

    CFArrayRef IOPMCopyScheduledPowerEvents ( void );

    Return Value

    A CFArray of CFDictionaries of power events. The CFArray must be released by the caller. NULL if there are no scheduled events.

    Discussion

    Returns a CFArray of CFDictionaries of power events. Each CFDictionary contains keys for CFSTR(kIOPMPowerEventTimeKey), CFSTR(kIOPMPowerEventAppNameKey), and CFSTR(kIOPMPowerEventTypeKey).

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.3 and later.

  • Schedule the machine to wake from sleep, power on, go to sleep, or shutdown.

    Declaration

    Objective-C

    IOReturn IOPMSchedulePowerEvent ( CFDateRef time_to_wake, CFStringRef my_id, CFStringRef type );

    Parameters

    time_to_wake

    Date and time that the system will power on/off.

    my_id

    A CFStringRef identifying the calling app by CFBundleIdentifier. May be NULL.

    type

    The type of power on you desire, either wake from sleep or power on. Choose from: CFSTR(kIOPMAutoWake) == wake machine, CFSTR(kIOPMAutoPowerOn) == power on machine, CFSTR(kIOPMAutoWakeOrPowerOn) == wake or power on, CFSTR(kIOPMAutoSleep) == sleep machine, CFSTR(kIOPMAutoShutdown) == power off machine, CFSTR(kIOPMAutoRestart) == restart the machine.

    Return Value

    kIOReturnSuccess on success, otherwise on failure

    Discussion

    This event will be added to the system's queue of power events and stored persistently on disk. The sleep and shutdown events present a graphical warning and allow a console user to cancel the event. Must be called as root.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.3 and later.

  • The caller acknowledges notification of a power state change on a device it has registered for notifications for via IORegisterForSystemPower or IORegisterApp.

    Declaration

    Objective-C

    IOReturn IOAllowPowerChange ( io_connect_t kernelPort, long notificationID );

    Parameters

    kernelPort

    Port used to communicate to the kernel, from IORegisterApp or IORegisterForSystemPower.

    notificationID

    A copy of the notification ID which came as part of the power state change notification being acknowledged.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Discussion

    Must be used when handling kIOMessageCanSystemSleep and kIOMessageSystemWillSleep messages from IOPMrootDomain system power. The caller should not call IOAllowPowerChange in response to any messages except for these two.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • The caller denies an idle system sleep power state change.

    Declaration

    Objective-C

    IOReturn IOCancelPowerChange ( io_connect_t kernelPort, long notificationID );

    Parameters

    kernelPort

    Port used to communicate to the kernel, from IORegisterApp or IORegisterForSystemPower.

    notificationID

    A copy of the notification ID which came as part of the power state change notification being acknowledged.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Discussion

    Should only called in response to kIOMessageCanSystemSleep messages from IOPMrootDomain. IOCancelPowerChange has no meaning for responding to kIOMessageSystemWillSleep (which is non-abortable) or any other messages.

    When an app responds to a kIOMessageCanSystemSleep message by calling IOCancelPowerChange, the app vetoes the idle sleep request. The system will stay awake. The idle timer will elapse again after a period of inactivity, and the system will send out the same kIOMessageCanSystemSleep message, and interested applications will respond gain.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Disconnects the caller from an IOService after receiving power state change notifications from the IOService. (Caller must also release IORegisterApp's return io_connect_t and returned IONotificationPortRef for complete clean-up).

    Declaration

    Objective-C

    IOReturn IODeregisterApp ( io_object_t *notifier );

    Parameters

    notifier

    An object from IORegisterApp.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Disconnects the caller from the Root Power Domain IOService after receiving system power state change notifications. (Caller must also destroy the IONotificationPortRef returned from IORegisterForSystemPower.)

    Declaration

    Objective-C

    IOReturn IODeregisterForSystemPower ( io_object_t *notifier );

    Parameters

    notifier

    The object returned from IORegisterForSystemPower.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Connects the caller to an IOService for the purpose of receiving power state change notifications for the device controlled by the IOService.

    Declaration

    Objective-C

    io_connect_t IORegisterApp ( void *refcon, io_service_t theDriver, IONotificationPortRef *thePortRef, IOServiceInterestCallback callback, io_object_t *notifier );

    Parameters

    refcon

    Data returned on power state change notifications and not used by the kernel.

    theDriver

    Representation of the IOService, probably from IOServiceGetMatchingService.

    thePortRef

    Pointer to a port on which the caller will receive power state change notifications. The port is allocated by the calling application.

    callback

    A c-function which is called during the notification.

    notifier

    Pointer to a notifier which caller must keep and pass to subsequent call to IODeregisterApp.

    Return Value

    Returns a io_connect_t session for the IOService or MACH_PORT_NULL if request failed. Caller must close return value via IOServiceClose() after calling IODeregisterApp on the notifier argument.

    Discussion

    IORegisterApp requires that the IOService of interest implement an IOUserClient. In addition, that IOUserClient must implement the allowPowerChange and cancelPowerChange methods defined in IOPMLibDefs.h. If you're interested in receiving power state notifications from a device without an IOUserClient, try using IOServiceAddInterestNotification with interest type gIOGeneralInterest instead.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.9.

  • Connects the caller to the Root Power Domain IOService for the purpose of receiving sleep & wake notifications for the system. Does not provide system shutdown and restart notifications.

    Declaration

    Objective-C

    io_connect_t IORegisterForSystemPower ( void *refcon, IONotificationPortRef *thePortRef, IOServiceInterestCallback callback, io_object_t *notifier );

    Parameters

    refcon

    Caller may provide data to receive s an argument to 'callback' on power state changes.

    thePortRef

    On return, thePortRef is a pointer to an IONotificationPortRef, which will deliver the power notifications. The port is allocated by this function and must be later released by the caller (after calling IODeregisterForSystemPower). The caller should also enable IONotificationPortRef by calling IONotificationPortGetRunLoopSource, or IONotificationPortGetMachPort, or IONotificationPortSetDispatchQueue.

    callback

    A c-function which is called during the notification.

    notifier

    On success, returns a pointer to a unique notifier which caller must keep and pass to a subsequent call to IODeregisterForSystemPower.

    Return Value

    Returns a io_connect_t session for the IOPMrootDomain or MACH_PORT_NULL if request failed. Caller must close return value via IOServiceClose() after calling IODeregisterForSystemPower on the notifier argument.

    Discussion

    Provides sleep/wake notifications to applications. Requires that applications acknowledge some, but not all notifications. Register for sleep/wake notifications will deliver these messages over the sleep/wake lifecycle:

    - kIOMessageSystemWillSleep is delivered at the point the system is initiating a non-abortable sleep. Callers MUST acknowledge this event by calling IOAllowPowerChange. If a caller does not acknowledge the sleep notification, the sleep will continue anyway after a 30 second timeout (resulting in bad user experience). Delivered before any hardware is powered off.

    - kIOMessageSystemWillPowerOn is delivered at early wakeup time, before most hardware has been powered on. Be aware that any attempts to access disk, network, the display, etc. may result in errors or blocking your process until those resources become available. Caller must NOT acknowledge kIOMessageSystemWillPowerOn; the caller must simply return from its handler.

    - kIOMessageSystemHasPoweredOn is delivered at wakeup completion time, after all device drivers and hardware have handled the wakeup event. Expect this event 1-5 or more seconds after initiating system wakeup. Caller must NOT acknowledge kIOMessageSystemHasPoweredOn; the caller must simply return from its handler.

    - kIOMessageCanSystemSleep indicates the system is pondering an idle sleep, but gives apps the chance to veto that sleep attempt. Caller must acknowledge kIOMessageCanSystemSleep by calling IOAllowPowerChange or IOCancelPowerChange. Calling IOAllowPowerChange will not veto the sleep; any app that calls IOCancelPowerChange will veto the idle sleep. A kIOMessageCanSystemSleep notification will be followed up to 30 seconds later by a kIOMessageSystemWillSleep message. or a kIOMessageSystemWillNotSleep message.

    - kIOMessageSystemWillNotSleep is delivered when some app client has vetoed an idle sleep request. kIOMessageSystemWillNotSleep may follow a kIOMessageCanSystemSleep notification, but will not otherwise be sent. Caller must NOT acknowledge kIOMessageSystemWillNotSleep; the caller must simply return from its handler.

    To deregister for sleep/wake notifications, the caller must make two calls, in this order: - Call IODeregisterForSystemPower with the 'notifier' argument returned here. - Then call IONotificationPortDestroy passing the 'thePortRef' argument returned here.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Indicates how user activity, battery level, and thermal level each contribute to the overall "SystemLoadAdvisory" level. In the future, this combined level may represent new levels as well.

    Declaration

    Objective-C

    CFDictionaryRef IOCopySystemLoadAdvisoryDetailed ( void );

    Return Value

    Returns a CFDictionaryRef, or NULL on error. Caller must release the returned dictionary.

    Discussion

    See dictionary keys defined above.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.6 and later.

  • Returns a hint about whether now would be a good time to perform time-insensitive work.

    Declaration

    Objective-C

    IOSystemLoadAdvisoryLevel IOGetSystemLoadAdvisory ( void );

    Return Value

    IOSystemLoadAdvisoryLevel - one of: kIOSystemLoadAdvisoryLevelGreat - A Good time to perform time-insensitive work. kIOSystemLoadAdvisoryLevelOK - An OK time to perform time-insensitive work. kIOSystemLoadAdvisoryLevelBad - A Bad time to perform time-insensitive work.

    Discussion

    Based on user and system load, IOGetSystemLoadAdvisory determines "better" and "worse" times to run optional or time-insensitive CPU or disk work.

    Applications may use this result to avoid degrading the user experience. If it is a "Bad" or "OK" time to perform work, applications should slow down and perform work less aggressively.

    There is no guarantee that the system will ever be in "Great" condition to perform work - all essential work must still be performed even in "Bad", or "OK" times. Completely optional work, such as updating caches, may be postponed indefinitely.

    Note: You may more efficiently read the SystemLoadAdvisory level using notify_get_state() instead of IOGetSystemLoadAdvisory. The results are identical. notify_get_state() requires that you pass the token argument received by registering for SystemLoadAdvisory notifications.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.6 and later.

  • Copy status of all current CPU power levels.

    Declaration

    Objective-C

    IOReturn IOPMCopyCPUPowerStatus ( CFDictionaryRef *cpuPowerStatus );

    Parameters

    cpuPowerStatus

    Upon success, a pointer to a dictionary defining CPU power; otherwise NULL. Pointer will be populated with a newly created dictionary upon successful return. Caller must release dictionary.

    Return Value

    kIOReturnSuccess, or other error report. Returns kIOReturnNotFound if CPU PowerStatus has not been published.

    Discussion

    The returned dictionary may define some of these keys, as defined in IOPM.h: - kIOPMCPUPowerLimitProcessorSpeedKey - kIOPMCPUPowerLimitProcessorCountKey - kIOPMCPUPowerLimitSchedulerTimeKey

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Get thermal warning level of the system.

    Declaration

    Objective-C

    IOReturn IOPMGetThermalWarningLevel ( uint32_t *thermalLevel );

    Return Value

    kIOReturnSuccess, or other error report. Returns kIOReturnNotFound if thermal warning level has not been published.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Copies details about an IOPMAssertion

    Declaration

    Objective-C

    CFDictionaryRef IOPMAssertionCopyProperties ( IOPMAssertionID theAssertion );

    Parameters

    theAssertion

    The assertion ID to copy info about.

    Return Value

    A dictionary describing the assertion with keys specified in See IOPMAssertionDictionaryKeys. It's the caller's responsibility to release this dictionary.

    Discussion

    Returns a dictionary describing an IOPMAssertion's specifications and current state.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Dynamically requests a system behavior from the power management system.

    Declaration

    Objective-C

    IOReturn IOPMAssertionCreate ( CFStringRef AssertionType, IOPMAssertionLevel AssertionLevel, IOPMAssertionID *AssertionID );

    Parameters

    AssertionType

    The CFString assertion type to request from the PM system.

    AssertionLevel

    Pass kIOPMAssertionLevelOn or kIOPMAssertionLevelOff.

    AssertionID

    On success, a unique id will be returned in this parameter.

    Return Value

    Returns kIOReturnSuccess on success, any other return indicates PM could not successfully activate the specified assertion.

    Discussion

    No special privileges necessary to make this call - any process may activate a power assertion.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.5 and later.

    Deprecated in OS X v10.6.

  • Declaration

    Objective-C

    IOReturn IOPMAssertionCreateWithDescription ( CFStringRef AssertionType, CFStringRef Name, CFStringRef Details, CFStringRef HumanReadableReason, CFStringRef LocalizationBundlePath, CFTimeInterval Timeout, CFStringRef TimeoutAction, IOPMAssertionID *AssertionID );

    Parameters

    AssertionType

    An assertion type constant. Caller must specify this argument.

    Name

    A CFString value to correspond to key kIOPMAssertionNameKey. Caller must specify this argument.

    Details

    A CFString value to correspond to key kIOPMAssertionDetailsKey. Caller my pass NULL, but it helps power users and administrators identify the reasons for this assertion.

    HumanReadableReason

    A CFString value to correspond to key kIOPMAssertionHumanReadableReasonKey. Caller may pass NULL, but if it's specified OS X may display it to users to describe the active assertions on their system.

    LocalizationBundlePath

    A CFString value to correspond to key kIOPMAssertionLocalizationBundlePathKey. This bundle path should include a localization for the string HumanReadableReason Caller may pass NULL, but this argument is required if caller specifies HumanReadableReason

    Timeout

    Specifies a timeout for this assertion. Pass 0 for no timeout.

    TimeoutAction

    Specifies a timeout action. Caller my pass NULL. If a timeout is specified but a TimeoutAction is not, the default timeout action is kIOPMAssertionTimeoutActionTurnOff

    AssertionID

    (Output) On successful return, contains a unique reference to a PM assertion.

    Return Value

    kIOReturnSuccess, or another IOKit return code on error.

    Discussion

    Creates an IOPMAssertion. This is the preferred API to call to create an assertion. It allows the caller to specify the Name, Details, and HumanReadableReason at creation time. There are other keys that can further describe an assertion, but most developers don't need to use them. Use IOPMAssertionSetProperties or IOPMAssertionCreateWithProperties if you need to specify properties that aren't available here.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Dynamically requests a system behavior from the power management system.

    Declaration

    Objective-C

    IOReturn IOPMAssertionCreateWithName ( CFStringRef AssertionType, IOPMAssertionLevel AssertionLevel, CFStringRef AssertionName, IOPMAssertionID *AssertionID );

    Parameters

    AssertionType

    The CFString assertion type to request from the PM system.

    AssertionLevel

    Pass kIOPMAssertionLevelOn or kIOPMAssertionLevelOff.

    AssertionName

    A string that describes the name of the caller and the activity being handled by this assertion (e.g. "Mail Compacting Mailboxes"). Name may be no longer than 128 characters.

    AssertionID

    On success, a unique id will be returned in this parameter.

    Return Value

    Returns kIOReturnSuccess on success, any other return indicates PM could not successfully activate the specified assertion.

    Discussion

    No special privileges are necessary to make this call - any process may activate a power assertion. Caller must specify an AssertionName - NULL is not a valid input.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.6 and later.

  • Creates an IOPMAssertion with more flexibility than IOPMAssertionCreateWithDescription.

    Declaration

    Objective-C

    IOReturn IOPMAssertionCreateWithProperties ( CFDictionaryRef AssertionProperties, IOPMAssertionID *AssertionID );

    Parameters

    AssertionProperties

    Dictionary providing the properties of the assertion that need to be created.

    AssertionID

    (Output) On successful return, contains a unique reference to a PM assertion.

    Discussion

    Create a new PM assertion - the caller must specify the type of assertion, initial level, and its properties as IOPMAssertionDictionaryKeys keys in the AssertionProperties dictionary. The following keys are recommend and/or required to be specified in the AssertionProperties dictionary argument.

    • REQUIRED: kIOPMAssertionTypeKey define the assertion type.

    • REQUIRED: kIOPMAssertionValueKey define an inital value.

    • REQUIRED: kIOPMAssertionNameKey Caller must describe the name for the activity that requires the change in behavior provided by the assertion.

    • OPTIONAL: kIOPMAssertionDetailsKey Caller may describe context-specific data about the assertion.

    • OPTIONAL: kIOPMAssertionHumanReadableReasonKey Caller may describe the reason for creating the assertion in a localizable CFString. This should be a human readable phrase that describes the actions the calling process is taking while the assertion is held, like "Downloading TV episodes", or "Compiling Projects"

    • OPTIONAL: kIOPMAssertionLocalizationBundlePathKey Caller may provide its bundle's path, where OS X can localize for GUI display the CFString specified by kIOPMAssertionHumanReadableReasonKey.

    • OPTIONAL: kIOPMAssertionPlugInIDKey if the caller is a plugin with a different identity than the process it's loaded in.

    • OPTIONAL: kIOPMAssertionFrameworkIDKey if the caller is a framework acting on behalf of a process.

    • OPTIONAL: The caller may specify a timeout.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Declares that the user is active on the system. This causes the display to power on and postpone display sleep up to the user's display sleep Energy Saver settings. If you prefer to hold the display awake for a longer period and you know how long you'd like to hold it, consider taking assertion kIOPMAssertionTypePreventUserIdleDisplaySleep using IOPMAssertionCreateWithDescription API instead.

    Declaration

    Objective-C

    IOReturn IOPMAssertionDeclareUserActivity ( CFStringRef AssertionName, IOPMUserActiveType userType, IOPMAssertionID *AssertionID );

    Parameters

    AssertionName

    A string that describes the name of the caller and the activity being handled by this assertion (e.g. "Mail Compacting Mailboxes"). Name may be no longer than 128 characters.

    userType

    This parameter specifies if the active user is located locally in front of the system or connected to the system over the network. Various components of the system are maintained at different power levels depending on user location.

    AssertionID

    On Success, unique id will be returned in this parameter. Caller may call this function again with the unique id retured previously to report continous user activity. The unique id returned by this function may change on each call depending on how frequently this function call is repeated and the current display sleep timer value. If you make this call more than once, track the returned value for assertionID, and pass it in as an argument on each call.

    Return Value

    Returns kIOReturnSuccess on success, any other return indicates PM could not successfully activate the specified assertion.

    Discussion

    No special privileges are necessary to make this call - any process may call this API. Caller must specify an AssertionName - NULL is not a valid input.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Decrements the assertion's retain count.

    Declaration

    Objective-C

    IOReturn IOPMAssertionRelease ( IOPMAssertionID AssertionID );

    Parameters

    AssertionID

    The assertion_id, returned from IOPMAssertionCreate, to cancel.

    Return Value

    Returns kIOReturnSuccess on success.

    Discussion

    If the retain count becomes zero, then this also frees and deactivates the assertion referred to by assertionID

    Calls to IOPMAssertionCreate and IOPMAssertionRelease must each be paired with calls to IOPMAssertionRelease.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.5 and later.

  • Increments the assertion's retain count.

    Declaration

    Objective-C

    void IOPMAssertionRetain ( IOPMAssertionID theAssertion );

    Parameters

    theAssertion

    The assertion ID to retain.

    Discussion

    Increments the retain count according to CoreFoundation style retain/release semantics. Retain count can be inspected in the assertion's info dictionary at key kIOPMAssertionRetainCountKey

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Sets a property in the assertion.

    Declaration

    Objective-C

    IOReturn IOPMAssertionSetProperty ( IOPMAssertionID theAssertion, CFStringRef theProperty, CFTypeRef theValue );

    Parameters

    theAssertion

    The IOPMAssertionID of the assertion to modify.

    theProperty

    The CFString key, from IOPMAssertionDictionaryKeys to modify.

    theValue

    The property to set. It must be a CFNumber or CFString, as specified by the property key named in whichProperty.

    Return Value

    Returns kIOReturnNotPriviliged if the caller doesn't have permission to modify this assertion. Returns kIOReturnNotFound if PM can't locate this assertion. Returns kIOReturnError upon an unidentified error. Returns kIOReturnSuccess otherwise.

    Discussion

    Only the process that created an assertion may change its properties.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.7 and later.

  • Returns a dictionary listing all assertions, grouped by their owning process.

    Declaration

    Objective-C

    IOReturn IOPMCopyAssertionsByProcess ( CFDictionaryRef *AssertionsByPID );

    Parameters

    AssertionsByPID

    On success, this returns a dictionary of assertions per process. At the top level, keys to the CFDictionary are pids stored as CFNumbers (kCFNumberIntType). The value associated with each CFNumber pid is a CFArray of active assertions. Each entry in the CFArray is an assertion represented as a CFDictionary. See the keys kIOPMAssertionTypeKey and kIOPMAssertionLevelKey. Caller must CFRelease() this dictionary when done.

    Return Value

    Returns kIOReturnSuccess on success.

    Discussion

    Notes: One process may have multiple assertions. Several processes may have asserted the same assertion to different levels.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.5 and later.

  • Returns a list of available assertions and their system-wide levels.

    Declaration

    Objective-C

    IOReturn IOPMCopyAssertionsStatus ( CFDictionaryRef *AssertionsStatus );

    Parameters

    AssertionsStatus

    On success, this returns a CFDictionary of all assertions currently available. The keys in the dictionary are the assertion types, and the value of each is a CFNumber that represents the aggregate level for that assertion. Caller must CFRelease() this dictionary when done.

    Return Value

    Returns kIOReturnSuccess on success.

    Discussion

    The system-wide level is the maximum of all individual assertions' levels.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.5 and later.

  • Declaration

    Objective-C

    /*! */ #define kIOPMAssertionTimeoutKey CFSTR("TimeoutSeconds") /*! */ #define kIOPMAssertionTimeoutActionKey CFSTR("TimeoutAction") /*! */ #define kIOPMAssertionTimeoutActionLog CFSTR("TimeoutActionLog") /*! */ #define kIOPMAssertionTimeoutActionTurnOff CFSTR("TimeoutActionTurnOff") /*! */ #define kIOPMAssertionTimeoutActionRelease CFSTR("TimeoutActionRelease") /*! */ #define kIOPMAssertionRetainCountKey CFSTR("RetainCount") /*! */ #define kIOPMAssertionNameKey CFSTR("AssertName") /*! */ #define kIOPMAssertionDetailsKey CFSTR("Details") /*! */ #define kIOPMAssertionHumanReadableReasonKey CFSTR("HumanReadableReason") /*! */ #define kIOPMAssertionLocalizationBundlePathKey CFSTR("BundlePath") /*! */ #define kIOPMAssertionFrameworkIDKey CFSTR("FrameworkBundleID") /*! */ #define kIOPMAssertionPlugInIDKey CFSTR("PlugInBundleID") /*! */ #define kIOPMAssertionTypeKey CFSTR("AssertType") /*! */ #define kIOPMAssertionLevelKey CFSTR("AssertLevel")

    Discussion

    Keys into dictionaries describing assertions.

  • Use as AssertionType argument to IOPMAssertionCreate. The idle display will not sleep when enabled, and consequently the system will not idle sleep.

    Declaration

    Objective-C

    /*! */ #define kIOPMAssertionTypePreventUserIdleSystemSleep CFSTR("PreventUserIdleSystemSleep") /*! */ #define kIOPMAssertionTypePreventUserIdleDisplaySleep CFSTR("PreventUserIdleDisplaySleep") /*! */ #define kIOPMAssertionTypePreventSystemSleep CFSTR("PreventSystemSleep") /*! */ #define kIOPMAssertionTypeNoIdleSleep CFSTR("NoIdleSleepAssertion") /*! */ #define kIOPMAssertionTypeNoDisplaySleep CFSTR("NoDisplaySleepAssertion")

    Discussion

    When asserted and set to level kIOPMAssertionLevelOn, the system will prefer to enter the Dark Wake state, or remain in Dark Wake if already there, rather than go to sleep.

    Assertions are just suggestions to the OS, and the OS can only honor them to the best of its ability. In the case of low power or a thermal emergency, the system may sleep anyway despite the assertion.

    An assertion must publish the AssertionType in its assertion properties dictionary. The AssertionType should be a key in the properties dictionary, with a value of a CFNumber containing the kCFNumberIntegerType value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn.

  • Request raw battery data from the system.

    Declaration

    Objective-C

    IOReturn IOPMCopyBatteryInfo ( mach_port_t masterPort, CFArrayRef *info );

    Parameters

    masterPort

    The master port obtained from IOMasterPort(). Just pass MACH_PORT_NULL.

    info

    A CFArray of CFDictionaries containing raw battery data.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Discussion

    WARNING! IOPMCoyBatteryInfo is unsupported on ALL Intel CPU based systems. For PPC CPU based systems, it remains not recommended. For almost all purposes, developers should use the richer IOPowerSources API (with change notifications) instead of using IOPMCopyBatteryInfo. Keys to decipher IOPMCopyBatteryInfo's return CFArray exist in IOPM.h.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Finds the Root Power Domain IOService.

    Declaration

    Objective-C

    io_connect_t IOPMFindPowerManagement ( mach_port_t master_device_port );

    Parameters

    master_device_port

    Just pass in MACH_PORT_NULL for master device port.

    Return Value

    Returns a io_connect_t handle on the root domain. Must be released with IOServiceClose() when done.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Retrieves the current value of one of the aggressiveness factors in IOKit Power Management.

    Declaration

    Objective-C

    IOReturn IOPMGetAggressiveness ( io_connect_t fb, unsigned long type, unsigned long *aggressiveness );

    Parameters

    fb

    Representation of the Root Power Domain from IOPMFindPowerManagement.

    type

    Specifies which aggressiveness factor is being retrieved.

    aggressiveness

    Points to where to store the retrieved value of the aggressiveness factor.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Sets one of the aggressiveness factors in IOKit Power Management.

    Declaration

    Objective-C

    IOReturn IOPMSetAggressiveness ( io_connect_t fb, unsigned long type, unsigned long aggressiveness );

    Parameters

    fb

    Representation of the Root Power Domain from IOPMFindPowerManagement.

    type

    Specifies which aggressiveness factor is being set.

    aggressiveness

    New value of the aggressiveness factor.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Tells whether the system supports full sleep, or just doze

    Declaration

    Objective-C

    boolean_t IOPMSleepEnabled ( void );

    Return Value

    Returns true if the system supports sleep, false if some hardware prevents full sleep.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

  • Request that the system initiate sleep.

    Declaration

    Objective-C

    IOReturn IOPMSleepSystem ( io_connect_t fb );

    Parameters

    fb

    Port used to communicate to the kernel, from IOPMFindPowerManagement.

    Return Value

    Returns kIOReturnSuccess or an error condition if request failed.

    Discussion

    For security purposes, caller must be root or the console user.

    Import Statement

    Objective-C

    @import IOKit;

    Availability

    Available in OS X v10.0 and later.

Data Types

See the Overview for header-level documentation.

Constants

See the Overview for header-level documentation.

  • Declaration

    Objective-C

    /*! */ #define kIOPMAssertionDetailsKey CFSTR("Details") /*! */ #define kIOPMAssertionFrameworkIDKey CFSTR("FrameworkBundleID") /*! */ #define kIOPMAssertionHumanReadableReasonKey CFSTR("HumanReadableReason") /*! */ #define kIOPMAssertionLevelKey CFSTR("AssertLevel") /*! */ #define kIOPMAssertionLocalizationBundlePathKey CFSTR("BundlePath") /*! */ #define kIOPMAssertionNameKey CFSTR("AssertName") /*! */ #define kIOPMAssertionPlugInIDKey CFSTR("PlugInBundleID") /*! */ #define kIOPMAssertionRetainCountKey CFSTR("RetainCount") /*! */ #define kIOPMAssertionTimeoutActionKey CFSTR("TimeoutAction") /*! */ #define kIOPMAssertionTimeoutActionLog CFSTR("TimeoutActionLog") /*! */ #define kIOPMAssertionTimeoutActionRelease CFSTR("TimeoutActionRelease") /*! */ #define kIOPMAssertionTimeoutActionTurnOff CFSTR("TimeoutActionTurnOff") /*! */ #define kIOPMAssertionTimeoutKey CFSTR("TimeoutSeconds") /*! */ #define kIOPMAssertionTypeKey CFSTR("AssertType") /*! */ #define kIOPMAssertionTypeNoDisplaySleep CFSTR("NoDisplaySleepAssertion") /*! */ #define kIOPMAssertionTypeNoIdleSleep CFSTR("NoIdleSleepAssertion") /*! */ #define kIOPMAssertionTypePreventSystemSleep CFSTR("PreventSystemSleep") /*! */ #define kIOPMAssertionTypePreventUserIdleDisplaySleep CFSTR("PreventUserIdleDisplaySleep") /*! */ #define kIOPMAssertionTypePreventUserIdleSystemSleep CFSTR("PreventUserIdleSystemSleep") #define kIOPMCPUPowerNotificationKey "com.apple.system.power.CPU" #define kIOPMThermalWarningNotificationKey "com.apple.system.power.thermal_warning" #define kIOSystemLoadAdvisoryBatteryLevelKey CFSTR("BatteryLevel") #define kIOSystemLoadAdvisoryCombinedLevelKey CFSTR("CombinedLevel") #define kIOSystemLoadAdvisoryNotifyName "com.apple.system.powermanagement.SystemLoadAdvisory" #define kIOSystemLoadAdvisoryThermalLevelKey CFSTR("ThermalLevel") #define kIOSystemLoadAdvisoryUserLevelKey CFSTR("UserLevel")

    Constants

    • kIOPMAssertionDetailsKey

      kIOPMAssertionDetailsKey

      The CFDictionary key for assertion name. Setting this key is required when you're creating an assertion.

      kIOPMAssertionNameKey describes the the activity the assertion is protecting. The creator should specify a CFString value for this key in the dictionary passed to IOPMAssertionCreateWithProperties

      The assertion name is separate from the assertion type's behavior - specify a CFString like "Checking mail" or "Compiling" that describes the task that this assertion protects.

      The CFString you associate with this key does not have to be localizable (OS X will not attempt to localize it.)

      Describe your assertion as thoroughly as possible. See these other keys that can you can also set to add explanation to an assertion: OPTIONAL kIOPMAssertionDetailsKey OPTIONAL kIOPMAssertionHumanReadableReasonKey OPTIONAL kIOPMAssertionLocalizationBundlePathKey

      Available in OS X v10.7 and later.

    • kIOPMAssertionFrameworkIDKey

      kIOPMAssertionFrameworkIDKey

      Specify if the assertion creator is a framework.

      If the code that creates the assertion resides in a framework or library, the caller should specify a CFBundleIdentifier, as a CFString, identifying that bundle here. This info helps developers and administrators determine the source of an assertion.

      This key may be specified in the dictionary passed to IOPMAssertionCreateWithProperties.

      This key may be present in the dictionary returned from IOPMAssertionCopyProperties.

      Available in OS X v10.7 and later.

    • kIOPMAssertionHumanReadableReasonKey

      kIOPMAssertionHumanReadableReasonKey

      Optional key that provides a localizable string for OS X to display PM Assertions in the GUI.

      The caller should specify this string in IOPMAssertionCreateWithProperties. If present, OS X may display this string, localized to the user's language, to explain changes in system behavior caused by the assertion.

      If set, the caller must also specify a bundle path for the key kIOPMAssertionLocalizationBundlePathKey The bundle at that path should contain localization info for the specified string.

      This key may be specified in the dictionary passed to IOPMAssertionCreateWithProperties.

      This key may be present in the dictionary returned from IOPMAssertionCopyProperties.

      Describe your assertion as thoroughly as possible. See these other keys that can you can set to add explanation to an assertion: REQUIRED kIOPMAssertionNameKey OPTIONAL kIOPMAssertionDetailsKey

      Available in OS X v10.7 and later.

    • kIOPMAssertionLevelKey

      kIOPMAssertionLevelKey

      The CFDictionary key for assertion level in an assertion info dictionary.

      The value for this key will be a CFNumber, kCFNumberIntType with value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn. The level reflects the assertion's level set at creation, or adjusted via IOPMAssertionSetLevel

      Available in OS X v10.5 and later.

    • kIOPMAssertionLocalizationBundlePathKey

      kIOPMAssertionLocalizationBundlePathKey

      Refers to a CFURL, as a CFString, identifying the path to the caller's bundle, which contains localization info.

      The bundle must contain localizations for kIOPMAssertionHumanReadableReasonKey

      This key may be specified in the dictionary passed to IOPMAssertionCreateWithProperties.

      This key may be present in the dictionary returned from IOPMAssertionCopyProperties.

      Available in OS X v10.7 and later.

    • kIOPMAssertionNameKey

      kIOPMAssertionNameKey

      The CFDictionary key for assertion name. Setting this key is required when you're creating an assertion.

      kIOPMAssertionNameKey describes the the activity the assertion is protecting. The creator should specify a CFString value for this key in the dictionary passed to IOPMAssertionCreateWithProperties

      The assertion name is separate from the assertion type's behavior - specify a CFString like "Checking mail" or "Compiling" that describes the task that this assertion protects.

      The CFString you associate with this key does not have to be localizable (OS X will not attempt to localize it.)

      Describe your assertion as thoroughly as possible. See these other keys that can you can also set to add explanation to an assertion: OPTIONAL kIOPMAssertionDetailsKey OPTIONAL kIOPMAssertionHumanReadableReasonKey OPTIONAL kIOPMAssertionLocalizationBundlePathKey

      Available in OS X v10.6 and later.

    • kIOPMAssertionPlugInIDKey

      kIOPMAssertionPlugInIDKey

      Specify if the assertion creator is a plugin.

      If the code that creates the assertion resides in a plugin, the caller should specify a CFBundleIdentifier, as a CFString, identifying the plugin's bundle here. This info helps developers and administrators determine the source of an assertion.

      This key may be specified in the dictionary passed to IOPMAssertionCreateWithProperties.

      This key may be present in the dictionary returned from IOPMAssertionCopyProperties.

      Available in OS X v10.7 and later.

    • kIOPMAssertionRetainCountKey

      kIOPMAssertionRetainCountKey

      A potential value for kIOPMAssertionTimeoutActionKey

      kIOPMAssertionRetainCountKey reflects the CoreFoundation-style retain count on this assertion. Creating or retaining an assertion increments its retain count. Release an assertion decrements its retain count. When the retain count decrements to zero, the OS will destroy the object.

      This key can be found in the dictionary returned from IOPMAssertionCopyProperties.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTimeoutActionKey

      kIOPMAssertionTimeoutActionKey

      Specifies the action to take upon timeout expiration.

      Specifying the timeout action only has meaning if you also specify an kIOPMAssertionTimeoutKey If the caller does not specify a timeout action, the default action is kIOPMAssertionTimeoutActionTurnOff

      This key may be specified in the dictionary passed to IOPMAssertionCreateWithProperties.

      This key may be present in the dictionary returned from IOPMAssertionCopyProperties.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTimeoutActionLog

      kIOPMAssertionTimeoutActionLog

      A potential value for kIOPMAssertionTimeoutActionKey

      When this timeout action is specified, PM will log the timeout event but will not turn off or affect the setting of the assertion in any way.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTimeoutActionRelease

      kIOPMAssertionTimeoutActionRelease

      A potential value for kIOPMAssertionTimeoutActionKey

      When a timeout expires with this action, Power Management will log the timeout event, and will release the assertion.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTimeoutActionTurnOff

      kIOPMAssertionTimeoutActionTurnOff

      A potential value for kIOPMAssertionTimeoutActionKey

      When a timeout expires with this action, Power Management will log the timeout event, and will set the assertion's level to kIOPMAssertionLevelOff.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTimeoutKey

      kIOPMAssertionTimeoutKey

      kIOPMAssertionTimeoutKey specifies an outer bound, in seconds, that this assertion should be asserted.

      If your application hangs, or is unable to complete its assertion task in a reasonable amount of time, specifying a timeout allows PM to disable your assertion so the system can resume normal activity. Once a timeout with the kIOPMAssertionTimeoutActionTurnOff assertion fires, the level will be set to kIOPMAssertionTimeoutActionTurnOff. The assertion may be re-armed by calling IOPMAssertionSetLevel.

      This key may be specified in the dictionary passed to IOPMAssertionCreateWithProperties.

      This key may be present in the dictionary returned from IOPMAssertionCopyProperties.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTypeKey

      kIOPMAssertionTypeKey

      The CFDictionary key for assertion type in an assertion info dictionary.

      The value for this key will be a CFStringRef, with the value of the assertion type specified at creation time. Note that OS X may substitute a support assertion type string if the caller specifies a deprecated assertion type; in that case the value for this key could differ from the caller-provided assertion type.

      Available in OS X v10.5 and later.

    • kIOPMAssertionTypeNoDisplaySleep

      kIOPMAssertionTypeNoDisplaySleep

      Use as AssertionType argument to IOPMAssertionCreate. The idle display will not sleep when enabled, and consequently the system will not idle sleep.

      When asserted and set to level kIOPMAssertionLevelOn, the system will prefer to enter the Dark Wake state, or remain in Dark Wake if already there, rather than go to sleep.

      Assertions are just suggestions to the OS, and the OS can only honor them to the best of its ability. In the case of low power or a thermal emergency, the system may sleep anyway despite the assertion.

      An assertion must publish the AssertionType in its assertion properties dictionary. The AssertionType should be a key in the properties dictionary, with a value of a CFNumber containing the kCFNumberIntegerType value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn.

      Available in OS X v10.5 and later.

    • kIOPMAssertionTypeNoIdleSleep

      kIOPMAssertionTypeNoIdleSleep

      Pass as the AssertionType argument to IOPMAssertionCreate. The system will not idle sleep when enabled (display may sleep). Note that the system may sleep for other reasons.

      When asserted and set to level kIOPMAssertionLevelOn, the system will prefer to enter the Dark Wake state, or remain in Dark Wake if already there, rather than go to sleep.

      Assertions are just suggestions to the OS, and the OS can only honor them to the best of its ability. In the case of low power or a thermal emergency, the system may sleep anyway despite the assertion.

      An assertion must publish the AssertionType in its assertion properties dictionary. The AssertionType should be a key in the properties dictionary, with a value of a CFNumber containing the kCFNumberIntegerType value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn.

      Available in OS X v10.5 and later.

    • kIOPMAssertionTypePreventSystemSleep

      kIOPMAssertionTypePreventSystemSleep

      Prevents the system from sleeping and allows the system to reside in Dark Wake for an arbitrary length of time.

      When asserted and set to level kIOPMAssertionLevelOn, the system will prefer to enter the Dark Wake state, or remain in Dark Wake if already there, rather than go to sleep.

      Assertions are just suggestions to the OS, and the OS can only honor them to the best of its ability. In the case of low power or a thermal emergency, the system may sleep anyway despite the assertion.

      An assertion must publish the AssertionType in its assertion properties dictionary. The AssertionType should be a key in the properties dictionary, with a value of a CFNumber containing the kCFNumberIntegerType value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTypePreventUserIdleDisplaySleep

      kIOPMAssertionTypePreventUserIdleDisplaySleep

      Prevents the display from dimming automatically.

      When asserted and set to level kIOPMAssertionLevelOn, will prevent the display from turning off due to a period of idle user activity. Note that the display may still sleep from other reasons, like a user closing a portable's lid or the machine sleeping. If the display is already off, this assertion does not light up the display. If display needs to be turned on, then consider calling function IOPMAssertionDeclareUserActivity.

      While the display is prevented from dimming, the system cannot go into idle sleep.

      This assertion does not put the system into Dark Wake.

      A caller publish the AssertionType in its assertion properties dictionary. The AssertionType should be a key in the properties dictionary, with a value of a CFNumber containing the kCFNumberIntegerType value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn.

      Available in OS X v10.7 and later.

    • kIOPMAssertionTypePreventUserIdleSystemSleep

      kIOPMAssertionTypePreventUserIdleSystemSleep

      Prevents the system from sleeping automatically due to a lack of user activity.

      When asserted and set to level kIOPMAssertionLevelOn, will prevent the system from sleeping due to a period of idle user activity.

      The display may dim and idle sleep while kIOPMAssertionTypePreventUserIdleSystemSleep is enabled, but the system may not idle sleep.

      The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons.

      This assertion does not put the system into Dark Wake.

      A caller publish the AssertionType in its assertion properties dictionary. The AssertionType should be a key in the properties dictionary, with a value of a CFNumber containing the kCFNumberIntegerType value kIOPMAssertionLevelOff or kIOPMAssertionLevelOn.

      Available in OS X v10.7 and later.

    • kIOPMCPUPowerNotificationKey

      kIOPMCPUPowerNotificationKey

      Key to register for BSD style notifications on CPU power or thermal change.

      Available in OS X v10.7 and later.

    • kIOPMThermalWarningNotificationKey

      kIOPMThermalWarningNotificationKey

      Key to register for BSD style notifications on system thermal warnings.

      Available in OS X v10.7 and later.

    • kIOSystemLoadAdvisoryBatteryLevelKey

      kIOSystemLoadAdvisoryBatteryLevelKey

      Key for dictionary returned by IOCopySystemLoadAdvisoryDetailed

      Indicates battery constraints on the current SystemLoadAdvisory level.

      Available in OS X v10.6 and later.

    • kIOSystemLoadAdvisoryCombinedLevelKey

      kIOSystemLoadAdvisoryCombinedLevelKey

      Key for dictionary returned by IOCopySystemLoadAdvisoryDetailed

      Provides a combined level based on UserLevel, BatteryLevel, and ThermalLevels; the combined level is the minimum of these levels. In the future, this combined level may represent new levels as well. The combined level is identical to the value returned by IOGetSystemLoadAdvisory().

      Available in OS X v10.6 and later.

    • kIOSystemLoadAdvisoryNotifyName

      kIOSystemLoadAdvisoryNotifyName

      The notification by this name fires when system "SystemLoadAdvisory" status changes.

      Pass this string as an argument to register via notify(3). You can query SystemLoadAdvisory state via notify_get_state() when this notification fires - this is more efficient than calling IOGetSystemLoadAdvisory(), and returns an identical combined SystemLoadAdvisory value.

      Available in OS X v10.6 and later.

    • kIOSystemLoadAdvisoryThermalLevelKey

      kIOSystemLoadAdvisoryThermalLevelKey

      Key for dictionary returned by IOCopySystemLoadAdvisoryDetailed

      Indicates thermal constraints on the current SystemLoadAdvisory level.

      Available in OS X v10.6 and later.

    • kIOSystemLoadAdvisoryUserLevelKey

      kIOSystemLoadAdvisoryUserLevelKey

      Key for dictionary returned by IOCopySystemLoadAdvisoryDetailed

      Indicates user activity constraints on the current SystemLoadAdvisory level.

      Available in OS X v10.6 and later.

  • Level for an enabled assertion, passed as an argument to IOPMAssertionCreate.

    Declaration

    Objective-C

    enum { /*! */ kIOPMAssertionLevelOff = 0, /*! */ kIOPMAssertionLevelOn = 255 };

    Constants

    • kIOPMAssertionLevelOff

      kIOPMAssertionLevelOff

      Available in OS X v10.5 and later.

    • kIOPMAssertionLevelOn

      kIOPMAssertionLevelOn

      Available in OS X v10.5 and later.

    Discussion

    Levels

  • This value represents a non-initialized assertion ID

    Declaration

    Objective-C

    enum { kIOPMNullAssertionID = 0 };

    Constants

    • kIOPMNullAssertionID

      kIOPMNullAssertionID

      This value represents a non-initialized assertion ID.

      Available in OS X v10.5 and later.