View Javadoc
1   /*
2    * Copyright 2020-2023 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware.platform.unix.aix;
6   
7   import java.util.ArrayList;
8   import java.util.List;
9   import java.util.Locale;
10  import java.util.function.Supplier;
11  
12  import oshi.annotation.concurrent.Immutable;
13  import oshi.hardware.GraphicsCard;
14  import oshi.hardware.common.AbstractGraphicsCard;
15  import oshi.util.Constants;
16  import oshi.util.ParseUtil;
17  import oshi.util.Util;
18  
19  /**
20   * Graphics Card info obtained from lscfg
21   */
22  @Immutable
23  final class AixGraphicsCard extends AbstractGraphicsCard {
24  
25      /**
26       * Constructor for AixGraphicsCard
27       *
28       * @param name        The name
29       * @param deviceId    The device ID
30       * @param vendor      The vendor
31       * @param versionInfo The version info
32       * @param vram        The VRAM
33       */
34      AixGraphicsCard(String name, String deviceId, String vendor, String versionInfo, long vram) {
35          super(name, deviceId, vendor, versionInfo, vram);
36      }
37  
38      /**
39       * Gets graphics cards
40       *
41       * @param lscfg A memoized lscfg list
42       *
43       * @return List of graphics cards
44       */
45      public static List<GraphicsCard> getGraphicsCards(Supplier<List<String>> lscfg) {
46          List<GraphicsCard> cardList = new ArrayList<>();
47          boolean display = false;
48          String name = null;
49          String vendor = null;
50          List<String> versionInfo = new ArrayList<>();
51          for (String line : lscfg.get()) {
52              String s = line.trim();
53              if (s.startsWith("Name:") && s.contains("display")) {
54                  display = true;
55              } else if (display && s.toLowerCase(Locale.ROOT).contains("graphics")) {
56                  name = s;
57              } else if (display && name != null) {
58                  if (s.startsWith("Manufacture ID")) {
59                      vendor = ParseUtil.removeLeadingDots(s.substring(14));
60                  } else if (s.contains("Level")) {
61                      versionInfo.add(s.replaceAll("\\.\\.+", "="));
62                  } else if (s.startsWith("Hardware Location Code")) {
63                      cardList.add(new AixGraphicsCard(name, Constants.UNKNOWN,
64                              Util.isBlank(vendor) ? Constants.UNKNOWN : vendor,
65                              versionInfo.isEmpty() ? Constants.UNKNOWN : String.join(",", versionInfo), 0L));
66                      display = false;
67                  }
68              }
69          }
70          return cardList;
71      }
72  }