Commit 88eb252a6fea3867647beb936a638c172b1b294d

Authored by LightBase Consultoria em Software Publico
1 parent e513f2d3
Exists in master

Timer de execução do daemon. Refactoring em outros metodos.

cacic-daemon/cacicD/cacicD.pro
... ... @@ -21,13 +21,14 @@ TEMPLATE = app
21 21 SOURCES += main.cpp \
22 22 ../../src/ccacic.cpp \
23 23 cacicd.cpp \
24   - cacictimer.cpp
  24 + cacictimer.cpp \
25 25 ../../src/cacic_computer.cpp \
26 26 ../../src/operatingsystem.cpp
27 27  
28 28 HEADERS += \
29 29 ../../src/ccacic.h \
30 30 cacicd.h \
  31 + cacictimer.h \
31 32 ../../src/cacic_computer.h \
32 33 ../../src/operatingsystem.h \
33 34 ../../src/cacic_comm.h
... ...
cacic-daemon/cacicD/cacicd.cpp
... ... @@ -3,8 +3,8 @@
3 3 cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv, "CacicD")
4 4 {
5 5 try{
6   - OCacicComm = new CacicComm();
7   - OCacicTimer = new CacicTimer();
  6 + Ocacictimer = new CacicTimer();
  7 + ccacic = new CCacic;
8 8 setServiceDescription("Cacic Daemon");
9 9 setServiceFlags(QtService::Default);
10 10 } catch (...){
... ... @@ -26,9 +26,12 @@ void cacicD::start() {
26 26 this->app = application();
27 27 qDebug() << "\nServiço iniciado em" << app->applicationDirPath();
28 28 QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json");
29   - if(!result.contains("error")){
30   - OCacicTimer->iniciarTimer(result["codestatus"].toInt());
31   - }
  29 + //if(!result.contains("error") && !result.isEmpty()){
  30 + //Ocacictimer->iniciarTimer(result["codestatus"].toInt(), app->applicationDirPath());
  31 + Ocacictimer->iniciarTimer(1000, app->applicationDirPath());
  32 + //}else{
  33 + // qDebug() << "getConfig.json não encontrado.";
  34 + //}
32 35 }catch (...){
33 36 qCritical() << "Error desconhecido ao iniciar o serviço.";
34 37 }
... ... @@ -61,76 +64,4 @@ void cacicD::stop()
61 64 }
62 65 }
63 66  
64   -bool cacicD::getTest(){
65   - try{
66   - qDebug() << app->applicationDirPath() + "getTest.json";
67   - OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php");
68   - OCacicComm->setUsuario("cacic");
69   - OCacicComm->setPassword("cacic123");
70   - bool ok;
71   - QJsonObject as;
72   - as["computador"] = OCacic_Computer.toJsonObject();
73   - QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as);
74   - if(jsonresult.contains("error")){
75   - return false;
76   - }
77   - try{
78   - qDebug() << app->applicationDirPath() + "getTest.json";
79   - ccacic->setJsonToFile(jsonresult, app->applicationDirPath() + "/getTest.json");
80   - return true;
81   - } catch (...) {
82   - qDebug() << "Erro ao salvar o arquivo de configurações.";
83   - return false;
84   - }
85   - } catch (...){
86   - qDebug() << "Erro ao conectar com o servidor.";
87   - return false;
88   - }
89   -}
90   -
91   -bool cacicD::getConfig(){
92   - try{
93   - OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php");
94   - OCacicComm->setUsuario("cacic");
95   - OCacicComm->setPassword("cacic123");
96   - bool ok;
97   - QJsonObject as;
98   - as["computador"] = OCacic_Computer.toJsonObject();
99   - QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as);
100   - if(jsonresult.contains("error")){
101   - return false;
102   - }
103   - try{
104   - ccacic->setJsonToFile(jsonresult, app->applicationDirPath() + "/getConfig.json");
105   - return true;
106   - } catch (...) {
107   - qDebug() << "Erro ao salvar o arquivo de configurações.";
108   - return false;
109   - }
110   - } catch (...){
111   - qDebug() << "Erro ao conectar com o servidor.";
112   - return false;
113   - }
114   -}
115 67  
116   -void cacicD::registraInicio()
117   -{
118   -
119   -}
120   -
121   -void cacicD::registraFim()
122   -{
123   -
124   -}
125   -
126   -bool cacicD::compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig){
127   - QString getconfigMD5 = QString(QCryptographicHash::hash(
128   - (getconfigfile.toVariant().toByteArray()),QCryptographicHash::Md5).toHex());
129   - QString getconfigMD52 = QString(QCryptographicHash::hash(
130   - (getConfig.toVariant().toByteArray()),QCryptographicHash::Md5).toHex());
131   - if(getconfigMD5 == getconfigMD52){
132   - return true;
133   - }else{
134   - return false;
135   - }
136   -}
... ...
cacic-daemon/cacicD/cacicd.h
1 1 #ifndef CACICD_H
2 2 #define CACICD_H
3   -#include <QTextStream>
4   -#include <QVariant>
5   -#include <QCryptographicHash>
  3 +
6 4 #include <QCoreApplication>
7 5 #include "qtservice.h"
8 6 #include "cacictimer.h"
9 7  
  8 +
10 9 class cacicD : public QtService<QCoreApplication>
11 10 {
12 11 public:
13 12 QCoreApplication *app;
  13 + CacicTimer *Ocacictimer;
14 14 CCacic *ccacic;
15   - CACIC_Computer OCacic_Computer;
16   - CacicComm *OCacicComm;
17   - CacicTimer *OCacicTimer;
18 15 cacicD(int argc, char **argv);
19 16 ~cacicD();
20 17 void start();
21 18 void pause();
22 19 void resume();
23 20 void stop();
24   -
25   -private:
26   - bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig);
27   - void registraInicio();
28   - void registraFim();
29   -
30   -public slots:
31   - bool getTest();
32   - bool getConfig();
33   -
34 21 };
35 22 #endif // CACICD_H
... ...
cacic-daemon/cacicD/cacictimer.cpp 0 → 100644
... ... @@ -0,0 +1,112 @@
  1 +#include "cacictimer.h"
  2 +
  3 +CacicTimer::CacicTimer()
  4 +{
  5 + OCacicComm = new CacicComm();
  6 + ccacic = new CCacic();
  7 + timer = new QTimer(this);
  8 + connect(timer,SIGNAL(timeout()),this,SLOT(mslot()));
  9 +}
  10 +
  11 +void CacicTimer::iniciarTimer(int x, QString applicationDirPath)
  12 +{
  13 + setApplicationDirPath(applicationDirPath);
  14 + timer->start(x);
  15 +}
  16 +
  17 +void CacicTimer::mslot(){
  18 + if(getTest()){
  19 + qDebug() << "getTest() success. - " + QDateTime::currentDateTime().toLocalTime().toString();
  20 + if(getConfig()){
  21 + qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString();
  22 +
  23 + //aqui irá abrir o semaforo e iniciar a coleta.
  24 +
  25 + }else{
  26 + qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString();
  27 + }
  28 + }else{
  29 + qDebug() << "getTest() failed. - " + QDateTime::currentDateTime().toLocalTime().toString();
  30 + }
  31 +}
  32 +
  33 +bool CacicTimer::getTest(){
  34 + try{
  35 + OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php");
  36 + OCacicComm->setUsuario("cacic");
  37 + OCacicComm->setPassword("cacic123");
  38 + bool ok;
  39 + QJsonObject as;
  40 + as["computador"] = OCacic_Computer.toJsonObject();
  41 + QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as);
  42 + if(jsonresult.contains("error")){
  43 + return false;
  44 + }
  45 + try{
  46 + ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getTest.json");
  47 + return true;
  48 + } catch (...) {
  49 + qDebug() << "Erro ao salvar o arquivo de configurações.";
  50 + return false;
  51 + }
  52 + } catch (...){
  53 + qDebug() << "Erro ao conectar com o servidor.";
  54 + return false;
  55 + }
  56 +}
  57 +
  58 +bool CacicTimer::getConfig(){
  59 + try{
  60 + OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php");
  61 + OCacicComm->setUsuario("cacic");
  62 + OCacicComm->setPassword("cacic123");
  63 + bool ok;
  64 + QJsonObject as;
  65 + as["computador"] = OCacic_Computer.toJsonObject();
  66 + QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as);
  67 + if(jsonresult.contains("error")){
  68 + return false;
  69 + }
  70 + try{
  71 + ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getConfig.json");
  72 + return true;
  73 + } catch (...) {
  74 + qDebug() << "Erro ao salvar o arquivo de configurações.";
  75 + return false;
  76 + }
  77 + } catch (...){
  78 + qDebug() << "Erro ao conectar com o servidor.";
  79 + return false;
  80 + }
  81 +}
  82 +
  83 +void CacicTimer::registraInicio()
  84 +{
  85 +}
  86 +
  87 +QString CacicTimer::getApplicationDirPath() const
  88 +{
  89 + return applicationDirPath;
  90 +}
  91 +
  92 +void CacicTimer::setApplicationDirPath(const QString &value)
  93 +{
  94 + applicationDirPath = value;
  95 +}
  96 +
  97 +
  98 +void CacicTimer::registraFim()
  99 +{
  100 +}
  101 +
  102 +bool CacicTimer::compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig){
  103 + QString getconfigMD5 = QString(QCryptographicHash::hash(
  104 + (getconfigfile.toVariant().toByteArray()),QCryptographicHash::Md5).toHex());
  105 + QString getconfigMD52 = QString(QCryptographicHash::hash(
  106 + (getConfig.toVariant().toByteArray()),QCryptographicHash::Md5).toHex());
  107 + if(getconfigMD5 == getconfigMD52){
  108 + return true;
  109 + }else{
  110 + return false;
  111 + }
  112 +}
... ...
cacic-daemon/cacicD/cacictimer.h 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +#ifndef CACICTIMER_H
  2 +#define CACICTIMER_H
  3 +#include <QtCore>
  4 +#include <QTimer>
  5 +#include <QDebug>
  6 +#include <QDir>
  7 +#include <QDateTime>
  8 +#include "ccacic.h"
  9 +#include "cacic_comm.h"
  10 +#include "cacic_computer.h"
  11 +
  12 +class CacicTimer : public QObject
  13 +{
  14 + Q_OBJECT
  15 +public:
  16 + CacicTimer();
  17 + QTimer *timer;
  18 + CacicComm *OCacicComm;
  19 + CACIC_Computer OCacic_Computer;
  20 + CCacic *ccacic;
  21 + void iniciarTimer(int x, QString applicationDirPath);
  22 + bool getTest();
  23 + bool getConfig();
  24 + bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig);
  25 + QString getApplicationDirPath() const;
  26 + void setApplicationDirPath(const QString &value);
  27 +
  28 +private:
  29 + void registraFim();
  30 + void registraInicio();
  31 + QString applicationDirPath;
  32 +
  33 +private slots:
  34 + void mslot();
  35 +};
  36 +
  37 +#endif // CACICTIMER_H
... ...