设备监控-过滤

This commit is contained in:
flower_linux
2026-03-23 17:45:32 +08:00
parent 51fa0bb51b
commit bc07fa0e6e
23 changed files with 300 additions and 34 deletions

View File

@@ -4,6 +4,7 @@
#include <QJsonDocument>
#include <QSerialPort>
#include <QSet>
// #include <algorithm>
#include "hardware/drivers/serial/SerialQtDriver.h"
@@ -58,6 +59,44 @@ bool DeviceBusManager::initialize(const QJsonObject& rootConfig)
return true;
}
bool DeviceBusManager::reconcileFromTreeModel()
{
if (!m_treeModel) {
return false;
}
QSet<QString> desiredSerialEndpoints;
const auto nodes = m_treeModel->nodes();
for (const auto& n : nodes) {
if (!n.enabled) continue;
if (!n.params.value(QStringLiteral("online")).toBool(true)) continue;
auto kind = softbus::devices::kindFromType(n.type);
if (kind == softbus::devices::DeviceKind::Unknown) {
kind = softbus::devices::inferDeviceKindFromEndpoint(n.endpoint);
}
if (kind == softbus::devices::DeviceKind::Serial) {
desiredSerialEndpoints.insert(n.endpoint);
if (!m_serialDevicesByEndpoint.contains(n.endpoint)) {
initializeSerialDevice(n.endpoint, n.params);
}
m_deviceEndpointsMap.insert(n.endpoint, kind);
}
}
// Remove runtime devices that are no longer desired/offline
const auto currentKeys = m_serialDevicesByEndpoint.keys();
for (const auto& endpoint : currentKeys) {
if (!desiredSerialEndpoints.contains(endpoint)) {
shutdownSerialDevice(endpoint);
m_deviceEndpointsMap.remove(endpoint);
}
}
return true;
}
void DeviceBusManager::shutdown()
{
// 关闭并销毁所有串口设备