Commit 6cdb3e6b40629d08d9100986c42d5e662f45241e
1 parent
23179c20
Exists in
master
Implementação do semáforo e chamada do gercols.
Showing
5 changed files
with
86 additions
and
55 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
... | ... | @@ -5,7 +5,7 @@ cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv, |
5 | 5 | try{ |
6 | 6 | this->createApplication(argc, argv); |
7 | 7 | |
8 | - Ocacictimer = new CacicTimer(); | |
8 | + Ocacictimer = new CacicTimer(application()->applicationDirPath()); | |
9 | 9 | ccacic = new CCacic; |
10 | 10 | setServiceDescription("Cacic Daemon"); |
11 | 11 | setServiceFlags(QtService::Default); |
... | ... | @@ -31,18 +31,15 @@ cacicD::~cacicD() |
31 | 31 | void cacicD::start() { |
32 | 32 | try{ |
33 | 33 | qDebug() << "Inicio do daemon"; |
34 | - | |
35 | 34 | qDebug() << "\nServiço iniciado em" << application()->applicationDirPath(); |
36 | 35 | QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); |
37 | - | |
38 | - QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); | |
36 | + QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath().append("/getConfig.json")); | |
39 | 37 | if(!result.contains("error") && !result.isEmpty()){ |
40 | - Ocacictimer->iniciarTimer(result["codestatus"].toInt(), application()->applicationDirPath()); | |
38 | + Ocacictimer->iniciarTimer(result["codestatus"].toInt()); | |
41 | 39 | }else{ |
42 | 40 | qDebug() << "getConfig.json não encontrado."; |
43 | 41 | } |
44 | - | |
45 | - QLogger::QLog_Info("Cacic Daemon", "Serviço finalizado."); | |
42 | + //QLogger::QLog_Info("Cacic Daemon", "Serviço finalizado."); | |
46 | 43 | }catch (...){ |
47 | 44 | qCritical() << "Error desconhecido ao iniciar o serviço."; |
48 | 45 | } | ... | ... |
cacic-daemon/cacicD/cacicthread.cpp
cacic-daemon/cacicD/cacicthread.h
... | ... | @@ -1,18 +0,0 @@ |
1 | -#ifndef CACICTHREAD_H | |
2 | -#define CACICTHREAD_H | |
3 | - | |
4 | -#include <QThread> | |
5 | - | |
6 | -class CacicThread : public QThread | |
7 | -{ | |
8 | - Q_OBJECT | |
9 | -public: | |
10 | - explicit CacicThread(QObject *parent = 0); | |
11 | - | |
12 | -signals: | |
13 | - | |
14 | -public slots: | |
15 | - | |
16 | -}; | |
17 | - | |
18 | -#endif // CACICTHREAD_H |
cacic-daemon/cacicD/cacictimer.cpp
1 | 1 | #include "cacictimer.h" |
2 | 2 | |
3 | -CacicTimer::CacicTimer() | |
3 | +CacicTimer::CacicTimer(QString dirpath) | |
4 | 4 | { |
5 | - OCacicComm = new CacicComm(); | |
6 | - ccacic = new CCacic(); | |
7 | - timer = new QTimer(this); | |
8 | - //manager = QLogger::QLoggerManager::getInstance(); | |
9 | - //manager->addDestination("cacicLog.txt", QStringList("CacicD"), QLogger::LogLevel); | |
5 | + qDebug() << "iniciou o constructor"; | |
6 | + definirDirGercols(dirpath); | |
7 | + setApplicationDirPath(dirpath); | |
8 | + iniciarInstancias(); | |
10 | 9 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); |
11 | 10 | } |
12 | 11 | |
13 | -void CacicTimer::iniciarTimer(int x, QString applicationDirPath) | |
12 | +void CacicTimer::iniciarTimer(int x) | |
14 | 13 | { |
15 | - setApplicationDirPath(applicationDirPath); | |
16 | 14 | timer->start(x); |
17 | 15 | } |
18 | 16 | |
19 | 17 | void CacicTimer::mslot(){ |
18 | + cMutex->lock(); | |
20 | 19 | if(getTest()){ |
21 | - //manager->QLogger::QLog_Trace("ModuleName", "Message: "); | |
22 | 20 | if(getConfig()){ |
23 | - qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
24 | - | |
25 | - //aqui irá abrir o semaforo e iniciar a coleta. | |
26 | - | |
21 | + QLogger::QLog_Info("Cacic Timer", QString("semáforo fechado.")); | |
22 | + iniciarGercols(); | |
23 | + cMutex->unlock(); | |
24 | + QLogger::QLog_Info("Cacic Timer", QString("semáforo aberto.")); | |
27 | 25 | }else{ |
28 | 26 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
29 | 27 | } |
... | ... | @@ -41,9 +39,9 @@ bool CacicTimer::getTest(){ |
41 | 39 | QJsonObject as; |
42 | 40 | as["computador"] = OCacic_Computer.toJsonObject(); |
43 | 41 | QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as); |
44 | - if(jsonresult.contains("error")){ | |
45 | - return false; | |
46 | - } | |
42 | + // if(jsonresult.contains("error")){ | |
43 | + // return false; | |
44 | + // } | |
47 | 45 | try{ |
48 | 46 | ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getTest.json"); |
49 | 47 | return true; |
... | ... | @@ -66,9 +64,9 @@ bool CacicTimer::getConfig(){ |
66 | 64 | QJsonObject as; |
67 | 65 | as["computador"] = OCacic_Computer.toJsonObject(); |
68 | 66 | QJsonObject jsonresult = OCacicComm->comm("/ws/neo/login", &ok, as); |
69 | - if(jsonresult.contains("error")){ | |
70 | - return false; | |
71 | - } | |
67 | + // if(jsonresult.contains("error")){ | |
68 | + // return false; | |
69 | + // } | |
72 | 70 | try{ |
73 | 71 | ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getConfig.json"); |
74 | 72 | return true; |
... | ... | @@ -86,14 +84,45 @@ void CacicTimer::registraInicio() |
86 | 84 | { |
87 | 85 | } |
88 | 86 | |
87 | +QString CacicTimer::getDirProgram() const | |
88 | +{ | |
89 | + return dirProgram; | |
90 | +} | |
91 | + | |
89 | 92 | QString CacicTimer::getApplicationDirPath() const |
90 | 93 | { |
91 | 94 | return applicationDirPath; |
92 | 95 | } |
93 | 96 | |
97 | +void CacicTimer::setDirProgram(const QString &value) | |
98 | +{ | |
99 | + dirProgram = value; | |
100 | +} | |
101 | + | |
102 | + | |
103 | +void CacicTimer::iniciarGercols() | |
104 | +{ | |
105 | + | |
106 | + QProcess proc; | |
107 | + proc.children(); | |
108 | + proc.execute(getDirProgram()); | |
109 | + if(proc.atEnd()){ | |
110 | + | |
111 | + } | |
112 | + // QString retorno = ccacic->startProcess(getDirProgram(),true,ok); | |
113 | + // qDebug() << retorno; | |
114 | + QLogger::QLog_Info("Cacic Timer","processo finalizado."); | |
115 | + // if (myProcess.waitForFinished(-1)){ | |
116 | + // qDebug() << "erro:" << myProcess.errorString(); | |
117 | + // }else{ | |
118 | + // qDebug() << "não deu erro:" << myProcess.readAll(); | |
119 | + // QLogger::QLog_Info("Cacic Timer","processo está aberto."); | |
120 | + // } | |
121 | +} | |
122 | + | |
94 | 123 | void CacicTimer::setApplicationDirPath(const QString &value) |
95 | 124 | { |
96 | - applicationDirPath = value; | |
125 | + this->applicationDirPath = value; | |
97 | 126 | } |
98 | 127 | |
99 | 128 | |
... | ... | @@ -112,3 +141,22 @@ bool CacicTimer::compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getCo |
112 | 141 | return false; |
113 | 142 | } |
114 | 143 | } |
144 | + | |
145 | +void CacicTimer::iniciarInstancias(){ | |
146 | + logManager = QLogger::QLoggerManager::getInstance(); | |
147 | + logManager->addDestination(getApplicationDirPath().append("/log.txt"),"Cacic Timer",QLogger::InfoLevel); | |
148 | + logManager->addDestination(getApplicationDirPath().append("/log.txt"),"Cacic Timer",QLogger::ErrorLevel); | |
149 | + OCacicComm = new CacicComm(); | |
150 | + ccacic = new CCacic(); | |
151 | + timer = new QTimer(this); | |
152 | + cMutex = new QMutex(QMutex::Recursive); | |
153 | + QLogger::QLog_Info("Cacic Timer", QString("terminou as instancias")); | |
154 | +} | |
155 | + | |
156 | +void CacicTimer::definirDirGercols(QString applicationDirPath){ | |
157 | +#if defined (Q_OS_WIN) | |
158 | + setDirProgram(applicationDirPath.append("\cacic-gercols.exe")); | |
159 | +#elif defined (Q_OS_LINUX) | |
160 | + setDirProgram(applicationDirPath.append("/cacic-gercols")); | |
161 | +#endif | |
162 | +} | ... | ... |
cacic-daemon/cacicD/cacictimer.h
... | ... | @@ -5,6 +5,8 @@ |
5 | 5 | #include <QDebug> |
6 | 6 | #include <QDir> |
7 | 7 | #include <QDateTime> |
8 | +#include <QMutex> | |
9 | +#include <QProcess> | |
8 | 10 | #include "ccacic.h" |
9 | 11 | #include "cacic_comm.h" |
10 | 12 | #include "cacic_computer.h" |
... | ... | @@ -14,23 +16,31 @@ class CacicTimer : public QObject |
14 | 16 | { |
15 | 17 | Q_OBJECT |
16 | 18 | public: |
17 | - CacicTimer(); | |
19 | + CacicTimer(QString dirpath); | |
18 | 20 | QTimer *timer; |
19 | 21 | CacicComm *OCacicComm; |
20 | 22 | CACIC_Computer OCacic_Computer; |
21 | 23 | CCacic *ccacic; |
22 | - //QLogger::QLoggerManager *manager; | |
23 | - void iniciarTimer(int x, QString applicationDirPath); | |
24 | + QMutex *cMutex; | |
25 | + void iniciarTimer(int x); | |
24 | 26 | bool getTest(); |
25 | 27 | bool getConfig(); |
26 | 28 | bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); |
27 | - QString getApplicationDirPath() const; | |
28 | 29 | void setApplicationDirPath(const QString &value); |
30 | + QString getApplicationDirPath() const; | |
31 | + void setDirProgram(const QString &value); | |
29 | 32 | |
30 | 33 | private: |
31 | 34 | void registraFim(); |
32 | 35 | void registraInicio(); |
36 | + QLogger::QLoggerManager *logManager; | |
37 | + QString dirProgram; | |
38 | + //QProcess *myProcess; | |
33 | 39 | QString applicationDirPath; |
40 | + QString getDirProgram() const; | |
41 | + void iniciarGercols(); | |
42 | + void iniciarInstancias(); | |
43 | + void definirDirGercols(QString applicationDirPath); | |
34 | 44 | |
35 | 45 | private slots: |
36 | 46 | void mslot(); | ... | ... |