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 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | 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 | 4 | <qtcreator> |
5 | 5 | <data> |
6 | - <variable>EnvironmentId</variable> | |
7 | - <value type="QByteArray">{6923937e-3382-40eb-9eb3-825260fc7246}</value> | |
8 | - </data> | |
9 | - <data> | |
10 | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
11 | 7 | <value type="int">0</value> |
12 | 8 | </data> |
... | ... | @@ -58,14 +54,14 @@ |
58 | 54 | <data> |
59 | 55 | <variable>ProjectExplorer.Project.Target.0</variable> |
60 | 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 | 60 | <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> |
65 | 61 | <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> |
66 | 62 | <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> |
67 | 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 | 65 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
70 | 66 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
71 | 67 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
... | ... | @@ -124,7 +120,7 @@ |
124 | 120 | <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> |
125 | 121 | </valuemap> |
126 | 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 | 124 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
129 | 125 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
130 | 126 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
... | ... | @@ -236,7 +232,7 @@ |
236 | 232 | <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> |
237 | 233 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">cacic-service</value> |
238 | 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 | 236 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> |
241 | 237 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">cacic-service.pro</value> |
242 | 238 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
... | ... | @@ -257,11 +253,11 @@ |
257 | 253 | <value type="int">1</value> |
258 | 254 | </data> |
259 | 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 | 258 | </data> |
263 | 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 | 262 | </data> |
267 | 263 | </qtcreator> | ... | ... |
cacic-teste/testcacic.cpp
cacic-teste/testcacic.h
cacicD/cacicD.pro
... | ... | @@ -22,13 +22,15 @@ SOURCES += main.cpp \ |
22 | 22 | ../src/ccacic.cpp \ |
23 | 23 | cacicd.cpp \ |
24 | 24 | ../src/cacic_computer.cpp \ |
25 | - ../src/operatingsystem.cpp | |
25 | + ../src/operatingsystem.cpp \ | |
26 | + cacictimer.cpp | |
26 | 27 | |
27 | 28 | HEADERS += \ |
28 | 29 | ../src/ccacic.h \ |
29 | 30 | cacicd.h \ |
30 | 31 | ../src/cacic_computer.h \ |
31 | - ../src/operatingsystem.h | |
32 | + ../src/operatingsystem.h \ | |
33 | + cacictimer.h | |
32 | 34 | |
33 | 35 | include(../src/qtservice/src/qtservice.pri) |
34 | 36 | ... | ... |
cacicD/cacicd.cpp
... | ... | @@ -3,6 +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 | 8 | setServiceDescription("Cacic Daemon"); |
7 | 9 | setServiceFlags(QtService::Default); |
8 | 10 | } catch (...){ |
... | ... | @@ -19,22 +21,15 @@ cacicD::~cacicD() |
19 | 21 | } |
20 | 22 | } |
21 | 23 | |
22 | -void cacicD::start() | |
23 | -{ | |
24 | +void cacicD::start() { | |
24 | 25 | try{ |
25 | 26 | this->app = application(); |
26 | 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 | 33 | qCritical() << "Error desconhecido ao iniciar o serviço."; |
39 | 34 | } |
40 | 35 | } |
... | ... | @@ -68,16 +63,20 @@ void cacicD::stop() |
68 | 63 | |
69 | 64 | bool cacicD::getTest(){ |
70 | 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 | 70 | bool ok; |
76 | 71 | QJsonObject as; |
77 | 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 | 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 | 80 | return true; |
82 | 81 | } catch (...) { |
83 | 82 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
... | ... | @@ -91,16 +90,18 @@ bool cacicD::getTest(){ |
91 | 90 | |
92 | 91 | bool cacicD::getConfig(){ |
93 | 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 | 96 | bool ok; |
99 | 97 | QJsonObject as; |
100 | 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 | 103 | try{ |
103 | - saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getConfig.conf"); | |
104 | + ccacic->setJsonToFile(jsonresult, app->applicationDirPath() + "/getConfig.json"); | |
104 | 105 | return true; |
105 | 106 | } catch (...) { |
106 | 107 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
... | ... | @@ -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 | 1 | #ifndef CACICD_H |
2 | 2 | #define CACICD_H |
3 | - | |
4 | -#include <QCoreApplication> | |
5 | -#include <QObject> | |
6 | -#include <QDebug> | |
7 | -#include <QDir> | |
8 | 3 | #include <QTextStream> |
9 | 4 | #include <QVariant> |
5 | +#include <QCryptographicHash> | |
6 | +#include <QCoreApplication> | |
10 | 7 | #include "qtservice.h" |
11 | -#include "cacic_comm.h" | |
12 | -#include "cacic_computer.h" | |
13 | - | |
8 | +#include "cacictimer.h" | |
14 | 9 | |
15 | 10 | class cacicD : public QtService<QCoreApplication> |
16 | 11 | { |
17 | 12 | public: |
13 | + QCoreApplication *app; | |
14 | + CCacic *ccacic; | |
15 | + CACIC_Computer OCacic_Computer; | |
16 | + CacicComm *OCacicComm; | |
17 | + CacicTimer *OCacicTimer; | |
18 | 18 | cacicD(int argc, char **argv); |
19 | 19 | ~cacicD(); |
20 | 20 | void start(); |
21 | 21 | void pause(); |
22 | 22 | void resume(); |
23 | 23 | void stop(); |
24 | - QCoreApplication *app; | |
25 | - void saveJson(QJsonDocument document, QString fileName); | |
26 | - QJsonDocument loadJson(QString fileName); | |
27 | 24 | |
28 | 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 | 31 | bool getTest(); |
34 | 32 | bool getConfig(); |
35 | -}; | |
36 | 33 | |
34 | +}; | |
37 | 35 | #endif // CACICD_H | ... | ... |
cacicD/cacictimer.cpp
... | ... | @@ -2,4 +2,16 @@ |
2 | 2 | |
3 | 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 | 1 | #ifndef CACICTIMER_H |
2 | 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 | 13 | public: |
7 | 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 | 26 | #endif // CACICTIMER_H | ... | ... |