Commit 6f49ab5e05bf7fbce7e3253ee064ae02179fbe19
1 parent
71a28907
Exists in
master
Qtimer
Showing
9 changed files
with
102 additions
and
79 deletions
Show diff stats
cacic-service/cacic-service.pro.user
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <!DOCTYPE QtCreatorProject> | 2 | <!DOCTYPE QtCreatorProject> |
3 | -<!-- Written by QtCreator 3.2.0, 2014-09-02T12:19:07. --> | 3 | +<!-- Written by QtCreator 3.1.2, 2014-09-03T15:17:46. --> |
4 | <qtcreator> | 4 | <qtcreator> |
5 | <data> | 5 | <data> |
6 | - <variable>EnvironmentId</variable> | ||
7 | - <value type="QByteArray">{6923937e-3382-40eb-9eb3-825260fc7246}</value> | ||
8 | - </data> | ||
9 | - <data> | ||
10 | <variable>ProjectExplorer.Project.ActiveTarget</variable> | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
11 | <value type="int">0</value> | 7 | <value type="int">0</value> |
12 | </data> | 8 | </data> |
@@ -58,14 +54,14 @@ | @@ -58,14 +54,14 @@ | ||
58 | <data> | 54 | <data> |
59 | <variable>ProjectExplorer.Project.Target.0</variable> | 55 | <variable>ProjectExplorer.Project.Target.0</variable> |
60 | <valuemap type="QVariantMap"> | 56 | <valuemap type="QVariantMap"> |
61 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> | ||
62 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value> | ||
63 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{ee9c574b-e4fe-4328-9914-eb06b7267a22}</value> | 57 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.3 GCC 64bit</value> |
58 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.3 GCC 64bit</value> | ||
59 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.53.gcc_64_kit</value> | ||
64 | <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> | 60 | <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> |
65 | <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> | 61 | <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> |
66 | <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> | 62 | <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> |
67 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> | 63 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> |
68 | - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/thiroc80/lightbase/build-cacic-service-Desktop-Debug</value> | 64 | + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/lightbase/cacic-agente/build-cacic-service-Desktop_Qt_5_3_GCC_64bit-Debug</value> |
69 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> | 65 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
70 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> | 66 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
71 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> | 67 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
@@ -124,7 +120,7 @@ | @@ -124,7 +120,7 @@ | ||
124 | <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> | 120 | <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> |
125 | </valuemap> | 121 | </valuemap> |
126 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> | 122 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> |
127 | - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/thiroc80/lightbase/build-cacic-service-Desktop-Release</value> | 123 | + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/lightbase/cacic-agente/build-cacic-service-Desktop_Qt_5_3_GCC_64bit-Release</value> |
128 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> | 124 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
129 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> | 125 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
130 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> | 126 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
@@ -236,7 +232,7 @@ | @@ -236,7 +232,7 @@ | ||
236 | <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> | 232 | <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> |
237 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">cacic-service</value> | 233 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">cacic-service</value> |
238 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> | 234 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
239 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/thiroc80/lightbase/cacic-service/cacic-service.pro</value> | 235 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/lightbase/cacic-agente/cacic-service/cacic-service.pro</value> |
240 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> | 236 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> |
241 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">cacic-service.pro</value> | 237 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">cacic-service.pro</value> |
242 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> | 238 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
@@ -257,11 +253,11 @@ | @@ -257,11 +253,11 @@ | ||
257 | <value type="int">1</value> | 253 | <value type="int">1</value> |
258 | </data> | 254 | </data> |
259 | <data> | 255 | <data> |
260 | - <variable>ProjectExplorer.Project.Updater.FileVersion</variable> | ||
261 | - <value type="int">16</value> | 256 | + <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable> |
257 | + <value type="QByteArray">{ece4f619-8231-4029-8d3b-e5858b910820}</value> | ||
262 | </data> | 258 | </data> |
263 | <data> | 259 | <data> |
264 | - <variable>Version</variable> | ||
265 | - <value type="int">16</value> | 260 | + <variable>ProjectExplorer.Project.Updater.FileVersion</variable> |
261 | + <value type="int">15</value> | ||
266 | </data> | 262 | </data> |
267 | </qtcreator> | 263 | </qtcreator> |
cacic-teste/testcacic.cpp
@@ -212,9 +212,6 @@ void CTestCacic::testRemoveRegistry() | @@ -212,9 +212,6 @@ void CTestCacic::testRemoveRegistry() | ||
212 | confirmaTeste.sync(); | 212 | confirmaTeste.sync(); |
213 | } | 213 | } |
214 | 214 | ||
215 | -void CTestCacic::testIniciarDaemon(){ | ||
216 | - | ||
217 | -} | ||
218 | 215 | ||
219 | void CTestCacic::testColetaSoftware() | 216 | void CTestCacic::testColetaSoftware() |
220 | { | 217 | { |
cacic-teste/testcacic.h
@@ -68,7 +68,6 @@ private slots: | @@ -68,7 +68,6 @@ private slots: | ||
68 | void testSetRegistry(); | 68 | void testSetRegistry(); |
69 | void testGetValueFromRegistry(); | 69 | void testGetValueFromRegistry(); |
70 | void testRemoveRegistry(); | 70 | void testRemoveRegistry(); |
71 | - void testIniciarDaemon(); | ||
72 | void testColetaSoftware(); | 71 | void testColetaSoftware(); |
73 | void testColetaHardware(); | 72 | void testColetaHardware(); |
74 | void testConvertDouble(); | 73 | void testConvertDouble(); |
cacicD/cacicD.pro
@@ -22,13 +22,15 @@ SOURCES += main.cpp \ | @@ -22,13 +22,15 @@ SOURCES += main.cpp \ | ||
22 | ../src/ccacic.cpp \ | 22 | ../src/ccacic.cpp \ |
23 | cacicd.cpp \ | 23 | cacicd.cpp \ |
24 | ../src/cacic_computer.cpp \ | 24 | ../src/cacic_computer.cpp \ |
25 | - ../src/operatingsystem.cpp | 25 | + ../src/operatingsystem.cpp \ |
26 | + cacictimer.cpp | ||
26 | 27 | ||
27 | HEADERS += \ | 28 | HEADERS += \ |
28 | ../src/ccacic.h \ | 29 | ../src/ccacic.h \ |
29 | cacicd.h \ | 30 | cacicd.h \ |
30 | ../src/cacic_computer.h \ | 31 | ../src/cacic_computer.h \ |
31 | - ../src/operatingsystem.h | 32 | + ../src/operatingsystem.h \ |
33 | + cacictimer.h | ||
32 | 34 | ||
33 | include(../src/qtservice/src/qtservice.pri) | 35 | include(../src/qtservice/src/qtservice.pri) |
34 | 36 |
cacicD/cacicd.cpp
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv, "CacicD") | 3 | cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv, "CacicD") |
4 | { | 4 | { |
5 | try{ | 5 | try{ |
6 | + OCacicComm = new CacicComm(); | ||
7 | + OCacicTimer = new CacicTimer(); | ||
6 | setServiceDescription("Cacic Daemon"); | 8 | setServiceDescription("Cacic Daemon"); |
7 | setServiceFlags(QtService::Default); | 9 | setServiceFlags(QtService::Default); |
8 | } catch (...){ | 10 | } catch (...){ |
@@ -19,22 +21,15 @@ cacicD::~cacicD() | @@ -19,22 +21,15 @@ cacicD::~cacicD() | ||
19 | } | 21 | } |
20 | } | 22 | } |
21 | 23 | ||
22 | -void cacicD::start() | ||
23 | -{ | 24 | +void cacicD::start() { |
24 | try{ | 25 | try{ |
25 | this->app = application(); | 26 | this->app = application(); |
26 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); | 27 | qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); |
27 | - if(getTest()){ | ||
28 | - qDebug() << "\ngetTest() success."; | ||
29 | - }else{ | ||
30 | - qDebug() << "\ngetTest() error."; | ||
31 | - } | ||
32 | - if(getConfig()){ | ||
33 | - qDebug() << "\ngetconfig() success."; | ||
34 | - }else{ | ||
35 | - qDebug() << "\ngetconfig() error."; | 28 | + QJsonObject result = ccacic->getJsonFromFile(app->applicationDirPath() + "/getConfig.json"); |
29 | + if(!result.contains("error")){ | ||
30 | + OCacicTimer->iniciarTimer(result["codestatus"].toInt()); | ||
36 | } | 31 | } |
37 | - } catch (...){ | 32 | + }catch (...){ |
38 | qCritical() << "Error desconhecido ao iniciar o serviço."; | 33 | qCritical() << "Error desconhecido ao iniciar o serviço."; |
39 | } | 34 | } |
40 | } | 35 | } |
@@ -68,16 +63,20 @@ void cacicD::stop() | @@ -68,16 +63,20 @@ void cacicD::stop() | ||
68 | 63 | ||
69 | bool cacicD::getTest(){ | 64 | bool cacicD::getTest(){ |
70 | try{ | 65 | try{ |
71 | - CacicComm OCacicComm; | ||
72 | - OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); | ||
73 | - OCacicComm.setUsuario("cacic"); | ||
74 | - OCacicComm.setPassword("cacic123"); | 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"); | ||
75 | bool ok; | 70 | bool ok; |
76 | QJsonObject as; | 71 | QJsonObject as; |
77 | as["computador"] = OCacic_Computer.toJsonObject(); | 72 | as["computador"] = OCacic_Computer.toJsonObject(); |
78 | - QJsonObject jsonresult = OCacicComm.comm("/ws/neo/login", &ok, as); | 73 | + QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as); |
74 | + if(jsonresult.contains("error")){ | ||
75 | + return false; | ||
76 | + } | ||
79 | try{ | 77 | try{ |
80 | - saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getTest.conf"); | 78 | + qDebug() << app->applicationDirPath() + "getTest.json"; |
79 | + ccacic->setJsonToFile(jsonresult, app->applicationDirPath() + "/getTest.json"); | ||
81 | return true; | 80 | return true; |
82 | } catch (...) { | 81 | } catch (...) { |
83 | qDebug() << "Erro ao salvar o arquivo de configurações."; | 82 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
@@ -91,16 +90,18 @@ bool cacicD::getTest(){ | @@ -91,16 +90,18 @@ bool cacicD::getTest(){ | ||
91 | 90 | ||
92 | bool cacicD::getConfig(){ | 91 | bool cacicD::getConfig(){ |
93 | try{ | 92 | try{ |
94 | - CacicComm OCacicComm; | ||
95 | - OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); | ||
96 | - OCacicComm.setUsuario("cacic"); | ||
97 | - OCacicComm.setPassword("cacic123"); | 93 | + OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); |
94 | + OCacicComm->setUsuario("cacic"); | ||
95 | + OCacicComm->setPassword("cacic123"); | ||
98 | bool ok; | 96 | bool ok; |
99 | QJsonObject as; | 97 | QJsonObject as; |
100 | as["computador"] = OCacic_Computer.toJsonObject(); | 98 | as["computador"] = OCacic_Computer.toJsonObject(); |
101 | - QJsonObject jsonresult = OCacicComm.comm("/ws/neo/login", &ok, as); | 99 | + QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as); |
100 | + if(jsonresult.contains("error")){ | ||
101 | + return false; | ||
102 | + } | ||
102 | try{ | 103 | try{ |
103 | - saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getConfig.conf"); | 104 | + ccacic->setJsonToFile(jsonresult, app->applicationDirPath() + "/getConfig.json"); |
104 | return true; | 105 | return true; |
105 | } catch (...) { | 106 | } catch (...) { |
106 | qDebug() << "Erro ao salvar o arquivo de configurações."; | 107 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
@@ -112,23 +113,24 @@ bool cacicD::getConfig(){ | @@ -112,23 +113,24 @@ bool cacicD::getConfig(){ | ||
112 | } | 113 | } |
113 | } | 114 | } |
114 | 115 | ||
115 | -void cacicD::saveJson(QJsonDocument document, QString fileName) { | ||
116 | -#if defined(Q_OS_LINUX) | ||
117 | - QFile jsonFile(app->applicationDirPath().append("/" + fileName)); | ||
118 | -#elif defined(Q_OS_WIN) | ||
119 | - QFile jsonFile(app->applicationDirPath().append("\\" + fileName)); | ||
120 | -#endif | ||
121 | - jsonFile.open(QFile::WriteOnly); | ||
122 | - jsonFile.write(document.toJson()); | ||
123 | - jsonFile.close(); | 116 | +void cacicD::registraInicio() |
117 | +{ | ||
118 | + | ||
124 | } | 119 | } |
125 | 120 | ||
126 | -QJsonDocument cacicD::loadJson(QString fileName) { | ||
127 | -#if defined(Q_OS_LINUX) | ||
128 | - QFile jsonFile(app->applicationDirPath().append("/" + fileName)); | ||
129 | -#elif defined(Q_OS_WIN) | ||
130 | - QFile jsonFile(app->applicationDirPath().append("\\" + fileName)); | ||
131 | -#endif | ||
132 | - jsonFile.open(QFile::ReadOnly); | ||
133 | - return QJsonDocument().fromJson(jsonFile.readAll()); | 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 | + } | ||
134 | } | 136 | } |
cacicD/cacicd.h
1 | #ifndef CACICD_H | 1 | #ifndef CACICD_H |
2 | #define CACICD_H | 2 | #define CACICD_H |
3 | - | ||
4 | -#include <QCoreApplication> | ||
5 | -#include <QObject> | ||
6 | -#include <QDebug> | ||
7 | -#include <QDir> | ||
8 | #include <QTextStream> | 3 | #include <QTextStream> |
9 | #include <QVariant> | 4 | #include <QVariant> |
5 | +#include <QCryptographicHash> | ||
6 | +#include <QCoreApplication> | ||
10 | #include "qtservice.h" | 7 | #include "qtservice.h" |
11 | -#include "cacic_comm.h" | ||
12 | -#include "cacic_computer.h" | ||
13 | - | 8 | +#include "cacictimer.h" |
14 | 9 | ||
15 | class cacicD : public QtService<QCoreApplication> | 10 | class cacicD : public QtService<QCoreApplication> |
16 | { | 11 | { |
17 | public: | 12 | public: |
13 | + QCoreApplication *app; | ||
14 | + CCacic *ccacic; | ||
15 | + CACIC_Computer OCacic_Computer; | ||
16 | + CacicComm *OCacicComm; | ||
17 | + CacicTimer *OCacicTimer; | ||
18 | cacicD(int argc, char **argv); | 18 | cacicD(int argc, char **argv); |
19 | ~cacicD(); | 19 | ~cacicD(); |
20 | void start(); | 20 | void start(); |
21 | void pause(); | 21 | void pause(); |
22 | void resume(); | 22 | void resume(); |
23 | void stop(); | 23 | void stop(); |
24 | - QCoreApplication *app; | ||
25 | - void saveJson(QJsonDocument document, QString fileName); | ||
26 | - QJsonDocument loadJson(QString fileName); | ||
27 | 24 | ||
28 | private: | 25 | private: |
29 | - QString testPath; | ||
30 | - QString testIniPath; | ||
31 | - QJsonObject session; | ||
32 | - CACIC_Computer OCacic_Computer; | 26 | + bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); |
27 | + void registraInicio(); | ||
28 | + void registraFim(); | ||
29 | + | ||
30 | +public slots: | ||
33 | bool getTest(); | 31 | bool getTest(); |
34 | bool getConfig(); | 32 | bool getConfig(); |
35 | -}; | ||
36 | 33 | ||
34 | +}; | ||
37 | #endif // CACICD_H | 35 | #endif // CACICD_H |
cacicD/cacictimer.cpp
@@ -2,4 +2,16 @@ | @@ -2,4 +2,16 @@ | ||
2 | 2 | ||
3 | CacicTimer::CacicTimer() | 3 | CacicTimer::CacicTimer() |
4 | { | 4 | { |
5 | + timer = new QTimer(this); | ||
6 | + connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); | ||
7 | +} | ||
8 | + | ||
9 | +void CacicTimer::iniciarTimer(int x) | ||
10 | +{ | ||
11 | + timer->start(x); | ||
12 | +} | ||
13 | + | ||
14 | +void CacicTimer::mslot() | ||
15 | +{ | ||
16 | + qDebug() << "timer executado"; | ||
5 | } | 17 | } |
cacicD/cacictimer.h
1 | #ifndef CACICTIMER_H | 1 | #ifndef CACICTIMER_H |
2 | #define CACICTIMER_H | 2 | #define CACICTIMER_H |
3 | +#include <QtCore> | ||
4 | +#include <QTimer> | ||
5 | +#include <QDebug> | ||
6 | +#include "ccacic.h" | ||
7 | +#include "cacic_comm.h" | ||
8 | +#include "cacic_computer.h" | ||
3 | 9 | ||
4 | -class CacicTimer | 10 | +class CacicTimer : public QObject |
5 | { | 11 | { |
12 | + Q_OBJECT | ||
6 | public: | 13 | public: |
7 | CacicTimer(); | 14 | CacicTimer(); |
15 | + QTimer *timer; | ||
16 | + void iniciarTimer(int x); | ||
17 | + | ||
18 | +signals: | ||
19 | + void getTestSi(); | ||
20 | + void getConfigSi(); | ||
21 | + | ||
22 | +private slots: | ||
23 | + void mslot(); | ||
8 | }; | 24 | }; |
9 | 25 | ||
10 | #endif // CACICTIMER_H | 26 | #endif // CACICTIMER_H |