1
2
3
4
5 package oshi.hardware.platform.unix.solaris;
6
7 import static oshi.hardware.platform.unix.solaris.SolarisComputerSystem.SmbType.SMB_TYPE_BIOS;
8 import static oshi.hardware.platform.unix.solaris.SolarisComputerSystem.SmbType.SMB_TYPE_SYSTEM;
9 import static oshi.hardware.platform.unix.solaris.SolarisComputerSystem.SmbType.SMB_TYPE_BASEBOARD;
10 import static oshi.util.Memoizer.memoize;
11 import static oshi.util.ParseUtil.getValueOrUnknown;
12
13 import java.util.EnumMap;
14 import java.util.HashMap;
15 import java.util.Map;
16 import java.util.function.Supplier;
17
18 import oshi.annotation.concurrent.Immutable;
19 import oshi.hardware.Baseboard;
20 import oshi.hardware.Firmware;
21 import oshi.hardware.common.AbstractComputerSystem;
22 import oshi.hardware.platform.unix.UnixBaseboard;
23 import oshi.util.ExecutingCommand;
24 import oshi.util.ParseUtil;
25 import oshi.util.Util;
26
27
28
29
30 @Immutable
31 final class SolarisComputerSystem extends AbstractComputerSystem {
32 public enum SmbType {
33
34
35
36 SMB_TYPE_BIOS,
37
38
39
40 SMB_TYPE_SYSTEM,
41
42
43
44 SMB_TYPE_BASEBOARD
45 }
46
47 private final Supplier<SmbiosStrings> smbiosStrings = memoize(SolarisComputerSystem::readSmbios);
48
49 @Override
50 public String getManufacturer() {
51 return smbiosStrings.get().manufacturer;
52 }
53
54 @Override
55 public String getModel() {
56 return smbiosStrings.get().model;
57 }
58
59 @Override
60 public String getSerialNumber() {
61 return smbiosStrings.get().serialNumber;
62 }
63
64 @Override
65 public String getHardwareUUID() {
66 return smbiosStrings.get().uuid;
67 }
68
69 @Override
70 public Firmware createFirmware() {
71 return new SolarisFirmware(smbiosStrings.get().biosVendor, smbiosStrings.get().biosVersion,
72 smbiosStrings.get().biosDate);
73 }
74
75 @Override
76 public Baseboard createBaseboard() {
77 return new UnixBaseboard(smbiosStrings.get().boardManufacturer, smbiosStrings.get().boardModel,
78 smbiosStrings.get().boardSerialNumber, smbiosStrings.get().boardVersion);
79 }
80
81 private static SmbiosStrings readSmbios() {
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 final String serialNumMarker = "Serial Number";
119
120 SmbType smbTypeId = null;
121
122 EnumMap<SmbType, Map<String, String>> smbTypesMap = new EnumMap<>(SmbType.class);
123 smbTypesMap.put(SMB_TYPE_BIOS, new HashMap<>());
124 smbTypesMap.put(SMB_TYPE_SYSTEM, new HashMap<>());
125 smbTypesMap.put(SMB_TYPE_BASEBOARD, new HashMap<>());
126
127
128 for (final String checkLine : ExecutingCommand.runNative("smbios")) {
129
130 if (checkLine.contains("SMB_TYPE_") && (smbTypeId = getSmbType(checkLine)) == null) {
131
132 break;
133 }
134
135 Integer colonDelimiterIndex = checkLine.indexOf(":");
136 if (smbTypeId != null && colonDelimiterIndex >= 0) {
137 String key = checkLine.substring(0, colonDelimiterIndex).trim();
138 String val = checkLine.substring(colonDelimiterIndex + 1).trim();
139 smbTypesMap.get(smbTypeId).put(key, val);
140 }
141 }
142
143 Map<String, String> smbTypeBIOSMap = smbTypesMap.get(SMB_TYPE_BIOS);
144 Map<String, String> smbTypeSystemMap = smbTypesMap.get(SMB_TYPE_SYSTEM);
145 Map<String, String> smbTypeBaseboardMap = smbTypesMap.get(SMB_TYPE_BASEBOARD);
146
147
148 if (!smbTypeSystemMap.containsKey(serialNumMarker) || Util.isBlank(smbTypeSystemMap.get(serialNumMarker))) {
149 smbTypeSystemMap.put(serialNumMarker, readSerialNumber());
150 }
151 return new SmbiosStrings(smbTypeBIOSMap, smbTypeSystemMap, smbTypeBaseboardMap);
152 }
153
154 private static SmbType getSmbType(String checkLine) {
155 for (SmbType smbType : SmbType.values()) {
156 if (checkLine.contains(smbType.name())) {
157 return smbType;
158 }
159 }
160
161
162 return null;
163 }
164
165 private static String readSerialNumber() {
166
167 String serialNumber = ExecutingCommand.getFirstAnswer("sneep");
168
169 if (serialNumber.isEmpty()) {
170 String marker = "chassis-sn:";
171 for (String checkLine : ExecutingCommand.runNative("prtconf -pv")) {
172 if (checkLine.contains(marker)) {
173 serialNumber = ParseUtil.getSingleQuoteStringValue(checkLine);
174 break;
175 }
176 }
177 }
178 return serialNumber;
179 }
180
181 private static final class SmbiosStrings {
182 private final String biosVendor;
183 private final String biosVersion;
184 private final String biosDate;
185
186 private final String manufacturer;
187 private final String model;
188 private final String serialNumber;
189 private final String uuid;
190
191 private final String boardManufacturer;
192 private final String boardModel;
193 private final String boardVersion;
194 private final String boardSerialNumber;
195
196 private SmbiosStrings(Map<String, String> smbTypeBIOSStrings, Map<String, String> smbTypeSystemStrings,
197 Map<String, String> smbTypeBaseboardStrings) {
198 final String vendorMarker = "Vendor";
199 final String biosDateMarker = "Release Date";
200 final String biosVersionMarker = "Version String";
201
202 final String manufacturerMarker = "Manufacturer";
203 final String productMarker = "Product";
204 final String serialNumMarker = "Serial Number";
205 final String uuidMarker = "UUID";
206 final String versionMarker = "Version";
207
208 this.biosVendor = getValueOrUnknown(smbTypeBIOSStrings, vendorMarker);
209 this.biosVersion = getValueOrUnknown(smbTypeBIOSStrings, biosVersionMarker);
210 this.biosDate = getValueOrUnknown(smbTypeBIOSStrings, biosDateMarker);
211 this.manufacturer = getValueOrUnknown(smbTypeSystemStrings, manufacturerMarker);
212 this.model = getValueOrUnknown(smbTypeSystemStrings, productMarker);
213 this.serialNumber = getValueOrUnknown(smbTypeSystemStrings, serialNumMarker);
214 this.uuid = getValueOrUnknown(smbTypeSystemStrings, uuidMarker);
215 this.boardManufacturer = getValueOrUnknown(smbTypeBaseboardStrings, manufacturerMarker);
216 this.boardModel = getValueOrUnknown(smbTypeBaseboardStrings, productMarker);
217 this.boardVersion = getValueOrUnknown(smbTypeBaseboardStrings, versionMarker);
218 this.boardSerialNumber = getValueOrUnknown(smbTypeBaseboardStrings, serialNumMarker);
219 }
220 }
221 }