设备监控-过滤
This commit is contained in:
@@ -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()
|
||||
{
|
||||
// 关闭并销毁所有串口设备
|
||||
|
||||
Reference in New Issue
Block a user