diff --git a/cacic-daemon/cacicD/cacicD.pro b/cacic-daemon/cacicD/cacicD.pro index f478ca4..eadb77e 100644 --- a/cacic-daemon/cacicD/cacicD.pro +++ b/cacic-daemon/cacicD/cacicD.pro @@ -21,13 +21,14 @@ TEMPLATE = app SOURCES += main.cpp \ ../../src/ccacic.cpp \ cacicd.cpp \ - cacictimer.cpp + cacictimer.cpp \ ../../src/cacic_computer.cpp \ ../../src/operatingsystem.cpp HEADERS += \ ../../src/ccacic.h \ cacicd.h \ + cacictimer.h \ ../../src/cacic_computer.h \ ../../src/operatingsystem.h \ ../../src/cacic_comm.h diff --git a/cacic-daemon/cacicD/cacicd.cpp b/cacic-daemon/cacicD/cacicd.cpp index 33a8e33..fdc20ec 100644 --- a/cacic-daemon/cacicD/cacicd.cpp +++ b/cacic-daemon/cacicD/cacicd.cpp @@ -3,8 +3,8 @@ cacicD::cacicD(int argc, char **argv) : QtService(argc, argv, "CacicD") { try{ - OCacicComm = new CacicComm(); - OCacicTimer = new CacicTimer(); + Ocacictimer = new CacicTimer(); + ccacic = new CCacic; setServiceDescription("Cacic Daemon"); setServiceFlags(QtService::Default); } catch (...){ @@ -26,9 +26,12 @@ 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")){ - OCacicTimer->iniciarTimer(result["codestatus"].toInt()); - } + //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."; + //} }catch (...){ qCritical() << "Error desconhecido ao iniciar o serviço."; } @@ -61,76 +64,4 @@ void cacicD::stop() } } -bool cacicD::getTest(){ - try{ - qDebug() << app->applicationDirPath() + "getTest.json"; - 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{ - qDebug() << app->applicationDirPath() + "getTest.json"; - ccacic->setJsonToFile(jsonresult, app->applicationDirPath() + "/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 cacicD::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, app->applicationDirPath() + "/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 cacicD::registraInicio() -{ - -} - -void cacicD::registraFim() -{ - -} - -bool cacicD::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/cacicd.h b/cacic-daemon/cacicD/cacicd.h index 27d3500..f0c1890 100644 --- a/cacic-daemon/cacicD/cacicd.h +++ b/cacic-daemon/cacicD/cacicd.h @@ -1,35 +1,22 @@ #ifndef CACICD_H #define CACICD_H -#include -#include -#include + #include #include "qtservice.h" #include "cacictimer.h" + class cacicD : public QtService { public: QCoreApplication *app; + CacicTimer *Ocacictimer; CCacic *ccacic; - CACIC_Computer OCacic_Computer; - CacicComm *OCacicComm; - CacicTimer *OCacicTimer; cacicD(int argc, char **argv); ~cacicD(); void start(); void pause(); void resume(); void stop(); - -private: - bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); - void registraInicio(); - void registraFim(); - -public slots: - bool getTest(); - bool getConfig(); - }; #endif // CACICD_H diff --git a/cacic-daemon/cacicD/cacictimer.cpp b/cacic-daemon/cacicD/cacictimer.cpp new file mode 100644 index 0000000..74e8bfd --- /dev/null +++ b/cacic-daemon/cacicD/cacictimer.cpp @@ -0,0 +1,112 @@ +#include "cacictimer.h" + +CacicTimer::CacicTimer() +{ + OCacicComm = new CacicComm(); + ccacic = new CCacic(); + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); +} + +void CacicTimer::iniciarTimer(int x, QString applicationDirPath) +{ + setApplicationDirPath(applicationDirPath); + timer->start(x); +} + +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() +{ +} + +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 new file mode 100644 index 0000000..a02a59f --- /dev/null +++ b/cacic-daemon/cacicD/cacictimer.h @@ -0,0 +1,37 @@ +#ifndef CACICTIMER_H +#define CACICTIMER_H +#include +#include +#include +#include +#include +#include "ccacic.h" +#include "cacic_comm.h" +#include "cacic_computer.h" + +class CacicTimer : public QObject +{ + Q_OBJECT +public: + CacicTimer(); + QTimer *timer; + 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); + +private: + void registraFim(); + void registraInicio(); + QString applicationDirPath; + +private slots: + void mslot(); +}; + +#endif // CACICTIMER_H -- libgit2 0.21.2