Subversion Repositories OpenInventory

Rev

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

Rev 243 Rev 246
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
/*
-
 
27

26
-
 
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(tr("%"));
32
    query_string.append(tr("%"));
33
    query_string.append(password);
33
    query_string.append(password);
34
    query_string.append(tr(" //"));
34
    query_string.append(tr(" //"));
35
    query_string.append(host);
35
    query_string.append(host);
36
    query_string.append(tr(" \""));
36
    query_string.append(tr(" \""));
37
    query_string.append(wmi_string);
37
    query_string.append(wmi_string);
38
    query_string.append(tr("\""));
38
    query_string.append(tr("\""));
39
    // process.start(query_string);
39
    // process.start(query_string);
40
    process.start("ls\n");
40
    process.start("ls\n");
41
//    while (!stopped) {;}
41
//    while (!stopped) {;}
42

42

-
 
43
*/
43

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