Power Management & The Energy Saver APIBy Vinnie MoscaritoloApple Developer Technical Support (DTS) http://webstuff.apple.com/~vinnie/ vinnie@apple.com |
![]()
CONTENTS |
In an effort to provide a consistent method of controlling the various power conservation hardware and software features implemented on the Macintosh platform, Apple has introduced the Energy Saver system. In addition to providing developers with a standard way to control power management features such as display sleep/dimming, hard drive spindown, idle shutdown or sleep, the Energy Services API also provides a consistant way to synchronize the Human Interfaces for multiple concurrent applications that need to access these features. This Note discusses how to communicate with the Macintosh Energy Saver Extension through the Energy Services API and is important for developers who wish to access Mac OS power management features from their applications. This Note also includes the public interfaces for the Energy Services API. |
Energy Saver OverviewEnergy Saver provides a consistent method of controlling the various power conservation hardware and software features implemented on the Macintosh platform. Although the features it supports vary depending on the machines' capabilities, Energy Saver typically attempts to reduce power consumption by controlling such operations as:
The Energy Services API also provides a way to synchronize the Human Interfaces for multiple concurrent applications that need to access the power management features.
Components of the Energy SaverEnergy Saver is actually composed of two separate components: a system extension and a control panel.
Figure 1 provides an overview of the Energy Saver components.
FIGURE 1. Energy Saver Overview
|
|
Energy Services AccessApplications can safely use the same mechanism to manipulate the Energy Saver preference file as the Energy Saver control panel. This is accomplished through the Energy Services API. The purpose of this API is to provide homogenous support for high-level power management features that are not provided by the Power Manager, as well as provide standardized preference support for power manager functions that do not have persistent PRAM settings. The Energy Saver Extension provides auto power on/off features for all Macs with an Egret or Cuda microcontrollers. In addition, it will manage preferences for Screen dimming, Hard disk spin down, sleep mode, and options for all these features. There are calls that can be used to obtain and set the preferences, as well as calls to activate the settings in the preferences passed. Whenever possible, application developers should use this functionality instead of creating their own from scratch, at least to the extent of updating the preferences, so that other applications and control panels will reflect user choices made in all applications. |
Determining If Your Mac Supports the Energy Services APIThe proper way to determine if a particular Macintosh model supports the Energy Services API is to use the Gestalt function to check for the 'wnkl' selector. Then check the response for non nil value. This will indicate that Energy Services API is loaded. |
Calling the Energy Services APIOnce you have established the existence of the Energy Services Manager you can access the energy services API via the gestalt selector 'wnkl' response value. The response is a Handle to a data structure whose first field is a pointer to the Main routine. The interface to this routine is:
To faclitate developer usage, the
Calling the
|
|
Energy Services API |
The ESGlobals StructureThe Energy Saver Extension maintains a set of preferences globals. These globals are defined in the
|
|
ESLoadPreferences
PROTOTYPEOSErr ESLoadPreferences(ESGlobalsPtr thePrefs);
RESULT CODE
IMPORTANT
|
|
ESGetPreferences
PROTOTYPEOSErr ESGetPreferences(ESGlobalsPtr thePrefs);
RESULT CODE
|
|
ESSetPreferences
PROTOTYPEOSErr ESSetPreferences(ESGlobalsPtr thePrefs);
RESULT CODE
IMPORTANT
ESRefreshSettings() to cause the new settings to take
affect.
|
|
ESRefreshSettings
PROTOTYPEOSErr ESRefreshSettings(); RESULT CODE
|
|
ESSavePreferences
PROTOTYPEOSErr ESSavePreferences(ESGlobalsPtr thePrefs);
RESULT CODE
IMPORTANT
WUSoundResID or SDSoundResID field of ESGlobals record, you should ensure that those resources are in the current resource chain. This is important because ESSavePreferences will cause them to be loaded, detached and copied into System Heap.
|
|
ESAddNoteProc
ESAddNoteProc to install an
Energy Saver notification response procedure. This
notfifier can be used to inform your application that the
energy saver prefs are being read or written.
PROTOTYPEOSErr ESAddNoteProc(ESNotifyProcPtr theProc, long data);
RESULT CODE
SEE ALSO
|
|
ESRemoveNoteProc
ESRemoveNoteProc to remove
an Energy Saver notification response procedure.
PROTOTYPEOSErr ESRemoveNoteProc(ESNotifyProcPtr theProc);
RESULT CODE
SEE ALSO
|
|
Energy Saver Notification Function
ESAddNoteProc
function, your notification procedure will be called when
any application attempts to access the ES prefs.
The notfifer will be called with the selector
You are also called when someone copies new prefs to
the Energy Saver Extension with a
This allows your application to dynamically update the display of the ESGlobals or to filter data values. PROTOTYPEpascal long MyESNotifyProc (short selector, ESGlobalsPtr theData);
DESCRIPTION
|
|
ESRestoreDefaultsESRestoreDefaults is used to restore the
system to the machine-dependent default settings as
stored in the extension resource data. Use this call
whenever you want
to return the Energy Saver
back to the installed default settings.
You also get a copy of the ESGlobals so that you can see what those defaults are. Getting the ESGlobals is convenient so that you can update your HI to reflect the current machine state. One possible use for this is in response to a "Apple Defaults" menu item. PROTOTYPEOSErr ESRestoreDefaults(ESGlobalsPtr thePrefs);
RESULT CODE
|
|
ESGetUnsavedFolder
PROTOTYPEOSErr ESGetUnsavedFolder(Ptr theString);
RESULT CODE
|
|
ESSetUnsavedFolder
ESSetUnsavedFolder to set
the pathname of the Unsaved Document folder used by the
Autosave feature.
PROTOTYPEOSErr ESSetUnsavedFolder(Ptr theString);
RESULT CODE
|
|
ESGetINITVersion
PROTOTYPEOSErr ESGetINITVersion(Handle* theVers);
RESULT CODE
|
|
SummaryAs the Macintosh platform continues to evolve, the Energy Saver API provides a consistent method of monitoring and controlling power management features. In addition, the Energy Saver API also presents a few interesting opportunities for third-party developer applications. Further ReferencesDownloadables
AcknowledgmentsSpecial thanks to Dave West, Nancy Zayed and Bun-Bun the Rabbit. |