View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware.platform.windows;
6   
7   import static oshi.util.Memoizer.memoize;
8   
9   import java.util.function.Supplier;
10  
11  import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;
12  
13  import oshi.annotation.concurrent.Immutable;
14  import oshi.driver.windows.wmi.Win32BaseBoard;
15  import oshi.driver.windows.wmi.Win32BaseBoard.BaseBoardProperty;
16  import oshi.hardware.common.AbstractBaseboard;
17  import oshi.util.Constants;
18  import oshi.util.Util;
19  import oshi.util.platform.windows.WmiUtil;
20  import oshi.util.tuples.Quartet;
21  
22  /**
23   * Baseboard data obtained from WMI
24   */
25  @Immutable
26  final class WindowsBaseboard extends AbstractBaseboard {
27  
28      private final Supplier<Quartet<String, String, String, String>> manufModelVersSerial = memoize(
29              WindowsBaseboard::queryManufModelVersSerial);
30  
31      @Override
32      public String getManufacturer() {
33          return manufModelVersSerial.get().getA();
34      }
35  
36      @Override
37      public String getModel() {
38          return manufModelVersSerial.get().getB();
39      }
40  
41      @Override
42      public String getVersion() {
43          return manufModelVersSerial.get().getC();
44      }
45  
46      @Override
47      public String getSerialNumber() {
48          return manufModelVersSerial.get().getD();
49      }
50  
51      private static Quartet<String, String, String, String> queryManufModelVersSerial() {
52          String manufacturer = null;
53          String model = null;
54          String version = null;
55          String serialNumber = null;
56          WmiResult<BaseBoardProperty> win32BaseBoard = Win32BaseBoard.queryBaseboardInfo();
57          if (win32BaseBoard.getResultCount() > 0) {
58              manufacturer = WmiUtil.getString(win32BaseBoard, BaseBoardProperty.MANUFACTURER, 0);
59              model = WmiUtil.getString(win32BaseBoard, BaseBoardProperty.MODEL, 0);
60              version = WmiUtil.getString(win32BaseBoard, BaseBoardProperty.VERSION, 0);
61              serialNumber = WmiUtil.getString(win32BaseBoard, BaseBoardProperty.SERIALNUMBER, 0);
62          }
63          return new Quartet<>(Util.isBlank(manufacturer) ? Constants.UNKNOWN : manufacturer,
64                  Util.isBlank(model) ? Constants.UNKNOWN : model, Util.isBlank(version) ? Constants.UNKNOWN : version,
65                  Util.isBlank(serialNumber) ? Constants.UNKNOWN : serialNumber);
66      }
67  }