HxNvr/HxVideoCaptor/main.cpp
2024-01-25 18:38:39 +08:00

87 lines
2.3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "main.h"
#include "HxDevice.h"
#include "HxRecordCleanup.h"
/* 是否为初次启动 */
static bool is_startup = true;
/* 视频设备 */
static HxDevice* main_device[16];
static void broadcast_receive_event(QByteArray data);
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
/* 设置最大线程个数 */
QThreadPool::globalInstance()->setMaxThreadCount(100);
/* UDP广播 初始化 */
HxBroadcast::initialization(BROADCAST_PORT);
QObject::connect(HxBroadcast::context(), &HxBroadcast::receive_event, [=](QByteArray data) { broadcast_receive_event(data); });
WRITE_SYSTEM_LOG("系统启动", HxReadMe::version());
/* 启动录像清理线程 */
HxTask::run(&HxRecordCleanup::process, 60000, QUuid::createUuid());
HxTask::run([=]()
{
/* 判断是否为第一次启动, 没有获取到过设置信息, 需要定时查询 */
if (is_startup)
{
/* 向服务程序发送 设置请求 */
HxBroadcast::publish_json(1);
HxTrace::debug_write_line("application", "无法获取到设置信息请检查server程序状态");
}
/* 向服务程序发送 心跳数据 */
HxBroadcast::publish_json(0, { {"name", "HxNvr"}, {"version", "1.00"} });
}, 5000, QUuid::createUuid());
return a.exec();
}
void broadcast_receive_event(QByteArray data)
{
int action_type = -1;
auto document = QJsonDocument::fromJson(data);
auto root = document.object();
if (!root.contains("action_type"))
return;
action_type = root.value("action_type").toInt();
switch (action_type)
{
case 1:
HxTask::invoke([=](QJsonObject _msginfo) {
if(_msginfo.size() == 0)
return;
HxRecordCleanup::set(_msginfo);
if (is_startup)
{
for (int i = 0; i < CHANNEL_MAX; i++)
{
main_device[i] = new HxDevice(i);
main_device[i]->startup(_msginfo);
}
is_startup = false;
}
}, root.value("msgInfo").toObject());
break;
case 5:
HxRecordCleanup::set_records_array(root.value("msgInfo").toArray());
break;
}
}