| 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 <spdlog/spdlog.h> |
| 9 | #include <string> |
| 10 | |
| 11 | class SWInfoKernelDataSource : public IDataSource<std::string> |
| 12 | { |
| 13 | public: |
| 14 | std::string source() const override |
| 15 | { |
| 16 | return "/proc/version"; |
| 17 | } |
| 18 | |
| 19 | bool read(std::string &data) override |
| 20 | { |
| 21 | auto const lines = Utils::File::readFileLines(source()); |
| 22 | if (!lines.empty()) { |
| 23 | data = lines.front(); |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | SPDLOG_WARN("Cannot retrieve kernel version"); |
| 28 | return false; |
| 29 | } |
| 30 | }; |