| 1 |
/* |
| 2 |
* Copyright (C) 2019 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 "deviceinfo.h" |
| 20 |
#include <string> |
| 21 |
#include <memory> |
| 22 |
#include <iostream> |
| 23 |
#include <vector> |
| 24 |
|
| 25 |
void print(std::string str) { |
| 26 |
std::cout << str << std::endl; |
| 27 |
} |
| 28 |
|
| 29 |
int get(std::string arg, std::shared_ptr<DeviceInfo> info) { |
| 30 |
if (arg == "Name") { |
| 31 |
print(info->name()); |
| 32 |
return 0; |
| 33 |
} |
| 34 |
if (arg == "PrettyName") { |
| 35 |
print(info->prettyName()); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
if (arg == "DeviceType") { |
| 39 |
print(DeviceInfo::deviceTypeToString(info->deviceType())); |
| 40 |
return 0; |
| 41 |
} |
| 42 |
if (arg == "DriverType") { |
| 43 |
print(DeviceInfo::driverTypeToString(info->driverType())); |
| 44 |
return 0; |
| 45 |
} |
| 46 |
if (arg == "GridUnit") { |
| 47 |
print(std::to_string(info->gridUnit())); |
| 48 |
return 0; |
| 49 |
} |
| 50 |
if (arg == "SupportedOrientations") { |
| 51 |
for (auto r : info->supportedOrientations()) |
| 52 |
print(r); |
| 53 |
return 0; |
| 54 |
} |
| 55 |
if (arg == "PrimaryOrientation") { |
| 56 |
print(info->primaryOrientation()); |
| 57 |
return 0; |
| 58 |
} |
| 59 |
if (arg == "PortraitOrientation") { |
| 60 |
print(info->portraitOrientation()); |
| 61 |
return 0; |
| 62 |
} |
| 63 |
if (arg == "InvertedPortraitOrientation") { |
| 64 |
print(info->invertedPortraitOrientation()); |
| 65 |
return 0; |
| 66 |
} |
| 67 |
if (arg == "LandscapeOrientation") { |
| 68 |
print(info->landscapeOrientation()); |
| 69 |
return 0; |
| 70 |
} |
| 71 |
if (arg == "InvertedLandscapeOrientation") { |
| 72 |
print(info->invertedLandscapeOrientation()); |
| 73 |
return 0; |
| 74 |
} |
| 75 |
if (arg == "GridUnit") { |
| 76 |
print(std::to_string(info->gridUnit())); |
| 77 |
return 0; |
| 78 |
} |
| 79 |
if (info->contains(arg)) { |
| 80 |
print(info->get(arg, "")); |
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
print("Unknown prop"); |
| 85 |
return 1; |
| 86 |
} |
| 87 |
|
| 88 |
int printAboutMe(std::shared_ptr<DeviceInfo> info) |
| 89 |
{ |
| 90 |
std::cout << " -- About this device --" << std::endl; |
| 91 |
std::cout << "Name: " << info->name() << std::endl; |
| 92 |
std::cout << "PrettyName: " << info->prettyName() << std::endl; |
| 93 |
std::cout << "DeviceType: " << DeviceInfo::deviceTypeToString(info->deviceType()) << std::endl; |
| 94 |
std::cout << "DriverType: " << DeviceInfo::driverTypeToString(info->driverType()) << std::endl; |
| 95 |
|
| 96 |
std::cout << "GridUnit: " << info->gridUnit() << std::endl; |
| 97 |
|
| 98 |
std::cout << "SupportedOrientations: "; |
| 99 |
for (auto r : info->supportedOrientations()) |
| 100 |
std::cout << r << " "; |
| 101 |
std::cout << std::endl; |
| 102 |
|
| 103 |
std::cout << "PrimaryOrientation: " << info->primaryOrientation() << std::endl; |
| 104 |
std::cout << "PortraitOrientation: " << info->portraitOrientation() << std::endl; |
| 105 |
std::cout << "InvertedPortraitOrientation: " << info->invertedPortraitOrientation() << std::endl; |
| 106 |
std::cout << "LandscapeOrientation: " << info->landscapeOrientation() << std::endl; |
| 107 |
std::cout << "InvertedLandscapeOrientation: " << info->invertedLandscapeOrientation() << std::endl; |
| 108 |
|
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
void help() { |
| 113 |
print("device-info usage:"); |
| 114 |
print(" - device-info - list all about device"); |
| 115 |
print(" - device-info get [prop] - get specific prop"); |
| 116 |
} |
| 117 |
|
| 118 |
int main (int argc, char *argv[]) { |
| 119 |
if (argc == 1) { |
| 120 |
return printAboutMe(std::make_shared<DeviceInfo>()); |
| 121 |
} else if (argc == 3) { |
| 122 |
std::string argv1 = argv[1]; |
| 123 |
if (argv1 == "get") { |
| 124 |
// We shoud not log anything as that might mess with scripts using this |
| 125 |
return get(std::string(argv[2]), std::make_shared<DeviceInfo>(DeviceInfo::PrintMode::None)); |
| 126 |
} |
| 127 |
// TODO: add set function |
| 128 |
} |
| 129 |
|
| 130 |
help(); |
| 131 |
return 1; |
| 132 |
} |