Mac Developer Library

Developer

IOPMPowerSource Class Reference

Options
Deployment Target:

On This Page

IOPMPowerSource

See IOKit/pwr_mgt/IOPM.h for power source keys relevant to this class. These report-type keys are required for calls to IOPMPowerSource::setReportables(), and they define the IORegistry interface through which data is passed back up to the rest of the system.

A subclassing driver that doesn't want to do anything fancy should:

  1. Subclass IOPMPowerSource

  2. Install its own battery change notifications or polling routine that can converse with actual battery hardware.

  3. When battery state changes, change the relevant member variables through setCurrentCapacity() style accessors.

  4. Call updateStatus() on itself when all such settings have been updated.

The subclass driver should also initially populate its settings and call updateStatus() on launch.

Settings:

  1. ExternalConnected
  2. Type: bool
  3. IORegistry Key: kIOPMPSExternalConnectedKey
  4. True if computer is drawing external power
  5. ExternalChargeCapable
  6. Type: bool
  7. IORegistry Key: kIOPMPSExternalChargeCapableKey
  8. True if external power is capable of charging internal battery
  9. BatteryInstalled
  10. Type: bool
  11. IORegistry Key: kIOPMPSBatteryInstalledKey
  12. True if a battery is present; false if removed
  13. IsCharging
  14. Type: bool
  15. IORegistry Key: kIOPMPSIsChargingKey
  16. True if battery is charging itself from external power
  17. AtWarnLevel
  18. Type: bool
  19. IORegistry Key: kIOPMPSAtWarnLevelKey
  20. True if draining battery capacity and past warn level
  21. AtCriticalLevel
  22. Type: bool
  23. IORegistry Key: kIOPMPSAtCriticalLevelKey
  24. True if draining battery capacity and past critical level
  25. CurrentCapacity
  26. MaxCapacity
  27. Type: unsigned int
  28. IORegistry Key: kIOPMPSCurrentCapacityKey, kIOPMPSMaxCapacityKey
  29. Capacity measured in mAh
  30. TimeRemaining
  31. Type: int
  32. IORegistry Key: kIOPMPSTimeRemainingKey
  33. Time remaining measured in minutes
  34. Amperage
  35. Type: int
  36. IORegistry Key: kIOPMPSAmperageKey
  37. Current is measured in mA
  38. Voltage
  39. Type: unsigned int
  40. IORegistry Key: kIOPMPSVoltageKey
  41. Voltage measured in mV
  42. CycleCount
  43. Type: unsigned int
  44. IORegistry Key: kIOPMPSCycleCountKey
  45. Number of charge/discharge cycles
  46. AdapterInfo
  47. Type: int
  48. IORegistry Key: kIOPMPSAdapterInfoKey
  49. Power adapter information
  50. Location
  51. Type: int
  52. IORegistry Key: kIOPMPSLocationKey
  53. Clue about battery's location in machine - Left vs. Right
  54. ErrorCondition
  55. Type: OSSymbol
  56. IORegistry Key: kIOPMPSErrorConditionKey
  57. String describing error state of battery
  58. Manufacturer
  59. Type: OSSymbol
  60. IORegistry Key: kIOPMPSManufacturerKey
  61. String describing battery manufacturer
  62. Manufactured Date
  63. Type: unsigned 16-bit bitfield
  64. IORegistry Key: kIOPMPSManufactureDateKey
  65. Date is published in a bitfield per the Smart Battery Data spec rev 1.1
  66. in section 5.1.26
  67. Bits 0...4 => day (value 1-31; 5 bits)
  68. Bits 5...8 => month (value 1-12; 4 bits)
  69. Bits 9...15 => years since 1980 (value 0-127; 7 bits)
  70. Model
  71. Type: OSSymbol
  72. IORegistry Key: kIOPMPSModelKey
  73. String describing model number
  74. Serial
  75. Type: OSSymbol
  76. IORegistry Key: kIOPMPSSerialKey
  77. String describing serial number or unique info
  78. The serial number published hear bears no correspondence to the Apple serial
  79. number printed on each battery. This is a manufacturer serial number with
  80. no correlation to the printed serial number.
  81. LegacyIOBatteryInfo
  82. Type: OSDictionary
  83. IORegistry Key: kIOPMPSLegacyBatteryInfoKey
  84. Dictionary conforming to the OS X 10.0-10.4
  • Creates a new IOPMPowerSource nub. Must be attached to IORegistry, and registered by provider.

    Declaration

    static IOPMPowerSource *powerSource( void);

  • Declaration

    void setPSProperty( const OSSymbol *, OSObject *);

    Discussion

    All of these methods funnel through the generic accessor method setPSProperty. Caller can pass in any arbitrary OSSymbol key, and that value will be stored in the PM settings dictionary, and relayed onto the IORegistry at update time.

  • Must be called by physical battery controller when battery state has changed significantly.

    Declaration

    virtual void updateStatus( void);

    Discussion

    The system will not poll this object for battery updates. Rather \ the battery's controller must call updateStatus() every time state changes \ and the settings will be relayed to higher levels of power management. \ The subclassing driver should override this only if the driver needs to add \ new settings to the base class.

Instance Variables

  • Used by subclasses to determine if any settings have been modified via the accessors below since last call to update(). true is settings have changed; false otherwise.

    Declaration

    bool settingsChangedSinceUpdate;

  • Used by subclasses to determine if any settings have been modified via the accessors below since last call to update(). true is settings have changed; false otherwise.

    Declaration

    bool settingsChangedSinceUpdate;

  • Stores power source state

    Declaration

    OSDictionary *properties;