Commit 77f3226ecd53628f79fdd2b5d0b8602336970437
1 parent
f6fa4d47
Exists in
master
Serviço ler parametros de inicialização e realiza getTest() e getconfig() de acordo com eles.
Showing
4 changed files
with
120 additions
and
14 deletions
Show diff stats
cacic-daemon/cacicD/cacicD.pro
@@ -7,12 +7,13 @@ | @@ -7,12 +7,13 @@ | ||
7 | QT += core | 7 | QT += core |
8 | QT -= gui | 8 | QT -= gui |
9 | QT += network | 9 | QT += network |
10 | -QT += axcontainer | 10 | + |
11 | TARGET = cacic-service | 11 | TARGET = cacic-service |
12 | CONFIG += console | 12 | CONFIG += console |
13 | CONFIG -= app_bundle | 13 | CONFIG -= app_bundle |
14 | win32 { | 14 | win32 { |
15 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | 15 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp |
16 | + QT += axcontainer | ||
16 | } else { | 17 | } else { |
17 | LIBS += -L/usr/lib -lcryptopp | 18 | LIBS += -L/usr/lib -lcryptopp |
18 | } | 19 | } |
cacic-daemon/cacicD/cacicd.cpp
@@ -26,12 +26,11 @@ void cacicD::start() { | @@ -26,12 +26,11 @@ void cacicD::start() { | ||
26 | this->app = application(); | 26 | this->app = application(); |
27 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); | 27 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); |
28 | QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); | 28 | QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); |
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 | - //} | 29 | + if(!result.contains("error") && !result.isEmpty()){ |
30 | + Ocacictimer->iniciarTimer(result["codestatus"].toInt(), app->applicationDirPath()); | ||
31 | + }else{ | ||
32 | + qDebug() << "getConfig.json não encontrado."; | ||
33 | + } | ||
35 | }catch (...){ | 34 | }catch (...){ |
36 | qCritical() << "Error desconhecido ao iniciar o serviço."; | 35 | qCritical() << "Error desconhecido ao iniciar o serviço."; |
37 | } | 36 | } |
cacic-daemon/cacicD/cacictimer.cpp
@@ -2,16 +2,111 @@ | @@ -2,16 +2,111 @@ | ||
2 | 2 | ||
3 | CacicTimer::CacicTimer() | 3 | CacicTimer::CacicTimer() |
4 | { | 4 | { |
5 | + OCacicComm = new CacicComm(); | ||
6 | + ccacic = new CCacic(); | ||
5 | timer = new QTimer(this); | 7 | timer = new QTimer(this); |
6 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); | 8 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); |
7 | } | 9 | } |
8 | 10 | ||
9 | -void CacicTimer::iniciarTimer(int x) | 11 | +void CacicTimer::iniciarTimer(int x, QString applicationDirPath) |
10 | { | 12 | { |
13 | + setApplicationDirPath(applicationDirPath); | ||
11 | timer->start(x); | 14 | timer->start(x); |
12 | } | 15 | } |
13 | 16 | ||
14 | -void CacicTimer::mslot() | 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() | ||
15 | { | 99 | { |
16 | - qDebug() << "timer executado"; | 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 | + } | ||
17 | } | 112 | } |
cacic-daemon/cacicD/cacictimer.h
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | #include <QtCore> | 3 | #include <QtCore> |
4 | #include <QTimer> | 4 | #include <QTimer> |
5 | #include <QDebug> | 5 | #include <QDebug> |
6 | +#include <QDir> | ||
7 | +#include <QDateTime> | ||
6 | #include "ccacic.h" | 8 | #include "ccacic.h" |
7 | #include "cacic_comm.h" | 9 | #include "cacic_comm.h" |
8 | #include "cacic_computer.h" | 10 | #include "cacic_computer.h" |
@@ -13,11 +15,20 @@ class CacicTimer : public QObject | @@ -13,11 +15,20 @@ class CacicTimer : public QObject | ||
13 | public: | 15 | public: |
14 | CacicTimer(); | 16 | CacicTimer(); |
15 | QTimer *timer; | 17 | QTimer *timer; |
16 | - void iniciarTimer(int x); | 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); | ||
17 | 27 | ||
18 | -signals: | ||
19 | - void getTestSi(); | ||
20 | - void getConfigSi(); | 28 | +private: |
29 | + void registraFim(); | ||
30 | + void registraInicio(); | ||
31 | + QString applicationDirPath; | ||
21 | 32 | ||
22 | private slots: | 33 | private slots: |
23 | void mslot(); | 34 | void mslot(); |