From 77f3226ecd53628f79fdd2b5d0b8602336970437 Mon Sep 17 00:00:00 2001 From: LightBase Consultoria em Software Publico Date: Tue, 9 Sep 2014 12:08:15 -0300 Subject: [PATCH] Serviço ler parametros de inicialização e realiza getTest() e getconfig() de acordo com eles. --- cacic-daemon/cacicD/cacicD.pro | 3 ++- cacic-daemon/cacicD/cacicd.cpp | 11 +++++------ cacic-daemon/cacicD/cacictimer.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- cacic-daemon/cacicD/cacictimer.h | 19 +++++++++++++++---- 4 files changed, 120 insertions(+), 14 deletions(-) diff --git a/cacic-daemon/cacicD/cacicD.pro b/cacic-daemon/cacicD/cacicD.pro index 85832be..c1a7c70 100644 --- a/cacic-daemon/cacicD/cacicD.pro +++ b/cacic-daemon/cacicD/cacicD.pro @@ -7,12 +7,13 @@ QT += core QT -= gui QT += network -QT += axcontainer + TARGET = cacic-service CONFIG += console CONFIG -= app_bundle win32 { LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp + QT += axcontainer } else { LIBS += -L/usr/lib -lcryptopp } diff --git a/cacic-daemon/cacicD/cacicd.cpp b/cacic-daemon/cacicD/cacicd.cpp index fdc20ec..871eff3 100644 --- a/cacic-daemon/cacicD/cacicd.cpp +++ b/cacic-daemon/cacicD/cacicd.cpp @@ -26,12 +26,11 @@ void cacicD::start() { this->app = application(); qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); - //if(!result.contains("error") && !result.isEmpty()){ - //Ocacictimer->iniciarTimer(result["codestatus"].toInt(), app->applicationDirPath()); - Ocacictimer->iniciarTimer(1000, app->applicationDirPath()); - //}else{ - // qDebug() << "getConfig.json não encontrado."; - //} + if(!result.contains("error") && !result.isEmpty()){ + Ocacictimer->iniciarTimer(result["codestatus"].toInt(), app->applicationDirPath()); + }else{ + qDebug() << "getConfig.json não encontrado."; + } }catch (...){ qCritical() << "Error desconhecido ao iniciar o serviço."; } diff --git a/cacic-daemon/cacicD/cacictimer.cpp b/cacic-daemon/cacicD/cacictimer.cpp index 93a8df1..74e8bfd 100644 --- a/cacic-daemon/cacicD/cacictimer.cpp +++ b/cacic-daemon/cacicD/cacictimer.cpp @@ -2,16 +2,111 @@ CacicTimer::CacicTimer() { + OCacicComm = new CacicComm(); + ccacic = new CCacic(); timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); } -void CacicTimer::iniciarTimer(int x) +void CacicTimer::iniciarTimer(int x, QString applicationDirPath) { + setApplicationDirPath(applicationDirPath); timer->start(x); } -void CacicTimer::mslot() +void CacicTimer::mslot(){ + if(getTest()){ + qDebug() << "getTest() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); + if(getConfig()){ + qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); + + //aqui irá abrir o semaforo e iniciar a coleta. + + }else{ + qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); + } + }else{ + qDebug() << "getTest() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); + } +} + +bool CacicTimer::getTest(){ + try{ + OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); + OCacicComm->setUsuario("cacic"); + OCacicComm->setPassword("cacic123"); + bool ok; + QJsonObject as; + as["computador"] = OCacic_Computer.toJsonObject(); + QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as); + if(jsonresult.contains("error")){ + return false; + } + try{ + ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getTest.json"); + return true; + } catch (...) { + qDebug() << "Erro ao salvar o arquivo de configurações."; + return false; + } + } catch (...){ + qDebug() << "Erro ao conectar com o servidor."; + return false; + } +} + +bool CacicTimer::getConfig(){ + try{ + OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); + OCacicComm->setUsuario("cacic"); + OCacicComm->setPassword("cacic123"); + bool ok; + QJsonObject as; + as["computador"] = OCacic_Computer.toJsonObject(); + QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as); + if(jsonresult.contains("error")){ + return false; + } + try{ + ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getConfig.json"); + return true; + } catch (...) { + qDebug() << "Erro ao salvar o arquivo de configurações."; + return false; + } + } catch (...){ + qDebug() << "Erro ao conectar com o servidor."; + return false; + } +} + +void CacicTimer::registraInicio() +{ +} + +QString CacicTimer::getApplicationDirPath() const +{ + return applicationDirPath; +} + +void CacicTimer::setApplicationDirPath(const QString &value) +{ + applicationDirPath = value; +} + + +void CacicTimer::registraFim() { - qDebug() << "timer executado"; +} + +bool CacicTimer::compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig){ + QString getconfigMD5 = QString(QCryptographicHash::hash( + (getconfigfile.toVariant().toByteArray()),QCryptographicHash::Md5).toHex()); + QString getconfigMD52 = QString(QCryptographicHash::hash( + (getConfig.toVariant().toByteArray()),QCryptographicHash::Md5).toHex()); + if(getconfigMD5 == getconfigMD52){ + return true; + }else{ + return false; + } } diff --git a/cacic-daemon/cacicD/cacictimer.h b/cacic-daemon/cacicD/cacictimer.h index 8c380fc..a02a59f 100644 --- a/cacic-daemon/cacicD/cacictimer.h +++ b/cacic-daemon/cacicD/cacictimer.h @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "ccacic.h" #include "cacic_comm.h" #include "cacic_computer.h" @@ -13,11 +15,20 @@ class CacicTimer : public QObject public: CacicTimer(); QTimer *timer; - void iniciarTimer(int x); + CacicComm *OCacicComm; + CACIC_Computer OCacic_Computer; + CCacic *ccacic; + void iniciarTimer(int x, QString applicationDirPath); + bool getTest(); + bool getConfig(); + bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); + QString getApplicationDirPath() const; + void setApplicationDirPath(const QString &value); -signals: - void getTestSi(); - void getConfigSi(); +private: + void registraFim(); + void registraInicio(); + QString applicationDirPath; private slots: void mslot(); -- libgit2 0.21.2