From 2bff7f03033d1ced5447cbcbc7beaee20b6c8978 Mon Sep 17 00:00:00 2001 From: Thiago Rocha Date: Mon, 18 Aug 2014 12:42:01 -0300 Subject: [PATCH] Criado métodos slot para coleta das informações a partir de um json config inicial, e um teste simples para isto. --- gercols/gercols.cpp | 40 ++++++++++++++++++++++++++++++++++------ gercols/gercols.h | 9 ++++++++- gercols/gercols.pro | 1 + gercols/main.cpp | 3 +++ src/ccoleta.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/ccoleta.h | 36 ++++++++++++++++++++++++++++++++++-- 6 files changed, 163 insertions(+), 10 deletions(-) diff --git a/gercols/gercols.cpp b/gercols/gercols.cpp index b0184bb..ca94002 100644 --- a/gercols/gercols.cpp +++ b/gercols/gercols.cpp @@ -7,6 +7,29 @@ Gercols::Gercols(QObject *parent) * quais coletas serao necessárias e realiza a conexão dos sinais com * slots de coletas (coletaHardware, coletaSoftware, etc..) */ + + /* Cria um json de configuração para teste. + ******************************************/ + QJsonObject configTeste; + QJsonObject configComputer; + configComputer["operating_system"] = ""; + configComputer["user"] = ""; + configComputer["network_interface"] = ""; + configTeste["computer"] = configComputer; + configTeste["hardware"] = ""; + configTeste["software"] = ""; + + oCacic.setJsonToFile(configTeste,"configReq.json"); + /******************************************/ + + getConfigJson(); +qDebug() << "TESTE"; + oColeta = new CColeta(); + oColeta->setColeta(configReq); +qDebug() << oColeta->getColeta(); + QObject::connect(this, SIGNAL(iniciaConfiguracao()), oColeta, SLOT(configuraColetas())); + QObject::connect(this, SIGNAL(iniciaColeta()), oColeta, SLOT(run())); + } void Gercols::run() @@ -18,18 +41,23 @@ void Gercols::run() */ //Inicializa as classes e seta valores necessários oCacic.setCacicMainFolder(), por exemplo. + // ... ainda a ser pensado + emit iniciaConfiguracao(); //emite sinal para começar a coleta + emit iniciaColeta(); - //aguarda todas as coletas serem realizadas //salva coleta em json - coleta["computador"] = oColeta.getOComputer().toJsonObject(); - coleta["software"] = QJsonValue::fromVariant(QString("Aqui vai coleta de software")); - coleta["hardware"] = QJsonValue::fromVariant(QString("Aqui vai coleta de hardware")); - qDebug() << coleta; + qDebug() << oColeta->getColeta(); //salva json em arquivo - oCacic.setJsonToFile(coleta, "coleta.json"); + oCacic.setJsonToFile(oColeta->getColeta(), "coleta.json"); //emite sinal "finished" pra finalizar a aplicação emit finished(); } + +bool Gercols::getConfigJson() +{ + configReq = oCacic.getJsonFromFile("configReq.json"); + oCacic.deleteFile("configReq.json"); +} diff --git a/gercols/gercols.h b/gercols/gercols.h index ead5805..c6e25b5 100644 --- a/gercols/gercols.h +++ b/gercols/gercols.h @@ -1,6 +1,7 @@ #ifndef GERCOLS_H #define GERCOLS_H #include +#include #include #include @@ -9,7 +10,11 @@ class Gercols : public QObject Q_OBJECT private: CCacic oCacic; - CColeta oColeta; + CColeta *oColeta; + QJsonObject configReq; + + bool getConfigJson(); + public: explicit Gercols(QObject *parent = 0); @@ -18,6 +23,8 @@ public slots: signals: void finished(); + void iniciaConfiguracao(); + void iniciaColeta(); void fimColeta(); }; diff --git a/gercols/gercols.pro b/gercols/gercols.pro index be1e8f2..9bf8727 100644 --- a/gercols/gercols.pro +++ b/gercols/gercols.pro @@ -11,6 +11,7 @@ QT -= gui TARGET = gercols CONFIG += console CONFIG -= app_bundle +CONFIG += qt win32 { LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp diff --git a/gercols/main.cpp b/gercols/main.cpp index 9a2e8ce..ac1069a 100644 --- a/gercols/main.cpp +++ b/gercols/main.cpp @@ -4,11 +4,14 @@ int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); + //crio o objeto que será responsável pela execução Gercols *oGercols = new Gercols(&a); + //conecto o sinal "finished" do objeto oGercols ao slot "quit" do objeto a(QCoreApplication) //ou seja, quando o finished for chamado, a aplicacao é encerrada. a.connect(oGercols, SIGNAL(finished()), &a, SLOT(quit())); + //invoco o metodo "run" do objeto oGercols assim que o loop (a.exec()) comecar QMetaObject::invokeMethod(oGercols, "run", Qt::QueuedConnection); return a.exec(); diff --git a/src/ccoleta.cpp b/src/ccoleta.cpp index a3444bf..6c98268 100644 --- a/src/ccoleta.cpp +++ b/src/ccoleta.cpp @@ -1,11 +1,93 @@ #include "ccoleta.h" -CColeta::CColeta() +CColeta::CColeta(QObject *parent) { + +} + +void CColeta::coletaComputer() +{ + qDebug() << "coletaComputer() executado"; + QJsonObject coletaComputer = coleta["computer"].toObject(); + if( coletaComputer.contains("operating_system") ) + emit beginOperatingSystem(); + if( coletaComputer.contains("user") ) + emit beginUser(); + +} + +void CColeta::coletaHardware() +{ + qDebug() << "coletaHardware() executado"; + QJsonObject coletaHardware = coleta["hardware"].toObject(); +} + +void CColeta::coletaNetworkInterfaces() +{ + qDebug() << "coletaOperatingSystem() executado"; + +// QJsonObject coletaComputer = coleta["computer"].toObject(); +// coletaComputer["network_interfaces"] = QJsonValue::fromVariant(QString(oComputer.getNetworkInterface())); + +// coleta["computer"] = coletaComputer; +} + +void CColeta::coletaOperatingSystem() +{ + qDebug() << "coletaOperatingSystem() executado"; + + QJsonObject coletaComputer = coleta["computer"].toObject(); + coletaComputer["operating_system"] = QJsonValue::fromVariant(QString(oComputer.getOs().getNomeOs())); + + coleta["computer"] = coletaComputer; } +void CColeta::coletaSoftware() +{ + qDebug() << "coletaSoftware() executado"; + QJsonObject coletaSoftware = coleta["software"].toObject(); +} + +void CColeta::coletaUser() +{ + qDebug() << "coletauser() executado"; + + QJsonObject coletaComputer = coleta["computer"].toObject(); + coletaComputer["user"] = QJsonValue::fromVariant(QString::fromStdString(oComputer.getUser())); + + coleta["computer"] = coletaComputer; +} + +void CColeta::configuraColetas(){ + QObject::connect(this, SIGNAL(beginComputer()), this, SLOT(coletaComputer())); + QObject::connect(this, SIGNAL(beginNetworkInterfaces()), this, SLOT(coletaNetworkInterfaces())); + QObject::connect(this, SIGNAL(beginOperatingSystem()), this, SLOT(coletaOperatingSystem())); + QObject::connect(this, SIGNAL(beginUser()), this, SLOT(coletaUser())); + QObject::connect(this, SIGNAL(beginHardware()), this, SLOT(coletaHardware())); + QObject::connect(this, SIGNAL(beginSoftware()), this, SLOT(coletaSoftware())); +} + +QJsonObject CColeta::getColeta() const +{ + return coleta; +} CACIC_Computer CColeta::getOComputer() const { return oComputer; } + +void CColeta::run() +{ + if( coleta.contains("computer") ) + emit beginComputer(); + if( coleta.contains("hardware") ) + emit beginHardware(); + if ( coleta.contains("software") ) + emit beginSoftware(); +} + +void CColeta::setColeta(QJsonObject config) +{ + this->coleta = config; +} diff --git a/src/ccoleta.h b/src/ccoleta.h index 9fa6ef6..fe835f6 100644 --- a/src/ccoleta.h +++ b/src/ccoleta.h @@ -1,14 +1,46 @@ #ifndef CCOLETA_H #define CCOLETA_H +#include +#include +#include +#include #include -class CColeta + +class CColeta : public QObject { + Q_OBJECT + private: + QJsonObject coleta; + CACIC_Computer oComputer; + public: - CColeta(); + explicit CColeta(QObject *parent = 0); + + QJsonObject getColeta() const; CACIC_Computer getOComputer() const; + void setColeta(QJsonObject config); + +public slots: + void coletaComputer(); + void coletaHardware(); + void coletaNetworkInterfaces(); + void coletaOperatingSystem(); + void coletaSoftware(); + void coletaUser(); + void configuraColetas(); + void run(); + +signals: + void beginComputer(); + void beginHardware(); + void beginNetworkInterfaces(); + void beginOperatingSystem(); + void beginSoftware(); + void beginUser(); + void finished(); }; #endif // CCOLETA_H -- libgit2 0.21.2