View Javadoc
1   /*
2    * Copyright 2021-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware.platform.unix.openbsd;
6   
7   import static oshi.util.Memoizer.memoize;
8   
9   import java.util.function.Supplier;
10  
11  import oshi.annotation.concurrent.Immutable;
12  import oshi.hardware.Baseboard;
13  import oshi.hardware.Firmware;
14  import oshi.hardware.common.AbstractComputerSystem;
15  import oshi.hardware.platform.unix.UnixBaseboard;
16  import oshi.util.Constants;
17  import oshi.util.platform.unix.openbsd.OpenBsdSysctlUtil;
18  
19  /**
20   * OpenBSD ComputerSystem implementation
21   */
22  @Immutable
23  public class OpenBsdComputerSystem extends AbstractComputerSystem {
24  
25      private final Supplier<String> manufacturer = memoize(OpenBsdComputerSystem::queryManufacturer);
26  
27      private final Supplier<String> model = memoize(OpenBsdComputerSystem::queryModel);
28  
29      private final Supplier<String> serialNumber = memoize(OpenBsdComputerSystem::querySerialNumber);
30  
31      private final Supplier<String> uuid = memoize(OpenBsdComputerSystem::queryUUID);
32  
33      @Override
34      public String getManufacturer() {
35          return manufacturer.get();
36      }
37  
38      @Override
39      public String getModel() {
40          return model.get();
41      }
42  
43      @Override
44      public String getSerialNumber() {
45          return serialNumber.get();
46      }
47  
48      @Override
49      public String getHardwareUUID() {
50          return uuid.get();
51      }
52  
53      @Override
54      protected Firmware createFirmware() {
55          return new OpenBsdFirmware();
56      }
57  
58      @Override
59      protected Baseboard createBaseboard() {
60          return new UnixBaseboard(manufacturer.get(), model.get(), serialNumber.get(),
61                  OpenBsdSysctlUtil.sysctl("hw.product", Constants.UNKNOWN));
62      }
63  
64      private static String queryManufacturer() {
65          return OpenBsdSysctlUtil.sysctl("hw.vendor", Constants.UNKNOWN);
66      }
67  
68      private static String queryModel() {
69          return OpenBsdSysctlUtil.sysctl("hw.version", Constants.UNKNOWN);
70      }
71  
72      private static String querySerialNumber() {
73          return OpenBsdSysctlUtil.sysctl("hw.serialno", Constants.UNKNOWN);
74      }
75  
76      private static String queryUUID() {
77          return OpenBsdSysctlUtil.sysctl("hw.uuid", Constants.UNKNOWN);
78      }
79  }