Class SmcUtil


  • @ThreadSafe
    public final class SmcUtil
    extends java.lang.Object
    Provides access to SMC calls on macOS
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SmcUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int smcCall​(com.sun.jna.platform.mac.IOKit.IOConnect conn, int index, IOKit.SMCKeyData inputStructure, IOKit.SMCKeyData outputStructure)
      Call SMC
      static int smcClose​(com.sun.jna.platform.mac.IOKit.IOConnect conn)
      Close connection to SMC.
      static double smcGetFloat​(com.sun.jna.platform.mac.IOKit.IOConnect conn, java.lang.String key)
      Get a value from SMC which is in a floating point datatype (SP78, FPE2, FLT)
      static int smcGetKeyInfo​(com.sun.jna.platform.mac.IOKit.IOConnect conn, IOKit.SMCKeyData inputStructure, IOKit.SMCKeyData outputStructure)
      Get cached keyInfo if it exists, or generate new keyInfo
      static long smcGetLong​(com.sun.jna.platform.mac.IOKit.IOConnect conn, java.lang.String key)
      Get a 64-bit integer value from SMC
      static com.sun.jna.platform.mac.IOKit.IOConnect smcOpen()
      Open a connection to SMC.
      static int smcReadKey​(com.sun.jna.platform.mac.IOKit.IOConnect conn, java.lang.String key, IOKit.SMCVal val)
      Read a key from SMC
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • IO

        private static final IOKit IO
      • keyInfoCache

        private static java.util.Map<java.lang.Integer,​IOKit.SMCKeyDataKeyInfo> keyInfoCache
        Thread-safe map for caching info retrieved by a key necessary for subsequent calls.
      • DATATYPE_SP78

        private static final byte[] DATATYPE_SP78
        Byte array used for matching return type
      • DATATYPE_FPE2

        private static final byte[] DATATYPE_FPE2
      • DATATYPE_FLT

        private static final byte[] DATATYPE_FLT
      • SMC_KEY_FAN_SPEED

        public static final java.lang.String SMC_KEY_FAN_SPEED
        See Also:
        Constant Field Values
      • SMC_KEY_CPU_TEMP

        public static final java.lang.String SMC_KEY_CPU_TEMP
        See Also:
        Constant Field Values
      • SMC_KEY_CPU_VOLTAGE

        public static final java.lang.String SMC_KEY_CPU_VOLTAGE
        See Also:
        Constant Field Values
    • Constructor Detail

      • SmcUtil

        private SmcUtil()
    • Method Detail

      • smcOpen

        public static com.sun.jna.platform.mac.IOKit.IOConnect smcOpen()
        Open a connection to SMC.
        Returns:
        The connection if successful, null if failure
      • smcClose

        public static int smcClose​(com.sun.jna.platform.mac.IOKit.IOConnect conn)
        Close connection to SMC.
        Parameters:
        conn - The connection
        Returns:
        0 if successful, nonzero if failure
      • smcGetFloat

        public static double smcGetFloat​(com.sun.jna.platform.mac.IOKit.IOConnect conn,
                                         java.lang.String key)
        Get a value from SMC which is in a floating point datatype (SP78, FPE2, FLT)
        Parameters:
        conn - The connection
        key - The key to retrieve
        Returns:
        Double representing the value
      • smcGetLong

        public static long smcGetLong​(com.sun.jna.platform.mac.IOKit.IOConnect conn,
                                      java.lang.String key)
        Get a 64-bit integer value from SMC
        Parameters:
        conn - The connection
        key - The key to retrieve
        Returns:
        Long representing the value
      • smcGetKeyInfo

        public static int smcGetKeyInfo​(com.sun.jna.platform.mac.IOKit.IOConnect conn,
                                        IOKit.SMCKeyData inputStructure,
                                        IOKit.SMCKeyData outputStructure)
        Get cached keyInfo if it exists, or generate new keyInfo
        Parameters:
        conn - The connection
        inputStructure - Key data input
        outputStructure - Key data output
        Returns:
        0 if successful, nonzero if failure
      • smcReadKey

        public static int smcReadKey​(com.sun.jna.platform.mac.IOKit.IOConnect conn,
                                     java.lang.String key,
                                     IOKit.SMCVal val)
        Read a key from SMC
        Parameters:
        conn - The connection
        key - Key to read
        val - Structure to receive the result
        Returns:
        0 if successful, nonzero if failure
      • smcCall

        public static int smcCall​(com.sun.jna.platform.mac.IOKit.IOConnect conn,
                                  int index,
                                  IOKit.SMCKeyData inputStructure,
                                  IOKit.SMCKeyData outputStructure)
        Call SMC
        Parameters:
        conn - The connection
        index - Kernel index
        inputStructure - Key data input
        outputStructure - Key data output
        Returns:
        0 if successful, nonzero if failure