Commit fb84683c7fbe7faee716cbcc3ddf09d3ebbef8e1
1 parent
ebde75cb
Exists in
master
Finalizado semaforo, chamada da coleta e timer.
Showing
4 changed files
with
144 additions
and
184 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
| ... | ... | @@ -11,8 +11,8 @@ cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv, |
| 11 | 11 | setServiceFlags(QtService::Default); |
| 12 | 12 | |
| 13 | 13 | logManager = QLogger::QLoggerManager::getInstance(); |
| 14 | - logManager->addDestination(application()->applicationDirPath().append("/log.txt"),"Cacic Daemon",QLogger::InfoLevel); | |
| 15 | - logManager->addDestination(application()->applicationDirPath().append("/log.txt"),"Cacic Daemon",QLogger::ErrorLevel); | |
| 14 | + logManager->addDestination(application()->applicationDirPath() + "/cacicLog.txt","Cacic Daemon",QLogger::InfoLevel); | |
| 15 | + logManager->addDestination(application()->applicationDirPath() + "/cacicLog.txt","Cacic Daemon",QLogger::ErrorLevel); | |
| 16 | 16 | } catch (...){ |
| 17 | 17 | qCritical() << "Error desconhecido no construtor."; |
| 18 | 18 | } |
| ... | ... | @@ -34,9 +34,6 @@ void cacicD::start() { |
| 34 | 34 | qDebug() << "\nServiço iniciado em" << application()->applicationDirPath(); |
| 35 | 35 | QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); |
| 36 | 36 | QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath().append("/getConfig.json")); |
| 37 | - | |
| 38 | - QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); | |
| 39 | - | |
| 40 | 37 | if(!result.contains("error") && !result.isEmpty()){ |
| 41 | 38 | Ocacictimer->iniciarTimer(result["codestatus"].toInt()); |
| 42 | 39 | }else{ | ... | ... |
cacic-daemon/cacicD/cacictimer.cpp
| ... | ... | @@ -2,43 +2,12 @@ |
| 2 | 2 | |
| 3 | 3 | CacicTimer::CacicTimer(QString dirpath) |
| 4 | 4 | { |
| 5 | - qDebug() << "iniciou o constructor"; | |
| 6 | 5 | definirDirGercols(dirpath); |
| 7 | 6 | setApplicationDirPath(dirpath); |
| 8 | 7 | iniciarInstancias(); |
| 9 | 8 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); |
| 10 | 9 | } |
| 11 | 10 | |
| 12 | -void CacicTimer::iniciarTimer(int x) | |
| 13 | -{ | |
| 14 | -======= | |
| 15 | - OCacicComm = new CacicComm(); | |
| 16 | - ccacic = new CCacic(); | |
| 17 | - timer = new QTimer(this); | |
| 18 | - logManager = QLogger::QLoggerManager::getInstance(); | |
| 19 | - | |
| 20 | - OCacicComm = CacicComm("http://teste.cacic.cc", | |
| 21 | - "rG/HcIDVTZ3pPKCf[[MAIS]]I6aigUb7OMeij3FfC7qNaznk0rBRYb6q6kSK3eNfjgptS8BfwW5yJqCvD2ai7xlw9I6P21j6cvQUqlHmAJpCbfwR13urdRE9AhjfokMcPrH6R1/zXPGMHveLRRgKLcqWu2X96rmoQQdRq9EW1SXmYUAx1dCV[[MAIS]]3Ha61XBw5pq58q35zH8Gjt998rTi3ecV8ShXXevqyK[[MAIS]]W07xpgTjbbd6Fbs/35gPfdRRgMNFjq7Gq[[MAIS]]llFgYMJ6UcEhw8f0ZLQo2oL/eRW/CNyeBW6wG0hIo6EIdpi/Ht0/95Uwn2Og[[MAIS]]2UPXsmKKuTMeGwUvPdbEfexlinUO0[[MAIS]]j9qIa2dpjtl0Y5Fyk1Bvw2ZYRTXwgJpUHsBboWmtTFpgX3wSGOWMipE80K8ktRTVYOp[[MAIS]]4qS/SzKWXpfCuZoCncfwE0lCEoreTH[[MAIS]]MLrTkHJP2oqYMAyFyQcjC0UGr3BQGa2edSNXjG7jrTdddga/SODUiF94jgh/QBwhiZby34b__CRYPTED__", | |
| 22 | - "P198PVwtz5F5CfZPSUrzuaQA/QG1sTnwzl/rBnj8M7y5MglANGodG5LLD4q7oY809HuDR4g5tL64lZRBKvKPmEgWd9iAZKvT4UAm9XWN3nKKLGaznCaJohmntNGqrJP1Zd9riTHGu10mPbg/Uh3TCbBHVOICvu5sDlINlCR6A3[[MAIS]]a55RhfKNidvr5uX0kozCxr5t2DyOb5oPocEGyJKyHLQ==__CRYPTED__", | |
| 23 | - "1", | |
| 24 | - "0", | |
| 25 | - "0", | |
| 26 | - "YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
| 27 | - "8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
| 28 | - "wshPlZWvLPhbUEQFQ1aQmA==__CRYPTED__", | |
| 29 | - "E9aKtVz/OSmGv7v1xW4FwaFukOob3qQ/HFDIz916K3ys82qfX9vBDz[[MAIS]]M2cdoYedhNkXt[[MAIS]]UVb10nD[[MAIS]]tOfbn7mlOlTDoGzUl9CgdPCsb[[MAIS]]Qa4wzuCrMw0BcCuaKfr62E3b8vh6Ug4JJbOgBo3ohG3x5O7Ap0D94GKtAWjMuTXRBbhGxPrRS4M6AhzvaN5P8pWd9FikrCLWuMs4ebnRlftef3RmVKScBDQ5zmK6sKxYNmX[[MAIS]]kKn/Gi2[[MAIS]]HftZ7HD9JLvZBpYhp4yjqShblQ67d6PlWgrRWXxwDseIiJe3NlF70zrCPBBelkeAhVDXMXnsYtLms3ElsLzxa3c5vpWzTfgyE[[MAIS]]hvALy4ivew7zaxEwrg2KY1T7GOSWZ7vljIvbhVZJgtzbnYiulFjJTtm5W4uJMKLuUJNzB0rxMkzToIE9/kDmeO2OKiwFbIfbe2Wdq0VpllOkjKtj9WM676iBSpYAXG0MsmLMj9CZ/sNi06hGF[[MAIS]]rXxiOSk66M0Hq[[MAIS]]OeUBh4z3Ra6f9yPJn0K9hIQyT[[MAIS]]Dr/QW/QdJIOkLTW8ZyyAF4DW9ojiTlUdySvB5EB1jyZ5nNTpzyE38qIdg7uM1tdWdm9FZGYxMdHwi1tS2dBeIWkDfWEjih01xiVt2dmdRgo0zIZvmmYDJ9LhCU3XPDlwdeQ8[[MAIS]]F7fnxDfxGqZQjZJ[[MAIS]]Y/Q8bdLpgbhcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__", | |
| 30 | - "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__", | |
| 31 | - "Dcr8b5IfZOJjt6qyH5dGyw==__CRYPTED__", | |
| 32 | - "2.5.1.1.256.32", | |
| 33 | - "2.8.1.7", | |
| 34 | - "2.8.1.6"); | |
| 35 | - OCacicComm->setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); | |
| 36 | - OCacicComm->setUsuario("cacic"); | |
| 37 | - OCacicComm->setPassword("cacic123"); | |
| 38 | - | |
| 39 | - connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); | |
| 40 | -} | |
| 41 | - | |
| 42 | 11 | CacicTimer::~CacicTimer() |
| 43 | 12 | { |
| 44 | 13 | logManager->closeLogger(); |
| ... | ... | @@ -47,125 +16,129 @@ CacicTimer::~CacicTimer() |
| 47 | 16 | delete OCacicComm; |
| 48 | 17 | } |
| 49 | 18 | |
| 50 | -void CacicTimer::iniciarTimer(int x, QString applicationDirPath) | |
| 19 | +void CacicTimer::iniciarTimer(int x) | |
| 51 | 20 | { |
| 52 | - setApplicationDirPath(applicationDirPath); | |
| 53 | - logManager->addDestination(getApplicationDirPath().append("/cacicLog.txt"), QStringList("Cacic Daemon"), QLogger::InfoLevel); | |
| 54 | - logManager->addDestination(getApplicationDirPath().append("/cacicLog.txt"), QStringList("Cacic Daemon"), QLogger::ErrorLevel); | |
| 55 | 21 | timer->start(x); |
| 56 | 22 | } |
| 57 | 23 | |
| 58 | 24 | void CacicTimer::mslot(){ |
| 25 | + QLogger::QLog_Info("Cacic Daemon (Timer)", QString("mslot();")); | |
| 59 | 26 | cMutex->lock(); |
| 60 | - if(getTest()){ | |
| 61 | - if(getConfig()){ | |
| 62 | - QLogger::QLog_Info("Cacic Timer", QString("semáforo fechado.")); | |
| 63 | - iniciarGercols(); | |
| 64 | - cMutex->unlock(); | |
| 65 | - QLogger::QLog_Info("Cacic Timer", QString("semáforo aberto.")); | |
| 66 | - qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
| 67 | - QLogger::QLog_Info("Cacic Daemon", "getConfig() executado com sucesso."); | |
| 68 | - | |
| 69 | - // Compara o novo arquivo de configuração com um antigo e se forem diferentes | |
| 70 | - // mantem o mais recente; caso iguais simplesmente apaga o novo. | |
| 71 | - QFile *fileOld; | |
| 72 | - QFile *fileNew; | |
| 73 | - | |
| 74 | - fileOld = new QFile(getApplicationDirPath().append("/getConfig.json")); | |
| 75 | - fileNew = new QFile(getApplicationDirPath().append("/getConfigNew.json")); | |
| 76 | - if( fileOld->exists() && fileNew->exists() ){ | |
| 77 | - if( Md5IsEqual(QVariant::fromValue(fileOld), QVariant::fromValue(fileNew)) ) { | |
| 78 | - fileNew->remove(); | |
| 79 | - } else { | |
| 80 | - // Renomeia getConfigNew.json para getConfig.json | |
| 81 | - fileOld->remove(); | |
| 82 | - fileNew->rename("getConfigNew.json","getConfig.json"); | |
| 83 | - } | |
| 84 | - jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); | |
| 85 | - } else if( fileOld->exists() ){ | |
| 86 | - jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); | |
| 87 | - } else { | |
| 88 | - QLogger::QLog_Error("Cacic Daemon", "Arquivo de configuração não criado."); | |
| 89 | - } | |
| 90 | - delete fileOld; | |
| 91 | - delete fileNew; | |
| 92 | - | |
| 93 | - /* lê json de configurações e armazena quais módulos executáveis. | |
| 94 | - * E faz o mesmo tipo de comparação de hashs, com o fim de: | |
| 95 | - * ou mantem o binário do módulo ou baixa um novo. | |
| 96 | - */ | |
| 97 | - | |
| 98 | - /* Aqui estou assumindo um formato do .json em que: | |
| 99 | - * há a key modulos contem uma lista com o nome dos executaveis e os seus valores hash md5 | |
| 100 | - * há a key metodo que explicita o método de download dos executaveis | |
| 101 | - */ | |
| 102 | - foreach( QJsonValue moduloValues, jsonConfig["modulos"].toArray() ) { | |
| 103 | - QString moduloKey, moduloValue; | |
| 104 | - | |
| 105 | - moduloKey = moduloValues.toObject()["md5"].toString(); | |
| 106 | - moduloValue = moduloValues.toObject()["nome"].toString(); | |
| 107 | - | |
| 108 | - moduleMap.insert(moduloKey, moduloValue); | |
| 109 | - } | |
| 110 | - metodoDownload = jsonConfig["metodo"].toString(); | |
| 111 | - | |
| 112 | - int countExecNotFound = 0; | |
| 113 | - QMap<QString, QString>::const_iterator mapIterator = moduleMap.constBegin(); | |
| 114 | - while (mapIterator != moduleMap.constEnd()) { | |
| 115 | - QString nomeModulo = mapIterator.value(); | |
| 116 | - QString hashModulo = mapIterator.key(); | |
| 117 | - | |
| 118 | - // Calcula hash do binario atual | |
| 119 | -#if defined(Q_OS_WIN) | |
| 120 | - fileOld = new QFile(getApplicationDirPath().append("/").append(modulo).append(".exe")); | |
| 121 | -#else | |
| 122 | - fileOld = new QFile(getApplicationDirPath().append("/").append(nomeModulo)); | |
| 123 | -#endif | |
| 124 | - if(!fileOld->exists()) { | |
| 125 | - QLogger::QLog_Error("Cacic Daemon", QString("Módulo ").append(nomeModulo).append(" não encontrado.")); | |
| 126 | - | |
| 127 | - countExecNotFound++; | |
| 128 | - if( countExecNotFound == moduleMap.size() ) { | |
| 129 | - QLogger::QLog_Error("Cacic Daemon", "Não foi possível encontrar nenhum módulo executável!"); | |
| 130 | - return; | |
| 131 | - } | |
| 132 | - continue; | |
| 133 | - } | |
| 134 | - | |
| 135 | - QString oldMd5 = QString(QCryptographicHash::hash(fileOld->readAll(),QCryptographicHash::Md5).toHex()); | |
| 136 | - | |
| 137 | - if ( oldMd5 != hashModulo ) { | |
| 138 | - | |
| 139 | - fileOld->rename(getApplicationDirPath().append("/").append(nomeModulo), | |
| 140 | - getApplicationDirPath().append("/").append("nomeModulo").append("Old") ); | |
| 141 | - | |
| 142 | - // Download nova versão do executável | |
| 143 | - if(metodoDownload == "ftp" || metodoDownload == "") { | |
| 144 | -// OCacicComm->ftpDownload( QString("/ws/get/").append(nomeModulo) ); | |
| 145 | - } | |
| 146 | - | |
| 147 | - | |
| 148 | - fileOld->remove(); | |
| 149 | - delete fileOld; | |
| 150 | - } | |
| 151 | - | |
| 152 | - mapIterator++; | |
| 153 | - } | |
| 154 | - }else{ | |
| 155 | - qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
| 156 | - QLogger::QLog_Error("Cacic Daemon", "Falha na obtenção do arquivo de configuração."); | |
| 157 | - } | |
| 158 | - }else{ | |
| 159 | - qDebug() << "getTest() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
| 160 | - QLogger::QLog_Error("Cacic Daemon", "Falha na execução do getTest()."); | |
| 161 | - } | |
| 27 | + QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo fechado.")); | |
| 28 | + //if(getTest()){ | |
| 29 | + // QLogger::QLog_Info("Cacic Daemon (Timer)", QString("getTeste() success.")); | |
| 30 | + // if(getConfig()){ | |
| 31 | + // QLogger::QLog_Info("Cacic Daemon (Timer)", QString("getConfig() success.")); | |
| 32 | + iniciarGercols(); | |
| 33 | + // } | |
| 34 | + // } | |
| 35 | + cMutex->unlock(); | |
| 36 | + QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo aberto.")); | |
| 162 | 37 | } |
| 163 | 38 | |
| 39 | +// QLogger::QLog_Info("Cacic Timer", QString("semáforo aberto.")); | |
| 40 | +// qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
| 41 | +// QLogger::QLog_Info("Cacic Daemon (Timer)", "getConfig() executado com sucesso."); | |
| 42 | + | |
| 43 | +// // Compara o novo arquivo de configuração com um antigo e se forem diferentes | |
| 44 | +// // mantem o mais recente; caso iguais simplesmente apaga o novo. | |
| 45 | +// QFile *fileOld; | |
| 46 | +// QFile *fileNew; | |
| 47 | + | |
| 48 | +// fileOld = new QFile(getApplicationDirPath().append("/getConfig.json")); | |
| 49 | +// fileNew = new QFile(getApplicationDirPath().append("/getConfigNew.json")); | |
| 50 | +// if( fileOld->exists() && fileNew->exists() ){ | |
| 51 | +// if( Md5IsEqual(QVariant::fromValue(fileOld), QVariant::fromValue(fileNew)) ) { | |
| 52 | +// fileNew->remove(); | |
| 53 | +// } else { | |
| 54 | +// // Renomeia getConfigNew.json para getConfig.json | |
| 55 | +// fileOld->remove(); | |
| 56 | +// fileNew->rename("getConfigNew.json","getConfig.json"); | |
| 57 | +// } | |
| 58 | +// jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); | |
| 59 | +// } else if( fileOld->exists() ){ | |
| 60 | +// jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); | |
| 61 | +// } else { | |
| 62 | +// QLogger::QLog_Error("Cacic Daemon (Timer)", "Arquivo de configuração não criado."); | |
| 63 | +// } | |
| 64 | +// delete fileOld; | |
| 65 | +// delete fileNew; | |
| 66 | + | |
| 67 | +// /* lê json de configurações e armazena quais módulos executáveis. | |
| 68 | +// * E faz o mesmo tipo de comparação de hashs, com o fim de: | |
| 69 | +// * ou mantem o binário do módulo ou baixa um novo. | |
| 70 | +// */ | |
| 71 | + | |
| 72 | +// /* Aqui estou assumindo um formato do .json em que: | |
| 73 | +// * há a key modulos contem uma lista com o nome dos executaveis e os seus valores hash md5 | |
| 74 | +// * há a key metodo que explicita o método de download dos executaveis | |
| 75 | +// */ | |
| 76 | +// foreach( QJsonValue moduloValues, jsonConfig["modulos"].toArray() ) { | |
| 77 | +// QString moduloKey, moduloValue; | |
| 78 | + | |
| 79 | +// moduloKey = moduloValues.toObject()["md5"].toString(); | |
| 80 | +// moduloValue = moduloValues.toObject()["nome"].toString(); | |
| 81 | + | |
| 82 | +// moduleMap.insert(moduloKey, moduloValue); | |
| 83 | +// } | |
| 84 | +// metodoDownload = jsonConfig["metodo"].toString(); | |
| 85 | + | |
| 86 | +// int countExecNotFound = 0; | |
| 87 | +// QMap<QString, QString>::const_iterator mapIterator = moduleMap.constBegin(); | |
| 88 | +// while (mapIterator != moduleMap.constEnd()) { | |
| 89 | +// QString nomeModulo = mapIterator.value(); | |
| 90 | +// QString hashModulo = mapIterator.key(); | |
| 91 | + | |
| 92 | +// // Calcula hash do binario atual | |
| 93 | +//#if defined(Q_OS_WIN) | |
| 94 | +// fileOld = new QFile(getApplicationDirPath().append("/").append(modulo).append(".exe")); | |
| 95 | +//#else | |
| 96 | +// fileOld = new QFile(getApplicationDirPath().append("/").append(nomeModulo)); | |
| 97 | +//#endif | |
| 98 | +// if(!fileOld->exists()) { | |
| 99 | +// QLogger::QLog_Error("Cacic Daemon (Timer)", QString("Módulo ").append(nomeModulo).append(" não encontrado.")); | |
| 100 | + | |
| 101 | +// countExecNotFound++; | |
| 102 | +// if( countExecNotFound == moduleMap.size() ) { | |
| 103 | +// QLogger::QLog_Error("Cacic Daemon (Timer)", "Não foi possível encontrar nenhum módulo executável!"); | |
| 104 | +// return; | |
| 105 | +// } | |
| 106 | +// continue; | |
| 107 | +// } | |
| 108 | + | |
| 109 | +// QString oldMd5 = QString(QCryptographicHash::hash(fileOld->readAll(),QCryptographicHash::Md5).toHex()); | |
| 110 | + | |
| 111 | +// if ( oldMd5 != hashModulo ) { | |
| 112 | + | |
| 113 | +// fileOld->rename(getApplicationDirPath().append("/").append(nomeModulo), | |
| 114 | +// getApplicationDirPath().append("/").append("nomeModulo").append("Old") ); | |
| 115 | + | |
| 116 | +// // Download nova versão do executável | |
| 117 | +// if(metodoDownload == "ftp" || metodoDownload == "") { | |
| 118 | +// // OCacicComm->ftpDownload( QString("/ws/get/").append(nomeModulo) ); | |
| 119 | +// } | |
| 120 | + | |
| 121 | + | |
| 122 | +// fileOld->remove(); | |
| 123 | +// delete fileOld; | |
| 124 | +// } | |
| 125 | + | |
| 126 | +// mapIterator++; | |
| 127 | +// } | |
| 128 | +// }else{ | |
| 129 | +// qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
| 130 | +// QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); | |
| 131 | +// } | |
| 132 | +// }else{ | |
| 133 | +// qDebug() << "getTest() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | |
| 134 | +// QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na execução do getTest()."); | |
| 135 | +// } | |
| 136 | +// } | |
| 137 | +// } | |
| 138 | +//} | |
| 139 | + | |
| 164 | 140 | bool CacicTimer::getTest(){ |
| 165 | 141 | try{ |
| 166 | - OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); | |
| 167 | - OCacicComm->setUsuario("cacic"); | |
| 168 | - OCacicComm->setPassword("cacic123"); | |
| 169 | 142 | bool ok; |
| 170 | 143 | QJsonObject as; |
| 171 | 144 | as["computador"] = OCacic_Computer.toJsonObject(); |
| ... | ... | @@ -174,7 +147,7 @@ bool CacicTimer::getTest(){ |
| 174 | 147 | // return false; |
| 175 | 148 | // } |
| 176 | 149 | try{ |
| 177 | - ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getTest.json"); | |
| 150 | + ccacic->setJsonToFile(jsonresult, this->applicationDirPath + "/getTest.json"); | |
| 178 | 151 | return true; |
| 179 | 152 | } catch (...) { |
| 180 | 153 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
| ... | ... | @@ -188,9 +161,6 @@ bool CacicTimer::getTest(){ |
| 188 | 161 | |
| 189 | 162 | bool CacicTimer::getConfig(){ |
| 190 | 163 | try{ |
| 191 | - OCacicComm->setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); | |
| 192 | - OCacicComm->setUsuario("cacic"); | |
| 193 | - OCacicComm->setPassword("cacic123"); | |
| 194 | 164 | bool ok; |
| 195 | 165 | QJsonObject as; |
| 196 | 166 | as["computador"] = OCacic_Computer.toJsonObject(); |
| ... | ... | @@ -199,7 +169,7 @@ bool CacicTimer::getConfig(){ |
| 199 | 169 | // return false; |
| 200 | 170 | // } |
| 201 | 171 | try{ |
| 202 | - ccacic->setJsonToFile(jsonresult, getApplicationDirPath().append("/getConfigNew.json")); | |
| 172 | + ccacic->setJsonToFile(jsonresult, this->applicationDirPath + "/getConfigNew.json"); | |
| 203 | 173 | return true; |
| 204 | 174 | } catch (...) { |
| 205 | 175 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
| ... | ... | @@ -213,6 +183,7 @@ bool CacicTimer::getConfig(){ |
| 213 | 183 | |
| 214 | 184 | void CacicTimer::registraInicio() |
| 215 | 185 | { |
| 186 | + QLogger::QLog_Info("Cacic Daemon (Timer)","Coleta iniciada em: " + QDateTime::currentDateTime().toLocalTime().toString()); | |
| 216 | 187 | } |
| 217 | 188 | |
| 218 | 189 | QString CacicTimer::getDirProgram() const |
| ... | ... | @@ -220,11 +191,6 @@ QString CacicTimer::getDirProgram() const |
| 220 | 191 | return dirProgram; |
| 221 | 192 | } |
| 222 | 193 | |
| 223 | -QString CacicTimer::getApplicationDirPath() const | |
| 224 | -{ | |
| 225 | - return applicationDirPath; | |
| 226 | -} | |
| 227 | - | |
| 228 | 194 | void CacicTimer::setDirProgram(const QString &value) |
| 229 | 195 | { |
| 230 | 196 | dirProgram = value; |
| ... | ... | @@ -233,22 +199,20 @@ void CacicTimer::setDirProgram(const QString &value) |
| 233 | 199 | |
| 234 | 200 | void CacicTimer::iniciarGercols() |
| 235 | 201 | { |
| 236 | - | |
| 202 | + registraInicio(); | |
| 203 | + QDir::setCurrent(this->applicationDirPath); | |
| 237 | 204 | QProcess proc; |
| 238 | - proc.children(); | |
| 205 | + proc.setWorkingDirectory(this->applicationDirPath); | |
| 239 | 206 | proc.execute(getDirProgram()); |
| 240 | - if(proc.atEnd()){ | |
| 241 | - | |
| 207 | + if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ | |
| 208 | + registraFim("SUCESSO"); | |
| 209 | + }else{ | |
| 210 | + proc.waitForFinished(120000); | |
| 211 | + if((!proc.atEnd()) || (proc.exitStatus() == QProcess::CrashExit)){ | |
| 212 | + registraFim("ERRO"); | |
| 213 | + proc.kill(); | |
| 214 | + } | |
| 242 | 215 | } |
| 243 | - // QString retorno = ccacic->startProcess(getDirProgram(),true,ok); | |
| 244 | - // qDebug() << retorno; | |
| 245 | - QLogger::QLog_Info("Cacic Timer","processo finalizado."); | |
| 246 | - // if (myProcess.waitForFinished(-1)){ | |
| 247 | - // qDebug() << "erro:" << myProcess.errorString(); | |
| 248 | - // }else{ | |
| 249 | - // qDebug() << "não deu erro:" << myProcess.readAll(); | |
| 250 | - // QLogger::QLog_Info("Cacic Timer","processo está aberto."); | |
| 251 | - // } | |
| 252 | 216 | } |
| 253 | 217 | |
| 254 | 218 | void CacicTimer::setApplicationDirPath(const QString &value) |
| ... | ... | @@ -257,8 +221,9 @@ void CacicTimer::setApplicationDirPath(const QString &value) |
| 257 | 221 | } |
| 258 | 222 | |
| 259 | 223 | |
| 260 | -void CacicTimer::registraFim() | |
| 224 | +void CacicTimer::registraFim(QString msg) | |
| 261 | 225 | { |
| 226 | + QLogger::QLog_Info("Cacic Daemon (Timer)","Coleta finalizada com " + msg + " em: " + QDateTime::currentDateTime().toLocalTime().toString()); | |
| 262 | 227 | } |
| 263 | 228 | |
| 264 | 229 | bool CacicTimer::Md5IsEqual(QVariant document01,QVariant document02){ |
| ... | ... | @@ -275,19 +240,21 @@ bool CacicTimer::Md5IsEqual(QVariant document01,QVariant document02){ |
| 275 | 240 | |
| 276 | 241 | void CacicTimer::iniciarInstancias(){ |
| 277 | 242 | logManager = QLogger::QLoggerManager::getInstance(); |
| 278 | - logManager->addDestination(getApplicationDirPath().append("/log.txt"),"Cacic Timer",QLogger::InfoLevel); | |
| 279 | - logManager->addDestination(getApplicationDirPath().append("/log.txt"),"Cacic Timer",QLogger::ErrorLevel); | |
| 280 | - OCacicComm = new CacicComm(); | |
| 243 | + logManager->addDestination(this->applicationDirPath + "/cacicLog.txt","Cacic Daemon (Timer)",QLogger::InfoLevel); | |
| 244 | + logManager->addDestination(this->applicationDirPath + "/cacicLog.txt","Cacic Daemon (Timer)",QLogger::ErrorLevel); | |
| 281 | 245 | ccacic = new CCacic(); |
| 282 | 246 | timer = new QTimer(this); |
| 283 | 247 | cMutex = new QMutex(QMutex::Recursive); |
| 284 | - QLogger::QLog_Info("Cacic Timer", QString("terminou as instancias")); | |
| 248 | + OCacicComm = new CacicComm(); | |
| 249 | + OCacicComm->setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); | |
| 250 | + OCacicComm->setUsuario("cacic"); | |
| 251 | + OCacicComm->setPassword("cacic123"); | |
| 285 | 252 | } |
| 286 | 253 | |
| 287 | -void CacicTimer::definirDirGercols(QString applicationDirPath){ | |
| 254 | +void CacicTimer::definirDirGercols(QString appDirPath){ | |
| 288 | 255 | #if defined (Q_OS_WIN) |
| 289 | - setDirProgram(applicationDirPath.append("\cacic-gercols.exe")); | |
| 256 | + setDirProgram(appDirPath + "\cacic-gercols.exe"); | |
| 290 | 257 | #elif defined (Q_OS_LINUX) |
| 291 | - setDirProgram(applicationDirPath.append("/cacic-gercols")); | |
| 258 | + setDirProgram(appDirPath + "/cacic-gercols"); | |
| 292 | 259 | #endif |
| 293 | 260 | } | ... | ... |
cacic-daemon/cacicD/cacictimer.h
| ... | ... | @@ -18,6 +18,7 @@ class CacicTimer : public QObject |
| 18 | 18 | Q_OBJECT |
| 19 | 19 | public: |
| 20 | 20 | CacicTimer(QString dirpath); |
| 21 | + ~CacicTimer(); | |
| 21 | 22 | QTimer *timer; |
| 22 | 23 | CacicComm *OCacicComm; |
| 23 | 24 | CACIC_Computer OCacic_Computer; |
| ... | ... | @@ -26,15 +27,12 @@ public: |
| 26 | 27 | void iniciarTimer(int x); |
| 27 | 28 | bool getTest(); |
| 28 | 29 | bool getConfig(); |
| 29 | - bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); | |
| 30 | 30 | bool Md5IsEqual(QVariant document01,QVariant document02); |
| 31 | - QString getApplicationDirPath() const; | |
| 32 | 31 | void setApplicationDirPath(const QString &value); |
| 33 | - QString getApplicationDirPath() const; | |
| 34 | 32 | void setDirProgram(const QString &value); |
| 35 | 33 | |
| 36 | 34 | private: |
| 37 | - void registraFim(); | |
| 35 | + void registraFim(QString msg); | |
| 38 | 36 | void registraInicio(); |
| 39 | 37 | QLogger::QLoggerManager *logManager; |
| 40 | 38 | QString dirProgram; |
| ... | ... | @@ -43,10 +41,8 @@ private: |
| 43 | 41 | QString getDirProgram() const; |
| 44 | 42 | void iniciarGercols(); |
| 45 | 43 | void iniciarInstancias(); |
| 46 | - void definirDirGercols(QString applicationDirPath); | |
| 44 | + void definirDirGercols(QString appDirPath); | |
| 47 | 45 | QJsonObject jsonConfig; |
| 48 | - QLogger::QLoggerManager *logManager; | |
| 49 | - QString applicationDirPath; | |
| 50 | 46 | QString metodoDownload; |
| 51 | 47 | QMap<QString, QString> moduleMap; // key = hash md5, value = nome do modulo |
| 52 | 48 | ... | ... |
src/cacic_comm.h
| ... | ... | @@ -62,7 +62,7 @@ public: |
| 62 | 62 | if (isSsl){ |
| 63 | 63 | url = urlSsl.isEmpty() ? "https://" + this->urlGerente + route : this->urlSsl + route; |
| 64 | 64 | if (!url.isValid()){ |
| 65 | - jsonObj["error"] = QVariant("Invalid Url"); | |
| 65 | + jsonObj["error"] = QVariant("Invalid Url").toJsonValue(); | |
| 66 | 66 | return jsonObj; |
| 67 | 67 | } |
| 68 | 68 | req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); | ... | ... |