1
2
3
4
5 package oshi.hardware.platform.unix.solaris;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import oshi.annotation.concurrent.Immutable;
11 import oshi.hardware.GraphicsCard;
12 import oshi.hardware.common.AbstractGraphicsCard;
13 import oshi.util.Constants;
14 import oshi.util.ExecutingCommand;
15 import oshi.util.ParseUtil;
16
17
18
19
20 @Immutable
21 final class SolarisGraphicsCard extends AbstractGraphicsCard {
22
23 private static final String PCI_CLASS_DISPLAY = "0003";
24
25
26
27
28
29
30
31
32
33
34 SolarisGraphicsCard(String name, String deviceId, String vendor, String versionInfo, long vram) {
35 super(name, deviceId, vendor, versionInfo, vram);
36 }
37
38
39
40
41
42
43 public static List<GraphicsCard> getGraphicsCards() {
44 List<GraphicsCard> cardList = new ArrayList<>();
45
46 List<String> devices = ExecutingCommand.runNative("prtconf -pv");
47 if (devices.isEmpty()) {
48 return cardList;
49 }
50 String name = "";
51 String vendorId = "";
52 String productId = "";
53 String classCode = "";
54 List<String> versionInfoList = new ArrayList<>();
55 for (String line : devices) {
56
57
58 if (line.contains("Node 0x")) {
59 if (PCI_CLASS_DISPLAY.equals(classCode)) {
60 cardList.add(new SolarisGraphicsCard(name.isEmpty() ? Constants.UNKNOWN : name,
61 productId.isEmpty() ? Constants.UNKNOWN : productId,
62 vendorId.isEmpty() ? Constants.UNKNOWN : vendorId,
63 versionInfoList.isEmpty() ? Constants.UNKNOWN : String.join(", ", versionInfoList), 0L));
64 }
65
66 name = "";
67 vendorId = Constants.UNKNOWN;
68 productId = Constants.UNKNOWN;
69 classCode = "";
70 versionInfoList.clear();
71 } else {
72 String[] split = line.trim().split(":", 2);
73 if (split.length == 2) {
74 if (split[0].equals("model")) {
75
76 name = ParseUtil.getSingleQuoteStringValue(line);
77 } else if (split[0].equals("name")) {
78
79
80 if (name.isEmpty()) {
81 name = ParseUtil.getSingleQuoteStringValue(line);
82 }
83 } else if (split[0].equals("vendor-id")) {
84
85 vendorId = "0x" + line.substring(line.length() - 4);
86 } else if (split[0].equals("device-id")) {
87
88 productId = "0x" + line.substring(line.length() - 4);
89 } else if (split[0].equals("revision-id")) {
90
91 versionInfoList.add(line.trim());
92 } else if (split[0].equals("class-code")) {
93
94
95 classCode = line.substring(line.length() - 8, line.length() - 4);
96 }
97 }
98 }
99 }
100
101 if (PCI_CLASS_DISPLAY.equals(classCode)) {
102 cardList.add(new SolarisGraphicsCard(name.isEmpty() ? Constants.UNKNOWN : name,
103 productId.isEmpty() ? Constants.UNKNOWN : productId,
104 vendorId.isEmpty() ? Constants.UNKNOWN : vendorId,
105 versionInfoList.isEmpty() ? Constants.UNKNOWN : String.join(", ", versionInfoList), 0L));
106 }
107 return cardList;
108 }
109 }