1
2
3
4
5 package oshi.hardware.platform.unix.freebsd;
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.common.AbstractFirmware;
13 import oshi.util.Constants;
14 import oshi.util.ExecutingCommand;
15 import oshi.util.ParseUtil;
16 import oshi.util.Util;
17 import oshi.util.tuples.Triplet;
18
19
20
21
22 @Immutable
23 final class FreeBsdFirmware extends AbstractFirmware {
24
25 private final Supplier<Triplet<String, String, String>> manufVersRelease = memoize(FreeBsdFirmware::readDmiDecode);
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
43
44
45
46 private static Triplet<String, String, String> readDmiDecode() {
47 String manufacturer = null;
48 String version = null;
49 String releaseDate = "";
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 final String manufacturerMarker = "Vendor:";
66 final String versionMarker = "Version:";
67 final String releaseDateMarker = "Release Date:";
68
69
70 for (final String checkLine : ExecutingCommand.runNative("dmidecode -t bios")) {
71 if (checkLine.contains(manufacturerMarker)) {
72 manufacturer = checkLine.split(manufacturerMarker)[1].trim();
73 } else if (checkLine.contains(versionMarker)) {
74 version = checkLine.split(versionMarker)[1].trim();
75 } else if (checkLine.contains(releaseDateMarker)) {
76 releaseDate = checkLine.split(releaseDateMarker)[1].trim();
77 }
78 }
79 releaseDate = ParseUtil.parseMmDdYyyyToYyyyMmDD(releaseDate);
80 return new Triplet<>(Util.isBlank(manufacturer) ? Constants.UNKNOWN : manufacturer,
81 Util.isBlank(version) ? Constants.UNKNOWN : version,
82 Util.isBlank(releaseDate) ? Constants.UNKNOWN : releaseDate);
83 }
84 }