Commit 057ff81bcdd0f1f91a58770c5b35a057ea1514b9

Authored by LightBase Consultoria em Software Publico
1 parent d4ccf4a1
Exists in master

Implementações: Daemon do Cacic, getTest() e getConfig()

cacicD/cacicD.pro
@@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
5 #------------------------------------------------- 5 #-------------------------------------------------
6 6
7 QT += core 7 QT += core
8 -  
9 QT -= gui 8 QT -= gui
10 9
11 TARGET = cacicD 10 TARGET = cacicD
@@ -21,13 +20,18 @@ TEMPLATE = app @@ -21,13 +20,18 @@ TEMPLATE = app
21 20
22 SOURCES += main.cpp \ 21 SOURCES += main.cpp \
23 ../src/ccacic.cpp \ 22 ../src/ccacic.cpp \
24 - cacicd.cpp 23 + cacicd.cpp \
  24 + ../src/cacic_computer.cpp \
  25 + ../src/operatingsystem.cpp
25 26
26 HEADERS += \ 27 HEADERS += \
27 ../src/ccacic.h \ 28 ../src/ccacic.h \
28 - cacicd.h 29 + cacicd.h \
  30 + ../src/cacic_computer.h \
  31 + ../src/operatingsystem.h
29 32
30 include(../src/qtservice/src/qtservice.pri) 33 include(../src/qtservice/src/qtservice.pri)
31 34
32 INCLUDEPATH += ../src \ 35 INCLUDEPATH += ../src \
33 ../src/crypto++/include/ 36 ../src/crypto++/include/
  37 +
cacicD/cacicd.cpp
@@ -22,12 +22,20 @@ cacicD::~cacicD() @@ -22,12 +22,20 @@ cacicD::~cacicD()
22 void cacicD::start() 22 void cacicD::start()
23 { 23 {
24 try{ 24 try{
25 - QCoreApplication *app = application();  
26 - qDebug() << "Serviço iniciado.";  
27 - qDebug() << app->applicationDirPath();  
28 - 25 + this->app = application();
  26 + qDebug() << "\nServiço iniciado em" << app->applicationDirPath();
  27 + if(getTest()){
  28 + qDebug() << "\ngetTest() success.";
  29 + }else{
  30 + qDebug() << "\ngetTest() error.";
  31 + }
  32 + if(getConfig()){
  33 + qDebug() << "\ngetconfig() success.";
  34 + }else{
  35 + qDebug() << "\ngetconfig() error.";
  36 + }
29 } catch (...){ 37 } catch (...){
30 - qCritical() << "Error desconhecido no desconstrutor."; 38 + qCritical() << "Error desconhecido ao iniciar o serviço.";
31 } 39 }
32 } 40 }
33 41
@@ -57,3 +65,70 @@ void cacicD::stop() @@ -57,3 +65,70 @@ void cacicD::stop()
57 qCritical() << "Error desconhecido ao parar o serviço."; 65 qCritical() << "Error desconhecido ao parar o serviço.";
58 } 66 }
59 } 67 }
  68 +
  69 +bool cacicD::getTest(){
  70 + try{
  71 + CacicComm OCacicComm;
  72 + OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php");
  73 + OCacicComm.setUsuario("cacic");
  74 + OCacicComm.setPassword("cacic123");
  75 + bool ok;
  76 + QJsonObject as;
  77 + as["computador"] = OCacic_Computer.toJsonObject();
  78 + QJsonObject jsonresult = OCacicComm.comm("/ws/neo/login", &ok, as);
  79 + try{
  80 + saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getTest.conf");
  81 + return true;
  82 + } catch (...) {
  83 + qDebug() << "Erro ao salvar o arquivo de configurações.";
  84 + return false;
  85 + }
  86 + } catch (...){
  87 + qDebug() << "Erro ao conectar com o servidor.";
  88 + return false;
  89 + }
  90 +}
  91 +
  92 +bool cacicD::getConfig(){
  93 + try{
  94 + CacicComm OCacicComm;
  95 + OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php");
  96 + OCacicComm.setUsuario("cacic");
  97 + OCacicComm.setPassword("cacic123");
  98 + bool ok;
  99 + QJsonObject as;
  100 + as["computador"] = OCacic_Computer.toJsonObject();
  101 + QJsonObject jsonresult = OCacicComm.comm("/ws/neo/login", &ok, as);
  102 + try{
  103 + saveJson(QJsonDocument::fromVariant(jsonresult.toVariantMap()), "getConfig.conf");
  104 + return true;
  105 + } catch (...) {
  106 + qDebug() << "Erro ao salvar o arquivo de configurações.";
  107 + return false;
  108 + }
  109 + } catch (...){
  110 + qDebug() << "Erro ao conectar com o servidor.";
  111 + return false;
  112 + }
  113 +}
  114 +
  115 +void cacicD::saveJson(QJsonDocument document, QString fileName) {
  116 +#if defined(Q_OS_LINUX)
  117 + QFile jsonFile(app->applicationDirPath().append("/" + fileName));
  118 +#elif defined(Q_OS_WIN)
  119 + QFile jsonFile(app->applicationDirPath().append("\\" + fileName));
  120 +#endif
  121 + jsonFile.open(QFile::WriteOnly);
  122 + jsonFile.write(document.toJson());
  123 + jsonFile.close();
  124 +}
  125 +
  126 +QJsonDocument cacicD::loadJson(QString fileName) {
  127 +#if defined(Q_OS_LINUX)
  128 + QFile jsonFile(app->applicationDirPath().append("/" + fileName));
  129 +#elif defined(Q_OS_WIN)
  130 + QFile jsonFile(app->applicationDirPath().append("\\" + fileName));
  131 +#endif
  132 + jsonFile.open(QFile::ReadOnly);
  133 + return QJsonDocument().fromJson(jsonFile.readAll());
  134 +}
cacicD/cacicd.h
@@ -4,40 +4,34 @@ @@ -4,40 +4,34 @@
4 #include <QCoreApplication> 4 #include <QCoreApplication>
5 #include <QObject> 5 #include <QObject>
6 #include <QDebug> 6 #include <QDebug>
  7 +#include <QDir>
  8 +#include <QTextStream>
  9 +#include <QVariant>
7 #include "qtservice.h" 10 #include "qtservice.h"
  11 +#include "cacic_comm.h"
  12 +#include "cacic_computer.h"
8 13
9 14
10 class cacicD : public QtService<QCoreApplication> 15 class cacicD : public QtService<QCoreApplication>
11 { 16 {
12 public: 17 public:
13 - /**  
14 - * @brief cacicD Construtor  
15 - * @param argc  
16 - * @param argv  
17 - */  
18 cacicD(int argc, char **argv); 18 cacicD(int argc, char **argv);
19 - /**  
20 - * @brief cacicD Desconstrutor  
21 - */  
22 ~cacicD(); 19 ~cacicD();
23 - /**  
24 - * @brief inicia o serviço  
25 - */  
26 void start(); 20 void start();
27 - /**  
28 - * @brief pausa o serviço  
29 - */  
30 void pause(); 21 void pause();
31 - /**  
32 - * @brief resume a execução do serviço  
33 - */  
34 void resume(); 22 void resume();
35 - /**  
36 - * @brief para a execução do serviço  
37 - */  
38 void stop(); 23 void stop();
  24 + QCoreApplication *app;
  25 + void saveJson(QJsonDocument document, QString fileName);
  26 + QJsonDocument loadJson(QString fileName);
39 27
40 - 28 +private:
  29 + QString testPath;
  30 + QString testIniPath;
  31 + QJsonObject session;
  32 + CACIC_Computer OCacic_Computer;
  33 + bool getTest();
  34 + bool getConfig();
41 }; 35 };
42 36
43 #endif // CACICD_H 37 #endif // CACICD_H
src/cacic_comm.h
@@ -64,7 +64,7 @@ public: @@ -64,7 +64,7 @@ public:
64 url = urlSsl.isEmpty() ? "https://" + this->urlGerente + route : this->urlSsl + route; 64 url = urlSsl.isEmpty() ? "https://" + this->urlGerente + route : this->urlSsl + route;
65 req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); 65 req.setSslConfiguration(QSslConfiguration::defaultConfiguration());
66 } else 66 } else
67 - url = urlGerente + route; 67 + url = "http://" + urlGerente + route;
68 req.setUrl(url); 68 req.setUrl(url);
69 req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); 69 req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
70 if (json.empty()) 70 if (json.empty())