1
2
3
4
5 package oshi.hardware.platform.linux;
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.driver.linux.Devicetree;
13 import oshi.driver.linux.Dmidecode;
14 import oshi.driver.linux.Lshal;
15 import oshi.driver.linux.Lshw;
16 import oshi.driver.linux.Sysfs;
17 import oshi.driver.linux.proc.CpuInfo;
18 import oshi.hardware.Baseboard;
19 import oshi.hardware.Firmware;
20 import oshi.hardware.common.AbstractComputerSystem;
21 import oshi.util.Constants;
22
23
24
25
26 @Immutable
27 final class LinuxComputerSystem extends AbstractComputerSystem {
28
29 private final Supplier<String> manufacturer = memoize(LinuxComputerSystem::queryManufacturer);
30
31 private final Supplier<String> model = memoize(LinuxComputerSystem::queryModel);
32
33 private final Supplier<String> serialNumber = memoize(LinuxComputerSystem::querySerialNumber);
34
35 private final Supplier<String> uuid = memoize(LinuxComputerSystem::queryUUID);
36
37 @Override
38 public String getManufacturer() {
39 return manufacturer.get();
40 }
41
42 @Override
43 public String getModel() {
44 return model.get();
45 }
46
47 @Override
48 public String getSerialNumber() {
49 return serialNumber.get();
50 }
51
52 @Override
53 public String getHardwareUUID() {
54 return uuid.get();
55 }
56
57 @Override
58 public Firmware createFirmware() {
59 return new LinuxFirmware();
60 }
61
62 @Override
63 public Baseboard createBaseboard() {
64 return new LinuxBaseboard();
65 }
66
67 private static String queryManufacturer() {
68 String result = null;
69 if ((result = Sysfs.querySystemVendor()) == null && (result = CpuInfo.queryCpuManufacturer()) == null) {
70 return Constants.UNKNOWN;
71 }
72 return result;
73 }
74
75 private static String queryModel() {
76 String result = null;
77 if ((result = Sysfs.queryProductModel()) == null && (result = Devicetree.queryModel()) == null
78 && (result = Lshw.queryModel()) == null) {
79 return Constants.UNKNOWN;
80 }
81 return result;
82 }
83
84 private static String querySerialNumber() {
85 String result = null;
86 if ((result = Sysfs.queryProductSerial()) == null && (result = Dmidecode.querySerialNumber()) == null
87 && (result = Lshal.querySerialNumber()) == null && (result = Lshw.querySerialNumber()) == null) {
88 return Constants.UNKNOWN;
89 }
90 return result;
91 }
92
93 private static String queryUUID() {
94 String result = null;
95 if ((result = Sysfs.queryUUID()) == null && (result = Dmidecode.queryUUID()) == null
96 && (result = Lshal.queryUUID()) == null && (result = Lshw.queryUUID()) == null) {
97 return Constants.UNKNOWN;
98 }
99 return result;
100 }
101 }