Class MacPowerSource

java.lang.Object
oshi.hardware.common.AbstractPowerSource
oshi.hardware.common.platform.mac.MacPowerSource
All Implemented Interfaces:
PowerSource

@ThreadSafe public abstract class MacPowerSource extends AbstractPowerSource
Abstract base for the macOS PowerSource. The AppleSmartBattery registry read and the per-power-source field computation are shared; the JNA and FFM subclasses supply an IOKitProvider and read the IOKit Power Sources (IOPS) list into MacPowerSource.PowerSourceData carriers via buildPowerSources(IOKitProvider, double, List, MacPowerSource.PowerSourceFactory).
  • Constructor Details

    • MacPowerSource

      protected MacPowerSource(String psName, String psDeviceName, double psRemainingCapacityPercent, double psTimeRemainingEstimated, double psTimeRemainingInstant, double psPowerUsageRate, double psVoltage, double psAmperage, boolean psPowerOnLine, boolean psCharging, boolean psDischarging, PowerSource.CapacityUnits psCapacityUnits, int psCurrentCapacity, int psMaxCapacity, int psDesignCapacity, int psCycleCount, String psChemistry, LocalDate psManufactureDate, String psManufacturer, String psSerialNumber, double psTemperature)
      Creates a MacPowerSource.
      Parameters:
      psName - power source name
      psDeviceName - device name
      psRemainingCapacityPercent - remaining capacity percentage
      psTimeRemainingEstimated - estimated time remaining
      psTimeRemainingInstant - instant time remaining
      psPowerUsageRate - power usage rate
      psVoltage - voltage
      psAmperage - amperage
      psPowerOnLine - whether on AC power
      psCharging - whether charging
      psDischarging - whether discharging
      psCapacityUnits - capacity units
      psCurrentCapacity - current capacity
      psMaxCapacity - max capacity
      psDesignCapacity - design capacity
      psCycleCount - cycle count
      psChemistry - chemistry
      psManufactureDate - manufacture date
      psManufacturer - manufacturer
      psSerialNumber - serial number
      psTemperature - temperature
  • Method Details

    • buildPowerSources

      protected static List<PowerSource> buildPowerSources(IOKitProvider ioKit, double timeRemainingEstimated, List<MacPowerSource.PowerSourceData> sources, MacPowerSource.PowerSourceFactory factory)
      Reads the AppleSmartBattery registry entry (via ioKit) and merges it with the per-source IOPS readings into a list of power sources.

      Mac PowerSource information comes from two sources: the IORegistry's AppleSmartBattery entry (battery-wide fields, read here through the shared IOKitProvider) and the IOKit's IOPS functions (one entry per power source, read natively by the caller into sources).

      Parameters:
      ioKit - the IOKit provider backing the registry read
      timeRemainingEstimated - the estimated time remaining (-1 unknown, -2 unlimited) from IOPS
      sources - the present power sources read from the IOPS list
      factory - creates the platform-specific instance
      Returns:
      a list of power sources, one per element of sources