Commit 2bff7f03033d1ced5447cbcbc7beaee20b6c8978
1 parent
f9bf9177
Exists in
master
Criado métodos slot para coleta das informações a partir de um json config inici…
…al, e um teste simples para isto.
Showing
6 changed files
with
163 additions
and
10 deletions
Show diff stats
gercols/gercols.cpp
... | ... | @@ -7,6 +7,29 @@ Gercols::Gercols(QObject *parent) |
7 | 7 | * quais coletas serao necessárias e realiza a conexão dos sinais com |
8 | 8 | * slots de coletas (coletaHardware, coletaSoftware, etc..) |
9 | 9 | */ |
10 | + | |
11 | + /* Cria um json de configuração para teste. | |
12 | + ******************************************/ | |
13 | + QJsonObject configTeste; | |
14 | + QJsonObject configComputer; | |
15 | + configComputer["operating_system"] = ""; | |
16 | + configComputer["user"] = ""; | |
17 | + configComputer["network_interface"] = ""; | |
18 | + configTeste["computer"] = configComputer; | |
19 | + configTeste["hardware"] = ""; | |
20 | + configTeste["software"] = ""; | |
21 | + | |
22 | + oCacic.setJsonToFile(configTeste,"configReq.json"); | |
23 | + /******************************************/ | |
24 | + | |
25 | + getConfigJson(); | |
26 | +qDebug() << "TESTE"; | |
27 | + oColeta = new CColeta(); | |
28 | + oColeta->setColeta(configReq); | |
29 | +qDebug() << oColeta->getColeta(); | |
30 | + QObject::connect(this, SIGNAL(iniciaConfiguracao()), oColeta, SLOT(configuraColetas())); | |
31 | + QObject::connect(this, SIGNAL(iniciaColeta()), oColeta, SLOT(run())); | |
32 | + | |
10 | 33 | } |
11 | 34 | |
12 | 35 | void Gercols::run() |
... | ... | @@ -18,18 +41,23 @@ void Gercols::run() |
18 | 41 | */ |
19 | 42 | |
20 | 43 | //Inicializa as classes e seta valores necessários oCacic.setCacicMainFolder(), por exemplo. |
44 | + // ... ainda a ser pensado | |
21 | 45 | |
46 | + emit iniciaConfiguracao(); | |
22 | 47 | //emite sinal para começar a coleta |
48 | + emit iniciaColeta(); | |
23 | 49 | |
24 | - //aguarda todas as coletas serem realizadas | |
25 | 50 | |
26 | 51 | //salva coleta em json |
27 | - coleta["computador"] = oColeta.getOComputer().toJsonObject(); | |
28 | - coleta["software"] = QJsonValue::fromVariant(QString("Aqui vai coleta de software")); | |
29 | - coleta["hardware"] = QJsonValue::fromVariant(QString("Aqui vai coleta de hardware")); | |
30 | - qDebug() << coleta; | |
52 | + qDebug() << oColeta->getColeta(); | |
31 | 53 | //salva json em arquivo |
32 | - oCacic.setJsonToFile(coleta, "coleta.json"); | |
54 | + oCacic.setJsonToFile(oColeta->getColeta(), "coleta.json"); | |
33 | 55 | //emite sinal "finished" pra finalizar a aplicação |
34 | 56 | emit finished(); |
35 | 57 | } |
58 | + | |
59 | +bool Gercols::getConfigJson() | |
60 | +{ | |
61 | + configReq = oCacic.getJsonFromFile("configReq.json"); | |
62 | + oCacic.deleteFile("configReq.json"); | |
63 | +} | ... | ... |
gercols/gercols.h
1 | 1 | #ifndef GERCOLS_H |
2 | 2 | #define GERCOLS_H |
3 | 3 | #include <QtCore> |
4 | +#include <QJsonObject> | |
4 | 5 | #include <ccoleta.h> |
5 | 6 | #include <ccacic.h> |
6 | 7 | |
... | ... | @@ -9,7 +10,11 @@ class Gercols : public QObject |
9 | 10 | Q_OBJECT |
10 | 11 | private: |
11 | 12 | CCacic oCacic; |
12 | - CColeta oColeta; | |
13 | + CColeta *oColeta; | |
14 | + QJsonObject configReq; | |
15 | + | |
16 | + bool getConfigJson(); | |
17 | + | |
13 | 18 | public: |
14 | 19 | explicit Gercols(QObject *parent = 0); |
15 | 20 | |
... | ... | @@ -18,6 +23,8 @@ public slots: |
18 | 23 | |
19 | 24 | signals: |
20 | 25 | void finished(); |
26 | + void iniciaConfiguracao(); | |
27 | + void iniciaColeta(); | |
21 | 28 | void fimColeta(); |
22 | 29 | }; |
23 | 30 | ... | ... |
gercols/gercols.pro
gercols/main.cpp
... | ... | @@ -4,11 +4,14 @@ |
4 | 4 | int main(int argc, char *argv[]) |
5 | 5 | { |
6 | 6 | QCoreApplication a(argc, argv); |
7 | + | |
7 | 8 | //crio o objeto que será responsável pela execução |
8 | 9 | Gercols *oGercols = new Gercols(&a); |
10 | + | |
9 | 11 | //conecto o sinal "finished" do objeto oGercols ao slot "quit" do objeto a(QCoreApplication) |
10 | 12 | //ou seja, quando o finished for chamado, a aplicacao é encerrada. |
11 | 13 | a.connect(oGercols, SIGNAL(finished()), &a, SLOT(quit())); |
14 | + | |
12 | 15 | //invoco o metodo "run" do objeto oGercols assim que o loop (a.exec()) comecar |
13 | 16 | QMetaObject::invokeMethod(oGercols, "run", Qt::QueuedConnection); |
14 | 17 | return a.exec(); | ... | ... |
src/ccoleta.cpp
1 | 1 | #include "ccoleta.h" |
2 | 2 | |
3 | -CColeta::CColeta() | |
3 | +CColeta::CColeta(QObject *parent) | |
4 | 4 | { |
5 | + | |
6 | +} | |
7 | + | |
8 | +void CColeta::coletaComputer() | |
9 | +{ | |
10 | + qDebug() << "coletaComputer() executado"; | |
11 | + QJsonObject coletaComputer = coleta["computer"].toObject(); | |
12 | + if( coletaComputer.contains("operating_system") ) | |
13 | + emit beginOperatingSystem(); | |
14 | + if( coletaComputer.contains("user") ) | |
15 | + emit beginUser(); | |
16 | + | |
17 | +} | |
18 | + | |
19 | +void CColeta::coletaHardware() | |
20 | +{ | |
21 | + qDebug() << "coletaHardware() executado"; | |
22 | + QJsonObject coletaHardware = coleta["hardware"].toObject(); | |
23 | +} | |
24 | + | |
25 | +void CColeta::coletaNetworkInterfaces() | |
26 | +{ | |
27 | + qDebug() << "coletaOperatingSystem() executado"; | |
28 | + | |
29 | +// QJsonObject coletaComputer = coleta["computer"].toObject(); | |
30 | +// coletaComputer["network_interfaces"] = QJsonValue::fromVariant(QString(oComputer.getNetworkInterface())); | |
31 | + | |
32 | +// coleta["computer"] = coletaComputer; | |
33 | +} | |
34 | + | |
35 | +void CColeta::coletaOperatingSystem() | |
36 | +{ | |
37 | + qDebug() << "coletaOperatingSystem() executado"; | |
38 | + | |
39 | + QJsonObject coletaComputer = coleta["computer"].toObject(); | |
40 | + coletaComputer["operating_system"] = QJsonValue::fromVariant(QString(oComputer.getOs().getNomeOs())); | |
41 | + | |
42 | + coleta["computer"] = coletaComputer; | |
5 | 43 | } |
6 | 44 | |
45 | +void CColeta::coletaSoftware() | |
46 | +{ | |
47 | + qDebug() << "coletaSoftware() executado"; | |
48 | + QJsonObject coletaSoftware = coleta["software"].toObject(); | |
49 | +} | |
50 | + | |
51 | +void CColeta::coletaUser() | |
52 | +{ | |
53 | + qDebug() << "coletauser() executado"; | |
54 | + | |
55 | + QJsonObject coletaComputer = coleta["computer"].toObject(); | |
56 | + coletaComputer["user"] = QJsonValue::fromVariant(QString::fromStdString(oComputer.getUser())); | |
57 | + | |
58 | + coleta["computer"] = coletaComputer; | |
59 | +} | |
60 | + | |
61 | +void CColeta::configuraColetas(){ | |
62 | + QObject::connect(this, SIGNAL(beginComputer()), this, SLOT(coletaComputer())); | |
63 | + QObject::connect(this, SIGNAL(beginNetworkInterfaces()), this, SLOT(coletaNetworkInterfaces())); | |
64 | + QObject::connect(this, SIGNAL(beginOperatingSystem()), this, SLOT(coletaOperatingSystem())); | |
65 | + QObject::connect(this, SIGNAL(beginUser()), this, SLOT(coletaUser())); | |
66 | + QObject::connect(this, SIGNAL(beginHardware()), this, SLOT(coletaHardware())); | |
67 | + QObject::connect(this, SIGNAL(beginSoftware()), this, SLOT(coletaSoftware())); | |
68 | +} | |
69 | + | |
70 | +QJsonObject CColeta::getColeta() const | |
71 | +{ | |
72 | + return coleta; | |
73 | +} | |
7 | 74 | |
8 | 75 | CACIC_Computer CColeta::getOComputer() const |
9 | 76 | { |
10 | 77 | return oComputer; |
11 | 78 | } |
79 | + | |
80 | +void CColeta::run() | |
81 | +{ | |
82 | + if( coleta.contains("computer") ) | |
83 | + emit beginComputer(); | |
84 | + if( coleta.contains("hardware") ) | |
85 | + emit beginHardware(); | |
86 | + if ( coleta.contains("software") ) | |
87 | + emit beginSoftware(); | |
88 | +} | |
89 | + | |
90 | +void CColeta::setColeta(QJsonObject config) | |
91 | +{ | |
92 | + this->coleta = config; | |
93 | +} | ... | ... |
src/ccoleta.h
1 | 1 | #ifndef CCOLETA_H |
2 | 2 | #define CCOLETA_H |
3 | +#include <QtCore> | |
4 | +#include <QObject> | |
5 | +#include <QJsonObject> | |
6 | +#include <QDebug> | |
3 | 7 | #include <cacic_computer.h> |
4 | 8 | |
5 | -class CColeta | |
9 | + | |
10 | +class CColeta : public QObject | |
6 | 11 | { |
12 | + Q_OBJECT | |
13 | + | |
7 | 14 | private: |
15 | + QJsonObject coleta; | |
16 | + | |
8 | 17 | CACIC_Computer oComputer; |
18 | + | |
9 | 19 | public: |
10 | - CColeta(); | |
20 | + explicit CColeta(QObject *parent = 0); | |
21 | + | |
22 | + QJsonObject getColeta() const; | |
11 | 23 | CACIC_Computer getOComputer() const; |
24 | + void setColeta(QJsonObject config); | |
25 | + | |
26 | +public slots: | |
27 | + void coletaComputer(); | |
28 | + void coletaHardware(); | |
29 | + void coletaNetworkInterfaces(); | |
30 | + void coletaOperatingSystem(); | |
31 | + void coletaSoftware(); | |
32 | + void coletaUser(); | |
33 | + void configuraColetas(); | |
34 | + void run(); | |
35 | + | |
36 | +signals: | |
37 | + void beginComputer(); | |
38 | + void beginHardware(); | |
39 | + void beginNetworkInterfaces(); | |
40 | + void beginOperatingSystem(); | |
41 | + void beginSoftware(); | |
42 | + void beginUser(); | |
43 | + void finished(); | |
12 | 44 | }; |
13 | 45 | |
14 | 46 | #endif // CCOLETA_H | ... | ... |