From 7a68b1e2e036ac937e6bedbce5ac4314738d65ed Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Fri, 26 Jul 2024 12:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=9C=BA=E5=90=8Ekey=E4=B8=8D?= =?UTF-8?q?=E5=8F=98=E5=8C=96=EF=BC=8C=E4=B8=8D=E4=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8Cupdate=E5=8A=A0=E4=BF=9D=E6=8A=A4?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E8=AE=BE=E5=A4=87=E8=83=BD=E4=BD=BF=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../include/task/task_board.h | 3 +- .../capability_info_manager.cpp | 30 +++++++++++++++++-- .../src/resourcemanager/meta_info_manager.cpp | 30 +++++++++++++++++-- .../src/task/task_board.cpp | 13 ++++++++ .../src/task/task_factory.cpp | 5 ++-- .../src/utils/dh_context.cpp | 2 +- 6 files changed, 74 insertions(+), 9 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/task/task_board.h b/services/distributedhardwarefwkservice/include/task/task_board.h index 1e978c1c..a0e54c5e 100644 --- a/services/distributedhardwarefwkservice/include/task/task_board.h +++ b/services/distributedhardwarefwkservice/include/task/task_board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,6 +39,7 @@ public: const std::unordered_map GetEnabledDevice(); void DumpAllTasks(std::vector &taskInfos); + bool IsEnabledDevice(const std::string &enabledDeviceKey); private: void RemoveTaskInner(std::string taskId); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 8cbc29d3..6b4cc38a 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -26,6 +26,7 @@ #include "distributed_hardware_manager_factory.h" #include "task_executor.h" #include "task_factory.h" +#include "task_board.h" namespace OHOS { namespace DistributedHardware { @@ -380,12 +381,13 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vectorGetDeviceId()); if (uuid.empty()) { - DHLOGI("Find uuid failed and never enable"); + DHLOGE("Find uuid failed and never enable, deviceId: %{public}s", + GetAnonyString(capPtr->GetDeviceId()).c_str()); continue; } std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(uuid); if (networkId.empty()) { - DHLOGI("Find network failed and never enable, uuid: %{public}s", GetAnonyString(uuid).c_str()); + DHLOGE("Find network failed and never enable, uuid: %{public}s", GetAnonyString(uuid).c_str()); continue; } @@ -417,9 +419,33 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vectorGetDeviceId()); + if (uuid.empty()) { + DHLOGE("Find uuid failed and never enable, deviceId: %{public}s", + GetAnonyString(capPtr->GetDeviceId()).c_str()); + continue; + } + std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(uuid); + if (networkId.empty()) { + DHLOGE("Find network failed and never enable, uuid: %{public}s", GetAnonyString(uuid).c_str()); + continue; + } + std::string enabledDeviceKey = GetCapabilityKey(capPtr->GetDeviceId(), capPtr->GetDHId()); + if (TaskBoard::GetInstance().IsEnabledDevice(enabledDeviceKey)) { + DHLOGI("The deviceKey: %{public}s is enabled.", GetAnonyString(enabledDeviceKey).c_str()); + continue; + } const auto keyString = capPtr->GetKey(); DHLOGI("Update capability key: %{public}s", capPtr->GetAnonymousKey().c_str()); globalCapInfoMap_[keyString] = capPtr; + TaskParam taskParam = { + .networkId = networkId, + .uuid = uuid, + .dhId = capPtr->GetDHId(), + .dhType = capPtr->GetDHType() + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, nullptr); + TaskExecutor::GetInstance().PushTask(task); } } diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 79900d95..3fdc1fc2 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -25,6 +25,7 @@ #include "distributed_hardware_manager.h" #include "task_executor.h" #include "task_factory.h" +#include "task_board.h" namespace OHOS { namespace DistributedHardware { @@ -357,12 +358,13 @@ void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vectorGetDeviceId()); if (uuid.empty()) { - DHLOGI("Find uuid failed and never enable"); + DHLOGE("Find uuid failed and never enable, deviceId: %{public}s", + GetAnonyString(capPtr->GetDeviceId()).c_str()); continue; } std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(uuid); if (networkId.empty()) { - DHLOGI("Find network failed and never enable, uuid: %{public}s", GetAnonyString(uuid).c_str()); + DHLOGE("Find network failed and never enable, uuid: %{public}s", GetAnonyString(uuid).c_str()); continue; } @@ -390,9 +392,33 @@ void MetaInfoManager::HandleMetaCapabilityUpdateChange(const std::vectorGetDeviceId()); + if (uuid.empty()) { + DHLOGE("Find uuid failed and never enable, deviceId: %{public}s", + GetAnonyString(capPtr->GetDeviceId()).c_str()); + continue; + } + std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(uuid); + if (networkId.empty()) { + DHLOGE("Find network failed and never enable, uuid: %{public}s", GetAnonyString(uuid).c_str()); + continue; + } + std::string enabledDeviceKey = GetCapabilityKey(capPtr->GetDeviceId(), capPtr->GetDHId()); + if (TaskBoard::GetInstance().IsEnabledDevice(enabledDeviceKey)) { + DHLOGI("The deviceKey: %{public}s is enabled.", GetAnonyString(enabledDeviceKey).c_str()); + continue; + } const auto keyString = capPtr->GetKey(); DHLOGI("Update MetaCapability key: %{public}s", capPtr->GetAnonymousKey().c_str()); globalMetaInfoMap_[keyString] = capPtr; + TaskParam taskParam = { + .networkId = networkId, + .uuid = uuid, + .dhId = capPtr->GetDHId(), + .dhType = capPtr->GetDHType() + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, nullptr); + TaskExecutor::GetInstance().PushTask(task); } } diff --git a/services/distributedhardwarefwkservice/src/task/task_board.cpp b/services/distributedhardwarefwkservice/src/task/task_board.cpp index d21e1983..08c028a9 100644 --- a/services/distributedhardwarefwkservice/src/task/task_board.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_board.cpp @@ -128,5 +128,18 @@ const std::unordered_map TaskBoard::GetEnabledDevice() } return enabledDevices_; } + +bool TaskBoard::IsEnabledDevice(const std::string &enabledDeviceKey) +{ + std::lock_guard lock(enabledDevicesMutex_); + bool flag = false; + for (auto iter = enabledDevices_.begin(); iter != enabledDevices_.end(); iter++) { + if (iter->first == enabledDeviceKey) { + flag = true; + break; + } + } + return flag; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index 6578b614..7b931f35 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.cpp @@ -31,10 +31,9 @@ namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(TaskFactory); std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskParam, std::shared_ptr fatherTask) { - DHLOGI("taskType: %{public}d, networkId: %{public}s, uuid: %{public}s, uuid: %{public}s, dhId: %{public}s", + DHLOGI("taskType: %{public}d, networkId: %{public}s, uuid: %{public}s, dhId: %{public}s", static_cast(taskType), GetAnonyString(taskParam.networkId).c_str(), - GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.udid).c_str(), - GetAnonyString(taskParam.dhId).c_str()); + GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.dhId).c_str()); std::shared_ptr task = nullptr; switch (taskType) { case TaskType::ENABLE: { diff --git a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp index 0959d953..4f0aba35 100644 --- a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp +++ b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp @@ -53,7 +53,7 @@ void DHContext::RegisterPowerStateLinstener() if (!ret) { DHLOGE("DHFWK register power state callback failed"); } else { - DHLOGE("DHFWK register power state callback success"); + DHLOGI("DHFWK register power state callback success"); } } -- Gitee