View Javadoc
1   /*
2    * Copyright 2018-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
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   * Solaris Sound Card.
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       * Constructor for SolarisSoundCard.
29       *
30       * @param kernelVersion The version
31       * @param name          The name
32       * @param codec         The codec
33       */
34      SolarisSoundCard(String kernelVersion, String name, String codec) {
35          super(kernelVersion, name, codec);
36      }
37  
38      /**
39       * <p>
40       * getSoundCards.
41       * </p>
42       *
43       * @return a {@link java.util.List} object.
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                  // we have the key.
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  }