View Javadoc
1   /*
2    * Copyright 2020-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.windows.wmi;
6   
7   import java.util.Objects;
8   
9   import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery;
10  import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;
11  
12  import oshi.annotation.concurrent.ThreadSafe;
13  import oshi.util.platform.windows.WmiQueryHandler;
14  
15  /**
16   * Utility to query WMI class {@code MSAcpi_ThermalZoneTemperature}
17   */
18  @ThreadSafe
19  public final class MSAcpiThermalZoneTemperature {
20  
21      public static final String WMI_NAMESPACE = "ROOT\\WMI";
22      private static final String MS_ACPI_THERMAL_ZONE_TEMPERATURE = "MSAcpi_ThermalZoneTemperature";
23  
24      /**
25       * Current temperature property.
26       */
27      public enum TemperatureProperty {
28          CURRENTTEMPERATURE;
29      }
30  
31      private MSAcpiThermalZoneTemperature() {
32      }
33  
34      /**
35       * Queries the current temperature
36       *
37       * @return Temperature at thermal zone in tenths of degrees Kelvin.
38       */
39      public static WmiResult<TemperatureProperty> queryCurrentTemperature() {
40          WmiQuery<TemperatureProperty> curTempQuery = new WmiQuery<>(WMI_NAMESPACE, MS_ACPI_THERMAL_ZONE_TEMPERATURE,
41                  TemperatureProperty.class);
42          return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(curTempQuery);
43      }
44  }