Commit 7eb38ea59dc8472a3d03e69ed3884b6e7daa1263
1 parent
4e974e9c
Exists in
master
Inicia modulos dinâmicamente
Showing
3 changed files
with
16 additions
and
32 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
| ... | ... | @@ -31,15 +31,14 @@ 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 | - QLogger::QLog_Error("Cacic Daemon", QString("getConfig.json não encontrado.")); | |
| 40 | + QLogger::QLog_Error("Cacic Daemon", QString("Problemas com o arquivo getConfig.json")); | |
| 41 | 41 | } |
| 42 | - //QLogger::QLog_Info("Cacic Daemon", "Serviço finalizado."); | |
| 43 | 42 | }catch (...){ |
| 44 | 43 | QLogger::QLog_Error("Cacic Daemon", QString("Erro desconhecido ao iniciar o serviço.")); |
| 45 | 44 | } | ... | ... |
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,23 +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(); | |
| 45 | + definirDirModulo(getApplicationDirPath(), nome); | |
| 46 | + iniciarModulo(getDirProgram()); | |
| 50 | 47 | |
| 48 | + if(nome == "cacic-gercols"){ | |
| 51 | 49 | //Envio do json gerado na coleta |
| 52 | 50 | bool ok; |
| 53 | 51 | QJsonObject jsonColeta = ccacic->getJsonFromFile("coleta.json"); |
| 54 | 52 | OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta ); |
| 55 | - } else if( nome == "mapas" ) { | |
| 56 | - definirDirMapas(getApplicationDirPath()); | |
| 57 | - iniciarModulo(); | |
| 58 | 53 | } |
| 59 | 54 | } |
| 60 | 55 | } |
| 61 | - | |
| 62 | 56 | }else{ |
| 63 | 57 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
| 64 | 58 | QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); |
| ... | ... | @@ -165,13 +159,13 @@ void CacicTimer::setDirProgram(const QString &value) |
| 165 | 159 | } |
| 166 | 160 | |
| 167 | 161 | |
| 168 | -void CacicTimer::iniciarModulo() | |
| 162 | +void CacicTimer::iniciarModulo(QString modulo) | |
| 169 | 163 | { |
| 170 | 164 | registraInicioColeta(); |
| 171 | 165 | QDir::setCurrent(this->applicationDirPath); |
| 172 | 166 | QProcess proc; |
| 173 | 167 | proc.setWorkingDirectory(this->applicationDirPath); |
| 174 | - proc.execute(getDirProgram()); | |
| 168 | + proc.execute(modulo); | |
| 175 | 169 | if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ |
| 176 | 170 | registraFimColeta("SUCESSO"); |
| 177 | 171 | }else{ |
| ... | ... | @@ -223,8 +217,8 @@ void CacicTimer::verificarPeriodicidadeJson() |
| 223 | 217 | { |
| 224 | 218 | QJsonObject result = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json"); |
| 225 | 219 | if(!result.contains("error") && !result.isEmpty()){ |
| 226 | - if(getPeriodicidadeExecucao() != result["codestatus"].toInt()){ | |
| 227 | - setPeriodicidadeExecucao(result["codestatus"].toInt()); | |
| 220 | + if(getPeriodicidadeExecucao() != result["interval"].toInt()){ | |
| 221 | + setPeriodicidadeExecucao(result["interval"].toInt()); | |
| 228 | 222 | reiniciarTimer(); |
| 229 | 223 | } |
| 230 | 224 | }else{ |
| ... | ... | @@ -233,19 +227,11 @@ void CacicTimer::verificarPeriodicidadeJson() |
| 233 | 227 | } |
| 234 | 228 | |
| 235 | 229 | |
| 236 | -void CacicTimer::definirDirGercols(QString appDirPath){ | |
| 237 | -#if defined (Q_OS_WIN) | |
| 238 | - setDirProgram(appDirPath + "\cacic-gercols.exe"); | |
| 239 | -#elif defined (Q_OS_LINUX) | |
| 240 | - setDirProgram(appDirPath + "/cacic-gercols"); | |
| 241 | -#endif | |
| 242 | -} | |
| 243 | - | |
| 244 | -void CacicTimer::definirDirMapas(QString appDirPath){ | |
| 230 | +void CacicTimer::definirDirModulo(QString appDirPath, QString nome){ | |
| 245 | 231 | #if defined (Q_OS_WIN) |
| 246 | - setDirProgram(appDirPath + "\cacic-mapas.exe"); | |
| 232 | + setDirProgram(appDirPath + "\\" + nome + ".exe"); | |
| 247 | 233 | #elif defined (Q_OS_LINUX) |
| 248 | - setDirProgram(appDirPath + "/cacic-mapas"); | |
| 234 | + setDirProgram(appDirPath + "/"+ nome); | |
| 249 | 235 | #endif |
| 250 | 236 | } |
| 251 | 237 | ... | ... |
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; | ... | ... |