Subversion Repositories OpenInventory

Rev

Rev 242 | Rev 246 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 242 Rev 243
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
    process.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
    connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
11
 //   connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
11
    connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError()));
12
 //   connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError()));
12
13
13
14
14
15
15
}
16
}
16
17
17
void WmiThread::run(){
18
void WmiThread::run(){
18
19
19
20
-
 
21
   QEventLoop * loop = new QEventLoop();
-
 
22
    Woker woker; // îáúåêò äëÿ ðàáîòû â òåëå ïîòîêà
20
23
-
 
24
    // connect(&woker, SIGNAL(workEnd()), this, SLOT(wokerIsStopped()));
-
 
25
connect(&woker, SIGNAL(workEnd()), loop, SLOT(quit()));
-
 
26
/*
21
27

22
    QString query_string;
28
    QString query_string;
23
    error = false; //ñáðîñèì ôëàã îøèáêè
29
    error = false; //ñáðîñèì ôëàã îøèáêè
24
    query_string = tr("wmic -U ");
30
    query_string = tr("wmic -U ");
25
    query_string.append(user_name);
31
    query_string.append(user_name);
26
    query_string.append(tr("%"));
32
    query_string.append(tr("%"));
27
    query_string.append(password);
33
    query_string.append(password);
28
    query_string.append(tr(" //"));
34
    query_string.append(tr(" //"));
29
    query_string.append(host);
35
    query_string.append(host);
30
    query_string.append(tr(" \""));
36
    query_string.append(tr(" \""));
31
    query_string.append(wmi_string);
37
    query_string.append(wmi_string);
32
    query_string.append(tr("\""));
38
    query_string.append(tr("\""));
33
    // process.start(query_string);
39
    // process.start(query_string);
34
    process.start("ls\n");
40
    process.start("ls\n");
35
//    while (!stopped) {;}
41
//    while (!stopped) {;}
-
 
42

-
 
43

-
 
44
  */
-
 
45
36
    exec();
46
    woker.startProcess();
-
 
47
37
   // quit();
48
    loop->exec();
38
}
49
}
39
50
40
void WmiThread::stop(){
51
void WmiThread::stop(){
41
      mutex.lock();
52
      mutex.lock();
42
      stopped = true;
53
      stopped = true;
43
      mutex.unlock();
54
      mutex.unlock();
44
}
55
}
45
56
46
void WmiThread::readStandartProcessOutput(){
57
void WmiThread::readStandartProcessOutput(){
47
p_buffer = process.readAllStandardOutput();
58
p_buffer = process.readAllStandardOutput();
48
 qDebug() << QString(p_buffer);
59
 qDebug() << QString(p_buffer);
49
mutex.lock();
60
mutex.lock();
50
stopped = true;
61
stopped = true;
51
mutex.unlock();
62
mutex.unlock();
52
process.close();
63
process.close();
53
exit();
64
exit();
54
}
65
}
55
66
56
void WmiThread::readStandartProcessError(){
67
void WmiThread::readStandartProcessError(){
57
p_buffer = process.readAllStandardError();
68
p_buffer = process.readAllStandardError();
58
error = true; // åñëè îøèáêà, óñòàíîâèì ôëàã îøèáêè âûïîëíåíèÿ WMI-çàïðîñà
69
error = true; // åñëè îøèáêà, óñòàíîâèì ôëàã îøèáêè âûïîëíåíèÿ WMI-çàïðîñà
59
}
70
}
-
 
71
-
 
72
-
 
73
void WmiThread::wokerIsStopped(){
-
 
74
exit();
-
 
75
}
60
 
76