-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathchecktaskthread.cpp
More file actions
102 lines (88 loc) · 3.14 KB
/
checktaskthread.cpp
File metadata and controls
102 lines (88 loc) · 3.14 KB
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
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "checktaskthread.h"
#include "api/myhelper.h"
#include "api/api.h"
#include "api/dbhelper.h"
CheckTaskThread::CheckTaskThread(QObject *parent) : QThread(parent)
{
stopped = false;
}
void CheckTaskThread::stop()
{
stopped = true;
}
void CheckTaskThread::run()
{
while(!stopped) {
int taskCount = App::TaskList.count();
if (taskCount > 0) {
mutex.lock();
//每次取出一个任务进行处理
QString task = App::TaskList.takeFirst();
mutex.unlock();
qDebug() << TIMEMS << "task:" << task;
QStringList list = task.split("|");
QString type = list.at(0);
if (type == "Print") {
QString str = QString("防区:%1[%2]\n类型:%3\n时间:%4")
.arg(list.at(2)).arg(list.at(1)).arg(list.at(3)).arg(list.at(4));
//调用打印函数
API::AddMessage("打印警情");
DBHelper::AddEventInfoUser("打印警情");
} else if (type == "Snap") {
int snapCount = App::SnapList.count();
//只有告警图像名称存在时
if (snapCount > 0) {
mutex.lock();
QString fileName = App::SnapList.takeFirst();
mutex.unlock();
//抓拍告警联动图像
Snap(list.at(1), list.at(2), list.at(4), fileName);
API::AddMessage("告警抓拍图像");
DBHelper::AddEventInfoUser("告警抓拍图像");
}
} else if (type == "Video") {
//弹出告警联动视频
API::AddMessage("告警联动视频");
DBHelper::AddEventInfoUser("告警联动视频");
}
}
msleep(100);
}
stopped = false;
}
QByteArray CheckTaskThread::GetHtml(QString url)
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
QEventLoop eventLoop;
QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
eventLoop.exec();
return reply->readAll();
}
void CheckTaskThread::Snap(QString ip, QString ch, QString time, QString fileName)
{
//判断文件夹是否存在,不存在则先创建
#ifdef __arm__
QString savePath = QString("%1/%2")
.arg(App::SnapPath)
.arg(QDate::currentDate().toString("yyyy-MM-dd"));
#else
QString savePath = QString("%1%2/%3")
.arg(App::AppPath)
.arg(App::SnapPath)
.arg(QDate::currentDate().toString("yyyy-MM-dd"));
#endif
QDir dir(savePath);
if (!dir.exists()) {
dir.mkpath(savePath);
}
//构建抓拍告警图像url地址
QString url = QString("http://%1/doSnapshot?channel=%2&stream=%3&timeago=%4")
.arg(ip).arg(ch).arg(1).arg(time);
QImage image;
image.loadFromData(GetHtml(url));
image.save(fileName, "jpg");
}