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 com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery;
8   import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;
9   
10  import oshi.annotation.concurrent.ThreadSafe;
11  import oshi.util.platform.windows.WmiQueryHandler;
12  import oshi.util.platform.windows.WmiUtil;
13  
14  /**
15   * Utility to query Open Hardware Monitor WMI data for Hardware
16   */
17  @ThreadSafe
18  public final class OhmHardware {
19  
20      private static final String HARDWARE = "Hardware";
21  
22      /**
23       * HW Identifier Property
24       */
25      public enum IdentifierProperty {
26          IDENTIFIER;
27      }
28  
29      private OhmHardware() {
30      }
31  
32      /**
33       * Queries the hardware identifiers for a monitored type.
34       *
35       * @param h           An instantiated {@link WmiQueryHandler}. User should have already initialized COM.
36       * @param typeToQuery which type to filter based on
37       * @param typeName    the name of the type
38       * @return The sensor value.
39       */
40      public static WmiResult<IdentifierProperty> queryHwIdentifier(WmiQueryHandler h, String typeToQuery,
41              String typeName) {
42          StringBuilder sb = new StringBuilder(HARDWARE);
43          sb.append(" WHERE ").append(typeToQuery).append("Type=\"").append(typeName).append('\"');
44          WmiQuery<IdentifierProperty> cpuIdentifierQuery = new WmiQuery<>(WmiUtil.OHM_NAMESPACE, sb.toString(),
45                  IdentifierProperty.class);
46          return h.queryWMI(cpuIdentifierQuery, false);
47      }
48  }