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.List;
10  import java.util.function.Supplier;
11  
12  import oshi.annotation.concurrent.Immutable;
13  import oshi.hardware.common.AbstractFirmware;
14  import oshi.util.Constants;
15  import oshi.util.ExecutingCommand;
16  import oshi.util.ParseUtil;
17  import oshi.util.Util;
18  import oshi.util.tuples.Triplet;
19  
20  /**
21   * OpenBSD Firmware implementation
22   */
23  @Immutable
24  public class OpenBsdFirmware extends AbstractFirmware {
25      private final Supplier<Triplet<String, String, String>> manufVersRelease = memoize(OpenBsdFirmware::readDmesg);
26  
27      @Override
28      public String getManufacturer() {
29          return manufVersRelease.get().getA();
30      }
31  
32      @Override
33      public String getVersion() {
34          return manufVersRelease.get().getB();
35      }
36  
37      @Override
38      public String getReleaseDate() {
39          return manufVersRelease.get().getC();
40      }
41  
42      private static Triplet<String, String, String> readDmesg() {
43          String version = null;
44          String vendor = null;
45          String releaseDate = "";
46  
47          List<String> dmesg = ExecutingCommand.runNative("dmesg");
48          for (String line : dmesg) {
49              // bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xdcc0e000 (67 entries)
50              // bios0: vendor LENOVO version "GLET90WW (2.44 )" date 09/13/2017
51              // bios0: LENOVO 20AWA08J00
52              if (line.startsWith("bios0: vendor")) {
53                  version = ParseUtil.getStringBetween(line, '"');
54                  releaseDate = ParseUtil.parseMmDdYyyyToYyyyMmDD(ParseUtil.parseLastString(line));
55                  vendor = line.split("vendor")[1].trim();
56              }
57          }
58          return new Triplet<>(Util.isBlank(vendor) ? Constants.UNKNOWN : vendor,
59                  Util.isBlank(version) ? Constants.UNKNOWN : version,
60                  Util.isBlank(releaseDate) ? Constants.UNKNOWN : releaseDate);
61      }
62  }