| 1 |
/* |
| 2 |
* Copyright (C) 2020 UBports foundation. |
| 3 |
* Author(s): Marius Gripsgard <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify it under |
| 6 |
* the terms of the GNU General Public License version 3, as published by |
| 7 |
* the Free Software Foundation. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
| 11 |
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "linux.h" |
| 20 |
|
| 21 |
#include <memory> |
| 22 |
#include <string> |
| 23 |
#include <iterator> |
| 24 |
#include <fstream> |
| 25 |
#include <unistd.h> |
| 26 |
|
| 27 |
// dts based model |
| 28 |
#define LINUX_MODEL "/proc/device-tree/model" |
| 29 |
|
| 30 |
std::string platform::Linux::readFile(std::string file) |
| 31 |
{ |
| 32 |
std::ifstream model(file); |
| 33 |
std::string ret; |
| 34 |
if (model.good()) |
| 35 |
ret = std::string(std::istreambuf_iterator<char>{model}, |
| 36 |
std::istreambuf_iterator<char>()); |
| 37 |
return ret; |
| 38 |
} |
| 39 |
|
| 40 |
std::string platform::Linux::name() |
| 41 |
{ |
| 42 |
if (hasValidName()) { |
| 43 |
auto model = readFile(LINUX_MODEL); |
| 44 |
if (!model.empty()) |
| 45 |
return model; |
| 46 |
} |
| 47 |
|
| 48 |
return "generic-linux"; |
| 49 |
} |
| 50 |
|
| 51 |
bool platform::Linux::hasValidName() |
| 52 |
{ |
| 53 |
return access(LINUX_MODEL, F_OK) != -1; |
| 54 |
} |
| 55 |
|
| 56 |
// Just returns default value |
| 57 |
std::string platform::Linux::prettyName() |
| 58 |
{ |
| 59 |
return "Generic linux device"; |
| 60 |
} |
| 61 |
|
| 62 |
// Just returns default value |
| 63 |
// todo, may be filled with `uname`? |
| 64 |
std::string platform::Linux::buildId() |
| 65 |
{ |
| 66 |
return "unique build id"; |
| 67 |
} |
| 68 |
|
| 69 |
//todo: may be filled with `sudo cat /sys/class/dmi/id/product_uuid` |
| 70 |
std::string platform::Linux::deviceIdentifier() |
| 71 |
{ |
| 72 |
return "unique build id"; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
DeviceInfo::DeviceType platform::Linux::deviceType() |
| 77 |
{ |
| 78 |
return DeviceInfo::DeviceType::Unknown; |
| 79 |
} |
| 80 |
|
| 81 |
DeviceInfo::DriverType platform::Linux::driverType() |
| 82 |
{ |
| 83 |
return DeviceInfo::DriverType::Linux; |
| 84 |
} |