#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); /* 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, 1000, QUuid::createUuid()); HxTask::run([=]() { /* 判断是否为第一次启动, 没有获取到过设置信息, 需要定时查询 */ if (is_startup) HxBroadcast::publish_json(1); /* 发送心跳数据 */ HxBroadcast::publish_json(0, { {"name", "HxNvr"}, {"version", "1.00"} }); }, 1000, 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(); auto msginfo = root.value("msgInfo").toObject(); switch (action_type) { case 1: HxTask::invoke([=](QJsonObject _msginfo) { 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; } }, msginfo); break; case 5: HxRecordCleanup::set_records_array(root.value("msgInfo").toArray()); break; } }