| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/sysexplorer.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "sysexplorer.h"cxx . . $ `<file>/src/core/sysexplorer.h`/ |
| 5 | |
| 6 | #include "common/fileutils.h"cxx . . $ `<file>/src/common/fileutils.h`/ |
| 7 | #include "common/stringutils.h"cxx . . $ `<file>/src/common/stringutils.h`/ |
| 8 | #include <algorithm> |
| 9 | #include <spdlog/spdlog.h> |
| 10 | #include <utility> |
| 11 | |
| 12 | SysExplorercxx . . $ SysExplorer#::SysExplorercxx . . $ SysExplorer#SysExplorer(b8c159000a775c80).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<Vendorcxx . . $ Vendor#> gpuVendors) noexcept |
| 13 | : gpuVendors_cxx . . $ SysExplorer#gpuVendors_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(gpuVendors)) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> SysExplorercxx . . $ SysExplorer#::rendererscxx . . $ SysExplorer#renderers(c1a9bfb60daa162d).() |
| 18 | { |
| 19 | namespace fs = stdcxx . . $ std/::filesystem; |
| 20 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> devicescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 21 | |
| 22 | fs::pathcxx . . $ std/filesystem/__cxx11/path# renderBasePathcxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).{"/sys/class/drm"}; |
| 23 | for (auto const &drmEntry : fscxx . . $ std/filesystem/__cxx11/directory_iterator#directory_iterator(3f42e2c2fac0d5fc).::directory_iteratorcxx . . $ std/filesystem/__cxx11/directory_iterator#(renderBasePath)) { |
| 24 | auto const &renderDPath = drmEntry.pathcxx . . $ std/filesystem/__cxx11/directory_entry#path(3df3a2cdf6f4d926).(); |
| 25 | |
| 26 | // use the entries starting with "renderD" |
| 27 | auto const renderDName = renderDPath.filenamecxx . . $ std/filesystem/__cxx11/path#filename(159787a050b29eb0).().stringcxx . . $ std/filesystem/__cxx11/path#string(219584694fe2b248).(); |
| 28 | if (renderDName.findcxx . . $ std/__cxx11/basic_string#find(5ed402c22c298042).("renderD") == 0) { |
| 29 | |
| 30 | auto const sysPath = renderDPath /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "device"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).; |
| 31 | if (Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::isDirectoryPathValidcxx . . $ Utils/File/isDirectoryPathValid(c53a6ef3278968b1).(sysPath)) { |
| 32 | |
| 33 | // skip unsupported devices |
| 34 | if (!checkGPUVendorcxx . . $ SysExplorer#checkGPUVendor(53b4477d10196ba).(sysPathcxx . . $ std/filesystem/__cxx11/path#path(3f42e2c2fac0d5fc).)) |
| 35 | continue; |
| 36 | |
| 37 | devices.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(renderDName)); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return devicescxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 43 | } |
| 44 | |
| 45 | bool SysExplorercxx . . $ SysExplorer#::checkGPUVendorcxx . . $ SysExplorer#checkGPUVendor(53b4477d10196ba).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# sysPath) const |
| 46 | { |
| 47 | auto const vendorPath = sysPath /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "vendor"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).; |
| 48 | auto lines = Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::readFileLinescxx . . $ Utils/File/readFileLines(951e54d16e2206f).(vendorPath); |
| 49 | if (!lines.emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 50 | int vendor; |
| 51 | if (Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::toNumbercxx . . $ Utils/String/toNumber(c75d689ebd728b7b).<int>(vendor, lines.frontcxx . . $ std/vector#front(6baabfa6fc7b3a8e).(), 16)) { |
| 52 | if (stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(gpuVendors_cxx . . $ SysExplorer#gpuVendors_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), gpuVendors_cxx . . $ SysExplorer#gpuVendors_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), Vendorcxx . . $ Vendor#{vendor}) != |
| 53 | gpuVendors_cxx . . $ SysExplorer#gpuVendors_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) |
| 54 | return true; |
| 55 | } |
| 56 | else |
| 57 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot parse vendor id from file {}.", vendorPath.c_str()); |
| 58 | } |
| 59 | return false; |
| 60 | } |