Commit 12905195a33639e515ebbff974633ec36428e549
Exists in
master
Merge branch 'master' of https://github.com/lightbase/cacic-agente
Conflicts: cacic-daemon/cacicD/cacicd.cpp cacic-daemon/cacicD/cacictimer.cpp
Showing
6 changed files
with
24 additions
and
38 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
... | ... | @@ -31,16 +31,15 @@ cacicD::~cacicD() |
31 | 31 | |
32 | 32 | void cacicD::start() { |
33 | 33 | try{ |
34 | - QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); | |
35 | - QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath().append("/getConfig.json")); | |
34 | + QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em " + application()->applicationDirPath() + ".")); | |
35 | + QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); | |
36 | 36 | if(!result.contains("error") && !result.isEmpty()){ |
37 | - Ocacictimer->setPeriodicidadeExecucao(result["codestatus"].toInt()); | |
37 | + Ocacictimer->setPeriodicidadeExecucao(result["interval"].toInt()); | |
38 | 38 | Ocacictimer->iniciarTimer(); |
39 | 39 | }else{ |
40 | 40 | //TODO: deve iniciar com um timer default (4 horas é um tempo bom), pra não ficar freezado pra sempre. |
41 | - QLogger::QLog_Error("Cacic Daemon", QString("getConfig.json não encontrado.")); | |
41 | + QLogger::QLog_Error("Cacic Daemon", QString("Problemas com o arquivo getConfig.json")); | |
42 | 42 | } |
43 | - //QLogger::QLog_Info("Cacic Daemon", "Serviço finalizado."); | |
44 | 43 | }catch (...){ |
45 | 44 | QLogger::QLog_Error("Cacic Daemon", QString("Erro desconhecido ao iniciar o serviço.")); |
46 | 45 | } | ... | ... |
cacic-daemon/cacicD/cacictimer.cpp
... | ... | @@ -31,7 +31,6 @@ void CacicTimer::mslot(){ |
31 | 31 | verificarPeriodicidadeJson(); |
32 | 32 | }catch (...){ |
33 | 33 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json")); |
34 | - | |
35 | 34 | } |
36 | 35 | cMutex->lock(); |
37 | 36 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo fechado.")); |
... | ... | @@ -42,25 +41,18 @@ void CacicTimer::mslot(){ |
42 | 41 | QStringList nomesModulos = verificarModulos(); |
43 | 42 | |
44 | 43 | if ( !nomesModulos.empty() ) { |
45 | - | |
46 | 44 | foreach( QString nome, nomesModulos ) { |
47 | - if( nome == "gercols" ) { | |
48 | - definirDirGercols(getApplicationDirPath()); | |
49 | - //iniciarModulo não se refere à aplicação 'gercols' | |
50 | - iniciarModulo(); | |
45 | + definirDirModulo(getApplicationDirPath(), nome); | |
46 | + iniciarModulo(getDirProgram()); | |
51 | 47 | |
48 | + if(nome == "cacic-gercols"){ | |
52 | 49 | //Envio do json gerado na coleta |
53 | 50 | bool ok; |
54 | 51 | QJsonObject jsonColeta = ccacic->getJsonFromFile("coleta.json"); |
55 | 52 | OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta ); |
56 | - } else if( nome == "mapas" ) { | |
57 | - definirDirMapas(getApplicationDirPath()); | |
58 | - //iniciarModulo não se refere à aplicação 'mapas' | |
59 | - iniciarModulo(); | |
60 | 53 | } |
61 | 54 | } |
62 | 55 | } |
63 | - | |
64 | 56 | }else{ |
65 | 57 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
66 | 58 | QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); |
... | ... | @@ -169,13 +161,13 @@ void CacicTimer::setDirProgram(const QString &value) |
169 | 161 | } |
170 | 162 | |
171 | 163 | |
172 | -void CacicTimer::iniciarModulo() | |
164 | +void CacicTimer::iniciarModulo(QString modulo) | |
173 | 165 | { |
174 | 166 | registraInicioColeta(); |
175 | 167 | QDir::setCurrent(this->applicationDirPath); |
176 | 168 | QProcess proc; |
177 | 169 | proc.setWorkingDirectory(this->applicationDirPath); |
178 | - proc.execute(getDirProgram()); | |
170 | + proc.execute(modulo); | |
179 | 171 | if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ |
180 | 172 | registraFimColeta("SUCESSO"); |
181 | 173 | }else{ |
... | ... | @@ -229,7 +221,7 @@ void CacicTimer::verificarPeriodicidadeJson() |
229 | 221 | QJsonObject result = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json"); |
230 | 222 | if(!result.contains("error") && !result.isEmpty()){ |
231 | 223 | if(getPeriodicidadeExecucao() != result["nu_intervalo_exec"].toInt()){ |
232 | - setPeriodicidadeExecucao(result["nu_intervalo_exec"].toInt()); | |
224 | + setPeriodicidadeExecucao(result["nu_intervalo_exec"].toInt()); //segundo alteração do eduardo, o nome da variável ficou o mesmo de antes. me corrijam se estiver errado | |
233 | 225 | reiniciarTimer(); |
234 | 226 | } |
235 | 227 | }else{ |
... | ... | @@ -238,19 +230,11 @@ void CacicTimer::verificarPeriodicidadeJson() |
238 | 230 | } |
239 | 231 | |
240 | 232 | |
241 | -void CacicTimer::definirDirGercols(QString appDirPath){ | |
242 | -#if defined (Q_OS_WIN) | |
243 | - setDirProgram(appDirPath + "\\cacic-gercols.exe"); | |
244 | -#elif defined (Q_OS_LINUX) | |
245 | - setDirProgram(appDirPath + "/cacic-gercols"); | |
246 | -#endif | |
247 | -} | |
248 | - | |
249 | -void CacicTimer::definirDirMapas(QString appDirPath){ | |
233 | +void CacicTimer::definirDirModulo(QString appDirPath, QString nome){ | |
250 | 234 | #if defined (Q_OS_WIN) |
251 | - setDirProgram(appDirPath + "\\cacic-mapas.exe"); | |
235 | + setDirProgram(appDirPath + "\\" + nome + ".exe"); | |
252 | 236 | #elif defined (Q_OS_LINUX) |
253 | - setDirProgram(appDirPath + "/cacic-mapas"); | |
237 | + setDirProgram(appDirPath + "/"+ nome); | |
254 | 238 | #endif |
255 | 239 | } |
256 | 240 | ... | ... |
cacic-daemon/cacicD/cacictimer.h
... | ... | @@ -42,12 +42,11 @@ private: |
42 | 42 | QString dirProgram; |
43 | 43 | QString applicationDirPath; |
44 | 44 | QString getDirProgram() const; |
45 | - void iniciarModulo(); | |
45 | + void iniciarModulo(QString modulo); | |
46 | 46 | void iniciarInstancias(); |
47 | 47 | void verificarPeriodicidadeJson(); |
48 | 48 | void lerArquivoConfig( const QJsonObject &jsonConfig); |
49 | - void definirDirGercols(QString appDirPath); | |
50 | - void definirDirMapas(QString appDirPath); | |
49 | + void definirDirModulo(QString appDirPath, QString nome); | |
51 | 50 | QJsonObject jsonConfig; |
52 | 51 | int periodicidadeExecucao; |
53 | 52 | int getPeriodicidadeExecucao() const; | ... | ... |
install-cacic/install-cacic.pro
install-cacic/installcacic.cpp
... | ... | @@ -10,15 +10,18 @@ InstallCacic::InstallCacic(QObject *parent) : |
10 | 10 | void InstallCacic::run(QStringList argv, int argc) { |
11 | 11 | |
12 | 12 | QLogger::QLog_Debug("Install", "Inicio de instalacao"); |
13 | + | |
14 | + oCacicComm = new CacicComm(); | |
15 | + | |
13 | 16 | bool ok; |
14 | 17 | //valida os parametros repassados |
15 | 18 | QMap<QString, QString> param = validaParametros(argv, argc, &ok); |
16 | 19 | //se tiver usuario, senha e url |
17 | 20 | if (ok){ |
18 | - oCacicComm.setUrlGerente(this->argumentos["host"]); | |
19 | - oCacicComm.setUsuario(this->argumentos["user"]); | |
20 | - oCacicComm.setPassword(this->argumentos["password"]); | |
21 | - QJsonObject jsonLogin = oCacicComm.login(&ok); | |
21 | + oCacicComm->setUrlGerente(this->argumentos["host"]); | |
22 | + oCacicComm->setUsuario(this->argumentos["user"]); | |
23 | + oCacicComm->setPassword(this->argumentos["password"]); | |
24 | + QJsonObject jsonLogin = oCacicComm->login(&ok); | |
22 | 25 | if (ok){ |
23 | 26 | //conectado, grava a chave na classe; |
24 | 27 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); | ... | ... |
install-cacic/installcacic.h