diff --git a/services/distributedhardwarefwkservice/include/task/task_board.h b/services/distributedhardwarefwkservice/include/task/task_board.h index 1e978c1c4072d18ec2978d8fdf835ebe4f6acfc1..a0e54c5e39b79729a3f3c1f03934759b9780ec82 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 8cbc29d39fcafb6543c6e78d4365ff4a660b3e14..6b4cc38a62830c790f44fca8e01eb08d64835946 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 79900d95abfc4341f6e65af0fb507ffc3ee81119..3fdc1fc26392952b190ebad93f11d508ad4ef0de 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 d21e19839c3d31d5b55d26519f7607c1493c85c5..08c028a9fb07ecbd675f3e08944d27f95aad4268 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 6578b6140e5cb14bc06f4d9deaa6f15ea03797c7..7b931f35f72bb26e6cfc4735c57181d72c11338b 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 0959d9534fa3859706568f07e9e43ea47fc7e671..4f0aba35c96e195485dfbf4cf75a0a681c4b700c 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"); } }