1
2
3
4
5 package oshi.hardware.platform.unix.solaris;
6
7 import java.util.ArrayList;
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12 import oshi.annotation.concurrent.Immutable;
13 import oshi.hardware.SoundCard;
14 import oshi.hardware.common.AbstractSoundCard;
15 import oshi.util.ExecutingCommand;
16 import oshi.util.ParseUtil;
17
18
19
20
21 @Immutable
22 final class SolarisSoundCard extends AbstractSoundCard {
23
24 private static final String LSHAL = "lshal";
25 private static final String DEFAULT_AUDIO_DRIVER = "audio810";
26
27
28
29
30
31
32
33
34 SolarisSoundCard(String kernelVersion, String name, String codec) {
35 super(kernelVersion, name, codec);
36 }
37
38
39
40
41
42
43
44
45 public static List<SoundCard> getSoundCards() {
46 Map<String, String> vendorMap = new HashMap<>();
47 Map<String, String> productMap = new HashMap<>();
48 List<String> sounds = new ArrayList<>();
49 String key = "";
50 for (String line : ExecutingCommand.runNative(LSHAL)) {
51 line = line.trim();
52 if (line.startsWith("udi =")) {
53
54 key = ParseUtil.getSingleQuoteStringValue(line);
55 } else if (!key.isEmpty() && !line.isEmpty()) {
56 if (line.contains("info.solaris.driver =")
57 && DEFAULT_AUDIO_DRIVER.equals(ParseUtil.getSingleQuoteStringValue(line))) {
58 sounds.add(key);
59 } else if (line.contains("info.product")) {
60 productMap.put(key, ParseUtil.getStringBetween(line, '\''));
61 } else if (line.contains("info.vendor")) {
62 vendorMap.put(key, ParseUtil.getStringBetween(line, '\''));
63 }
64 }
65 }
66 List<SoundCard> soundCards = new ArrayList<>();
67 for (String s : sounds) {
68 soundCards.add(new SolarisSoundCard(productMap.get(s) + " " + DEFAULT_AUDIO_DRIVER,
69 vendorMap.get(s) + " " + productMap.get(s), productMap.get(s)));
70 }
71 return soundCards;
72 }
73 }