Commit 71c0c105ca8a6632c40fbc2575a92c7628f009c2
1 parent
a2b392a8
Exists in
master
Coleta de hardware no linux iniciada, já salvando informação de cpu e memória no JSON.
Showing
3 changed files
with
91 additions
and
3 deletions
Show diff stats
src/cacic_hardware.cpp
@@ -10,7 +10,6 @@ void cacic_hardware::iniciaColeta() | @@ -10,7 +10,6 @@ void cacic_hardware::iniciaColeta() | ||
10 | this->coletaHardware = coletaWin(); | 10 | this->coletaHardware = coletaWin(); |
11 | #elif defined(Q_OS_LINUX) | 11 | #elif defined(Q_OS_LINUX) |
12 | this->coletaHardware = coletaLinux(); | 12 | this->coletaHardware = coletaLinux(); |
13 | - | ||
14 | #endif | 13 | #endif |
15 | } | 14 | } |
16 | 15 | ||
@@ -24,5 +23,87 @@ QJsonObject cacic_hardware::coletaWin() | @@ -24,5 +23,87 @@ QJsonObject cacic_hardware::coletaWin() | ||
24 | 23 | ||
25 | QJsonObject cacic_hardware::coletaLinux() | 24 | QJsonObject cacic_hardware::coletaLinux() |
26 | { | 25 | { |
27 | - return QJsonObject(); | 26 | + |
27 | + OperatingSystem operatingSystem; | ||
28 | + ConsoleObject console; | ||
29 | + | ||
30 | + QJsonObject hardware; | ||
31 | + | ||
32 | + QFile lshwFile("lshwJson.json"); | ||
33 | + if( lshwFile.exists() ) | ||
34 | + lshwFile.remove(); | ||
35 | + | ||
36 | + console("lshw -json >> lshwJson.json"); | ||
37 | + | ||
38 | + | ||
39 | + QJsonObject lshwJson = oCacic.getJsonFromFile("lshwJson.json")["children"].toArray().first().toObject(); | ||
40 | + | ||
41 | + if( lshwJson.contains("id") && lshwJson["id"] == "core") { | ||
42 | + if ( lshwJson["children"].isArray() ){ | ||
43 | + qDebug() << "IS ARRAY!!"; | ||
44 | + QJsonArray componentsArray = lshwJson["children"].toArray(); | ||
45 | + | ||
46 | + foreach(QJsonValue componentValue, componentsArray ) { | ||
47 | + QJsonObject component = componentValue.toObject(); | ||
48 | + | ||
49 | + /* TODO: | ||
50 | + * - Formatar direito as quantidades (memória,clock do cpu) | ||
51 | + * com unidades mais amigáveis para humanos em todos métodos. | ||
52 | + * | ||
53 | + * coletaLinuxMem | ||
54 | + * coletaLinuxCpu | ||
55 | + * coletaLinuxPci - a fazer | ||
56 | + */ | ||
57 | + | ||
58 | + if( component["id"] == "memory" ) { | ||
59 | + coletaLinuxMem(hardware,component); | ||
60 | + } else if ( component["id"] == "cpu" ) { | ||
61 | + coletaLinuxCpu(hardware,component); | ||
62 | + } else if ( component["id"] == "pci" ) { | ||
63 | + QJsonArray pciArray = component["children"].toArray(); | ||
64 | + | ||
65 | + foreach(QJsonValue pciValue, pciArray){ | ||
66 | + QJsonObject pciObject = pciValue.toObject(); | ||
67 | + | ||
68 | + coletaLinuxPci(hardware, pciObject); | ||
69 | + } | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
76 | + } | ||
77 | + | ||
78 | + | ||
79 | + return hardware; | ||
80 | +} | ||
81 | + | ||
82 | +void cacic_hardware::coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component) | ||
83 | +{ | ||
84 | + QJsonObject memory; | ||
85 | + | ||
86 | + memory["size"] = QJsonValue::fromVariant(oCacic.convertDouble(component["size"].toDouble(),0) + " bytes"); | ||
87 | + | ||
88 | + hardware["memory"] = memory; | ||
89 | +} | ||
90 | + | ||
91 | +void cacic_hardware::coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component) | ||
92 | +{ | ||
93 | + QJsonObject cpu; | ||
94 | + | ||
95 | + cpu["name"] = component["product"]; | ||
96 | + cpu["vendor"] = component["vendor"]; | ||
97 | + cpu["clock"] = QJsonValue::fromVariant(oCacic.convertDouble(component["capacity"].toDouble(),0) + " Hz"); | ||
98 | + | ||
99 | + hardware["cpu"] = cpu; | ||
100 | +} | ||
101 | + | ||
102 | +void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson) | ||
103 | +{ | ||
104 | + | ||
105 | +} | ||
106 | + | ||
107 | +QJsonObject cacic_hardware::toJsonObject() { | ||
108 | + return coletaHardware; | ||
28 | } | 109 | } |
src/cacic_hardware.h
1 | #ifndef CACIC_HARDWARE_H | 1 | #ifndef CACIC_HARDWARE_H |
2 | #define CACIC_HARDWARE_H | 2 | #define CACIC_HARDWARE_H |
3 | #include <QtCore> | 3 | #include <QtCore> |
4 | +#include <QJsonArray> | ||
5 | +#include <QJsonArray> | ||
6 | +#include <cmath> | ||
4 | #include <ccacic.h> | 7 | #include <ccacic.h> |
5 | #include <console.h> | 8 | #include <console.h> |
6 | #include <operatingsystem.h> | 9 | #include <operatingsystem.h> |
@@ -25,6 +28,9 @@ public: | @@ -25,6 +28,9 @@ public: | ||
25 | private: | 28 | private: |
26 | QJsonObject coletaWin(); | 29 | QJsonObject coletaWin(); |
27 | QJsonObject coletaLinux(); | 30 | QJsonObject coletaLinux(); |
31 | + void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); | ||
32 | + void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); | ||
33 | + void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); | ||
28 | 34 | ||
29 | CCacic oCacic; | 35 | CCacic oCacic; |
30 | QJsonObject coletaHardware; | 36 | QJsonObject coletaHardware; |
src/ccoleta.cpp
@@ -8,7 +8,7 @@ CColeta::CColeta(QObject *parent) | @@ -8,7 +8,7 @@ CColeta::CColeta(QObject *parent) | ||
8 | void CColeta::coletaHardware() | 8 | void CColeta::coletaHardware() |
9 | { | 9 | { |
10 | qDebug() << "coletaHardware() executado"; | 10 | qDebug() << "coletaHardware() executado"; |
11 | -// oHardware.iniciaColeta(); | 11 | + oHardware.iniciaColeta(); |
12 | } | 12 | } |
13 | 13 | ||
14 | 14 | ||
@@ -55,5 +55,6 @@ QJsonObject CColeta::toJsonObject() | @@ -55,5 +55,6 @@ QJsonObject CColeta::toJsonObject() | ||
55 | QJsonObject coletaJson; | 55 | QJsonObject coletaJson; |
56 | coletaJson["computer"] = oComputer.toJsonObject(); | 56 | coletaJson["computer"] = oComputer.toJsonObject(); |
57 | coletaJson["software"] = oSoftware.toJsonObject(); | 57 | coletaJson["software"] = oSoftware.toJsonObject(); |
58 | + coletaJson["hardware"] = oHardware.toJsonObject(); | ||
58 | return coletaJson; | 59 | return coletaJson; |
59 | } | 60 | } |