Commit dab2fadb6aa331e2f899341baa37b7e23acaff44

Authored by Eric Menezes Noronha
1 parent f78ed3f8
Exists in master

debug e merge

cacic-teste/cacic-teste.pro
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 6
7 QT += testlib 7 QT += testlib
8 QT += network 8 QT += network
9 - 9 +QT += axcontainer
10 TARGET = cacic-teste 10 TARGET = cacic-teste
11 CONFIG -= app_bundle 11 CONFIG -= app_bundle
12 CONFIG += c++11 12 CONFIG += c++11
@@ -21,10 +21,11 @@ SOURCES += \ @@ -21,10 +21,11 @@ SOURCES += \
21 testcacic.cpp \ 21 testcacic.cpp \
22 ../src/ccacic.cpp \ 22 ../src/ccacic.cpp \
23 ../src/cacic_computer.cpp \ 23 ../src/cacic_computer.cpp \
24 - ../src/cacic_hardware.cpp \  
25 ../src/operatingsystem.cpp \ 24 ../src/operatingsystem.cpp \
26 ../src/cacic_software.cpp \ 25 ../src/cacic_software.cpp \
27 ../src/cacic_hardware.cpp \ 26 ../src/cacic_hardware.cpp \
  27 + ../src/vqtconvert.cpp \
  28 + ../src/vregistry.cpp \
28 # ../src/qtservice/src/qtservice.cpp \ 29 # ../src/qtservice/src/qtservice.cpp \
29 # ../src/qtservice/src/qtservice_unix.cpp \ 30 # ../src/qtservice/src/qtservice_unix.cpp \
30 # ../src/qtservice/src/qtservice_win.cpp \ 31 # ../src/qtservice/src/qtservice_win.cpp \
@@ -36,17 +37,19 @@ HEADERS += \ @@ -36,17 +37,19 @@ HEADERS += \
36 testcacic.h \ 37 testcacic.h \
37 ../src/ccacic.h \ 38 ../src/ccacic.h \
38 ../src/cacic_computer.h \ 39 ../src/cacic_computer.h \
39 - ../src/cacic_hardware.h \  
40 ../src/cacic_comm.h \ 40 ../src/cacic_comm.h \
41 ../src/console.h \ 41 ../src/console.h \
42 ../src/operatingsystem.h \ 42 ../src/operatingsystem.h \
43 ../src/cacic_software.h \ 43 ../src/cacic_software.h \
44 ../src/cacic_hardware.h \ 44 ../src/cacic_hardware.h \
  45 + ../src/vqtconvert.h \
  46 + ../src/vregistry.h \
45 # ../src/qtservice/src/qtservice.h \ 47 # ../src/qtservice/src/qtservice.h \
46 # ../src/qtservice/src/qtservice_p.h \ 48 # ../src/qtservice/src/qtservice_p.h \
47 # ../src/qtservice/src/qtunixserversocket.h \ 49 # ../src/qtservice/src/qtunixserversocket.h \
48 # ../src/qtservice/src/qtunixsocket.h 50 # ../src/qtservice/src/qtunixsocket.h
49 - ../src/cacic_hardware.h  
50 51
51 INCLUDEPATH += ../src \ 52 INCLUDEPATH += ../src \
52 ../src/crypto++/include/ 53 ../src/crypto++/include/
  54 +
  55 +include(../src/qtservice/src/qtservice.pri)
cacic-teste/testcacic.cpp
@@ -190,25 +190,6 @@ void CTestCacic::testStartService() @@ -190,25 +190,6 @@ void CTestCacic::testStartService()
190 QVERIFY(ok); 190 QVERIFY(ok);
191 } 191 }
192 192
193 -void CTestCacic::testReadConfig()  
194 -{  
195 -  
196 -// // Inicializa um arquivo de configuração stub  
197 -// // que seria parecido com o recebido do Gerente  
198 -// QJsonObject configJson;  
199 -// QJsonObject configHardware;  
200 -  
201 -// configHardware["computador"] = OCacicComp.toJsonObject();  
202 -  
203 -// configJson["hardware"] = configHardware;  
204 -  
205 -// OCacic.setJsonToFile(configJson,"configRequest.json");  
206 -  
207 - // Leitura do arquivo de configuração  
208 -  
209 - QVERIFY(false);  
210 -}  
211 -  
212 void CTestCacic::testSetRegistry() 193 void CTestCacic::testSetRegistry()
213 { 194 {
214 QVariantMap valueMap; 195 QVariantMap valueMap;
cacic-teste/testcacic.h
@@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
16 #include <iostream> 16 #include <iostream>
17 #include <QtNetwork/QtNetwork> 17 #include <QtNetwork/QtNetwork>
18 #include <QJsonObject> 18 #include <QJsonObject>
19 -#include "../install-cacic/installcacic.h"  
20 -#include "../gercols/gercols.h"  
21 -#include "../cacicD/cacicd.h"  
22 19
23 class CTestCacic : public QObject 20 class CTestCacic : public QObject
24 { 21 {
@@ -66,7 +63,6 @@ private slots: @@ -66,7 +63,6 @@ private slots:
66 void testJsonToFile(); 63 void testJsonToFile();
67 void testJsonFromFile(); 64 void testJsonFromFile();
68 void testStartService(); 65 void testStartService();
69 - void testReadConfig();  
70 void testSetRegistry(); 66 void testSetRegistry();
71 void testGetValueFromRegistry(); 67 void testGetValueFromRegistry();
72 void testRemoveRegistry(); 68 void testRemoveRegistry();
gercols/gercols.pro
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 QT += core 7 QT += core
8 QT += network 8 QT += network
9 QT -= gui 9 QT -= gui
  10 +QT += axcontainer
10 11
11 TARGET = gercols 12 TARGET = gercols
12 CONFIG += console 13 CONFIG += console
install-cacic/install-cacic.pro.user
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE QtCreatorProject> 2 <!DOCTYPE QtCreatorProject>
3 -<!-- Written by QtCreator 3.1.2, 2014-08-20T18:37:20. --> 3 +<!-- Written by QtCreator 3.1.2, 2014-08-26T18:17:49. -->
4 <qtcreator> 4 <qtcreator>
5 <data> 5 <data>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable> 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
src/cacic_hardware.cpp
1 #include "cacic_hardware.h" 1 #include "cacic_hardware.h"
2 -  
3 cacic_hardware::cacic_hardware() 2 cacic_hardware::cacic_hardware()
4 { 3 {
5 } 4 }
@@ -12,15 +11,30 @@ void cacic_hardware::iniciaColeta() @@ -12,15 +11,30 @@ void cacic_hardware::iniciaColeta()
12 this->coletaHardware = coletaLinux(); 11 this->coletaHardware = coletaLinux();
13 #endif 12 #endif
14 } 13 }
15 - 14 +#ifdef Q_OS_WIN
16 QJsonObject cacic_hardware::coletaWin() 15 QJsonObject cacic_hardware::coletaWin()
17 { 16 {
18 -#if defined(Q_OS_WIN)  
19 - // Implementação seguindo as definições na documentação WMI.  
20 -#endif 17 + QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator");
  18 + QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)",QString("."),QString("root\\cimv2"));
  19 + if (objWMIService->isNull())
  20 + {
  21 + return QJsonObject();
  22 + }
  23 + QAxObject *returnList = objWMIService->querySubObject("ExecQuery(QString&)",QString("select SystemType from win32_computersystem"));
  24 + QAxObject *enum1 = returnList->querySubObject("_NewEnum");
  25 + IEnumVARIANT* enumInterface; //to get this, include <windows.h>
  26 + enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface);
  27 + enumInterface->Reset(); //start at the beginning of the list.
  28 + for (int i=0;i<returnList->dynamicCall("Count").toInt();i++){
  29 + VARIANT *theItem;
  30 + enumInterface->Next(1,theItem,NULL);
  31 + QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal);
  32 + qDebug() << item->dynamicCall("Caption");
  33 + }
  34 +
21 return QJsonObject(); 35 return QJsonObject();
22 } 36 }
23 - 37 +#elif Q_OS_LINUX
24 QJsonObject cacic_hardware::coletaLinux() 38 QJsonObject cacic_hardware::coletaLinux()
25 { 39 {
26 40
@@ -78,161 +92,6 @@ QJsonObject cacic_hardware::coletaLinux() @@ -78,161 +92,6 @@ QJsonObject cacic_hardware::coletaLinux()
78 return hardware; 92 return hardware;
79 } 93 }
80 94
81 -int cacic_hardware::wmi()  
82 -{  
83 -// HRESULT hres;  
84 -  
85 -// // Step 1: --------------------------------------------------  
86 -// // Initialize COM. ------------------------------------------  
87 -  
88 -// hres = CoInitializeEx(0, COINIT_MULTITHREADED);  
89 -// if (FAILED(hres))  
90 -// {  
91 -// cout << "Failed to initialize COM library. Error code = 0x"  
92 -// << hex << hres << endl;  
93 -// return 1; // Program has failed.  
94 -// }  
95 -  
96 -// // Step 2: --------------------------------------------------  
97 -// // Set general COM security levels --------------------------  
98 -  
99 -// hres = CoInitializeSecurity(  
100 -// NULL,  
101 -// -1, // COM authentication  
102 -// NULL, // Authentication services  
103 -// NULL, // Reserved  
104 -// RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication  
105 -// RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
106 -// NULL, // Authentication info  
107 -// EOAC_NONE, // Additional capabilities  
108 -// NULL // Reserved  
109 -// );  
110 -  
111 -  
112 -// if (FAILED(hres))  
113 -// {  
114 -// cout << "Failed to initialize security. Error code = 0x"  
115 -// << hex << hres << endl;  
116 -// CoUninitialize();  
117 -// return 1; // Program has failed.  
118 -// }  
119 -  
120 -// // Step 3: ---------------------------------------------------  
121 -// // Obtain the initial locator to WMI -------------------------  
122 -  
123 -// IWbemLocator *pLoc = NULL;  
124 -  
125 -// hres = CoCreateInstance(  
126 -// CLSID_WbemLocator,  
127 -// 0,  
128 -// CLSCTX_INPROC_SERVER,  
129 -// IID_IWbemLocator, (LPVOID *) &pLoc);  
130 -  
131 -// if (FAILED(hres))  
132 -// {  
133 -// cout << "Failed to create IWbemLocator object."  
134 -// << " Err code = 0x"  
135 -// << hex << hres << endl;  
136 -// CoUninitialize();  
137 -// return 1; // Program has failed.  
138 -// }  
139 -  
140 -// // Step 4: -----------------------------------------------------  
141 -// // Connect to WMI through the IWbemLocator::ConnectServer method  
142 -  
143 -// IWbemServices *pSvc = NULL;  
144 -  
145 -// // Connect to the local root\cimv2 namespace  
146 -// // and obtain pointer pSvc to make IWbemServices calls.  
147 -// hres = pLoc->ConnectServer(  
148 -// _bstr_t(L"ROOT\\CIMV2"),  
149 -// NULL,  
150 -// NULL,  
151 -// 0,  
152 -// NULL,  
153 -// 0,  
154 -// 0,  
155 -// &pSvc  
156 -// );  
157 -  
158 -// if (FAILED(hres))  
159 -// {  
160 -// cout << "Could not connect. Error code = 0x"  
161 -// << hex << hres << endl;  
162 -// pLoc->Release();  
163 -// CoUninitialize();  
164 -// return 1; // Program has failed.  
165 -// }  
166 -  
167 -// cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;  
168 -  
169 -  
170 -// // Step 5: --------------------------------------------------  
171 -// // Set security levels on the proxy -------------------------  
172 -  
173 -// hres = CoSetProxyBlanket(  
174 -// pSvc, // Indicates the proxy to set  
175 -// RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx  
176 -// RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx  
177 -// NULL, // Server principal name  
178 -// RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx  
179 -// RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx  
180 -// NULL, // client identity  
181 -// EOAC_NONE // proxy capabilities  
182 -// );  
183 -  
184 -// if (FAILED(hres))  
185 -// {  
186 -// cout << "Could not set proxy blanket. Error code = 0x"  
187 -// << hex << hres << endl;  
188 -// pSvc->Release();  
189 -// pLoc->Release();  
190 -// CoUninitialize();  
191 -// return 1; // Program has failed.  
192 -// }  
193 -  
194 -// // Step 6: --------------------------------------------------  
195 -// // Use the IWbemServices pointer to make requests of WMI ----  
196 -  
197 -// // For example, get the name of the operating system.  
198 -// // The IWbemService::ExecQueryAsync method will call  
199 -// // the QuerySink::Indicate method when it receives a result  
200 -// // and the QuerySink::Indicate method will display the OS name  
201 -// QuerySink* pResponseSink = new QuerySink();  
202 -// hres = pSvc->ExecQueryAsync(  
203 -// bstr_t("WQL"),  
204 -// bstr_t("SELECT * FROM Win32_OperatingSystem"),  
205 -// WBEM_FLAG_BIDIRECTIONAL,  
206 -// NULL,  
207 -// pResponseSink);  
208 -  
209 -// if (FAILED(hres))  
210 -// {  
211 -// cout << "Query for operating system name failed."  
212 -// << " Error code = 0x"  
213 -// << hex << hres << endl;  
214 -// pSvc->Release();  
215 -// pLoc->Release();  
216 -// pResponseSink->Release();  
217 -// CoUninitialize();  
218 -// return 1; // Program has failed.  
219 -// }  
220 -  
221 -// // Step 7: -------------------------------------------------  
222 -// // Wait to get the data from the query in step 6 -----------  
223 -// Sleep(500);  
224 -// pSvc->CancelAsyncCall(pResponseSink);  
225 -  
226 -// // Cleanup  
227 -// // ========  
228 -// pSvc->Release();  
229 -// pLoc->Release();  
230 -// CoUninitialize();  
231 -  
232 - return 0; // Program successfully completed.  
233 -  
234 -}  
235 -  
236 void cacic_hardware::coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component) 95 void cacic_hardware::coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component)
237 { 96 {
238 QJsonObject memory; 97 QJsonObject memory;
@@ -297,7 +156,7 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &amp;hardware, const QJsonObject &amp;pc @@ -297,7 +156,7 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &amp;hardware, const QJsonObject &amp;pc
297 } 156 }
298 } 157 }
299 } 158 }
300 - 159 +#endif
301 QJsonObject cacic_hardware::toJsonObject() { 160 QJsonObject cacic_hardware::toJsonObject() {
302 return coletaHardware; 161 return coletaHardware;
303 } 162 }
src/cacic_hardware.h
@@ -3,20 +3,13 @@ @@ -3,20 +3,13 @@
3 #include <ccacic.h> 3 #include <ccacic.h>
4 #include <QtCore> 4 #include <QtCore>
5 #include <QJsonArray> 5 #include <QJsonArray>
6 -#include <QJsonArray>  
7 #include <cmath> 6 #include <cmath>
8 #include <ccacic.h> 7 #include <ccacic.h>
9 #include <console.h> 8 #include <console.h>
10 #include <operatingsystem.h> 9 #include <operatingsystem.h>
11 -  
12 -#if defined(Q_OS_WIN)  
13 - #define _WIN32_DCOM  
14 - #include <iostream>  
15 - //using namespace std;  
16 - #include <wbemidl.h> 10 +#ifdef Q_OS_WIN
  11 + #include <QAxObject>
17 #include <windows.h> 12 #include <windows.h>
18 - # pragma comment(lib, "wbemuuid.lib")  
19 -  
20 #endif 13 #endif
21 14
22 class cacic_hardware 15 class cacic_hardware
@@ -27,12 +20,14 @@ public: @@ -27,12 +20,14 @@ public:
27 QJsonObject toJsonObject(); 20 QJsonObject toJsonObject();
28 21
29 private: 22 private:
30 - int wmi(); 23 +#ifdef Q_OS_WIN
31 QJsonObject coletaWin(); 24 QJsonObject coletaWin();
  25 +#elif Q_OS_LINUX
32 QJsonObject coletaLinux(); 26 QJsonObject coletaLinux();
33 void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); 27 void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component);
34 void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); 28 void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component);
35 void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); 29 void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson);
  30 +#endif
36 31
37 CCacic oCacic; 32 CCacic oCacic;
38 QJsonObject coletaHardware; 33 QJsonObject coletaHardware;
src/cacic_software.cpp
@@ -49,7 +49,7 @@ QJsonObject cacic_software::coletaWin() @@ -49,7 +49,7 @@ QJsonObject cacic_software::coletaWin()
49 49
50 softwaresJson[key] = QJsonObject::fromVariantMap(software); 50 softwaresJson[key] = QJsonObject::fromVariantMap(software);
51 } 51 }
52 - qDebug() << softwaresJson; 52 +// qDebug() << softwaesJson;
53 } 53 }
54 return softwaresJson; 54 return softwaresJson;
55 } 55 }