ccoleta.cpp
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "ccoleta.h"
CColeta::CColeta(QObject *parent)
{
}
void CColeta::coletaHardware()
{
// qDebug() << "coletaHardware() começando sua execução";
oHardware.iniciaColeta();
// qDebug() << "coletaHardware() executado";
emit hardwareFinish();
}
void CColeta::coletaSoftware()
{
// qDebug() << "coletaSoftware() começando sua execução";
oSoftware.iniciaColeta();
// qDebug() << "coletaSoftware() executado";
emit softwareFinish();
}
void CColeta::configuraColetas(){
QObject::connect(this, SIGNAL(beginHardware()), this, SLOT(coletaHardware()));
QObject::connect(this, SIGNAL(beginSoftware()), this, SLOT(coletaSoftware()));
QObject::connect(this, SIGNAL(softwareFinish()), this, SLOT(softwareReady()));
QObject::connect(this, SIGNAL(hardwareFinish()), this, SLOT(hardwareReady()));
}
bool CColeta::waitToCollect()
{
int timeout = 0;
while(!(this->softwareIsFinish && this->hardwareIsFinish) && timeout != 30){
QThread::sleep(1);
timeout++;
}
return true;
}
void CColeta::run()
{
/* Versão do json de testes */
QJsonObject coleta = oCacic.getJsonFromFile("getConfig.json");
// qDebug() << coleta;
QJsonObject actions = coleta["agentcomputer"].toObject()["actions"].toObject();
// qDebug() << actions["col_hard"].toBool() << actions["col_soft"].toBool();
if( actions.contains("col_hard") && actions["col_hard"].toBool()){
this->hardwareIsFinish = false;
emit beginHardware();
} else
this->hardwareIsFinish = true;
if ( actions.contains("col_soft") && actions["col_soft"].toBool()){
this->softwareIsFinish = false;
emit beginSoftware();
} else
this->softwareIsFinish = true;
}
QJsonObject CColeta::toJsonObject()
{
QJsonObject coletaJson;
if (this->hardwareIsFinish && this->softwareIsFinish){
coletaJson["computador"] = oComputer.toJsonObject();
coletaJson["hardware"] = oHardware.toJsonObject();
coletaJson["software"] = oSoftware.toJsonObject();
}
return coletaJson;
}
void CColeta::hardwareReady()
{
this->hardwareIsFinish = true;
}
void CColeta::softwareReady()
{
this->softwareIsFinish = true;
}
CACIC_Computer CColeta::getOComputer() const
{
return oComputer;
}
cacic_software CColeta::getOSoftware() const
{
return oSoftware;
}
cacic_hardware CColeta::getOHardware() const
{
return oHardware;
}