/
common.cpp
116 lines (106 loc) · 3.39 KB
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "common.h"
#include <QTest>
#include <sstream>
#include <fstream>
#include <QRegExp>
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <iostream>
#include <QSettings>
#include <QDir>
#include <QTime>
#include <iostream>
#include<QFile>
using namespace std;
const QString glbstrXMLParamFile = "Top_block_param.xml";
QString glbExeName = "top_block.py";
QString glbLocalAdress = "127.0.0.1";
int glbLocalPort = 8010;
QString glbServerAdress = "127.0.0.1";
int glbServerPort = 9090;
int glbWatcherServerPort = 9001;
int glbMonitorServerPort = 9000;
QFile glbfileLog;
ClusterStatus glbWatcherStatus;
QString XMLFileName;
QString glboldString;
QString glbstrWorkDir;
void InitSystemParam()
{
QDir dir = QDir:: current();
QString sFile = "Option.ini";
if (!dir.exists(sFile))
{
cout << "Info:Option.ini is not existed,the program will build a new Option.ini."<<endl;
QSettings settings("Option.ini", QSettings::IniFormat); // 当前目录的INI文件
settings.beginGroup("DevOption");
settings.setValue("glbLocalAdress", glbLocalAdress);
settings.setValue("glbLocalPort", glbLocalPort);
settings.setValue("glbServerAdress", glbServerAdress);
settings.setValue("glbServerPort", glbServerPort);
settings.setValue("glbExeName", glbExeName);
settings.endGroup();
}
QSettings settings("Option.ini", QSettings::IniFormat); // 当前目录的INI文件
glbLocalAdress = settings.value("DevOption/glbLocalAdress").toString();
glbLocalPort = settings.value("DevOption/glbLocalPort").toInt();
glbServerAdress = settings.value("DevOption/glbServerAdress").toString();
glbServerPort = settings.value("DevOption/glbServerPort").toInt();
glbExeName = settings.value("DevOption/glbExeName").toString();
}
bool KillProcess(QString sName)
{
QString RE = "\\d\\d:\\d\\d:\\d\\d python " + sName; // python top_block.py";
QRegExp rgeexp(RE);
system("ps -ef | grep python > peinfo &");
QTest::qWait(1000);
QFile file("peinfo");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
cout << "Error:Can't find peinfo file!!!" << endl;
return false;
}
bool bFindTopblock = false;
QString strLine;
while (!file.atEnd()) {
strLine = QString(file.readLine());
qDebug()<< strLine;
if (strLine.contains(rgeexp))
{
bFindTopblock = true;
break;
}
}
if (!bFindTopblock)
{
cout << "Error:Can't find Radio Thread!!!" << endl;
file.close();
return false;
}
else
{
cout << "Info:Find Radio Thread!!!"<<endl;
QStringList list1 = strLine.split(QRegExp("\\s+"));
QString KillCmd = "kill -s 9 " + list1[1];
cout << "Info:" << KillCmd.toStdString().c_str() << endl;
system (KillCmd.toStdString().c_str());
QTest::qWait(100);
return true;
}
}
void LogOut(QString strLog)
{
cout << QTime::currentTime().toString("hh:mm:ss").toStdString().c_str() << " "<<strLog.toStdString().c_str() << endl;
}
void LogFile(QFile &file, QString strLog)
{
if (!file.exists())
{
LogOut("Log file is not exist.");
return;
}
strLog = QTime::currentTime().toString("hh:mm:ss.zzz ") + strLog + "\n";
file.write(strLog.toStdString().c_str(), strLog.length());
cout << strLog.toStdString().c_str();
}