| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2021 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "common/fileutils.h" |
| 7 | #include "core/idatasource.h" |
| 8 | #include <filesystem> |
| 9 | #include <spdlog/spdlog.h> |
| 10 | #include <string> |
| 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | |
| 14 | class GPUInfoUeventDataSource |
| 15 | : public IDataSource<std::vector<std::string>, std::filesystem::path const> |
| 16 | { |
| 17 | public: |
| 18 | std::string source() const override |
| 19 | { |
| 20 | return "uevent"; |
| 21 | } |
| 22 | |
| 23 | bool read(std::vector<std::string> &data, |
| 24 | std::filesystem::path const &path) override |
| 25 | { |
| 26 | auto const filePath = path / source(); |
| 27 | auto lines = Utils::File::readFileLines(filePath); |
| 28 | if (!lines.empty()) { |
| 29 | std::swap(data, lines); |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | SPDLOG_WARN("Cannot retrieve device information from {}", filePath.c_str()); |
| 34 | return false; |
| 35 | } |
| 36 | }; |