diff --git a/cacicD/cacicD.pro b/cacicD/cacicD.pro index 5fdd892..4de78c7 100644 --- a/cacicD/cacicD.pro +++ b/cacicD/cacicD.pro @@ -5,7 +5,6 @@ #------------------------------------------------- QT += core - QT -= gui TARGET = cacicD @@ -21,13 +20,18 @@ TEMPLATE = app SOURCES += main.cpp \ ../src/ccacic.cpp \ - cacicd.cpp + cacicd.cpp \ + ../src/cacic_computer.cpp \ + ../src/operatingsystem.cpp HEADERS += \ ../src/ccacic.h \ - cacicd.h + cacicd.h \ + ../src/cacic_computer.h \ + ../src/operatingsystem.h include(../src/qtservice/src/qtservice.pri) INCLUDEPATH += ../src \ ../src/crypto++/include/ + diff --git a/cacicD/cacicd.cpp b/cacicD/cacicd.cpp index 4b11668..c8fd075 100644 --- a/cacicD/cacicd.cpp +++ b/cacicD/cacicd.cpp @@ -22,12 +22,20 @@ cacicD::~cacicD() void cacicD::start() { try{ - QCoreApplication *app = application(); - qDebug() << "Serviço iniciado."; - qDebug() << app->applicationDirPath(); - + this->app = application(); + qDebug() << "\nServiço iniciado em" << app->applicationDirPath(); + if(getTest()){ + qDebug() << "\ngetTest() success."; + }else{ + qDebug() << "\ngetTest() error."; + } + if(getConfig()){ + qDebug() << "\ngetconfig() success."; + }else{ + qDebug() << "\ngetconfig() error."; + } } catch (...){ - qCritical() << "Error desconhecido no desconstrutor."; + qCritical() << "Error desconhecido ao iniciar o serviço."; } } @@ -57,3 +65,70 @@ void cacicD::stop() qCritical() << "Error desconhecido ao parar o serviço."; } } + +bool cacicD::getTest(){ + try{ + CacicComm OCacicComm; + OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); + OCacicComm.setUsuario("cacic"); + OCacicComm.setPassword("cacic123"); + bool ok; + QJsonObject as; + as["computador"] = OCacic_Computer.toJsonObject(); + QJsonObject jsonresult = OCacicComm.comm("/ws/neo/login", &ok, as); + try{ + saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getTest.conf"); + return true; + } catch (...) { + qDebug() << "Erro ao salvar o arquivo de configurações."; + return false; + } + } catch (...){ + qDebug() << "Erro ao conectar com o servidor."; + return false; + } +} + +bool cacicD::getConfig(){ + try{ + CacicComm OCacicComm; + OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); + OCacicComm.setUsuario("cacic"); + OCacicComm.setPassword("cacic123"); + bool ok; + QJsonObject as; + as["computador"] = OCacic_Computer.toJsonObject(); + QJsonObject jsonresult = OCacicComm.comm("/ws/neo/login", &ok, as); + try{ + saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getConfig.conf"); + return true; + } catch (...) { + qDebug() << "Erro ao salvar o arquivo de configurações."; + return false; + } + } catch (...){ + qDebug() << "Erro ao conectar com o servidor."; + return false; + } +} + +void cacicD::saveJson(QJsonDocument document, QString fileName) { +#if defined(Q_OS_LINUX) + QFile jsonFile(app->applicationDirPath().append("/" + fileName)); +#elif defined(Q_OS_WIN) + QFile jsonFile(app->applicationDirPath().append("\\" + fileName)); +#endif + jsonFile.open(QFile::WriteOnly); + jsonFile.write(document.toJson()); + jsonFile.close(); +} + +QJsonDocument cacicD::loadJson(QString fileName) { +#if defined(Q_OS_LINUX) + QFile jsonFile(app->applicationDirPath().append("/" + fileName)); +#elif defined(Q_OS_WIN) + QFile jsonFile(app->applicationDirPath().append("\\" + fileName)); +#endif + jsonFile.open(QFile::ReadOnly); + return QJsonDocument().fromJson(jsonFile.readAll()); +} diff --git a/cacicD/cacicd.h b/cacicD/cacicd.h index ef462b9..a08bca1 100644 --- a/cacicD/cacicd.h +++ b/cacicD/cacicd.h @@ -4,40 +4,34 @@ #include #include #include +#include +#include +#include #include "qtservice.h" +#include "cacic_comm.h" +#include "cacic_computer.h" class cacicD : public QtService { public: - /** - * @brief cacicD Construtor - * @param argc - * @param argv - */ cacicD(int argc, char **argv); - /** - * @brief cacicD Desconstrutor - */ ~cacicD(); - /** - * @brief inicia o serviço - */ void start(); - /** - * @brief pausa o serviço - */ void pause(); - /** - * @brief resume a execução do serviço - */ void resume(); - /** - * @brief para a execução do serviço - */ void stop(); + QCoreApplication *app; + void saveJson(QJsonDocument document, QString fileName); + QJsonDocument loadJson(QString fileName); - +private: + QString testPath; + QString testIniPath; + QJsonObject session; + CACIC_Computer OCacic_Computer; + bool getTest(); + bool getConfig(); }; #endif // CACICD_H diff --git a/src/cacic_comm.h b/src/cacic_comm.h index 81cd431..9951f61 100644 --- a/src/cacic_comm.h +++ b/src/cacic_comm.h @@ -64,7 +64,7 @@ public: url = urlSsl.isEmpty() ? "https://" + this->urlGerente + route : this->urlSsl + route; req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); } else - url = urlGerente + route; + url = "http://" + urlGerente + route; req.setUrl(url); req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); if (json.empty()) -- libgit2 0.21.2