Subversion Repositories OpenInventory

Rev

Rev 249 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 249 Rev 250
1
#include "wmithread.h"
1
#include "wmithread.h"
2
2
3
WmiThread::WmiThread(QObject *parent) :
3
WmiThread::WmiThread(QObject *parent) :
4
    QThread(parent)
4
    QThread(parent)
5
{
5
{
6
  //  woker.moveToThread(this);
6
  //  woker.moveToThread(this);
7
    mutex.lock();
7
    mutex.lock();
8
    stopped = false;
8
    stopped = false;
9
    mutex.unlock();
9
    mutex.unlock();
10
10
11
 //   connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
11
 //   connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
12
 //   connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError()));
12
 //   connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError()));
13
13
14
14
15
15
16
}
16
}
17
17
18
void WmiThread::run(){
18
void WmiThread::run(){
19
19
20
20
21
   QEventLoop loop; // = new QEventLoop();
21
   QEventLoop loop; // = new QEventLoop();
22
    Woker woker; // îáúåêò äëÿ ðàáîòû â òåëå ïîòîêà
22
    Woker woker; // îáúåêò äëÿ ðàáîòû â òåëå ïîòîêà
23
23
24
    // connect(&woker, SIGNAL(workEnd()), this, SLOT(wokerIsStopped()));
24
    // connect(&woker, SIGNAL(workEnd()), this, SLOT(wokerIsStopped()));
25
connect(&woker, SIGNAL(workEnd()), &loop, SLOT(quit()));
25
connect(&woker, SIGNAL(workEnd()), &loop, SLOT(quit()));
26
26
27
27
28
    QString query_string;
28
    QString query_string;
29
//    error = false; //ñáðîñèì ôëàã îøèáêè
29
//    error = false; //ñáðîñèì ôëàã îøèáêè
30
    query_string = tr("wmic -U ");
30
    query_string = tr("wmic -U ");
31
    query_string.append(user_name);
31
    query_string.append(user_name);
32
    query_string.append("%\"");
32
    query_string.append("%\"");
33
    query_string.append(password);
33
    query_string.append(password);
34
    query_string.append("\"");
34
    query_string.append("\"");
35
    query_string.append(tr(" //"));
35
    query_string.append(tr(" //"));
36
    query_string.append(host);
36
    query_string.append(host);
37
    query_string.append(tr(" \""));
37
    query_string.append(tr(" \""));
38
    query_string.append(wmi_string);
38
    query_string.append(wmi_string);
39
    query_string.append(tr("\""));
39
    query_string.append(tr("\""));
40
    // process.start(query_string);
40
    // process.start(query_string);
41
//    process.start("ls\n");
41
//    process.start("ls\n");
42
//    while (!stopped) {;}
42
//    while (!stopped) {;}
43
43
44
    qDebug() << query_string;
44
    qDebug() << query_string;
45
    woker.setProcessString(query_string);
45
    woker.setProcessString(query_string);
46
    woker.startProcess();
46
    woker.startProcess();
47
47
48
    loop.exec();
48
    loop.exec();
49
    p_buffer = woker.workBuffer();
49
    p_buffer = woker.workBuffer();
50
}
50
}
51
51
52
void WmiThread::stop(){
52
void WmiThread::stop(){
53
      mutex.lock();
53
      mutex.lock();
54
      stopped = true;
54
      stopped = true;
55
      mutex.unlock();
55
      mutex.unlock();
56
}
56
}
57
57
58
void WmiThread::readStandartProcessOutput(){
58
void WmiThread::readStandartProcessOutput(){
59
p_buffer = process.readAllStandardOutput();
59
p_buffer = process.readAllStandardOutput();
60
 qDebug() << QString(p_buffer);
60
 qDebug() << QString(p_buffer);
61
mutex.lock();
61
mutex.lock();
62
stopped = true;
62
stopped = true;
63
mutex.unlock();
63
mutex.unlock();
64
process.close();
64
process.close();
65
exit();
65
exit();
66
}
66
}
67
67
68
void WmiThread::readStandartProcessError(){
68
void WmiThread::readStandartProcessError(){
69
p_buffer = process.readAllStandardError();
69
p_buffer = process.readAllStandardError();
70
error = true; // åñëè îøèáêà, óñòàíîâèì ôëàã îøèáêè âûïîëíåíèÿ WMI-çàïðîñà
70
error = true; // åñëè îøèáêà, óñòàíîâèì ôëàã îøèáêè âûïîëíåíèÿ WMI-çàïðîñà
71
}
71
}
72
72
73
73
/*
74
void WmiThread::wokerIsStopped(){
74
void WmiThread::wokerIsStopped(){
75
exit();
75
exit();
76
}
76
}
-
 
77
*/
77
 
78