cacic_hardware.cpp
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "cacic_hardware.h"
cacic_hardware::cacic_hardware()
{
}
void cacic_hardware::iniciaColeta()
{
#ifdef Q_OS_WIN
this->coletaHardware = coletaWin();
#elif defined(Q_OS_LINUX)
this->coletaHardware = coletaLinux();
#endif
}
QJsonObject cacic_hardware::coletaWin()
{
#if defined(Q_OS_WIN)
// Implementação seguindo as definições na documentação WMI.
#endif
return QJsonObject();
}
QJsonObject cacic_hardware::coletaLinux()
{
OperatingSystem operatingSystem;
ConsoleObject console;
QJsonObject hardware;
QFile lshwFile("lshwJson.json");
if( lshwFile.exists() )
lshwFile.remove();
console("lshw -json >> lshwJson.json");
QJsonObject lshwJson = oCacic.getJsonFromFile("lshwJson.json")["children"].toArray().first().toObject();
if( lshwJson.contains("id") && lshwJson["id"] == "core") {
if ( lshwJson["children"].isArray() ){
qDebug() << "IS ARRAY!!";
QJsonArray componentsArray = lshwJson["children"].toArray();
foreach(QJsonValue componentValue, componentsArray ) {
QJsonObject component = componentValue.toObject();
/* TODO:
* - Formatar direito as quantidades (memória,clock do cpu)
* com unidades mais amigáveis para humanos em todos métodos.
*
* coletaLinuxMem
* coletaLinuxCpu
* coletaLinuxPci - a fazer
*/
if( component["id"] == "memory" ) {
coletaLinuxMem(hardware,component);
} else if ( component["id"] == "cpu" ) {
coletaLinuxCpu(hardware,component);
} else if ( component["id"] == "pci" ) {
QJsonArray pciArray = component["children"].toArray();
foreach(QJsonValue pciValue, pciArray){
QJsonObject pciObject = pciValue.toObject();
coletaLinuxPci(hardware, pciObject);
}
}
}
}
}
return hardware;
}
void cacic_hardware::coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component)
{
QJsonObject memory;
memory["size"] = QJsonValue::fromVariant(oCacic.convertDouble(component["size"].toDouble(),0) + " bytes");
hardware["memory"] = memory;
}
void cacic_hardware::coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component)
{
QJsonObject cpu;
cpu["name"] = component["product"];
cpu["vendor"] = component["vendor"];
cpu["clock"] = QJsonValue::fromVariant(oCacic.convertDouble(component["capacity"].toDouble(),0) + " Hz");
hardware["cpu"] = cpu;
}
void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson)
{
}
QJsonObject cacic_hardware::toJsonObject() {
return coletaHardware;
}