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,15 +31,14 @@ cacicD::~cacicD() | ||
| 31 | 31 | ||
| 32 | void cacicD::start() { | 32 | void cacicD::start() { |
| 33 | try{ | 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 | if(!result.contains("error") && !result.isEmpty()){ | 36 | if(!result.contains("error") && !result.isEmpty()){ |
| 37 | - Ocacictimer->setPeriodicidadeExecucao(result["codestatus"].toInt()); | 37 | + Ocacictimer->setPeriodicidadeExecucao(result["interval"].toInt()); |
| 38 | Ocacictimer->iniciarTimer(); | 38 | Ocacictimer->iniciarTimer(); |
| 39 | }else{ | 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 | }catch (...){ | 42 | }catch (...){ |
| 44 | QLogger::QLog_Error("Cacic Daemon", QString("Erro desconhecido ao iniciar o serviço.")); | 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,7 +31,6 @@ void CacicTimer::mslot(){ | ||
| 31 | verificarPeriodicidadeJson(); | 31 | verificarPeriodicidadeJson(); |
| 32 | }catch (...){ | 32 | }catch (...){ |
| 33 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json")); | 33 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json")); |
| 34 | - | ||
| 35 | } | 34 | } |
| 36 | cMutex->lock(); | 35 | cMutex->lock(); |
| 37 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo fechado.")); | 36 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo fechado.")); |
| @@ -42,23 +41,18 @@ void CacicTimer::mslot(){ | @@ -42,23 +41,18 @@ void CacicTimer::mslot(){ | ||
| 42 | QStringList nomesModulos = verificarModulos(); | 41 | QStringList nomesModulos = verificarModulos(); |
| 43 | 42 | ||
| 44 | if ( !nomesModulos.empty() ) { | 43 | if ( !nomesModulos.empty() ) { |
| 45 | - | ||
| 46 | foreach( QString nome, nomesModulos ) { | 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 | //Envio do json gerado na coleta | 49 | //Envio do json gerado na coleta |
| 52 | bool ok; | 50 | bool ok; |
| 53 | QJsonObject jsonColeta = ccacic->getJsonFromFile("coleta.json"); | 51 | QJsonObject jsonColeta = ccacic->getJsonFromFile("coleta.json"); |
| 54 | OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta ); | 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 | }else{ | 56 | }else{ |
| 63 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | 57 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
| 64 | QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); | 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,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 | registraInicioColeta(); | 164 | registraInicioColeta(); |
| 171 | QDir::setCurrent(this->applicationDirPath); | 165 | QDir::setCurrent(this->applicationDirPath); |
| 172 | QProcess proc; | 166 | QProcess proc; |
| 173 | proc.setWorkingDirectory(this->applicationDirPath); | 167 | proc.setWorkingDirectory(this->applicationDirPath); |
| 174 | - proc.execute(getDirProgram()); | 168 | + proc.execute(modulo); |
| 175 | if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ | 169 | if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ |
| 176 | registraFimColeta("SUCESSO"); | 170 | registraFimColeta("SUCESSO"); |
| 177 | }else{ | 171 | }else{ |
| @@ -223,8 +217,8 @@ void CacicTimer::verificarPeriodicidadeJson() | @@ -223,8 +217,8 @@ void CacicTimer::verificarPeriodicidadeJson() | ||
| 223 | { | 217 | { |
| 224 | QJsonObject result = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json"); | 218 | QJsonObject result = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json"); |
| 225 | if(!result.contains("error") && !result.isEmpty()){ | 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 | reiniciarTimer(); | 222 | reiniciarTimer(); |
| 229 | } | 223 | } |
| 230 | }else{ | 224 | }else{ |
| @@ -233,19 +227,11 @@ void CacicTimer::verificarPeriodicidadeJson() | @@ -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 | #if defined (Q_OS_WIN) | 231 | #if defined (Q_OS_WIN) |
| 246 | - setDirProgram(appDirPath + "\cacic-mapas.exe"); | 232 | + setDirProgram(appDirPath + "\\" + nome + ".exe"); |
| 247 | #elif defined (Q_OS_LINUX) | 233 | #elif defined (Q_OS_LINUX) |
| 248 | - setDirProgram(appDirPath + "/cacic-mapas"); | 234 | + setDirProgram(appDirPath + "/"+ nome); |
| 249 | #endif | 235 | #endif |
| 250 | } | 236 | } |
| 251 | 237 |
cacic-daemon/cacicD/cacictimer.h
| @@ -42,12 +42,11 @@ private: | @@ -42,12 +42,11 @@ private: | ||
| 42 | QString dirProgram; | 42 | QString dirProgram; |
| 43 | QString applicationDirPath; | 43 | QString applicationDirPath; |
| 44 | QString getDirProgram() const; | 44 | QString getDirProgram() const; |
| 45 | - void iniciarModulo(); | 45 | + void iniciarModulo(QString modulo); |
| 46 | void iniciarInstancias(); | 46 | void iniciarInstancias(); |
| 47 | void verificarPeriodicidadeJson(); | 47 | void verificarPeriodicidadeJson(); |
| 48 | void lerArquivoConfig( const QJsonObject &jsonConfig); | 48 | void lerArquivoConfig( const QJsonObject &jsonConfig); |
| 49 | - void definirDirGercols(QString appDirPath); | ||
| 50 | - void definirDirMapas(QString appDirPath); | 49 | + void definirDirModulo(QString appDirPath, QString nome); |
| 51 | QJsonObject jsonConfig; | 50 | QJsonObject jsonConfig; |
| 52 | int periodicidadeExecucao; | 51 | int periodicidadeExecucao; |
| 53 | int getPeriodicidadeExecucao() const; | 52 | int getPeriodicidadeExecucao() const; |