Commit 18065fa9f6932a0eb34d44f9a07f0ffb65dad20d
1 parent
b0435f21
Exists in
master
COLETA PRONTA! Até o momento, em linux e windows, funcionando.
Showing
10 changed files
with
261 additions
and
69 deletions
Show diff stats
cacic-teste/cacic-teste.pro
... | ... | @@ -9,11 +9,11 @@ QT += network |
9 | 9 | |
10 | 10 | TARGET = cacic-teste |
11 | 11 | |
12 | -QT += axcontainer | |
13 | 12 | CONFIG -= app_bundle |
14 | 13 | CONFIG += c++11 |
15 | 14 | TEMPLATE = app |
16 | 15 | win32 { |
16 | + QT += axcontainer | |
17 | 17 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp |
18 | 18 | } else { |
19 | 19 | LIBS += -L/usr/lib -lcryptopp |
... | ... | @@ -28,6 +28,7 @@ SOURCES += \ |
28 | 28 | ../src/cacic_hardware.cpp \ |
29 | 29 | ../src/vqtconvert.cpp \ |
30 | 30 | ../src/vregistry.cpp \ |
31 | + ../src/ccoleta.cpp \ | |
31 | 32 | # ../src/qtservice/src/qtservice.cpp \ |
32 | 33 | # ../src/qtservice/src/qtservice_unix.cpp \ |
33 | 34 | # ../src/qtservice/src/qtservice_win.cpp \ |
... | ... | @@ -46,6 +47,7 @@ HEADERS += \ |
46 | 47 | ../src/cacic_hardware.h \ |
47 | 48 | ../src/vqtconvert.h \ |
48 | 49 | ../src/vregistry.h \ |
50 | + ../src/ccoleta.h \ | |
49 | 51 | # ../src/qtservice/src/qtservice.h \ |
50 | 52 | # ../src/qtservice/src/qtservice_p.h \ |
51 | 53 | # ../src/qtservice/src/qtunixserversocket.h \ | ... | ... |
cacic-teste/testcacic.cpp
... | ... | @@ -101,14 +101,11 @@ void CTestCacic::testpegarOS(){ |
101 | 101 | |
102 | 102 | void CTestCacic::testConsole() |
103 | 103 | { |
104 | - ConsoleObject console; | |
105 | 104 | #if defined(Q_OS_LINUX) |
105 | + ConsoleObject console; | |
106 | 106 | QVERIFY(console("echo teste").toStdString() == "teste\n"); |
107 | -#elif defined(Q_OS_WIN) | |
108 | - qDebug() << console("echo teste"); | |
109 | - QVERIFY(console("echo teste").toStdString() == "teste"); | |
110 | 107 | #else |
111 | - QVERIFY(false); | |
108 | + QSKIP("Teste desnecessário nessa plataforma"); | |
112 | 109 | #endif |
113 | 110 | } |
114 | 111 | |
... | ... | @@ -245,11 +242,33 @@ void CTestCacic::testGetTest() |
245 | 242 | QJsonObject envio; |
246 | 243 | envio["computador"] = OCacicComp.toJsonObject(); |
247 | 244 | OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); |
245 | + OCacicComm.comm("/ws/neo/getTest", &ok, envio); | |
248 | 246 | QVERIFY(ok); |
249 | 247 | } |
250 | 248 | |
249 | +void CTestCacic::testColeta() | |
250 | +{ | |
251 | + QJsonObject configTeste; | |
252 | + QJsonObject configComputer; | |
253 | + configComputer["operating_system"] = QJsonValue::fromVariant(QString("")); | |
254 | + configComputer["user"] = QJsonValue::fromVariant(QString("")); | |
255 | + configComputer["network_interface"] = QJsonValue::fromVariant(QString("")); | |
256 | + configTeste["computer"] = configComputer; | |
257 | + configTeste["hardware"] = QJsonValue::fromVariant(QString("")); | |
258 | + configTeste["software"] = QJsonValue::fromVariant(QString("")); | |
259 | + | |
260 | + OCacic.setJsonToFile(configTeste,"configReq.json"); | |
261 | + oColeta.configuraColetas(); | |
262 | + oColeta.run(); | |
263 | + oColeta.waitToCollect(); | |
264 | +// qDebug() << oColeta.toJsonObject(); | |
265 | + QVERIFY(!oColeta.toJsonObject()["software"].toObject().isEmpty() && | |
266 | + !oColeta.toJsonObject()["hardware"].toObject().isEmpty()); | |
267 | +} | |
268 | + | |
251 | 269 | void CTestCacic::cleanupTestCase() |
252 | 270 | { |
253 | 271 | OCacic.deleteFile("configRequest.json"); |
254 | 272 | OCacic.deleteFile("teste.json"); |
273 | + OCacic.deleteFile("configReq.json"); | |
255 | 274 | } | ... | ... |
cacic-teste/testcacic.h
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | #include <iostream> |
17 | 17 | #include <QtNetwork/QtNetwork> |
18 | 18 | #include <QJsonObject> |
19 | +#include <ccoleta.h> | |
19 | 20 | |
20 | 21 | class CTestCacic : public QObject |
21 | 22 | { |
... | ... | @@ -33,6 +34,7 @@ private: |
33 | 34 | QString testIniPath; |
34 | 35 | QJsonObject session; |
35 | 36 | QString cripTeste; |
37 | + CColeta oColeta; | |
36 | 38 | // cacicD OcacicD; |
37 | 39 | |
38 | 40 | signals: |
... | ... | @@ -71,6 +73,7 @@ private slots: |
71 | 73 | void testColetaHardware(); |
72 | 74 | void testConvertDouble(); |
73 | 75 | void testGetTest(); |
76 | + void testColeta(); | |
74 | 77 | void cleanupTestCase(); |
75 | 78 | }; |
76 | 79 | ... | ... |
gercols/gercols.cpp
... | ... | @@ -23,7 +23,6 @@ Gercols::Gercols(QObject *parent) |
23 | 23 | //Pega chave do registro, que será pega na instalação. |
24 | 24 | oCacic.setChaveCrypt(oCacic.getValueFromRegistry("Lightbase", "Cacic", "key").toString()); |
25 | 25 | |
26 | -qDebug() << "TESTE"; | |
27 | 26 | oColeta = new CColeta(); |
28 | 27 | |
29 | 28 | QObject::connect(this, SIGNAL(iniciaConfiguracao()), oColeta, SLOT(configuraColetas())); |
... | ... | @@ -47,7 +46,7 @@ void Gercols::run() |
47 | 46 | emit iniciaColeta(); |
48 | 47 | |
49 | 48 | oCacic.deleteFile("configReq.json"); |
50 | - | |
49 | + oColeta->waitToCollect(); | |
51 | 50 | //salva json em arquivo |
52 | 51 | if (!oColeta->toJsonObject().isEmpty()) |
53 | 52 | oCacic.setJsonToFile(oColeta->toJsonObject(), "coleta.json"); | ... | ... |
gercols/gercols.pro
... | ... | @@ -12,6 +12,7 @@ TARGET = gercols |
12 | 12 | CONFIG += console |
13 | 13 | CONFIG -= app_bundle |
14 | 14 | CONFIG += qt |
15 | +CONFIG += c++11 | |
15 | 16 | |
16 | 17 | win32 { |
17 | 18 | QT += axcontainer |
... | ... | @@ -33,7 +34,6 @@ SOURCES += \ |
33 | 34 | ./gercols.cpp \ |
34 | 35 | ../src/vregistry.cpp \ |
35 | 36 | ../src/vqtconvert.cpp \ |
36 | -#win32 SOURCES += \ ../src/vregistry.cpp \ ../src/vqtconvert.cpp \ | |
37 | 37 | |
38 | 38 | HEADERS += \ |
39 | 39 | ../src/ccacic.h \ |
... | ... | @@ -46,7 +46,6 @@ HEADERS += \ |
46 | 46 | ./gercols.h \ |
47 | 47 | ../src/vregistry.h \ |
48 | 48 | ../src/vqtconvert.h \ |
49 | -#win32 HEADERS += \ ../src/vregistry.h \ ../src/vqtconvert.h \ | |
50 | 49 | |
51 | 50 | INCLUDEPATH += ../src \ |
52 | 51 | ../src/crypto++/include/ | ... | ... |
install-cacic/install-cacic.pro.user
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | 2 | <!DOCTYPE QtCreatorProject> |
3 | -<!-- Written by QtCreator 3.1.2, 2014-08-27T18:46:27. --> | |
3 | +<!-- Written by QtCreator 3.1.2, 2014-08-29T15:37:15. --> | |
4 | 4 | <qtcreator> |
5 | 5 | <data> |
6 | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
... | ... | @@ -217,9 +217,7 @@ |
217 | 217 | <value type="int">14</value> |
218 | 218 | </valuelist> |
219 | 219 | <value type="int" key="PE.EnvironmentAspect.Base">2</value> |
220 | - <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"> | |
221 | - <value type="QString">PROCESSOR_ARCHITECTURE=x64</value> | |
222 | - </valuelist> | |
220 | + <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> | |
223 | 221 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> |
224 | 222 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
225 | 223 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value> | ... | ... |
src/cacic_hardware.cpp
... | ... | @@ -16,111 +16,235 @@ QJsonObject cacic_hardware::coletaWin() |
16 | 16 | { |
17 | 17 | QJsonObject hardware; |
18 | 18 | QStringList params; |
19 | - QJsonObject wmi; | |
19 | + QJsonValue wmi; | |
20 | 20 | // Win32_ComputerSystem (Caption, Description, Domain, DNSHostName, Manufacturer, |
21 | 21 | // Model, Name, PrimaryOwnerName, TotalPhysicalMemory, Workgroup) |
22 | 22 | params << "Caption" << "Description" << "Domain" << "DNSHostName" << "Manufacturer" << "Model" |
23 | 23 | << "Name" << "PrimaryOwnerName" << "TotalPhysicalMemory" << "Workgroup"; |
24 | 24 | wmi = wmiSearch("Win32_ComputerSystem", params); |
25 | - if (!wmi.isEmpty()) | |
26 | - hardware["ComputerSystem"] = wmiSearch("Win32_ComputerSystem", params); | |
25 | + if (!wmi.isNull()) | |
26 | + hardware["ComputerSystem"] = wmi; | |
27 | 27 | //Win32_PortableBattery |
28 | 28 | // (Verifica se é notebook) |
29 | 29 | params.clear(); |
30 | - hardware["IsNotebook"] = QJsonValue::fromVariant(!wmiSearch("Win32_PortableBattery", params).isEmpty()); | |
30 | + hardware["IsNotebook"] = QJsonValue::fromVariant(!wmiSearch("Win32_PortableBattery", params).isNull()); | |
31 | 31 | //Win32_Bios |
32 | 32 | // (Manufacturer, SMBIOSBIOSVersion, BIOSVersion, Version, SerialNumber, ReleaseDate) |
33 | 33 | params.clear(); |
34 | 34 | params << "Manufacturer" << "SMBIOSBIOSVersion" << "BIOSVersion" << "Version" << "SerialNumber" << "ReleaseDate"; |
35 | 35 | wmi = wmiSearch("Win32_Bios", params); |
36 | - if (!wmi.isEmpty()) | |
36 | + if (!wmi.isNull()) | |
37 | 37 | hardware["Bios"] = wmi; |
38 | 38 | //Win32_BaseBoard |
39 | 39 | // (Manufacturer, Model, SerialNumber) |
40 | 40 | params.clear(); |
41 | 41 | params << "Manufacturer" << "Model" << "SerialNumber"; |
42 | 42 | wmi = wmiSearch("Win32_Baseboard", params); |
43 | - if (!wmi.isEmpty()) | |
43 | + if (!wmi.isNull()) | |
44 | 44 | hardware["BaseBoard"] = wmi; |
45 | 45 | //Win32_SystemEnclosure |
46 | 46 | // (Manufacturer, ChassisTypes, SerialNumber, SMBIOSAssetTag) |
47 | + params.clear(); | |
48 | + params << "Manufacturer" << "ChassisTypes" << "SerialNumber" << "SMBIOSAssetTag"; | |
49 | + wmi = wmiSearch("Win32_SystemEnclosure", params); | |
50 | + if (!wmi.isNull()) | |
51 | + hardware["SystemEnclosure"] = wmi; | |
47 | 52 | //Win32_FloppyDrive |
48 | 53 | // (Manufacturer, Caption, Description, Name, MediaType, Size) |
54 | + params.clear(); | |
55 | + params << "Manufacturer" << "Caption" << "Description" << "Name"; | |
56 | + wmi = wmiSearch("Win32_FloppyDrive", params); | |
57 | + if (!wmi.isNull()) | |
58 | + hardware["FloppyDrive"] = wmi; | |
49 | 59 | //Win32_DiskDrive |
50 | 60 | // (Manufacturer, Caption, Description, Name, MediaType, Size, SerialNumber, Model, FirmwareRevision) |
61 | + params.clear(); | |
62 | + params << "Manufacturer" << "Caption" << "Description" << "Name" << "MediaType" << "Size" << "SerialNumber" | |
63 | + << "Model" << "FirmwareRevision"; | |
64 | + wmi = wmiSearch("Win32_DiskDrive", params); | |
65 | + if (!wmi.isNull()) | |
66 | + hardware["DiskDrive"] = wmi; | |
51 | 67 | //Win32_CDROMDrive |
52 | 68 | // (Manufacturer, Caption, Description, Name, MediaType, Size) |
69 | + params.clear(); | |
70 | + params << "Manufacturer" << "Caption" << "Description" << "MediaType" << "Name" << "Size"; | |
71 | + wmi = wmiSearch("Win32_CDROMDrive", params); | |
72 | + if (!wmi.isNull()) | |
73 | + hardware["CDROMDrive"] = wmi; | |
53 | 74 | //Win32_FloppyController |
54 | 75 | // (Manufacturer, Caption, Description, Name) |
76 | + params.clear(); | |
77 | + params << "Manufacturer" << "Caption" << "Description" << "Name"; | |
78 | + wmi = wmiSearch("Win32_FloppyController", params); | |
79 | + if (!wmi.isNull()) | |
80 | + hardware["FloppyController"] = wmi; | |
55 | 81 | //Win32_SCSIController |
56 | 82 | // (Manufacturer, Caption, Description, Name, HardwareVersion) |
83 | + params.clear(); | |
84 | + params << "Manufacturer" << "Caption" << "Description" << "Name" << "HardwareVersion"; | |
85 | + wmi = wmiSearch("Win32_SCSIController", params); | |
86 | + if (!wmi.isNull()) | |
87 | + hardware["SCSIController"] = wmi; | |
57 | 88 | //Win32_InfraredDevice |
58 | 89 | // (Manufacturer, Caption, Description, Name) |
90 | + params.clear(); | |
91 | + params << "Manufacturer" << "Caption" << "Description" << "Name"; | |
92 | + wmi = wmiSearch("Win32_InfraredDevice", params); | |
93 | + if (!wmi.isNull()) | |
94 | + hardware["InfraredDevice"] = wmi; | |
59 | 95 | //Win32_USBController |
60 | 96 | // (Manufacturer, Caption, Description, Name) |
97 | + params.clear(); | |
98 | + params << "Manufacturer" << "Caption" << "Description" << "Name"; | |
99 | + wmi = wmiSearch("Win32_USBController", params); | |
100 | + if (!wmi.isNull()) | |
101 | + hardware["USBController"] = wmi; | |
61 | 102 | //Win32_PCMCIAController |
62 | 103 | // (Manufacturer, Caption, Description, Name) |
104 | + params.clear(); | |
105 | + params << "Manufacturer" << "Caption" << "Description" << "Name"; | |
106 | + wmi = wmiSearch("Win32_PCMCIAController", params); | |
107 | + if (!wmi.isNull()) | |
108 | + hardware["PCMCIAController"] = wmi; | |
63 | 109 | //Win32_VideoController |
64 | - // (Description, VideoProcessor, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution) | |
110 | + // (Description, VideoProcessor, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution, Caption, Name) | |
111 | + params.clear(); | |
112 | + params << "VideoProcessor" << "AdapterRAM" << "Description" << "Name" << "CurrentHorizontalResolution" | |
113 | + << "CurrentVerticalResolution" << "Caption" << "AcceleratorCapabilities"; | |
114 | + wmi = wmiSearch("Win32_VideoController", params); | |
115 | + if (!wmi.isNull()) | |
116 | + hardware["VideoController"] = wmi; | |
65 | 117 | //Win32_DesktopMonitor |
66 | - // (MonitorManufacturer, Caption, Description, MonitorType) | |
118 | + // (MonitorManufacturer, Caption, Description, MonitorType, Name) | |
119 | + params.clear(); | |
120 | + params << "MonitorManufacturer" << "Caption" << "Description" << "MonitorType" << "Name"; | |
121 | + wmi = wmiSearch("Win32_DesktopMonitor", params); | |
122 | + if (!wmi.isNull()) | |
123 | + hardware["DesktopMonitor"] = wmi; | |
67 | 124 | //Win32_Printer |
68 | 125 | // (Name, DriverName, PortName, ServerName, ShareName, HorizontalResolution, VerticalResolution, Comment, Shared, Network) |
126 | + params.clear(); | |
127 | + params << "Name" << "DriverName" << "PortName" << "ServerName" << "ShareName" << "HorizontalResolution" | |
128 | + << "VerticalResolution" << "Comment" << "Shared" << "Network"; | |
129 | + wmi = wmiSearch("Win32_Printer", params); | |
130 | + if (!wmi.isNull()) | |
131 | + hardware["Printer"] = wmi; | |
69 | 132 | //Win32_PortConnector |
70 | - // (ExternalReferenceDesignator, PortType, ConnectorType) | |
133 | + // (ExternalReferenceDesignator, PortType (verificar), ConnectorType (verificar), Manufacturer, Caption, Name) | |
134 | + params.clear(); | |
135 | + params << "ExternalReferenceDesignator" << "PortType" << "ConnectorType" << "Name" << "Caption" << "Manufacturer"; | |
136 | + wmi = wmiSearch("Win32_PortConnector", params); | |
137 | + if (!wmi.isNull()) | |
138 | + hardware["PortConnector"] = wmi; | |
71 | 139 | //Win32_SerialPort |
72 | 140 | // (Name, Caption, Description, StatusInfo) |
141 | + params.clear(); | |
142 | + params << "Name" << "Caption" << "Description" << "StatusInfo"; | |
143 | + wmi = wmiSearch("Win32_SerialPort", params); | |
144 | + if (!wmi.isNull()) | |
145 | + hardware["SerialPort"] = wmi; | |
73 | 146 | //Win32_Processor |
74 | - // (MaxClockSpeed, Name, Architecture, NumberOfCores, SocketDesignation, Manufacturer, Name, Architecture, NumberOfCores | |
147 | + // (MaxClockSpeed, Name, Architecture, NumberOfCores, SocketDesignation, Manufacturer, Architecture, NumberOfCores | |
75 | 148 | // CurrentClockSpeed, MaxClockSpeed, L2CacheSize, AddressWidth, DataWidth, VoltageCaps, CpuStatus, |
76 | 149 | // ProcessorId || UniqueId, AddressWidth) |
150 | + params.clear(); | |
151 | + params << "MaxClockSpeed" << "Name" << "Architecture" << "NumberOfCores" << "SocketDesignation" << "Manufacturer" | |
152 | + << "Architecture" << "NumberOfCores" << "CurrentClockSpeed" << "MaxClockSpeed" << "L2CacheSize" << "AddressWidth" | |
153 | + << "DataWidth" << "VoltageCaps" << "CpuStatus" << "ProcessorId" << "UniqueId" << "AddressWidth"; | |
154 | + wmi = wmiSearch("Win32_Processor", params); | |
155 | + if (!wmi.isNull()) | |
156 | + hardware["Processor"] = wmi; | |
77 | 157 | //Win32_OperatingSystem |
78 | 158 | // (Name, Version, CSDVersion, Description, InstallDate, Organization, RegisteredUser, SerialNumber) |
159 | + params.clear(); | |
160 | + params << "Name" << "Version" << "CSDVersion" << "Description" << "InstallDate" << "Organization" << "RegisteredUser" | |
161 | + << "SerialNumber"; | |
162 | + wmi = wmiSearch("Win32_OperatingSystem", params); | |
163 | + if (!wmi.isNull()) | |
164 | + hardware["OperatingSystem"] = wmi; | |
79 | 165 | //Win32_SystemSlot |
80 | 166 | // (Name, Description, SlotDesignation, CurrentUsage, Status, Shared) |
167 | + params.clear(); | |
168 | + params << "Name" << "Description" << "SlotDesignation" << "CurrentUsage" << "Status" << "Shared"; | |
169 | + wmi = wmiSearch("Win32_SystemSlot", params); | |
170 | + if (!wmi.isNull()) | |
171 | + hardware["SystemSlot"] = wmi; | |
81 | 172 | //Win32_LogicalDisk |
82 | 173 | // (Caption, DriveType, Filesystem, VolumeName, ProviderName, Filesystem, VolumeName, Size, FreeSpace) |
174 | + params.clear(); | |
175 | + params << "Caption" << "DriveType" << "Filesystem" << "VolumeName" << "ProviderName" << "Filesystem" << "VolumeName" | |
176 | + << "Size" << "FreeSpace"; | |
177 | + wmi = wmiSearch("Win32_LogicalDisk", params); | |
178 | + if (!wmi.isNull()) | |
179 | + hardware["LogicalDisk"] = wmi; | |
83 | 180 | //Win32_PhysicalMemory |
84 | - // (Caption, Description, BankLabel, DeviceLocator, Capacity, Speed, MemoryTypem, SerialNumber) | |
181 | + // (Caption, Description, BankLabel, DeviceLocator, Capacity, Speed, MemoryType, SerialNumber) | |
182 | + params.clear(); | |
183 | + params << "Caption" << "Description" << "BankLabel" << "DeviceLocator" << "Capacity" << "Speed" << "MemoryType"; | |
184 | + wmi = wmiSearch("Win32_PhysicalMemory", params); | |
185 | + if (!wmi.isNull()) | |
186 | + hardware["PhysicalMemory"] = wmi; | |
85 | 187 | //Win32_Keyboard |
86 | - // (Manufacturer, Caption, Description) | |
188 | + // (Caption, Description, Name) | |
189 | + params.clear(); | |
190 | + params << "Caption" << "Description" << "Name" << "Layout"; | |
191 | + wmi = wmiSearch("Win32_Keyboard", params); | |
192 | + if (!wmi.isNull()) | |
193 | + hardware["Keyboard"] = wmi; | |
87 | 194 | //Win32_PointingDevice |
88 | 195 | // (Manufacturer, Caption, Description, PointingType, DeviceInterface) |
196 | + params.clear(); | |
197 | + params << "Manufacturer" << "Caption" << "Description" << "PointingType" << "DeviceInterface"; | |
198 | + wmi = wmiSearch("Win32_PointingDevice", params); | |
199 | + if (!wmi.isNull()) | |
200 | + hardware["PointingDevice"] = wmi; | |
89 | 201 | //Win32_PnPSignedDriver |
90 | 202 | // (Manufacturer, DeviceName, Description, Location, DeviceClass) |
91 | - qDebug() << hardware; | |
203 | + params.clear(); | |
204 | + params << "Manufacturer" << "DeviceName" << "Description" << "Location" << "DeviceClass"; | |
205 | + wmi = wmiSearch("Win32_PnPSignedDriver", params); | |
206 | + if (!wmi.isNull()) | |
207 | + hardware["PnPSignedDriver"] = wmi; | |
208 | +// qDebug() << hardware; | |
92 | 209 | return hardware; |
93 | 210 | } |
94 | 211 | |
95 | -QJsonObject cacic_hardware::wmiSearch(QString classe, QStringList params) | |
212 | +QJsonValue cacic_hardware::wmiSearch(QString classe, QStringList params) | |
96 | 213 | { |
97 | - QJsonObject wmiReturn; | |
214 | + QJsonValue wmiReturn; | |
215 | + QJsonObject itemWmi; | |
216 | + QJsonArray arrayItens; | |
98 | 217 | QString paramsString; |
99 | 218 | if (!params.empty()){ |
100 | 219 | for(int i = 0; i!=params.size();i++) |
101 | 220 | paramsString.append(params.at(i) + ((i != params.size() - 1) ? "," : "")); |
102 | 221 | } |
103 | - QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); | |
222 | + QString query = "SELECT " + ((!paramsString.isEmpty()) ? paramsString : "*") + " FROM " + classe; | |
223 | + //conecta ao script (Como já estamos usando QObject, o WbemScripting... não funciona chamando normal, | |
224 | + // por isso deve ser usado o CoInitializeEx) | |
225 | + ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | |
226 | + QAxObject *objIWbemLocator = new QAxObject(); | |
227 | + objIWbemLocator->setControl("WbemScripting.SWbemLocator"); | |
228 | + if (objIWbemLocator->isNull()) | |
229 | + return QJsonValue(); | |
230 | + //conecta ao wmi | |
104 | 231 | QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)", |
105 | 232 | QString("."), |
106 | 233 | QString("root\\CIMV2") |
107 | 234 | ); |
108 | - QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", | |
109 | - QString("SELECT " + ((!paramsString.isEmpty()) ? | |
110 | - paramsString : "*") + | |
111 | - " FROM " + classe) | |
112 | - ); | |
235 | +// qDebug() << ">>>>>>>>>" << objIWbemLocator->isNull() << objWMIService->isNull(); | |
236 | + //Faz a pesquisa no wmi | |
237 | + QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", query); | |
238 | +// qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<"; | |
113 | 239 | QAxObject *enum1 = returnList->querySubObject("_NewEnum"); |
114 | - //ui->textBrowser_4->setHtml(enum1->generateDocumentation()); | |
240 | + | |
115 | 241 | IEnumVARIANT* enumInterface = 0; |
242 | + | |
116 | 243 | enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); |
117 | 244 | |
118 | - //ui->textBrowser_4->setHtml(enumInterface->); | |
119 | 245 | enumInterface->Reset(); |
120 | - // QAxObject *item = 0; | |
121 | - | |
122 | - //qDebug()<<"the count of objinterlist is "<<QString::number(objInterList->dynamicCall("Count").toInt()); | |
123 | - for (int i = 0; i < returnList->dynamicCall("Count").toInt(); i++) { | |
246 | + int countReturnListObj = returnList->dynamicCall("Count").toInt(); | |
247 | + for (int i = 0; i < countReturnListObj; i++) { | |
124 | 248 | VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); |
125 | 249 | if (enumInterface->Next(1,theItem,NULL) != S_FALSE){ |
126 | 250 | QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); |
... | ... | @@ -130,7 +254,6 @@ QJsonObject cacic_hardware::wmiSearch(QString classe, QStringList params) |
130 | 254 | QStringList instanceList = instance.split("\n\t"); |
131 | 255 | //Pra cada linha grava no json os valores com cada tag |
132 | 256 | foreach(QString value, instanceList){ |
133 | - qDebug() << value; | |
134 | 257 | QStringList valueList = value.split("="); |
135 | 258 | if (valueList.size() > 1){ |
136 | 259 | QString tag = valueList.at(0).trimmed(); |
... | ... | @@ -139,29 +262,41 @@ QJsonObject cacic_hardware::wmiSearch(QString classe, QStringList params) |
139 | 262 | aux.remove(";"); |
140 | 263 | aux.remove("\n"); |
141 | 264 | //verifica se é lista |
142 | - qDebug() << aux; | |
143 | - if(aux.contains("{") && aux.contains("}")){ | |
265 | + if(aux.startsWith("{") && aux.endsWith("}")){ | |
144 | 266 | QStringList auxList = aux.split(","); |
145 | 267 | QJsonArray jList; |
146 | 268 | foreach(QString valueList, auxList){ |
147 | 269 | if (valueList.contains("{")) |
148 | 270 | valueList.remove("{"); |
149 | - else if (valueList.contains("}")) | |
271 | + if (valueList.contains("}")) | |
150 | 272 | valueList.remove("}"); |
151 | 273 | jList.append(valueList.trimmed()); |
152 | 274 | } |
153 | - wmiReturn[tag] = jList; | |
275 | + itemWmi[tag] = jList; | |
154 | 276 | } else { |
155 | 277 | //O último valor sempre volta com "}" no final. |
156 | 278 | if (aux.contains("}")) |
157 | 279 | aux.remove("}"); |
158 | - wmiReturn[tag] = QJsonValue::fromVariant(aux.trimmed()); | |
280 | + itemWmi[tag] = QJsonValue::fromVariant(aux.trimmed()); | |
159 | 281 | } |
160 | 282 | } |
161 | - } | |
162 | - } | |
283 | + } // foreach(QString value, instanceList) | |
284 | + } // if(item) | |
285 | + } // if (enumInterface->Next(1,theItem,NULL) != S_FALSE) | |
286 | + //Se houver mais de um objeto, grava em uma lista | |
287 | + if (countReturnListObj > 1){ | |
288 | + arrayItens.append(QJsonValue(itemWmi)); | |
163 | 289 | } |
164 | 290 | } |
291 | + objIWbemLocator->clear(); | |
292 | + ::CoUninitialize(); | |
293 | + //se for mais de um objeto, retorna array. | |
294 | + if (!arrayItens.isEmpty()) | |
295 | + wmiReturn = QJsonValue(arrayItens); | |
296 | + //senão, se o objeto não for vazio (se tiver coletado algo) | |
297 | + else if (!itemWmi.isEmpty()) | |
298 | + wmiReturn = QJsonValue(itemWmi); | |
299 | + | |
165 | 300 | return wmiReturn; |
166 | 301 | } |
167 | 302 | #elif defined(Q_OS_LINUX) | ... | ... |
src/cacic_hardware.h
... | ... | @@ -22,7 +22,7 @@ public: |
22 | 22 | private: |
23 | 23 | #ifdef Q_OS_WIN |
24 | 24 | QJsonObject coletaWin(); |
25 | - QJsonObject wmiSearch(QString classe, QStringList params); | |
25 | + QJsonValue wmiSearch(QString classe, QStringList params); | |
26 | 26 | |
27 | 27 | #elif defined(Q_OS_LINUX) |
28 | 28 | QJsonObject coletaLinux(); | ... | ... |
src/ccoleta.cpp
... | ... | @@ -11,6 +11,7 @@ void CColeta::coletaHardware() |
11 | 11 | qDebug() << "coletaHardware() começando sua execução"; |
12 | 12 | oHardware.iniciaColeta(); |
13 | 13 | qDebug() << "coletaHardware() executado"; |
14 | + emit hardwareFinish(); | |
14 | 15 | } |
15 | 16 | |
16 | 17 | |
... | ... | @@ -19,45 +20,75 @@ void CColeta::coletaSoftware() |
19 | 20 | qDebug() << "coletaSoftware() começando sua execução"; |
20 | 21 | oSoftware.iniciaColeta(); |
21 | 22 | qDebug() << "coletaSoftware() executado"; |
22 | - | |
23 | + emit softwareFinish(); | |
23 | 24 | } |
24 | 25 | |
25 | 26 | void CColeta::configuraColetas(){ |
26 | 27 | QObject::connect(this, SIGNAL(beginHardware()), this, SLOT(coletaHardware())); |
27 | 28 | QObject::connect(this, SIGNAL(beginSoftware()), this, SLOT(coletaSoftware())); |
29 | + QObject::connect(this, SIGNAL(softwareFinish()), this, SLOT(softwareReady())); | |
30 | + QObject::connect(this, SIGNAL(hardwareFinish()), this, SLOT(hardwareReady())); | |
28 | 31 | } |
29 | 32 | |
30 | -CACIC_Computer CColeta::getOComputer() const | |
33 | +bool CColeta::waitToCollect() | |
31 | 34 | { |
32 | - return oComputer; | |
33 | -} | |
34 | - | |
35 | -cacic_software CColeta::getOSoftware() const | |
36 | -{ | |
37 | - return oSoftware; | |
38 | -} | |
39 | - | |
40 | -cacic_hardware CColeta::getOHardware() const | |
41 | -{ | |
42 | - return oHardware; | |
35 | + int timeout = 0; | |
36 | + while(!(this->softwareIsFinish && this->hardwareIsFinish) && timeout != 30){ | |
37 | + QThread::sleep(1); | |
38 | + timeout++; | |
39 | + } | |
40 | + return true; | |
43 | 41 | } |
44 | 42 | |
45 | 43 | void CColeta::run() |
46 | 44 | { |
47 | 45 | QJsonObject coleta = oCacic.getJsonFromFile("configReq.json"); |
48 | 46 | |
49 | - if( coleta.contains("hardware") ) | |
47 | + if( coleta.contains("hardware") ){ | |
48 | + this->hardwareIsFinish = false; | |
50 | 49 | emit beginHardware(); |
51 | - if ( coleta.contains("software") ) | |
50 | + } else | |
51 | + this->hardwareIsFinish = true; | |
52 | + if ( coleta.contains("software") ){ | |
53 | + this->softwareIsFinish = false; | |
52 | 54 | emit beginSoftware(); |
55 | + } else | |
56 | + this->softwareIsFinish = true; | |
53 | 57 | |
54 | 58 | } |
55 | 59 | |
56 | 60 | QJsonObject CColeta::toJsonObject() |
57 | 61 | { |
58 | 62 | QJsonObject coletaJson; |
59 | - coletaJson["computer"] = oComputer.toJsonObject(); | |
60 | - coletaJson["software"] = oSoftware.toJsonObject(); | |
61 | - coletaJson["hardware"] = oHardware.toJsonObject(); | |
63 | + if (this->hardwareIsFinish && this->softwareIsFinish){ | |
64 | + coletaJson["computer"] = oComputer.toJsonObject(); | |
65 | + coletaJson["software"] = oSoftware.toJsonObject(); | |
66 | + coletaJson["hardware"] = oHardware.toJsonObject(); | |
67 | + } | |
62 | 68 | return coletaJson; |
63 | 69 | } |
70 | + | |
71 | +void CColeta::hardwareReady() | |
72 | +{ | |
73 | + this->hardwareIsFinish = true; | |
74 | +} | |
75 | + | |
76 | +void CColeta::softwareReady() | |
77 | +{ | |
78 | + this->softwareIsFinish = true; | |
79 | +} | |
80 | + | |
81 | +CACIC_Computer CColeta::getOComputer() const | |
82 | +{ | |
83 | + return oComputer; | |
84 | +} | |
85 | + | |
86 | +cacic_software CColeta::getOSoftware() const | |
87 | +{ | |
88 | + return oSoftware; | |
89 | +} | |
90 | + | |
91 | +cacic_hardware CColeta::getOHardware() const | |
92 | +{ | |
93 | + return oHardware; | |
94 | +} | ... | ... |
src/ccoleta.h
... | ... | @@ -19,6 +19,8 @@ private: |
19 | 19 | CACIC_Computer oComputer; |
20 | 20 | cacic_software oSoftware; |
21 | 21 | cacic_hardware oHardware; |
22 | + bool hardwareIsFinish; | |
23 | + bool softwareIsFinish; | |
22 | 24 | |
23 | 25 | public: |
24 | 26 | explicit CColeta(QObject *parent = 0); |
... | ... | @@ -26,19 +28,23 @@ public: |
26 | 28 | CACIC_Computer getOComputer() const; |
27 | 29 | cacic_software getOSoftware() const; |
28 | 30 | cacic_hardware getOHardware() const; |
29 | - | |
31 | + bool waitToCollect(); | |
30 | 32 | QJsonObject toJsonObject(); |
31 | 33 | |
32 | 34 | public slots: |
33 | 35 | void coletaHardware(); |
34 | 36 | void coletaSoftware(); |
35 | 37 | void configuraColetas(); |
38 | + void hardwareReady(); | |
39 | + void softwareReady(); | |
36 | 40 | void run(); |
37 | 41 | |
38 | 42 | signals: |
39 | 43 | void beginComputer(); |
40 | 44 | void beginHardware(); |
41 | 45 | void beginSoftware(); |
46 | + void hardwareFinish(); | |
47 | + void softwareFinish(); | |
42 | 48 | void finished(); |
43 | 49 | }; |
44 | 50 | ... | ... |