From b1378c0b953b5faa42db7200049fa9171d2396b4 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Thu, 12 May 2022 17:27:27 +0800 Subject: [PATCH 01/24] add hidump Signed-off-by: wanderer-dl122 --- .../include/distributed_hardware_errno.h | 5 + .../include/distributed_hardware_service.h | 2 + .../src/distributed_hardware_service.cpp | 24 +++ .../componentmanager/component_manager.cpp | 3 + utils/BUILD.gn | 1 + utils/include/dh_hidump_helper.h | 68 +++++++ utils/src/dh_hidump_helper.cpp | 169 ++++++++++++++++++ 7 files changed, 272 insertions(+) create mode 100644 utils/include/dh_hidump_helper.h create mode 100644 utils/src/dh_hidump_helper.cpp diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index ffc05fd2..d3df079e 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -89,6 +89,11 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_ACCESS_UNINIT_DM_FAILED = -10901; constexpr int32_t ERR_DH_FWK_ACCESS_REGISTER_DM_FAILED = -10902; constexpr int32_t ERR_DH_FWK_ACCESS_UNREGISTER_DM_FAILED = -10903; + + /* Hidump errno, range: [-11000, -11000] */ + constexpr int32_t ERR_DH_FWK_HIDUMP_ERROR = -11000; + constexpr int32_t ERR_DH_FWK_HIDUMP_INVALID_ARGS = -11001; + constexpr int32_t ERR_DH_FWK_HIDUMP_UNKONW = 11002; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index 8f91391a..b9aef878 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -21,6 +21,7 @@ #include "distributed_hardware_stub.h" #include "single_instance.h" +#include "dhfwksa_hidump_helper.h" namespace OHOS { namespace DistributedHardware { @@ -35,6 +36,7 @@ public: DistributedHardwareService(int32_t saId, bool runOnCreate); ~DistributedHardwareService() = default; int32_t QuerySinkVersion(std::unordered_map &versionMap) override; + int Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 773c2434..5f5ba4cb 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -23,6 +23,7 @@ #include "system_ability_definition.h" #include "access_manager.h" +#include "dh_hidump_helper.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -82,5 +83,28 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map& args) +{ + DHLOGI("DistributedHardwareService Dump."); + std::string result; + std::vector argsStr; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + + if (!distributed_hardware_hidump_helper.h::GetInstance().Dump(argsStr, result)) { + DHLOGE("Hidump error"); + return ERR_DH_SCREEN_HIDUMP_ERROR; + } + + int ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + DHLOGE("dprintf error"); + return ERR_DH_SCREEN_HIDUMP_ERROR; + } + + return ERR_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index b07d364a..13e68490 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -25,6 +25,7 @@ #include "component_loader.h" #include "constants.h" #include "dh_context.h" +#include "dh_hidump_helper.h" #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -263,6 +264,8 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } return result; } + DHHidumpHelper::GetInstance().DumpEnabledComps(const DHType dhType, const std::string &dhId, + const int32_t enableResult); DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); return result; diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 27018ede..532ec850 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("distributedhardwareutils") { "src/anonymous_string.cpp", "src/dh_utils_tool.cpp", "src/log/dh_log.cpp", + "dh_hidump_helper.cpp", ] deps = [ diff --git a/utils/include/dh_hidump_helper.h b/utils/include/dh_hidump_helper.h new file mode 100644 index 00000000..26caaad7 --- /dev/null +++ b/utils/include/dh_hidump_helper.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H +#define OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H +#include +#include +#include + +#include "device_type.h" + +namespace OHOS { +namespace DistributedHardware { +enum class HidumpFlag { + UNKNOW = 0, + GET_HELP, + GET_LOADED_COMP_LIST, +}; + +struct HidumpParam { + HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; + std::string args; +}; + +struct EnabledDeviceInfo { + std::string dhId; + DHType dhType; + bool operator <(const DHInfo& other) const { + return ((this->dhId < other.dhId) || (this->dhType < other.dhType)); + } +}; + +class DHHidumpHelper { +DECLARE_SINGLE_INSTANCE_BASE(DHHidumpHelper); +public: + bool Dump(const std::vector& args, std::string &result); +private: + explicit HidumpHelper() = default; + ~HidumpHelper() = default; + int32_t ProcessOneParam(const std::string& args, std::string &result); + // int32_t ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, std::string &result); + void ShowHelp(std::string &result); + void ShowIllealInfomation(std::string &result); + int32_t ProcessDump(const HidumpParam& hidumpParam, std::string &result); + + // int32_t GetEnableInfo(std::string &result); + + void DumpEnabledComps(); + +private: + std::set setEnabledDeviceInfo_; +}; + +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/utils/src/dh_hidump_helper.cpp b/utils/src/dh_hidump_helper.cpp new file mode 100644 index 00000000..639a9bb8 --- /dev/null +++ b/utils/src/dh_hidump_helper.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2022-2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dh_hidump_helper.h" + +#include + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DHHidumpHelper); +namespace { +const int32_t MIN_ARGS_SIZE = 0; +const int32_t MAX_ARGS_SIZE = 1; +const int32_t FIRST_PARAM = 0; +const std::string ARGS_HELP = "-h"; +const std::string LOADED_COMP_LIST = "-loaded-list"; + +const std::unordered_map ARGS_MAP = { + { ARGS_HELP, HidumpFlag::GET_HELP }, + { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, +}; + +const std::map mapDhTypeName = { + { DHType::UNKNOWN, "UNKNOWN" }, + { DHType::CAMERA, "CAMERA" }, + { DHType::MIC, "MIC" }, + { DHType::SPEAKER, "SPEAKER" }, + { DHType::DISPLAY, "DISPLAY" }, + { DHType::GPS, "GPS" }, + { DHType::BUTTON, "BUTTON" }, + { DHType::HFP, "HFP" }, + { DHType::A2D, "A2D" }, + { DHType::VIRMODEM_MIC, "VIRMODEM_MIC" }, + { DHType::VIRMODEM_SPEAKER, "VIRMODEM_SPEAKER" }, +}; +} + +bool DHHidumpHelper::Dump(const std::vector& args, std::string &result) +{ + DHLOGI("DHfwkHidumpHelper Dump args.size():%d.", args.size()); + result.clear(); + int32_t errCode = DH_SUCCESS; + int32_t argsSize = static_cast(args.size()); + for (int i = 0; i < args.size(); i++) { + DHLOGI("DHfwkHidumpHelper Dump args[%d]: %s.", i, args.at(i).c_str()); + } + switch (argsSize) { + case MIN_ARGS_SIZE: { + errCode = ProcessDump(HidumpFlag::GET_HELP, result); + break; + } + case MAX_ARGS_SIZE: { + errCode = ProcessDump(args[FIRST_PARAM], result); + break; + } + default: { + errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; + break; + } + } + + bool ret = false; + switch (errCode) { + case DH_SUCCESS: { + ret = true; + break; + } + case ERR_DH_FWK_HIDUMP_INVALID_ARGS: { + ShowIllealInfomation(result); + ret = true; + break; + } + case ERR_DH_FWK_HIDUMP_UNKONW: { + result.append(""); + ret = true; + break; + } + default: { + break; + } + } + return ret; +} + +// int32_t DHHidumpHelper::ProcessOneParam(const std::string& args, std::string &result) +// { +// DHLOGI("ProcessOneParam Dump."); +// HidumpParam hidumpParam; +// auto operatorIter = ARGS_MAP.find(args); +// if (operatorIter != ARGS_MAP.end()) { +// hidumpParam.hidumpFlag = operatorIter->second; +// } + +// if (hidumpParam.hidumpFlag == HidumpFlag::GET_HELP) { +// ShowHelp(result); +// return DH_SUCCESS; +// } + +// return ProcessDump(hidumpParam, result); +// } + +int32_t DHHidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) +{ + DHLOGI("ProcessDump Dump."); + result.clear(); + int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; + switch (flag) { + case HidumpFlag::GET_HELP: { + errCode = ShowHelp(result); + break; + } + case HidumpFlag::GET_LOADED_COMP_LIST: { + errCode = GetAllLoadCompTypes(result); + break; + } + default: { + errCode = ERR_DH_FWK_HIDUMP_INVALID_ARGS; + break; + } + } + + return errCode; +} + +int32_t DHHidumpHelper::GetAllLoadCompTypes(std::string &result) +{ + DHLOGI("GetAllLoadCompTypes Dump."); + std::vector compTypes = ComponentLoader::GetInstance().GetAllCompTypes(); + result.append("loaded components:\n"); + for (auto comp : compTypes) { + result.append(mapDhTypeName[comp]); + result.append(" "); + } + result.append("\n"); + return DH_SUCCESS; +} + +int32_t DHHidumpHelper::ShowHelp(std::string &result) +{ + DHLOGI("ShowHelp Dump."); + result.append("Usage:dump \n") + .append("Description:\n") + .append("-loaded-comp-list ") + .append(": Show loaded components\n"); + + return DH_SUCCESS; +} + +void DHHidumpHelper::ShowIllealInfomation(std::string &result) +{ + DHLOGI("ShowIllealInfomation Dump."); + result.append("unrecognized option, -h for help"); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee From 48c610b3145f0da9b4fdcaae5256906a6c9ccd69 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 13 May 2022 09:17:34 +0800 Subject: [PATCH 02/24] add hidump Signed-off-by: wanderer-dl122 --- .../include/accessmanager/access_manager.h | 2 + .../distributed_hardware_manager_factory.h | 2 + .../src/accessmanager/access_manager.cpp | 5 ++ .../distributed_hardware_manager_factory.cpp | 11 +++ .../src/distributed_hardware_service.cpp | 22 ++--- .../include/dh_hidump_helper.h | 28 +++++-- .../include/distributed_hardware_manager.h | 2 + .../include/task/task_board.h | 1 + .../src/componentloader/component_loader.cpp | 4 + .../componentmanager/component_manager.cpp | 6 +- .../src/dh_hidump_helper.cpp | 80 +++++++++++++------ .../src/distributed_hardware_manager.cpp | 5 ++ .../src/task/task_board.cpp | 14 ++++ 13 files changed, 139 insertions(+), 43 deletions(-) rename {utils => services/distributedhardwarefwkserviceimpl}/include/dh_hidump_helper.h (76%) rename {utils => services/distributedhardwarefwkserviceimpl}/src/dh_hidump_helper.cpp (72%) diff --git a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h index 5156dcbb..27612a11 100644 --- a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h +++ b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h @@ -48,6 +48,8 @@ public: virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override; virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override; + int32_t Dump(const std::vector argsStr, std::string result); + private: AccessManager() = default; int32_t RegisterDevStateCallback(); diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index 6fbaae81..6270ec66 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -32,6 +32,8 @@ public: int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t GetComponentVersion(std::unordered_map &versionMap); + int Dump(const std::vector argsStr, std::string result); + private: bool Init(); void UnInit(); diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 51fd624d..bb25db45 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -166,5 +166,10 @@ void AccessManager::SendTrustedDeviceOnline() DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, deviceInfo.deviceTypeId); } } + +int32_t AccessManager:Dump(const std::vector argsStr, std::string result) +{ + return DistributedHardwareManagerFactory::GetInstance().Dump(argsStr, result); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 59312f05..9a337856 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -205,5 +205,16 @@ int32_t DistributedHardwareManagerFactory::GetComponentVersion(std::unordered_ma } return distributedHardwareMgrPtr_->GetComponentVersion(versionMap); } + +int32_t DistributedHardwareManagerFactory::Dump(const std::vector argsStr, std::string result) +{ + if (distributedHardwareMgrPtr_ == nullptr) { + DHLOGE("distributedHardwareMgr is null"); + return ERR_DH_FWK_HIDUMP_ERROR; + } + return distributedHardwareMgrPtr_->Dump(argsStr, result); +} +} + } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 5f5ba4cb..08c05ff5 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -93,18 +93,20 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vectorDump(argsStr, result)) { + DHLOGE("Hidump error"); + return ERR_DH_SCREEN_HIDUMP_ERROR; + } + + int ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + DHLOGE("dprintf error"); + } + + - return ERR_OK; + return DH_FWK_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/dh_hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/dh_hidump_helper.h similarity index 76% rename from utils/include/dh_hidump_helper.h rename to services/distributedhardwarefwkserviceimpl/include/dh_hidump_helper.h index 26caaad7..70f0deb8 100644 --- a/utils/include/dh_hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/dh_hidump_helper.h @@ -34,33 +34,45 @@ struct HidumpParam { std::string args; }; -struct EnabledDeviceInfo { - std::string dhId; - DHType dhType; +struct HidumpDeviceInfo { + std::string dhId_; + DHType dhType_; + bool operator <(const DHInfo& other) const { return ((this->dhId < other.dhId) || (this->dhType < other.dhType)); } }; +enum class HidumpTaskType : int32_t { + UNKNOWN = 0, + ENABLE = 1, + DISABLE = 2, + ON_LINE = 3, + OFF_LINE = 4 +}; + class DHHidumpHelper { DECLARE_SINGLE_INSTANCE_BASE(DHHidumpHelper); public: bool Dump(const std::vector& args, std::string &result); + + void DumpLoadedComps(const DHType dhType); + void DumpUnloadedComps(const DHType dhType); + void DumpEnabledComps(const DHType dhType, const std::string &dhId); + void DumpDisabledComps(const DHType dhType, const std::string &dhId); + private: explicit HidumpHelper() = default; ~HidumpHelper() = default; int32_t ProcessOneParam(const std::string& args, std::string &result); - // int32_t ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, std::string &result); void ShowHelp(std::string &result); void ShowIllealInfomation(std::string &result); int32_t ProcessDump(const HidumpParam& hidumpParam, std::string &result); - // int32_t GetEnableInfo(std::string &result); - - void DumpEnabledComps(); private: - std::set setEnabledDeviceInfo_; + std::set loadedCompsSet_; + std::set deviceInfoSet_; }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h index 77f92f6d..b12f4ca2 100644 --- a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h @@ -31,6 +31,8 @@ public: int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; size_t GetOnLineCount() override; int32_t GetComponentVersion(std::unordered_map &versionMap) override; + + int32_t Dump(const std::vector argsStr, std::string result); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h index d7ffaace..3bea6b31 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h @@ -34,6 +34,7 @@ public: void AddTask(std::shared_ptr task); void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); + void DumpAllTask(); private: void RemoveTaskInner(std::string taskId); diff --git a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp index 3f03d718..54229be1 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp @@ -22,6 +22,7 @@ #include "nlohmann/json.hpp" #include "constants.h" +#include "dh_hidump_helper.h" #include "distributed_hardware_log.h" using nlohmann::json; @@ -177,6 +178,7 @@ int32_t ComponentLoader::GetHardwareHandler(const DHType dhType, IHardwareHandle return ERR_DH_FWK_LOADER_HANDLER_IS_NULL; } hardwareHandlerPtr = getHardwareClassHandler(); + DHHidumpHelper::GetInstance().DumpLoadedComps(dhType); return DH_FWK_SUCCESS; } @@ -275,6 +277,8 @@ int32_t ComponentLoader::UnInit() ret += ReleaseHardwareHandler(iter->first); ret += ReleaseSource(iter->first); ret += ReleaseSink(iter->first); + + DHHidumpHelper::GetInstance()::DumpUnloadedComps(iter->first); } compHandlerMap_.clear(); return ret; diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index 13e68490..9eee8e55 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -258,16 +258,16 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { DHLOGE("enable success, retryCount = %d", retryCount); + DHHidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("enable failed, retryCount = %d", retryCount); } return result; } - DHHidumpHelper::GetInstance().DumpEnabledComps(const DHType dhType, const std::string &dhId, - const int32_t enableResult); DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); + DHHidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); return result; } @@ -289,6 +289,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { DHLOGE("disable success, retryCount = %d", retryCount); + DHHidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("disable failed, retryCount = %d", retryCount); @@ -297,6 +298,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); + DHHidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); return result; } diff --git a/utils/src/dh_hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp similarity index 72% rename from utils/src/dh_hidump_helper.cpp rename to services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp index 639a9bb8..9edd43d8 100644 --- a/utils/src/dh_hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp @@ -17,6 +17,7 @@ #include +#include "capability_info_manager.h" #include "distributed_hardware_log.h" namespace OHOS { @@ -34,7 +35,7 @@ const std::unordered_map ARGS_MAP = { { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, }; -const std::map mapDhTypeName = { +const std::unordered_map mapDhTypeName = { { DHType::UNKNOWN, "UNKNOWN" }, { DHType::CAMERA, "CAMERA" }, { DHType::MIC, "MIC" }, @@ -96,23 +97,6 @@ bool DHHidumpHelper::Dump(const std::vector& args, std::string &res return ret; } -// int32_t DHHidumpHelper::ProcessOneParam(const std::string& args, std::string &result) -// { -// DHLOGI("ProcessOneParam Dump."); -// HidumpParam hidumpParam; -// auto operatorIter = ARGS_MAP.find(args); -// if (operatorIter != ARGS_MAP.end()) { -// hidumpParam.hidumpFlag = operatorIter->second; -// } - -// if (hidumpParam.hidumpFlag == HidumpFlag::GET_HELP) { -// ShowHelp(result); -// return DH_SUCCESS; -// } - -// return ProcessDump(hidumpParam, result); -// } - int32_t DHHidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) { DHLOGI("ProcessDump Dump."); @@ -124,7 +108,7 @@ int32_t DHHidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) break; } case HidumpFlag::GET_LOADED_COMP_LIST: { - errCode = GetAllLoadCompTypes(result); + errCode = ShowAllLoadCompTypes(result); break; } default: { @@ -136,14 +120,64 @@ int32_t DHHidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) return errCode; } -int32_t DHHidumpHelper::GetAllLoadCompTypes(std::string &result) +void DumpLoadedComps(const DHType dhType) +{ + loadedCompsSet_.emplace(dhType); +} + +void DumpUnloadedComps(const DHType dhType) +{ + auto it = loadedCompsSet_.find(dhType); + if (it != loadedCompsSet_.end()) { + loadedCompsSet_.earse(it); + } +} + +int32_t DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) { DHLOGI("GetAllLoadCompTypes Dump."); - std::vector compTypes = ComponentLoader::GetInstance().GetAllCompTypes(); result.append("loaded components:\n"); - for (auto comp : compTypes) { + result.append(" "); + for (auto comp : loadedCompsSet_) { result.append(mapDhTypeName[comp]); - result.append(" "); + result.append(" | "); + } + result.append("\n"); + return DH_SUCCESS; +} + +void DHHidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dhId) +{ + HidumpDeviceInfo info = { + .dhId_ = dhId, + .dhType_ = dhType, + } + deviceInfoSet_.emplace(info); +} + +void DHHidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &dhId) +{ + HidumpDeviceInfo info = { + .dhId_ = dhId, + .dhType_ = dhType, + } + auto it = enabledDeviceInfoSet_.find(info); + if (it != enabledDeviceInfoSet_.end()) { + deviceInfoSet_.earse(it); + } +} + +int32_t DHHidumpHelper::ShowAllEnabledComps(std::string &result) +{ + DHLOGI("GetAllLoadCompTypes Dump."); + result.append("loaded components:\n"); + result.append(" "); + for (auto info : enabledDeviceInfoSet_) { + result.append(" DHType : "); + result.append(mapDhTypeName[info.dhType_]); + result.append(" DHId : "); + result.append(info.dhId_); + result.append(" | "); } result.append("\n"); return DH_SUCCESS; diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp index 5b741ba1..4c17c912 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp @@ -176,5 +176,10 @@ int32_t DistributedHardwareManager::GetComponentVersion(std::unordered_map argsStr, std::string result) +{ + +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp index 93ba6f0d..c1a643ce 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp @@ -64,6 +64,7 @@ void TaskBoard::AddTask(std::shared_ptr task) return; } this->tasks_.emplace(task->GetId(), task); + DumpAllTask(); } void TaskBoard::RemoveTask(std::string taskId) @@ -71,6 +72,7 @@ void TaskBoard::RemoveTask(std::string taskId) std::lock_guard lock(tasksMtx_); DHLOGI("Remove task, id: %s", taskId.c_str()); RemoveTaskInner(taskId); + DumpAllTask(); if (tasks_.empty()) { conVar_.notify_one(); } @@ -85,5 +87,17 @@ void TaskBoard::RemoveTaskInner(std::string taskId) tasks_.erase(taskId); } + +void TaskBoard::DumpAllTask() +{ + for (auto task : tasks_) { + task. + GetId + GetDhId + GetDhType + GetTaskType + } + +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 63ad859fcf8812a804996a01720d2f9ec357084a Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 13 May 2022 10:33:13 +0800 Subject: [PATCH 03/24] add dump Signed-off-by: wanderer-dl122 --- .../componentmanager/component_manager.h | 3 +++ .../componentmanager/component_manager.cpp | 10 +++++++ .../src/dh_hidump_helper.cpp | 27 +++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h index 7342a03b..86bbb1a3 100644 --- a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h @@ -17,6 +17,7 @@ #define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MANAGER_H #include +#include #include #include #include @@ -69,6 +70,8 @@ private: int32_t UpdateVersionCache(const std::string &networkId, const std::string &uuid); sptr GetRemoteDHMS(const std::string &networkId) const; + void DumpLoadedComps(std::set &compSourceType, std::set &compSinkType); + private: std::map compSource_; std::map compSink_; diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index 9eee8e55..e09dae51 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -417,5 +417,15 @@ sptr ComponentManager::GetRemoteDHMS(const std::string &ne } return iface_cast(object); } + +void ComponentManager::DumpLoadedComps(std::set &compSourceType, std::set &compSinkType) +{ + for (auto compSource : compSource_) { + compSourceType.emplace(compSource.first); + } + for (auto compSink : compSink_) { + compSinkType.emplace(compSink.first); + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp index 9edd43d8..2cec4558 100644 --- a/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp @@ -119,7 +119,7 @@ int32_t DHHidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) return errCode; } - +/* void DumpLoadedComps(const DHType dhType) { loadedCompsSet_.emplace(dhType); @@ -132,7 +132,6 @@ void DumpUnloadedComps(const DHType dhType) loadedCompsSet_.earse(it); } } - int32_t DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) { DHLOGI("GetAllLoadCompTypes Dump."); @@ -145,6 +144,30 @@ int32_t DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) result.append("\n"); return DH_SUCCESS; } +*/ + +void DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) +{ + std::set loadedCompSource; + std::set loadedCompSink; + ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink); + + DHLOGI("GetAllLoadCompTypes Dump."); + result.append("Local Loaded Components:\n"); + result.append(" Source: "); + for (auto comp : loadedCompSource) { + result.append(mapDhTypeName[comp]); + result.append(" | "); + } + result.append("\n"); + + result.append(" Sink: "); + for (auto comp : loadedCompSink) { + result.append(mapDhTypeName[comp]); + result.append(" | "); + } + result.append("\n\n"); +} void DHHidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dhId) { -- Gitee From 49963e454930079721254388fd214bcb04d4e91e Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 13 May 2022 14:03:50 +0800 Subject: [PATCH 04/24] add dump Signed-off-by: wanderer-dl122 --- .../include/distributed_hardware_errno.h | 2 +- .../src/distributed_hardware_service.cpp | 23 ++- .../BUILD.gn | 2 + .../hidump_helper.h} | 37 +++-- .../include/task/task_board.h | 2 +- .../src/componentloader/component_loader.cpp | 6 +- .../componentmanager/component_manager.cpp | 10 +- .../hidump_helper.cpp} | 144 ++++++++++++------ .../src/task/task_board.cpp | 13 +- 9 files changed, 141 insertions(+), 98 deletions(-) rename services/distributedhardwarefwkserviceimpl/include/{dh_hidump_helper.h => hidumphelper/hidump_helper.h} (78%) rename services/distributedhardwarefwkserviceimpl/src/{dh_hidump_helper.cpp => hidumphelper/hidump_helper.cpp} (52%) diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index d3df079e..7e71cf69 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -93,7 +93,7 @@ namespace DistributedHardware { /* Hidump errno, range: [-11000, -11000] */ constexpr int32_t ERR_DH_FWK_HIDUMP_ERROR = -11000; constexpr int32_t ERR_DH_FWK_HIDUMP_INVALID_ARGS = -11001; - constexpr int32_t ERR_DH_FWK_HIDUMP_UNKONW = 11002; + constexpr int32_t ERR_DH_FWK_HIDUMP_DPRINTF_ERROR = -11002; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 08c05ff5..a2fc1901 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -23,9 +23,9 @@ #include "system_ability_definition.h" #include "access_manager.h" -#include "dh_hidump_helper.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "hidump_helper.h" namespace OHOS { namespace DistributedHardware { @@ -93,20 +93,17 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vectorDump(argsStr, result)) + if (ret != DH_FWK_SUCCESS){ + DHLOGE("Dump error, ret = %d", ret); + } - if (!AccessManager::GetInstance()->Dump(argsStr, result)) { - DHLOGE("Hidump error"); - return ERR_DH_SCREEN_HIDUMP_ERROR; - } - - int ret = dprintf(fd, "%s\n", result.c_str()); - if (ret < 0) { - DHLOGE("dprintf error"); - } - - + if (dprintf(fd, "%s\n", result.c_str()) < 0) { + DHLOGE("Hidump dprintf error"); + ret = ERR_DH_FWK_HIDUMP_DPRINTF_ERROR; + } - return DH_FWK_SUCCESS; + return ret; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/BUILD.gn b/services/distributedhardwarefwkserviceimpl/BUILD.gn index 19efe651..d01cffae 100644 --- a/services/distributedhardwarefwkserviceimpl/BUILD.gn +++ b/services/distributedhardwarefwkserviceimpl/BUILD.gn @@ -29,6 +29,7 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "include/utils", "include/localhardwaremanager", "include/resourcemanager", + "include/hidumphelper", "${common_path}/log/include", "${common_path}/utils/include", "${utils_path}/include", @@ -59,6 +60,7 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "src/task/task_factory.cpp", "src/utils/dh_context.cpp", "src/versionmanager/version_manager.cpp", + "hidump_helper.cpp", ] deps = [ diff --git a/services/distributedhardwarefwkserviceimpl/include/dh_hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h similarity index 78% rename from services/distributedhardwarefwkserviceimpl/include/dh_hidump_helper.h rename to services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index 70f0deb8..3549d897 100644 --- a/services/distributedhardwarefwkserviceimpl/include/dh_hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -20,19 +20,16 @@ #include #include "device_type.h" +#include "task.h" namespace OHOS { namespace DistributedHardware { -enum class HidumpFlag { - UNKNOW = 0, - GET_HELP, - GET_LOADED_COMP_LIST, -}; -struct HidumpParam { - HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; - std::string args; -}; + +// struct HidumpParam { +// HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; +// std::string args; +// }; struct HidumpDeviceInfo { std::string dhId_; @@ -43,18 +40,18 @@ struct HidumpDeviceInfo { } }; -enum class HidumpTaskType : int32_t { - UNKNOWN = 0, - ENABLE = 1, - DISABLE = 2, - ON_LINE = 3, - OFF_LINE = 4 -}; +// enum class HidumpTaskType : int32_t { +// UNKNOWN = 0, +// ENABLE = 1, +// DISABLE = 2, +// ON_LINE = 3, +// OFF_LINE = 4 +// }; -class DHHidumpHelper { -DECLARE_SINGLE_INSTANCE_BASE(DHHidumpHelper); +class HidumpHelper { +DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); public: - bool Dump(const std::vector& args, std::string &result); + int32_t Dump(const std::vector& args, std::string &result); void DumpLoadedComps(const DHType dhType); void DumpUnloadedComps(const DHType dhType); @@ -71,7 +68,7 @@ private: private: - std::set loadedCompsSet_; + // std::set loadedCompsSet_; std::set deviceInfoSet_; }; diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h index 3bea6b31..8c899baf 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h @@ -34,7 +34,7 @@ public: void AddTask(std::shared_ptr task); void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); - void DumpAllTask(); + void DumpAllTask(std::unordered_map> &tasks); private: void RemoveTaskInner(std::string taskId); diff --git a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp index 54229be1..b1056fec 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp @@ -22,8 +22,8 @@ #include "nlohmann/json.hpp" #include "constants.h" -#include "dh_hidump_helper.h" #include "distributed_hardware_log.h" +#include "hidump_helper.h" using nlohmann::json; @@ -178,7 +178,7 @@ int32_t ComponentLoader::GetHardwareHandler(const DHType dhType, IHardwareHandle return ERR_DH_FWK_LOADER_HANDLER_IS_NULL; } hardwareHandlerPtr = getHardwareClassHandler(); - DHHidumpHelper::GetInstance().DumpLoadedComps(dhType); + HidumpHelper::GetInstance().DumpLoadedComps(dhType); return DH_FWK_SUCCESS; } @@ -278,7 +278,7 @@ int32_t ComponentLoader::UnInit() ret += ReleaseSource(iter->first); ret += ReleaseSink(iter->first); - DHHidumpHelper::GetInstance()::DumpUnloadedComps(iter->first); + HidumpHelper::GetInstance()::DumpUnloadedComps(iter->first); } compHandlerMap_.clear(); return ret; diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index e09dae51..8568424f 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -25,10 +25,10 @@ #include "component_loader.h" #include "constants.h" #include "dh_context.h" -#include "dh_hidump_helper.h" #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "hidump_helper.h" #include "ipc_object_stub.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -258,7 +258,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { DHLOGE("enable success, retryCount = %d", retryCount); - DHHidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); + HidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("enable failed, retryCount = %d", retryCount); @@ -267,7 +267,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); - DHHidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); + HidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); return result; } @@ -289,7 +289,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { DHLOGE("disable success, retryCount = %d", retryCount); - DHHidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); + HidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("disable failed, retryCount = %d", retryCount); @@ -298,7 +298,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); - DHHidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); + HidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); return result; } diff --git a/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp similarity index 52% rename from services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp rename to services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 2cec4558..166467f9 100644 --- a/services/distributedhardwarefwkserviceimpl/src/dh_hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "dh_hidump_helper.h" +#include "hidump_helper.h" #include @@ -22,20 +22,28 @@ namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DHHidumpHelper); +IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); namespace { const int32_t MIN_ARGS_SIZE = 0; const int32_t MAX_ARGS_SIZE = 1; const int32_t FIRST_PARAM = 0; +const std::string SEPARATOR = " | "; +const std::string TAB = " "; const std::string ARGS_HELP = "-h"; const std::string LOADED_COMP_LIST = "-loaded-list"; -const std::unordered_map ARGS_MAP = { +enum class HidumpFlag { + UNKNOW = 0, + GET_HELP, + GET_LOADED_COMP_LIST, +}; + +std::unordered_map g_mapArgs = { { ARGS_HELP, HidumpFlag::GET_HELP }, { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, }; -const std::unordered_map mapDhTypeName = { +std::unordered_map g_mapDhTypeName = { { DHType::UNKNOWN, "UNKNOWN" }, { DHType::CAMERA, "CAMERA" }, { DHType::MIC, "MIC" }, @@ -48,9 +56,35 @@ const std::unordered_map mapDhTypeName = { { DHType::VIRMODEM_MIC, "VIRMODEM_MIC" }, { DHType::VIRMODEM_SPEAKER, "VIRMODEM_SPEAKER" }, }; + +std::unordered_map g_mapTaskType = { + { TaskType::UNKNOWN, "UNKNOWN" }, + { TaskType::ENABLE, "ENABLE" }, + { TaskType::DISABLE, "DISABLE" }, + { TaskType::ON_LINE, "ON_LINE" }, + { TaskType::OFF_LINE, "OFF_LINE" }, +}; + +std::unordered_map g_mapTaskStep = { + { TaskStep::DO_ENABLE, "DO_ENABLE" }, + { TaskStep::DO_DISABLE, "DO_DISABLE" }, + { TaskStep::SYNC_ONLINE_INFO, "SYNC_ONLINE_INFO" }, + { TaskStep::REGISTER_ONLINE_DISTRIBUTED_HARDWARE, "REGISTER_ONLINE_DISTRIBUTED_HARDWARE" }, + { TaskStep::UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE, "UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE" }, + { TaskStep::CLEAR_OFFLINE_INFO, "CLEAR_OFFLINE_INFO" }, + { TaskStep::WAIT_UNREGISTGER_COMPLET, "WAIT_UNREGISTGER_COMPLET" }, +}; + +// enum class TaskState : int32_t { +const std::unordered_map g_mapTaskState = { + { TaskState::INIT, "INIT" }, + { TaskState::RUNNING, "RUNNING" }, + { TaskState::SUCCESS, "SUCCESS" }, + { TaskState::FAI, "FAI" }, +}; } -bool DHHidumpHelper::Dump(const std::vector& args, std::string &result) +int32_t HidumpHelper::Dump(const std::vector& args, std::string &result) { DHLOGI("DHfwkHidumpHelper Dump args.size():%d.", args.size()); result.clear(); @@ -65,7 +99,7 @@ bool DHHidumpHelper::Dump(const std::vector& args, std::string &res break; } case MAX_ARGS_SIZE: { - errCode = ProcessDump(args[FIRST_PARAM], result); + errCode = ProcessDump(g_mapArgs[args[FIRST_PARAM]], result); break; } default: { @@ -74,30 +108,22 @@ bool DHHidumpHelper::Dump(const std::vector& args, std::string &res } } - bool ret = false; switch (errCode) { case DH_SUCCESS: { - ret = true; break; } case ERR_DH_FWK_HIDUMP_INVALID_ARGS: { ShowIllealInfomation(result); - ret = true; - break; - } - case ERR_DH_FWK_HIDUMP_UNKONW: { - result.append(""); - ret = true; break; } default: { break; } } - return ret; + return errCode; } -int32_t DHHidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) +int32_t HidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) { DHLOGI("ProcessDump Dump."); result.clear(); @@ -132,21 +158,21 @@ void DumpUnloadedComps(const DHType dhType) loadedCompsSet_.earse(it); } } -int32_t DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) +int32_t HidumpHelper::ShowAllLoadCompTypes(std::string &result) { DHLOGI("GetAllLoadCompTypes Dump."); result.append("loaded components:\n"); result.append(" "); for (auto comp : loadedCompsSet_) { - result.append(mapDhTypeName[comp]); - result.append(" | "); + result.append(g_mapDhTypeName[comp]); + result.append(SEPARATOR); } result.append("\n"); return DH_SUCCESS; } */ -void DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) +void HidumpHelper::ShowAllLoadCompTypes(std::string &result) { std::set loadedCompSource; std::set loadedCompSink; @@ -154,22 +180,22 @@ void DHHidumpHelper::ShowAllLoadCompTypes(std::string &result) DHLOGI("GetAllLoadCompTypes Dump."); result.append("Local Loaded Components:\n"); - result.append(" Source: "); - for (auto comp : loadedCompSource) { - result.append(mapDhTypeName[comp]); - result.append(" | "); + result.append(" Source: "); + for (auto compSource : loadedCompSource) { + result.append(g_mapDhTypeName[compSource]); + result.append(SEPARATOR); } - result.append("\n"); + result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n"); - result.append(" Sink: "); - for (auto comp : loadedCompSink) { - result.append(mapDhTypeName[comp]); - result.append(" | "); + result.append(" Sink: "); + for (auto compSink : loadedCompSink) { + result.append(g_mapDhTypeName[compSink]); + result.append(SEPARATOR); } - result.append("\n\n"); + result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); } -void DHHidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dhId) +void HidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dhId) { HidumpDeviceInfo info = { .dhId_ = dhId, @@ -178,7 +204,7 @@ void DHHidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dh deviceInfoSet_.emplace(info); } -void DHHidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &dhId) +void HidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &dhId) { HidumpDeviceInfo info = { .dhId_ = dhId, @@ -190,23 +216,53 @@ void DHHidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &d } } -int32_t DHHidumpHelper::ShowAllEnabledComps(std::string &result) +int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) { - DHLOGI("GetAllLoadCompTypes Dump."); - result.append("loaded components:\n"); - result.append(" "); + DHLOGI("GetAllEnabledComps Dump."); + result.append("Enabled Components:\n"); + result.append(TAB); for (auto info : enabledDeviceInfoSet_) { - result.append(" DHType : "); - result.append(mapDhTypeName[info.dhType_]); - result.append(" DHId : "); - result.append(info.dhId_); - result.append(" | "); + result.append(" DHType :"); + result.append(g_mapDhTypeName[info.dhType_]); + result.append(" DHId :"); + result.append(GetAnonyString(info.dhId_)); + result.append(SEPARATOR); } - result.append("\n"); + result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); return DH_SUCCESS; } -int32_t DHHidumpHelper::ShowHelp(std::string &result) +int32_t HidumpHelper::ShowAllTaskInfo(std::string &result) +{ + DHLOGI("GetAllAllTaskInfos Dump."); + std::unordered_map> tasks; + TaskBoard::GetInstance().DumpAllTask(tasks); + + result.append("All TaskInfos:\n"); + + for (auto task : tasks) { + // std::string taskId = task.GetId(); + // std::string task.GetNetworkId(); + // std::string task.GetUUID(); + result.append(TAB); + result.append(" TaskType :"); + TaskType taskType = task.GetTaskType(); + result.append(" DHType :"); + result.append(g_mapDhTypeName[task.GetDhType()]); + // std::string dhId = + result.append(" DHId :"); + result.append(GetAnonyString(task.GetDhId())); + + // TaskState taskState = GetTaskState(); + result.append(" TaskState :"); + result.append(g_mapTaskState[GetTaskState()]); + std::vector taskStep = GetTaskSteps(); + + + } +} + +int32_t HidumpHelper::ShowHelp(std::string &result) { DHLOGI("ShowHelp Dump."); result.append("Usage:dump \n") @@ -217,7 +273,7 @@ int32_t DHHidumpHelper::ShowHelp(std::string &result) return DH_SUCCESS; } -void DHHidumpHelper::ShowIllealInfomation(std::string &result) +void HidumpHelper::ShowIllealInfomation(std::string &result) { DHLOGI("ShowIllealInfomation Dump."); result.append("unrecognized option, -h for help"); diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp index c1a643ce..00c7cd36 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp @@ -64,7 +64,6 @@ void TaskBoard::AddTask(std::shared_ptr task) return; } this->tasks_.emplace(task->GetId(), task); - DumpAllTask(); } void TaskBoard::RemoveTask(std::string taskId) @@ -72,7 +71,6 @@ void TaskBoard::RemoveTask(std::string taskId) std::lock_guard lock(tasksMtx_); DHLOGI("Remove task, id: %s", taskId.c_str()); RemoveTaskInner(taskId); - DumpAllTask(); if (tasks_.empty()) { conVar_.notify_one(); } @@ -88,16 +86,9 @@ void TaskBoard::RemoveTaskInner(std::string taskId) tasks_.erase(taskId); } -void TaskBoard::DumpAllTask() +void TaskBoard::DumpAllTask(std::unordered_map> &tasks) { - for (auto task : tasks_) { - task. - GetId - GetDhId - GetDhType - GetTaskType - } - + tasks = tasks_; } } // namespace DistributedHardware } // namespace OHOS -- Gitee From 7d975a68b06825f283d6ebd37eb7b78baae225ed Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 13 May 2022 18:30:49 +0800 Subject: [PATCH 05/24] add dump Signed-off-by: wanderer-dl122 --- .../include/hidumphelper/enabled_comps_dump.h | 55 +++++++++++++++++++ .../include/hidumphelper/hidump_helper.h | 51 +++++++---------- .../componentmanager/component_manager.cpp | 10 ++-- .../src/hidumphelper/enabled_comps_dump.cpp | 48 ++++++++++++++++ .../src/hidumphelper/hidump_helper.cpp | 28 +++++++--- utils/BUILD.gn | 1 - 6 files changed, 147 insertions(+), 46 deletions(-) create mode 100644 services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h create mode 100644 services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h new file mode 100644 index 00000000..b4cdd6a8 --- /dev/null +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H +#define OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H +#include +#include +#include + +#include "device_type.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { + +struct HidumpCompInfo { + std::string dhId_; + DHType dhType_; + + bool operator < (const HidumpCompInfo &other) const { + return ((this->dhType_ < other.dhType_) || + (this->dhType_ == other.dhType_) && (this->dhId_ < other.dhId_)); + } +}; + +class EnabledCompsDump { +DECLARE_SINGLE_INSTANCE_BASE(EnabledCompsDump); +public: + void DumpEnabledComp(const DHType dhType, const std::string &dhId); + void DumpDisabledComp(const DHType dhType, const std::string &dhId); + + void Dump(std::set &deviceInfoSet); + +private: + explicit EnabledCompsDump() = default; + ~EnabledCompsDump() = default; + + std::set deviceInfoSet_; +}; + +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index 3549d897..2f7a34ae 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -19,57 +19,46 @@ #include #include +#include "enabled_comps_dump.h" #include "device_type.h" +#include "single_instance.h" #include "task.h" namespace OHOS { namespace DistributedHardware { +// class HidumpDeviceInfo { +// public: +// HidumpDeviceInfo() +// std::string dhId_; +// DHType dhType_; -// struct HidumpParam { -// HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; -// std::string args; -// }; - -struct HidumpDeviceInfo { - std::string dhId_; - DHType dhType_; - - bool operator <(const DHInfo& other) const { - return ((this->dhId < other.dhId) || (this->dhType < other.dhType)); - } -}; - -// enum class HidumpTaskType : int32_t { -// UNKNOWN = 0, -// ENABLE = 1, -// DISABLE = 2, -// ON_LINE = 3, -// OFF_LINE = 4 +// bool operator == (const DHInfo& other) const { +// return ((this->dhId == other.dhId) && (this->dhType == other.dhType)); +// } +// private: +// std::string dhId_; +// DHType dhType_; // }; class HidumpHelper { DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); public: int32_t Dump(const std::vector& args, std::string &result); - - void DumpLoadedComps(const DHType dhType); - void DumpUnloadedComps(const DHType dhType); - void DumpEnabledComps(const DHType dhType, const std::string &dhId); - void DumpDisabledComps(const DHType dhType, const std::string &dhId); + // void DumpLoadedComps(const DHType dhType); + // void DumpUnloadedComps(const DHType dhType); private: explicit HidumpHelper() = default; ~HidumpHelper() = default; - int32_t ProcessOneParam(const std::string& args, std::string &result); + + // int32_t ProcessOneParam(const std::string& args, std::string &result); + int32_t ProcessDump(const HidumpParam& hidumpParam, std::string &result); void ShowHelp(std::string &result); void ShowIllealInfomation(std::string &result); - int32_t ProcessDump(const HidumpParam& hidumpParam, std::string &result); - -private: - // std::set loadedCompsSet_; - std::set deviceInfoSet_; +// private: +// std::set deviceInfoSet_; }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index 8568424f..94af15a5 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -28,7 +28,7 @@ #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" -#include "hidump_helper.h" +#include "enabled_comps_dump.h" #include "ipc_object_stub.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -258,7 +258,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { DHLOGE("enable success, retryCount = %d", retryCount); - HidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); + EnabledCompsDump::GetInstance().DumpEnabledComp(dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("enable failed, retryCount = %d", retryCount); @@ -267,7 +267,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); - HidumpHelper::GetInstance().DumpEnabledComps(dhType, dhId); + EnabledCompsDump::GetInstance().DumpEnabledComp(dhType, dhId); return result; } @@ -289,7 +289,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { DHLOGE("disable success, retryCount = %d", retryCount); - HidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); + EnabledCompsDump::GetInstance().DumpDisabledComp(dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("disable failed, retryCount = %d", retryCount); @@ -298,7 +298,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); - HidumpHelper::GetInstance().DumpDisabledComps(dhType, dhId); + EnabledCompsDump::GetInstance().DumpDisabledComp(dhType, dhId); return result; } diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp new file mode 100644 index 00000000..305c31ac --- /dev/null +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022-2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "enabled_comps_dump.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); + +void EnabledCompsDump::DumpEnabledComp(const DHType dhType, const std::string &dhId) +{ + HidumpCompInfo info = { + .dhId_ = dhId, + .dhType_ = dhType, + }; + deviceInfoSet_.emplace(info); +} + +void EnabledCompsDump::DumpDisabledComp(const DHType dhType, const std::string &dhId) +{ + HidumpCompInfo info = { + .dhId_ = dhId, + .dhType_ = dhType, + }; + auto it = deviceInfoSet_.find(info); + if (it != deviceInfoSet_.end()) { + deviceInfoSet_.erase(it); + } +} + +void EnabledCompsDump::Dump(std::set &deviceInfoSet) +{ + deviceInfoSet = deviceInfoSet_; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 166467f9..41a24b2d 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -75,23 +75,22 @@ std::unordered_map g_mapTaskStep = { { TaskStep::WAIT_UNREGISTGER_COMPLET, "WAIT_UNREGISTGER_COMPLET" }, }; -// enum class TaskState : int32_t { const std::unordered_map g_mapTaskState = { { TaskState::INIT, "INIT" }, { TaskState::RUNNING, "RUNNING" }, { TaskState::SUCCESS, "SUCCESS" }, - { TaskState::FAI, "FAI" }, + { TaskState::FAI, "FAILL" }, }; } int32_t HidumpHelper::Dump(const std::vector& args, std::string &result) { - DHLOGI("DHfwkHidumpHelper Dump args.size():%d.", args.size()); + DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); result.clear(); int32_t errCode = DH_SUCCESS; int32_t argsSize = static_cast(args.size()); for (int i = 0; i < args.size(); i++) { - DHLOGI("DHfwkHidumpHelper Dump args[%d]: %s.", i, args.at(i).c_str()); + DHLOGI("HidumpHelper Dump args[%d]: %s.", i, args.at(i).c_str()); } switch (argsSize) { case MIN_ARGS_SIZE: { @@ -195,6 +194,7 @@ void HidumpHelper::ShowAllLoadCompTypes(std::string &result) result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); } +/* void HidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dhId) { HidumpDeviceInfo info = { @@ -215,13 +215,16 @@ void HidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &dhI deviceInfoSet_.earse(it); } } +*/ int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) { DHLOGI("GetAllEnabledComps Dump."); + std::set deviceInfoSet; + EnabledCompsDump::GetInstance.Dump(deviceInfoSet); result.append("Enabled Components:\n"); result.append(TAB); - for (auto info : enabledDeviceInfoSet_) { + for (auto info : deviceInfoSet) { result.append(" DHType :"); result.append(g_mapDhTypeName[info.dhType_]); result.append(" DHId :"); @@ -238,7 +241,7 @@ int32_t HidumpHelper::ShowAllTaskInfo(std::string &result) std::unordered_map> tasks; TaskBoard::GetInstance().DumpAllTask(tasks); - result.append("All TaskInfos:\n"); + result.append("All Task Infos:\n"); for (auto task : tasks) { // std::string taskId = task.GetId(); @@ -246,7 +249,8 @@ int32_t HidumpHelper::ShowAllTaskInfo(std::string &result) // std::string task.GetUUID(); result.append(TAB); result.append(" TaskType :"); - TaskType taskType = task.GetTaskType(); + // TaskType taskType = task.GetTaskType(); + result.append(g_mapTaskType[task.GetTaskType()]); result.append(" DHType :"); result.append(g_mapDhTypeName[task.GetDhType()]); // std::string dhId = @@ -256,10 +260,16 @@ int32_t HidumpHelper::ShowAllTaskInfo(std::string &result) // TaskState taskState = GetTaskState(); result.append(" TaskState :"); result.append(g_mapTaskState[GetTaskState()]); - std::vector taskStep = GetTaskSteps(); - + result.append(" TaskStep :[ "); + std::vector taskStep = GetTaskSteps(); + for (auto step : taskStep) { + result.append(g_mapTaskStep[step]); + result.append(" "); + } + result.append("]\n"); } + result.append("\n"); } int32_t HidumpHelper::ShowHelp(std::string &result) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 532ec850..27018ede 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -31,7 +31,6 @@ ohos_shared_library("distributedhardwareutils") { "src/anonymous_string.cpp", "src/dh_utils_tool.cpp", "src/log/dh_log.cpp", - "dh_hidump_helper.cpp", ] deps = [ -- Gitee From f41134419bca14542496be1652be6e26a1492e26 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 13 May 2022 19:36:24 +0800 Subject: [PATCH 06/24] add dump Signed-off-by: wanderer-dl122 --- .../include/hidumphelper/hidump_helper.h | 32 ++++-------- .../resourcemanager/capability_info_manager.h | 2 + .../src/hidumphelper/hidump_helper.cpp | 50 +++++++++++++------ .../capability_info_manager.cpp | 6 +++ 4 files changed, 54 insertions(+), 36 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index 2f7a34ae..b9b84bc2 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -22,43 +22,31 @@ #include "enabled_comps_dump.h" #include "device_type.h" #include "single_instance.h" -#include "task.h" namespace OHOS { namespace DistributedHardware { - -// class HidumpDeviceInfo { -// public: -// HidumpDeviceInfo() -// std::string dhId_; -// DHType dhType_; - -// bool operator == (const DHInfo& other) const { -// return ((this->dhId == other.dhId) && (this->dhType == other.dhType)); -// } -// private: -// std::string dhId_; -// DHType dhType_; -// }; +enum class HidumpFlag { + UNKNOW = 0, + GET_HELP, + GET_LOADED_COMP_LIST, +}; class HidumpHelper { DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); public: int32_t Dump(const std::vector& args, std::string &result); - // void DumpLoadedComps(const DHType dhType); - // void DumpUnloadedComps(const DHType dhType); private: explicit HidumpHelper() = default; ~HidumpHelper() = default; - // int32_t ProcessOneParam(const std::string& args, std::string &result); - int32_t ProcessDump(const HidumpParam& hidumpParam, std::string &result); + int32_t ProcessDump(const HidumpFlag &flag, std::string &result); + void ShowAllLoadedCompTypes(std::string &result); + void ShowAllEnabledComps(std::string &result); + void ShowAllTaskInfos(std::string &result); + void ShowAllCapabilityInfos(std::string &result); void ShowHelp(std::string &result); void ShowIllealInfomation(std::string &result); - -// private: -// std::set deviceInfoSet_; }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h index bbbd9c26..daa640db 100644 --- a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h @@ -93,6 +93,8 @@ public: /* EventBus async processing callback */ void OnEvent(CapabilityInfoEvent &e) override; + void DumpCapabilityInfos(CapabilityInfoMap &capInfoMap); + private: CapabilityInfoManager(); void HandleCapabilityAddChange(const std::vector &insertRecords); diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 41a24b2d..a047a3c0 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -19,6 +19,7 @@ #include "capability_info_manager.h" #include "distributed_hardware_log.h" +#include "task_board.h" namespace OHOS { namespace DistributedHardware { @@ -32,12 +33,6 @@ const std::string TAB = " "; const std::string ARGS_HELP = "-h"; const std::string LOADED_COMP_LIST = "-loaded-list"; -enum class HidumpFlag { - UNKNOW = 0, - GET_HELP, - GET_LOADED_COMP_LIST, -}; - std::unordered_map g_mapArgs = { { ARGS_HELP, HidumpFlag::GET_HELP }, { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, @@ -122,7 +117,7 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re return errCode; } -int32_t HidumpHelper::ProcessDump(const HidumpFlag& flag, std::string &result) +int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) { DHLOGI("ProcessDump Dump."); result.clear(); @@ -171,13 +166,13 @@ int32_t HidumpHelper::ShowAllLoadCompTypes(std::string &result) } */ -void HidumpHelper::ShowAllLoadCompTypes(std::string &result) +void HidumpHelper::ShowAllLoadedCompTypes(std::string &result) { + DHLOGI("Dump AllLoadedCompTypes."); std::set loadedCompSource; std::set loadedCompSink; ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink); - DHLOGI("GetAllLoadCompTypes Dump."); result.append("Local Loaded Components:\n"); result.append(" Source: "); for (auto compSource : loadedCompSource) { @@ -217,9 +212,9 @@ void HidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &dhI } */ -int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) +void HidumpHelper::ShowAllEnabledComps(std::string &result) { - DHLOGI("GetAllEnabledComps Dump."); + DHLOGI("Dump AllEnabledComps."); std::set deviceInfoSet; EnabledCompsDump::GetInstance.Dump(deviceInfoSet); result.append("Enabled Components:\n"); @@ -235,9 +230,9 @@ int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) return DH_SUCCESS; } -int32_t HidumpHelper::ShowAllTaskInfo(std::string &result) +int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) { - DHLOGI("GetAllAllTaskInfos Dump."); + DHLOGI("Dump AllTaskInfos."); std::unordered_map> tasks; TaskBoard::GetInstance().DumpAllTask(tasks); @@ -272,7 +267,34 @@ int32_t HidumpHelper::ShowAllTaskInfo(std::string &result) result.append("\n"); } -int32_t HidumpHelper::ShowHelp(std::string &result) +void HidumpHelper::ShowAllCapabilityInfos(std::string &result) +{ + DHLOGI("GetAllAllCapabilityInfos Dump."); + // std::map>; + CapabilityInfoMap capInfoMap; + CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfoMap); + + result.append("All Capability Infos:\n"); + for (auto info : capInfoMap) { + result.append(TAB); + result.append(" DeviceName :"); + result.append(GetAnonyString(info->GetDeviceName())); + result.append(" DeviceId :"); + result.append(GetAnonyString(info->GetDeviceId())); + result.append(" DeviceType :"); + result.append(std::string(GetDeviceType())); + result.append(" DHType :"); + result.append(g_mapDhTypeName[info->GetDhType()]); + result.append(" DHId :"); + result.append(GetAnonyString(info->GetDHId())); + result.append(" DHAttrs :"); + result.append(GetAnonyString(info->GetDHAttrs())); + result.append("\n"); + } + result.append("\n"); +} + +void HidumpHelper::ShowHelp(std::string &result) { DHLOGI("ShowHelp Dump."); result.append("Usage:dump \n") diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index 7d6db2c0..153d9342 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -535,5 +535,11 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, } return DH_FWK_SUCCESS; } + +void CapabilityInfoManager::DumpCapabilityInfos(CapabilityInfoMap &capInfoMap) +{ + capInfoMap = globalCapInfoMap_; +} + } // namespace DistributedHardware } // namespace OHOS -- Gitee From f153d674f03f8835b8285a2072a83a41606f1ddc Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Mon, 16 May 2022 11:40:30 +0800 Subject: [PATCH 07/24] add hidump Signed-off-by: wanderer-dl122 --- .../include/idistributed_hardware_manager.h | 1 + .../include/distributed_hardware_service.h | 1 - .../src/accessmanager/access_manager.cpp | 2 +- .../distributed_hardware_manager_factory.cpp | 2 - .../src/distributed_hardware_service.cpp | 3 +- .../BUILD.gn | 4 +- .../componentmanager/component_manager.h | 4 +- .../include/distributed_hardware_manager.h | 2 +- .../include/hidumphelper/enabled_comps_dump.h | 12 +- .../include/hidumphelper/hidump_helper.h | 15 +- .../src/componentloader/component_loader.cpp | 3 - .../src/distributed_hardware_manager.cpp | 3 +- .../src/hidumphelper/enabled_comps_dump.cpp | 12 +- .../src/hidumphelper/hidump_helper.cpp | 145 +++++++----------- 14 files changed, 86 insertions(+), 123 deletions(-) diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index aed2954f..f6c543dd 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -34,6 +34,7 @@ public: uint16_t deviceType) = 0; virtual size_t GetOnLineCount() = 0; virtual int32_t GetComponentVersion(std::unordered_map &versionMap) = 0; + virtual int32_t Dump(const std::vector argsStr, std::string result) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index b9aef878..4b20930c 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -21,7 +21,6 @@ #include "distributed_hardware_stub.h" #include "single_instance.h" -#include "dhfwksa_hidump_helper.h" namespace OHOS { namespace DistributedHardware { diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index bb25db45..19e410dd 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -167,7 +167,7 @@ void AccessManager::SendTrustedDeviceOnline() } } -int32_t AccessManager:Dump(const std::vector argsStr, std::string result) +int32_t AccessManager::Dump(const std::vector argsStr, std::string result) { return DistributedHardwareManagerFactory::GetInstance().Dump(argsStr, result); } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 9a337856..5c9f5904 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -214,7 +214,5 @@ int32_t DistributedHardwareManagerFactory::Dump(const std::vector a } return distributedHardwareMgrPtr_->Dump(argsStr, result); } -} - } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index a2fc1901..d2be468c 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -25,7 +25,6 @@ #include "access_manager.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" -#include "hidump_helper.h" namespace OHOS { namespace DistributedHardware { @@ -93,7 +92,7 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vectorDump(argsStr, result)) + int ret = AccessManager::GetInstance()->Dump(argsStr, result); if (ret != DH_FWK_SUCCESS){ DHLOGE("Dump error, ret = %d", ret); } diff --git a/services/distributedhardwarefwkserviceimpl/BUILD.gn b/services/distributedhardwarefwkserviceimpl/BUILD.gn index d01cffae..0598921c 100644 --- a/services/distributedhardwarefwkserviceimpl/BUILD.gn +++ b/services/distributedhardwarefwkserviceimpl/BUILD.gn @@ -60,7 +60,9 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "src/task/task_factory.cpp", "src/utils/dh_context.cpp", "src/versionmanager/version_manager.cpp", - "hidump_helper.cpp", + "src/hidumphelper/enabled_comps_dump.cpp", + "src/hidumphelper/hidump_helper.cpp", + ] deps = [ diff --git a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h index 86bbb1a3..ac9a1ad9 100644 --- a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h @@ -45,6 +45,8 @@ public: int32_t Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType); + void DumpLoadedComps(std::set &compSourceType, std::set &compSinkType); + private: enum class Action : int32_t { START_SOURCE, @@ -70,8 +72,6 @@ private: int32_t UpdateVersionCache(const std::string &networkId, const std::string &uuid); sptr GetRemoteDHMS(const std::string &networkId) const; - void DumpLoadedComps(std::set &compSourceType, std::set &compSinkType); - private: std::map compSource_; std::map compSink_; diff --git a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h index b12f4ca2..338865ab 100644 --- a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h @@ -32,7 +32,7 @@ public: size_t GetOnLineCount() override; int32_t GetComponentVersion(std::unordered_map &versionMap) override; - int32_t Dump(const std::vector argsStr, std::string result); + int32_t Dump(const std::vector argsStr, std::string result) override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h index b4cdd6a8..f5b33c50 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H -#define OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H +#ifndef OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_H +#define OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_H #include #include #include @@ -30,8 +30,8 @@ struct HidumpCompInfo { DHType dhType_; bool operator < (const HidumpCompInfo &other) const { - return ((this->dhType_ < other.dhType_) || - (this->dhType_ == other.dhType_) && (this->dhId_ < other.dhId_)); + return (((this->dhType_ == other.dhType_) && (this->dhId_ < other.dhId_)) || + (this->dhType_ < other.dhType_)); } }; @@ -41,13 +41,13 @@ public: void DumpEnabledComp(const DHType dhType, const std::string &dhId); void DumpDisabledComp(const DHType dhType, const std::string &dhId); - void Dump(std::set &deviceInfoSet); + void Dump(std::set &compInfoSet); private: explicit EnabledCompsDump() = default; ~EnabledCompsDump() = default; - std::set deviceInfoSet_; + std::set compInfoSet_; }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index b9b84bc2..86e65670 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -29,6 +29,9 @@ enum class HidumpFlag { UNKNOW = 0, GET_HELP, GET_LOADED_COMP_LIST, + GET_ENABLED_COMP_LIST, + GET_TASK_LIST, + GET_CAPABILITY_LIST, }; class HidumpHelper { @@ -41,12 +44,12 @@ private: ~HidumpHelper() = default; int32_t ProcessDump(const HidumpFlag &flag, std::string &result); - void ShowAllLoadedCompTypes(std::string &result); - void ShowAllEnabledComps(std::string &result); - void ShowAllTaskInfos(std::string &result); - void ShowAllCapabilityInfos(std::string &result); - void ShowHelp(std::string &result); - void ShowIllealInfomation(std::string &result); + int32_t ShowAllLoadedComps(std::string &result); + int32_t ShowAllEnabledComps(std::string &result); + int32_t ShowAllTaskInfos(std::string &result); + int32_t ShowAllCapabilityInfos(std::string &result); + int32_t ShowHelp(std::string &result); + int32_t ShowIllealInfomation(std::string &result); }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp index b1056fec..39567703 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp @@ -178,7 +178,6 @@ int32_t ComponentLoader::GetHardwareHandler(const DHType dhType, IHardwareHandle return ERR_DH_FWK_LOADER_HANDLER_IS_NULL; } hardwareHandlerPtr = getHardwareClassHandler(); - HidumpHelper::GetInstance().DumpLoadedComps(dhType); return DH_FWK_SUCCESS; } @@ -277,8 +276,6 @@ int32_t ComponentLoader::UnInit() ret += ReleaseHardwareHandler(iter->first); ret += ReleaseSource(iter->first); ret += ReleaseSink(iter->first); - - HidumpHelper::GetInstance()::DumpUnloadedComps(iter->first); } compHandlerMap_.clear(); return ret; diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp index 4c17c912..3022797d 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp @@ -23,6 +23,7 @@ #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "hidump_helper.h" #include "local_hardware_manager.h" #include "task_board.h" #include "task_executor.h" @@ -179,7 +180,7 @@ int32_t DistributedHardwareManager::GetComponentVersion(std::unordered_map argsStr, std::string result) { - + return HidumpHelper::GetInstance().Dump(argsStr, result); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp index 305c31ac..0cf81805 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp @@ -25,7 +25,7 @@ void EnabledCompsDump::DumpEnabledComp(const DHType dhType, const std::string &d .dhId_ = dhId, .dhType_ = dhType, }; - deviceInfoSet_.emplace(info); + compInfoSet_.emplace(info); } void EnabledCompsDump::DumpDisabledComp(const DHType dhType, const std::string &dhId) @@ -34,15 +34,15 @@ void EnabledCompsDump::DumpDisabledComp(const DHType dhType, const std::string & .dhId_ = dhId, .dhType_ = dhType, }; - auto it = deviceInfoSet_.find(info); - if (it != deviceInfoSet_.end()) { - deviceInfoSet_.erase(it); + auto it = compInfoSet_.find(info); + if (it != compInfoSet_.end()) { + compInfoSet_.erase(it); } } -void EnabledCompsDump::Dump(std::set &deviceInfoSet) +void EnabledCompsDump::Dump(std::set &compInfoSet) { - deviceInfoSet = deviceInfoSet_; + compInfoSet = compInfoSet_; } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index a047a3c0..9d3ac4fd 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -18,6 +18,8 @@ #include #include "capability_info_manager.h" +#include "component_manager.h" +#include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "task_board.h" @@ -32,10 +34,16 @@ const std::string SEPARATOR = " | "; const std::string TAB = " "; const std::string ARGS_HELP = "-h"; const std::string LOADED_COMP_LIST = "-loaded-list"; +const std::string ENABLED_COMP_LIST = "-enabled-list"; +const std::string TASK_LIST = "-task-list"; +const std::string CAPABILITY_LIST = "-capability-list"; std::unordered_map g_mapArgs = { { ARGS_HELP, HidumpFlag::GET_HELP }, { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, + { ENABLED_COMP_LIST, HidumpFlag::GET_ENABLED_COMP_LIST }, + { TASK_LIST , HidumpFlag::GET_TASK_LIST }, + { CAPABILITY_LIST , HidumpFlag::GET_CAPABILITY_LIST }, }; std::unordered_map g_mapDhTypeName = { @@ -67,14 +75,14 @@ std::unordered_map g_mapTaskStep = { { TaskStep::REGISTER_ONLINE_DISTRIBUTED_HARDWARE, "REGISTER_ONLINE_DISTRIBUTED_HARDWARE" }, { TaskStep::UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE, "UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE" }, { TaskStep::CLEAR_OFFLINE_INFO, "CLEAR_OFFLINE_INFO" }, - { TaskStep::WAIT_UNREGISTGER_COMPLET, "WAIT_UNREGISTGER_COMPLET" }, + { TaskStep::WAIT_UNREGISTGER_COMPLETE, "WAIT_UNREGISTGER_COMPLETE" }, }; -const std::unordered_map g_mapTaskState = { +std::unordered_map g_mapTaskState = { { TaskState::INIT, "INIT" }, { TaskState::RUNNING, "RUNNING" }, { TaskState::SUCCESS, "SUCCESS" }, - { TaskState::FAI, "FAILL" }, + { TaskState::FAIL, "FAIL" }, }; } @@ -82,11 +90,8 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re { DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); result.clear(); - int32_t errCode = DH_SUCCESS; + int32_t errCode = DH_FWK_SUCCESS; int32_t argsSize = static_cast(args.size()); - for (int i = 0; i < args.size(); i++) { - DHLOGI("HidumpHelper Dump args[%d]: %s.", i, args.at(i).c_str()); - } switch (argsSize) { case MIN_ARGS_SIZE: { errCode = ProcessDump(HidumpFlag::GET_HELP, result); @@ -97,13 +102,13 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re break; } default: { - errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; + errCode = ERR_DH_FWK_HIDUMP_INVALID_ARGS; break; } } switch (errCode) { - case DH_SUCCESS: { + case DH_FWK_SUCCESS: { break; } case ERR_DH_FWK_HIDUMP_INVALID_ARGS: { @@ -117,6 +122,7 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re return errCode; } + int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) { DHLOGI("ProcessDump Dump."); @@ -128,7 +134,19 @@ int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) break; } case HidumpFlag::GET_LOADED_COMP_LIST: { - errCode = ShowAllLoadCompTypes(result); + errCode = ShowAllLoadedComps(result); + break; + } + case HidumpFlag::GET_ENABLED_COMP_LIST : { + errCode = ShowAllEnabledComps(result); + break; + } + case HidumpFlag::GET_TASK_LIST : { + errCode = ShowAllTaskInfos(result); + break; + } + case HidumpFlag::GET_CAPABILITY_LIST : { + errCode = ShowAllCapabilityInfos(result); break; } default: { @@ -139,34 +157,8 @@ int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) return errCode; } -/* -void DumpLoadedComps(const DHType dhType) -{ - loadedCompsSet_.emplace(dhType); -} - -void DumpUnloadedComps(const DHType dhType) -{ - auto it = loadedCompsSet_.find(dhType); - if (it != loadedCompsSet_.end()) { - loadedCompsSet_.earse(it); - } -} -int32_t HidumpHelper::ShowAllLoadCompTypes(std::string &result) -{ - DHLOGI("GetAllLoadCompTypes Dump."); - result.append("loaded components:\n"); - result.append(" "); - for (auto comp : loadedCompsSet_) { - result.append(g_mapDhTypeName[comp]); - result.append(SEPARATOR); - } - result.append("\n"); - return DH_SUCCESS; -} -*/ -void HidumpHelper::ShowAllLoadedCompTypes(std::string &result) +int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) { DHLOGI("Dump AllLoadedCompTypes."); std::set loadedCompSource; @@ -179,44 +171,22 @@ void HidumpHelper::ShowAllLoadedCompTypes(std::string &result) result.append(g_mapDhTypeName[compSource]); result.append(SEPARATOR); } - result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n"); + result.replace(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n"); result.append(" Sink: "); for (auto compSink : loadedCompSink) { result.append(g_mapDhTypeName[compSink]); result.append(SEPARATOR); } - result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); -} - -/* -void HidumpHelper::DumpEnabledComps(const DHType dhType, const std::string &dhId) -{ - HidumpDeviceInfo info = { - .dhId_ = dhId, - .dhType_ = dhType, - } - deviceInfoSet_.emplace(info); + result.replace(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); + return DH_FWK_SUCCESS; } -void HidumpHelper::DumpDisabledComps(const DHType dhType, const std::string &dhId) -{ - HidumpDeviceInfo info = { - .dhId_ = dhId, - .dhType_ = dhType, - } - auto it = enabledDeviceInfoSet_.find(info); - if (it != enabledDeviceInfoSet_.end()) { - deviceInfoSet_.earse(it); - } -} -*/ - -void HidumpHelper::ShowAllEnabledComps(std::string &result) +int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) { DHLOGI("Dump AllEnabledComps."); std::set deviceInfoSet; - EnabledCompsDump::GetInstance.Dump(deviceInfoSet); + EnabledCompsDump::GetInstance().Dump(deviceInfoSet); result.append("Enabled Components:\n"); result.append(TAB); for (auto info : deviceInfoSet) { @@ -226,8 +196,8 @@ void HidumpHelper::ShowAllEnabledComps(std::string &result) result.append(GetAnonyString(info.dhId_)); result.append(SEPARATOR); } - result.replce(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); - return DH_SUCCESS; + result.replace(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); + return DH_FWK_SUCCESS; } int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) @@ -237,27 +207,18 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) TaskBoard::GetInstance().DumpAllTask(tasks); result.append("All Task Infos:\n"); - for (auto task : tasks) { - // std::string taskId = task.GetId(); - // std::string task.GetNetworkId(); - // std::string task.GetUUID(); result.append(TAB); result.append(" TaskType :"); - // TaskType taskType = task.GetTaskType(); - result.append(g_mapTaskType[task.GetTaskType()]); + result.append(g_mapTaskType[task.second->GetTaskType()]); result.append(" DHType :"); - result.append(g_mapDhTypeName[task.GetDhType()]); - // std::string dhId = + result.append(g_mapDhTypeName[task.second->GetDhType()]); result.append(" DHId :"); - result.append(GetAnonyString(task.GetDhId())); - - // TaskState taskState = GetTaskState(); + result.append(GetAnonyString(task.second->GetDhId())); result.append(" TaskState :"); - result.append(g_mapTaskState[GetTaskState()]); - + result.append(g_mapTaskState[task.second->GetTaskState()]); result.append(" TaskStep :[ "); - std::vector taskStep = GetTaskSteps(); + std::vector taskStep = task.second->GetTaskSteps(); for (auto step : taskStep) { result.append(g_mapTaskStep[step]); result.append(" "); @@ -265,12 +226,12 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) result.append("]\n"); } result.append("\n"); + return DH_FWK_SUCCESS; } -void HidumpHelper::ShowAllCapabilityInfos(std::string &result) +int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) { DHLOGI("GetAllAllCapabilityInfos Dump."); - // std::map>; CapabilityInfoMap capInfoMap; CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfoMap); @@ -278,23 +239,24 @@ void HidumpHelper::ShowAllCapabilityInfos(std::string &result) for (auto info : capInfoMap) { result.append(TAB); result.append(" DeviceName :"); - result.append(GetAnonyString(info->GetDeviceName())); + result.append(GetAnonyString(info.second->GetDeviceName())); result.append(" DeviceId :"); - result.append(GetAnonyString(info->GetDeviceId())); + result.append(GetAnonyString(info.second->GetDeviceId())); result.append(" DeviceType :"); - result.append(std::string(GetDeviceType())); + result.append(std::to_string(info.second->GetDeviceType())); result.append(" DHType :"); - result.append(g_mapDhTypeName[info->GetDhType()]); + result.append(g_mapDhTypeName[info.second->GetDHType()]); result.append(" DHId :"); - result.append(GetAnonyString(info->GetDHId())); + result.append(GetAnonyString(info.second->GetDHId())); result.append(" DHAttrs :"); - result.append(GetAnonyString(info->GetDHAttrs())); + result.append(GetAnonyString(info.second->GetDHAttrs())); result.append("\n"); } result.append("\n"); + return DH_FWK_SUCCESS; } -void HidumpHelper::ShowHelp(std::string &result) +int32_t HidumpHelper::ShowHelp(std::string &result) { DHLOGI("ShowHelp Dump."); result.append("Usage:dump \n") @@ -302,13 +264,14 @@ void HidumpHelper::ShowHelp(std::string &result) .append("-loaded-comp-list ") .append(": Show loaded components\n"); - return DH_SUCCESS; + return DH_FWK_SUCCESS; } -void HidumpHelper::ShowIllealInfomation(std::string &result) +int32_t HidumpHelper::ShowIllealInfomation(std::string &result) { DHLOGI("ShowIllealInfomation Dump."); result.append("unrecognized option, -h for help"); + return DH_FWK_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 5bcbfd95338ba0f7b350f62ed2aeaf2869a89e80 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Mon, 16 May 2022 11:52:23 +0800 Subject: [PATCH 08/24] add hidump Signed-off-by: wanderer-dl122 --- .../src/hidumphelper/hidump_helper.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 9d3ac4fd..42905140 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -33,10 +33,10 @@ const int32_t FIRST_PARAM = 0; const std::string SEPARATOR = " | "; const std::string TAB = " "; const std::string ARGS_HELP = "-h"; -const std::string LOADED_COMP_LIST = "-loaded-list"; -const std::string ENABLED_COMP_LIST = "-enabled-list"; -const std::string TASK_LIST = "-task-list"; -const std::string CAPABILITY_LIST = "-capability-list"; +const std::string LOADED_COMP_LIST = "-l"; +const std::string ENABLED_COMP_LIST = "-e"; +const std::string TASK_LIST = "-t"; +const std::string CAPABILITY_LIST = "-c"; std::unordered_map g_mapArgs = { { ARGS_HELP, HidumpFlag::GET_HELP }, @@ -259,10 +259,18 @@ int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) int32_t HidumpHelper::ShowHelp(std::string &result) { DHLOGI("ShowHelp Dump."); - result.append("Usage:dump \n") - .append("Description:\n") - .append("-loaded-comp-list ") - .append(": Show loaded components\n"); + result.append("Usage:dump \n"); + result.append("Description:\n"); + result.append("-h "); + result.append(": Show help\n");; + result.append("-l "); + result.append(": Show all loaded components\n"); + result.append("-e "); + result.append(": Show all enabled components\n"); + result.append("-t "); + result.append(": Show all task\n"); + result.append("-c "); + result.append(": Show all capability infos\n"); return DH_FWK_SUCCESS; } -- Gitee From cbaf65f7eb7d78c50d8d7df0f62cc4a10c6489f1 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Mon, 16 May 2022 17:57:13 +0800 Subject: [PATCH 09/24] add hidump Signed-off-by: wanderer-dl122 --- .../src/distributed_hardware_service.cpp | 1 + .../src/hidumphelper/hidump_helper.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index d2be468c..1726c050 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -86,6 +86,7 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map& args) { DHLOGI("DistributedHardwareService Dump."); + dprintf(fd, "DistributedHardwareService::Dump"); std::string result; std::vector argsStr; for (auto item : args) { diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 42905140..acb38009 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -258,7 +258,7 @@ int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) int32_t HidumpHelper::ShowHelp(std::string &result) { - DHLOGI("ShowHelp Dump."); + DHLOGI("Show Dump Help."); result.append("Usage:dump \n"); result.append("Description:\n"); result.append("-h "); -- Gitee From 48cb709955ad90711801887434df447cfa757f2a Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Mon, 16 May 2022 18:11:28 +0800 Subject: [PATCH 10/24] add hidump Signed-off-by: wanderer-dl122 --- .../src/distributed_hardware_service.cpp | 2 +- .../include/hidumphelper/enabled_comps_dump.h | 6 +++--- .../src/hidumphelper/hidump_helper.cpp | 6 +++--- .../src/resourcemanager/capability_info_manager.cpp | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 1726c050..93790f8e 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -94,7 +94,7 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vectorDump(argsStr, result); - if (ret != DH_FWK_SUCCESS){ + if (ret != DH_FWK_SUCCESS) { DHLOGE("Dump error, ret = %d", ret); } diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h index f5b33c50..699b059b 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -24,12 +24,12 @@ namespace OHOS { namespace DistributedHardware { - struct HidumpCompInfo { std::string dhId_; DHType dhType_; - bool operator < (const HidumpCompInfo &other) const { + bool operator < (const HidumpCompInfo &other) const + { return (((this->dhType_ == other.dhType_) && (this->dhId_ < other.dhId_)) || (this->dhType_ < other.dhType_)); } @@ -47,9 +47,9 @@ private: explicit EnabledCompsDump() = default; ~EnabledCompsDump() = default; +private: std::set compInfoSet_; }; - } // namespace DistributedHardware } // namespace OHOS #endif \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index acb38009..7a54d00b 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -42,8 +42,8 @@ std::unordered_map g_mapArgs = { { ARGS_HELP, HidumpFlag::GET_HELP }, { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, { ENABLED_COMP_LIST, HidumpFlag::GET_ENABLED_COMP_LIST }, - { TASK_LIST , HidumpFlag::GET_TASK_LIST }, - { CAPABILITY_LIST , HidumpFlag::GET_CAPABILITY_LIST }, + { TASK_LIST, HidumpFlag::GET_TASK_LIST }, + { CAPABILITY_LIST, HidumpFlag::GET_CAPABILITY_LIST }, }; std::unordered_map g_mapDhTypeName = { @@ -262,7 +262,7 @@ int32_t HidumpHelper::ShowHelp(std::string &result) result.append("Usage:dump \n"); result.append("Description:\n"); result.append("-h "); - result.append(": Show help\n");; + result.append(": Show help\n"); result.append("-l "); result.append(": Show all loaded components\n"); result.append("-e "); diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index 153d9342..c5300983 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -540,6 +540,5 @@ void CapabilityInfoManager::DumpCapabilityInfos(CapabilityInfoMap &capInfoMap) { capInfoMap = globalCapInfoMap_; } - } // namespace DistributedHardware } // namespace OHOS -- Gitee From 9574f655c748c6b785f4252866a919378577b2de Mon Sep 17 00:00:00 2001 From: zhangpengpeng Date: Tue, 17 May 2022 11:21:23 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E9=80=82=E9=85=8Ddinput=E8=81=94?= =?UTF-8?q?=E8=B0=83=EF=BC=8C=E4=B8=B4=E6=97=B6=E4=BF=AE=E6=94=B9uid?= =?UTF-8?q?=E4=B8=BAroot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangpengpeng --- sa_profile/dhardware.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sa_profile/dhardware.cfg b/sa_profile/dhardware.cfg index f521718d..0efd2864 100644 --- a/sa_profile/dhardware.cfg +++ b/sa_profile/dhardware.cfg @@ -2,8 +2,8 @@ "services" : [{ "name" : "dhardware", "path" : ["/system/bin/sa_main", "/system/profile/dhardware.xml"], - "uid" : "system", - "gid" : ["system"], + "uid" : "root", + "gid" : ["system", "uhid", "root"], "ondemand" : true }] } \ No newline at end of file -- Gitee From 5975eab7d6f08cce4e2937072e786417350af858 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Tue, 17 May 2022 17:26:36 +0800 Subject: [PATCH 12/24] add dumper Signed-off-by: wanderer-dl122 --- .../include/idistributed_hardware_manager.h | 2 +- .../include/accessmanager/access_manager.h | 2 +- .../distributed_hardware_manager_factory.h | 2 +- .../src/accessmanager/access_manager.cpp | 2 +- .../distributed_hardware_manager_factory.cpp | 2 +- .../src/distributed_hardware_service.cpp | 2 +- .../include/distributed_hardware_manager.h | 2 +- .../include/task/task_board.h | 2 +- .../src/distributed_hardware_manager.cpp | 2 +- .../src/hidumphelper/hidump_helper.cpp | 143 ++++++++---------- .../src/task/task_board.cpp | 2 +- 11 files changed, 74 insertions(+), 89 deletions(-) diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index f6c543dd..1f7bd43f 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -34,7 +34,7 @@ public: uint16_t deviceType) = 0; virtual size_t GetOnLineCount() = 0; virtual int32_t GetComponentVersion(std::unordered_map &versionMap) = 0; - virtual int32_t Dump(const std::vector argsStr, std::string result) = 0; + virtual int32_t Dump(const std::vector &argsStr, std::string &result) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h index 27612a11..9e30b5fa 100644 --- a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h +++ b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h @@ -48,7 +48,7 @@ public: virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override; virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override; - int32_t Dump(const std::vector argsStr, std::string result); + int32_t Dump(const std::vector &argsStr, std::string &result); private: AccessManager() = default; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index 6270ec66..fd0271b8 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -32,7 +32,7 @@ public: int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t GetComponentVersion(std::unordered_map &versionMap); - int Dump(const std::vector argsStr, std::string result); + int Dump(const std::vector &argsStr, std::string &result); private: bool Init(); diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 19e410dd..672e9b38 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -167,7 +167,7 @@ void AccessManager::SendTrustedDeviceOnline() } } -int32_t AccessManager::Dump(const std::vector argsStr, std::string result) +int32_t AccessManager::Dump(const std::vector &argsStr, std::string &result) { return DistributedHardwareManagerFactory::GetInstance().Dump(argsStr, result); } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 5c9f5904..534122a7 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -206,7 +206,7 @@ int32_t DistributedHardwareManagerFactory::GetComponentVersion(std::unordered_ma return distributedHardwareMgrPtr_->GetComponentVersion(versionMap); } -int32_t DistributedHardwareManagerFactory::Dump(const std::vector argsStr, std::string result) +int32_t DistributedHardwareManagerFactory::Dump(const std::vector &argsStr, std::string &result) { if (distributedHardwareMgrPtr_ == nullptr) { DHLOGE("distributedHardwareMgr is null"); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 93790f8e..ddc6a8cf 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -86,7 +86,6 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map& args) { DHLOGI("DistributedHardwareService Dump."); - dprintf(fd, "DistributedHardwareService::Dump"); std::string result; std::vector argsStr; for (auto item : args) { @@ -98,6 +97,7 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vector &versionMap) override; - int32_t Dump(const std::vector argsStr, std::string result) override; + int32_t Dump(const std::vector &argsStr, std::string &result) override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h index 8c899baf..82adbe4d 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h @@ -34,7 +34,7 @@ public: void AddTask(std::shared_ptr task); void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); - void DumpAllTask(std::unordered_map> &tasks); + void DumpAllTasks(std::unordered_map> &tasks); private: void RemoveTaskInner(std::string taskId); diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp index 3022797d..e9862ca4 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp @@ -178,7 +178,7 @@ int32_t DistributedHardwareManager::GetComponentVersion(std::unordered_map argsStr, std::string result) +int32_t DistributedHardwareManager::Dump(const std::vector &argsStr, std::string &result) { return HidumpHelper::GetInstance().Dump(argsStr, result); } diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 7a54d00b..b8535df8 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -27,18 +27,13 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); namespace { -const int32_t MIN_ARGS_SIZE = 0; -const int32_t MAX_ARGS_SIZE = 1; -const int32_t FIRST_PARAM = 0; -const std::string SEPARATOR = " | "; -const std::string TAB = " "; const std::string ARGS_HELP = "-h"; const std::string LOADED_COMP_LIST = "-l"; const std::string ENABLED_COMP_LIST = "-e"; const std::string TASK_LIST = "-t"; const std::string CAPABILITY_LIST = "-c"; -std::unordered_map g_mapArgs = { +const std::unordered_map MAP_ARGS = { { ARGS_HELP, HidumpFlag::GET_HELP }, { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, { ENABLED_COMP_LIST, HidumpFlag::GET_ENABLED_COMP_LIST }, @@ -90,43 +85,25 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re { DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); result.clear(); - int32_t errCode = DH_FWK_SUCCESS; - int32_t argsSize = static_cast(args.size()); - switch (argsSize) { - case MIN_ARGS_SIZE: { - errCode = ProcessDump(HidumpFlag::GET_HELP, result); - break; - } - case MAX_ARGS_SIZE: { - errCode = ProcessDump(g_mapArgs[args[FIRST_PARAM]], result); - break; - } - default: { - errCode = ERR_DH_FWK_HIDUMP_INVALID_ARGS; - break; - } + int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; + + if (args.empty()) { + return ProcessDump(HidumpFlag::GET_HELP, result); } - switch (errCode) { - case DH_FWK_SUCCESS: { - break; - } - case ERR_DH_FWK_HIDUMP_INVALID_ARGS: { - ShowIllealInfomation(result); - break; - } - default: { - break; - } + auto flag = MAP_ARGS.find(args[0]); + if ((args.size() > 1) || (flag == MAP_ARGS.end())) { + errCode = ProcessDump(HidumpFlag::UNKNOW, result); + } else { + errCode = ProcessDump(flag->second, result); } + return errCode; } - int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) { DHLOGI("ProcessDump Dump."); - result.clear(); int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; switch (flag) { case HidumpFlag::GET_HELP: { @@ -150,7 +127,7 @@ int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) break; } default: { - errCode = ERR_DH_FWK_HIDUMP_INVALID_ARGS; + errCode = ShowIllealInfomation(result); break; } } @@ -165,38 +142,44 @@ int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) std::set loadedCompSink; ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink); - result.append("Local Loaded Components:\n"); - result.append(" Source: "); + result.append("Local Loaded Components:\n{"); + result.append("\n Source : ["); for (auto compSource : loadedCompSource) { + result.append(" "); result.append(g_mapDhTypeName[compSource]); - result.append(SEPARATOR); + result.append(","); } - result.replace(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n"); + result.replace(result.size() - 1, 1, " "); + result.append("]"); - result.append(" Sink: "); + result.append("\n Sink : ["); for (auto compSink : loadedCompSink) { + result.append(" "); result.append(g_mapDhTypeName[compSink]); - result.append(SEPARATOR); + result.append(","); } - result.replace(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); + result.replace(result.size() - 1, 1, " "); + result.append("]"); + result.append("\n}\n"); return DH_FWK_SUCCESS; } int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) { DHLOGI("Dump AllEnabledComps."); - std::set deviceInfoSet; - EnabledCompsDump::GetInstance().Dump(deviceInfoSet); - result.append("Enabled Components:\n"); - result.append(TAB); - for (auto info : deviceInfoSet) { - result.append(" DHType :"); + std::set compInfoSet; + EnabledCompsDump::GetInstance().Dump(compInfoSet); + + result.append("Enabled Components:"); + for (auto info : compInfoSet) { + result.append("\n{"); + result.append("\n DHType : "); result.append(g_mapDhTypeName[info.dhType_]); - result.append(" DHId :"); + result.append("\n DHId : "); result.append(GetAnonyString(info.dhId_)); - result.append(SEPARATOR); + result.append("\n},"); } - result.replace(result.size() - SEPARATOR.size(), SEPARATOR.size(), " \n\n"); + result.replace(result.size() - 1, 1, "\n"); return DH_FWK_SUCCESS; } @@ -204,28 +187,29 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) { DHLOGI("Dump AllTaskInfos."); std::unordered_map> tasks; - TaskBoard::GetInstance().DumpAllTask(tasks); + TaskBoard::GetInstance().DumpAllTasks(tasks); - result.append("All Task Infos:\n"); + result.append("All Task Infos:"); for (auto task : tasks) { - result.append(TAB); - result.append(" TaskType :"); + result.append("\n{"); + result.append("\n TaskType : "); result.append(g_mapTaskType[task.second->GetTaskType()]); - result.append(" DHType :"); + result.append("\n DHType : "); result.append(g_mapDhTypeName[task.second->GetDhType()]); - result.append(" DHId :"); + result.append("\n DHId : "); result.append(GetAnonyString(task.second->GetDhId())); - result.append(" TaskState :"); + result.append("\n TaskState : "); result.append(g_mapTaskState[task.second->GetTaskState()]); - result.append(" TaskStep :[ "); + result.append("\n TaskStep : [ "); std::vector taskStep = task.second->GetTaskSteps(); for (auto step : taskStep) { result.append(g_mapTaskStep[step]); result.append(" "); } result.append("]\n"); + result.append("},"); } - result.append("\n"); + result.replace(result.size() - 1, 1, "\n"); return DH_FWK_SUCCESS; } @@ -235,24 +219,24 @@ int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) CapabilityInfoMap capInfoMap; CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfoMap); - result.append("All Capability Infos:\n"); + result.append("All Capability Infos:"); for (auto info : capInfoMap) { - result.append(TAB); - result.append(" DeviceName :"); + result.append("\n{"); + result.append("\n DeviceName : "); result.append(GetAnonyString(info.second->GetDeviceName())); - result.append(" DeviceId :"); + result.append("\n DeviceId : "); result.append(GetAnonyString(info.second->GetDeviceId())); - result.append(" DeviceType :"); + result.append("\n DeviceType : "); result.append(std::to_string(info.second->GetDeviceType())); - result.append(" DHType :"); + result.append("\n DHType : "); result.append(g_mapDhTypeName[info.second->GetDHType()]); - result.append(" DHId :"); + result.append("\n DHId : "); result.append(GetAnonyString(info.second->GetDHId())); - result.append(" DHAttrs :"); - result.append(GetAnonyString(info.second->GetDHAttrs())); - result.append("\n"); + result.append("\n DHAttrs : "); + result.append(info.second->GetDHAttrs()); + result.append("\n},"); } - result.append("\n"); + result.replace(result.size() - 1, 1, "\n"); return DH_FWK_SUCCESS; } @@ -261,16 +245,16 @@ int32_t HidumpHelper::ShowHelp(std::string &result) DHLOGI("Show Dump Help."); result.append("Usage:dump \n"); result.append("Description:\n"); - result.append("-h "); + result.append(" -h "); result.append(": Show help\n"); - result.append("-l "); + result.append(" -l "); result.append(": Show all loaded components\n"); - result.append("-e "); + result.append(" -e "); result.append(": Show all enabled components\n"); - result.append("-t "); - result.append(": Show all task\n"); - result.append("-c "); - result.append(": Show all capability infos\n"); + result.append(" -t "); + result.append(": Show all tasks\n"); + result.append(" -c "); + result.append(": Show all capability infos\n\n"); return DH_FWK_SUCCESS; } @@ -278,8 +262,9 @@ int32_t HidumpHelper::ShowHelp(std::string &result) int32_t HidumpHelper::ShowIllealInfomation(std::string &result) { DHLOGI("ShowIllealInfomation Dump."); + result.clear(); result.append("unrecognized option, -h for help"); - return DH_FWK_SUCCESS; + return ERR_DH_FWK_HIDUMP_INVALID_ARGS; } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp index 00c7cd36..230092cf 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp @@ -86,7 +86,7 @@ void TaskBoard::RemoveTaskInner(std::string taskId) tasks_.erase(taskId); } -void TaskBoard::DumpAllTask(std::unordered_map> &tasks) +void TaskBoard::DumpAllTasks(std::unordered_map> &tasks) { tasks = tasks_; } -- Gitee From 43558c54f6873ded1bc5689d09b02fef0b65eb45 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Tue, 17 May 2022 20:36:32 +0800 Subject: [PATCH 13/24] add dumper Signed-off-by: wanderer-dl122 --- .../src/hidumphelper/hidump_helper.cpp | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index b8535df8..523682f6 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -83,7 +83,7 @@ std::unordered_map g_mapTaskState = { int32_t HidumpHelper::Dump(const std::vector& args, std::string &result) { - DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); + DHLOGI("HidumpHelper dump start."); result.clear(); int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; @@ -103,7 +103,7 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) { - DHLOGI("ProcessDump Dump."); + DHLOGI("Process Dump."); int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; switch (flag) { case HidumpFlag::GET_HELP: { @@ -137,12 +137,12 @@ int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) { - DHLOGI("Dump AllLoadedCompTypes."); + DHLOGI("Dump all loaded compTypes."); std::set loadedCompSource; std::set loadedCompSink; ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink); - result.append("Local Loaded Components:\n{"); + result.append("Local loaded components:\n{"); result.append("\n Source : ["); for (auto compSource : loadedCompSource) { result.append(" "); @@ -166,11 +166,11 @@ int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) { - DHLOGI("Dump AllEnabledComps."); + DHLOGI("Dump all enabled comps."); std::set compInfoSet; EnabledCompsDump::GetInstance().Dump(compInfoSet); - result.append("Enabled Components:"); + result.append("All enabled components:"); for (auto info : compInfoSet) { result.append("\n{"); result.append("\n DHType : "); @@ -185,11 +185,11 @@ int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) { - DHLOGI("Dump AllTaskInfos."); + DHLOGI("Dump all task infos."); std::unordered_map> tasks; TaskBoard::GetInstance().DumpAllTasks(tasks); - result.append("All Task Infos:"); + result.append("All task infos:"); for (auto task : tasks) { result.append("\n{"); result.append("\n TaskType : "); @@ -215,11 +215,11 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) { - DHLOGI("GetAllAllCapabilityInfos Dump."); + DHLOGI("Dump all capability infos."); CapabilityInfoMap capInfoMap; CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfoMap); - - result.append("All Capability Infos:"); + + result.append("All capability infos:"); for (auto info : capInfoMap) { result.append("\n{"); result.append("\n DeviceName : "); @@ -232,7 +232,7 @@ int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) result.append(g_mapDhTypeName[info.second->GetDHType()]); result.append("\n DHId : "); result.append(GetAnonyString(info.second->GetDHId())); - result.append("\n DHAttrs : "); + result.append("\n DHAttrs :\n"); result.append(info.second->GetDHAttrs()); result.append("\n},"); } @@ -242,9 +242,8 @@ int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) int32_t HidumpHelper::ShowHelp(std::string &result) { - DHLOGI("Show Dump Help."); - result.append("Usage:dump \n"); - result.append("Description:\n"); + DHLOGI("Show dump help."); + result.append("DistributedHardwareFramework dump options:\n"); result.append(" -h "); result.append(": Show help\n"); result.append(" -l "); @@ -263,7 +262,7 @@ int32_t HidumpHelper::ShowIllealInfomation(std::string &result) { DHLOGI("ShowIllealInfomation Dump."); result.clear(); - result.append("unrecognized option, -h for help"); + result.append("Unrecognized option, -h for help."); return ERR_DH_FWK_HIDUMP_INVALID_ARGS; } } // namespace DistributedHardware -- Gitee From a95cc21c7f6754d27366f337ab011b7218e45109 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Tue, 17 May 2022 20:51:12 +0800 Subject: [PATCH 14/24] add dumper Signed-off-by: wanderer-dl122 --- services/distributedhardwarefwkserviceimpl/BUILD.gn | 5 ++--- .../include/hidumphelper/hidump_helper.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/BUILD.gn b/services/distributedhardwarefwkserviceimpl/BUILD.gn index 0598921c..550fad7e 100644 --- a/services/distributedhardwarefwkserviceimpl/BUILD.gn +++ b/services/distributedhardwarefwkserviceimpl/BUILD.gn @@ -44,6 +44,8 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "src/componentmanager/component_manager.cpp", "src/distributed_hardware_manager.cpp", "src/distributed_hardware_proxy.cpp", + "src/hidumphelper/enabled_comps_dump.cpp", + "src/hidumphelper/hidump_helper.cpp", "src/localhardwaremanager/local_hardware_manager.cpp", "src/localhardwaremanager/plugin_listener_impl.cpp", "src/resourcemanager/capability_info.cpp", @@ -60,9 +62,6 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "src/task/task_factory.cpp", "src/utils/dh_context.cpp", "src/versionmanager/version_manager.cpp", - "src/hidumphelper/enabled_comps_dump.cpp", - "src/hidumphelper/hidump_helper.cpp", - ] deps = [ diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index 86e65670..7a162498 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -51,7 +51,6 @@ private: int32_t ShowHelp(std::string &result); int32_t ShowIllealInfomation(std::string &result); }; - } // namespace DistributedHardware } // namespace OHOS #endif \ No newline at end of file -- Gitee From b6ea7580d75ee78fe7d7a87df91f9d0ce8eeb1da Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Wed, 18 May 2022 09:12:53 +0800 Subject: [PATCH 15/24] add dumper Signed-off-by: wanderer-dl122 --- .../src/distributed_hardware_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index ddc6a8cf..d01506ec 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -97,7 +97,6 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vector Date: Wed, 18 May 2022 09:17:10 +0800 Subject: [PATCH 16/24] add dumper Signed-off-by: wanderer-dl122 --- .../distributedhardwarefwkserviceimpl/include/task/task_board.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h index 82adbe4d..1ab51de3 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h @@ -34,6 +34,7 @@ public: void AddTask(std::shared_ptr task); void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); + void DumpAllTasks(std::unordered_map> &tasks); private: -- Gitee From 3a8c288278511941380d0369c1e0bc5e54d75d7f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 18 May 2022 09:28:58 +0800 Subject: [PATCH 17/24] remove unused code Signed-off-by: zuojiangjiang --- .../include/resourcemanager/capability_info_manager.h | 2 -- .../src/resourcemanager/capability_info_manager.cpp | 4 ---- 2 files changed, 6 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h index bbbd9c26..8ee5083b 100644 --- a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h @@ -88,8 +88,6 @@ public: int32_t ManualSync(const std::string &networkId); /* Database data changes callback */ virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification) override; - virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification, - std::shared_ptr snapshot) override; /* EventBus async processing callback */ void OnEvent(CapabilityInfoEvent &e) override; diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index 7d6db2c0..2603e712 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -321,10 +321,6 @@ void CapabilityInfoManager::OnChange(const DistributedKv::ChangeNotification &ch } } -void CapabilityInfoManager::OnChange(const DistributedKv::ChangeNotification &changeNotification, - std::shared_ptr snapshot) -{} - void CapabilityInfoManager::OnEvent(CapabilityInfoEvent &ev) { switch (ev.GetAction()) { -- Gitee From 9ae690e28e065323d3668a3ce3eaa1ee6555fec6 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 20 May 2022 11:49:43 +0800 Subject: [PATCH 18/24] add dumper Signed-off-by: wanderer-dl122 --- .../src/distributed_hardware_service.cpp | 5 +- .../componentmanager/component_manager.h | 2 +- .../include/hidumphelper/enabled_comps_dump.h | 16 +++-- .../include/hidumphelper/hidump_helper.h | 2 +- .../resourcemanager/capability_info_manager.h | 2 +- .../include/task/task_board.h | 4 +- .../include/utils/impl_utils.h | 8 +++ .../componentmanager/component_manager.cpp | 10 ++-- .../src/hidumphelper/enabled_comps_dump.cpp | 20 +++---- .../src/hidumphelper/hidump_helper.cpp | 58 ++++++++++++------- .../capability_info_manager.cpp | 10 +++- .../src/task/task_board.cpp | 18 +++++- 12 files changed, 100 insertions(+), 55 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index d01506ec..a5acfbd9 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -86,12 +86,13 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map& args) { DHLOGI("DistributedHardwareService Dump."); - std::string result; - std::vector argsStr; + + std::vector argsStr {}; for (auto item : args) { argsStr.emplace_back(Str16ToStr8(item)); } + std::string result(""); int ret = AccessManager::GetInstance()->Dump(argsStr, result); if (ret != DH_FWK_SUCCESS) { DHLOGE("Dump error, ret = %d", ret); diff --git a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h index ac9a1ad9..8a592df8 100644 --- a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h index 699b059b..dc9371df 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022-2022 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 @@ -16,6 +16,7 @@ #ifndef OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_H #define OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_H #include +#include #include #include @@ -25,21 +26,25 @@ namespace OHOS { namespace DistributedHardware { struct HidumpCompInfo { + std::string deviceId_; std::string dhId_; DHType dhType_; + HidumpCompInfo(std::string deviceId, DHType dhType, std::string dhId) : + deviceId_(deviceId), dhId_(dhId), dhType_(dhType) {} + bool operator < (const HidumpCompInfo &other) const { - return (((this->dhType_ == other.dhType_) && (this->dhId_ < other.dhId_)) || - (this->dhType_ < other.dhType_)); + return (((this->deviceId_ == other.deviceId_) && (this->dhId_ < other.dhId_)) || + (this->deviceId_ < other.deviceId_)); } }; class EnabledCompsDump { DECLARE_SINGLE_INSTANCE_BASE(EnabledCompsDump); public: - void DumpEnabledComp(const DHType dhType, const std::string &dhId); - void DumpDisabledComp(const DHType dhType, const std::string &dhId); + void DumpEnabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId); + void DumpDisabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId); void Dump(std::set &compInfoSet); @@ -48,6 +53,7 @@ private: ~EnabledCompsDump() = default; private: + std::mutex compInfosMutex_; std::set compInfoSet_; }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index 7a162498..31049086 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -26,7 +26,7 @@ namespace OHOS { namespace DistributedHardware { enum class HidumpFlag { - UNKNOW = 0, + UNKNOWN = 0, GET_HELP, GET_LOADED_COMP_LIST, GET_ENABLED_COMP_LIST, diff --git a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h index daa640db..c5e384e3 100644 --- a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h @@ -93,7 +93,7 @@ public: /* EventBus async processing callback */ void OnEvent(CapabilityInfoEvent &e) override; - void DumpCapabilityInfos(CapabilityInfoMap &capInfoMap); + void DumpCapabilityInfos(std::vector &capInfos); private: CapabilityInfoManager(); diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h index 1ab51de3..46395512 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -35,7 +35,7 @@ public: void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); - void DumpAllTasks(std::unordered_map> &tasks); + void DumpAllTasks(std::vector &taskInfos); private: void RemoveTaskInner(std::string taskId); diff --git a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h index 4c7ab4c7..3dfc2a3d 100644 --- a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h @@ -67,6 +67,14 @@ struct TaskParam { std::string dhId; DHType dhType; }; + +struct TaskDump { + std::string id; + TaskType taskType; + TaskParam taskParm; + TaskState taskState; + std::vector taskSteps; +}; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index 94af15a5..e4335167 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -258,7 +258,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { DHLOGE("enable success, retryCount = %d", retryCount); - EnabledCompsDump::GetInstance().DumpEnabledComp(dhType, dhId); + EnabledCompsDump::GetInstance().DumpEnabledComp(uuid, dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("enable failed, retryCount = %d", retryCount); @@ -267,7 +267,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); - EnabledCompsDump::GetInstance().DumpEnabledComp(dhType, dhId); + EnabledCompsDump::GetInstance().DumpEnabledComp(uuid, dhType, dhId); return result; } @@ -289,7 +289,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { DHLOGE("disable success, retryCount = %d", retryCount); - EnabledCompsDump::GetInstance().DumpDisabledComp(dhType, dhId); + EnabledCompsDump::GetInstance().DumpDisabledComp(uuid, dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("disable failed, retryCount = %d", retryCount); @@ -298,7 +298,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); - EnabledCompsDump::GetInstance().DumpDisabledComp(dhType, dhId); + EnabledCompsDump::GetInstance().DumpDisabledComp(uuid, dhType, dhId); return result; } diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp index 0cf81805..931ff547 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp @@ -14,26 +14,25 @@ */ #include "enabled_comps_dump.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); -void EnabledCompsDump::DumpEnabledComp(const DHType dhType, const std::string &dhId) +void EnabledCompsDump::DumpEnabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId) { - HidumpCompInfo info = { - .dhId_ = dhId, - .dhType_ = dhType, - }; + HidumpCompInfo info (GetDeviceIdByUUID(uuid), dhType, dhId); + + std::lock_guard lock(compInfosMutex_); compInfoSet_.emplace(info); } -void EnabledCompsDump::DumpDisabledComp(const DHType dhType, const std::string &dhId) +void EnabledCompsDump::DumpDisabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId) { - HidumpCompInfo info = { - .dhId_ = dhId, - .dhType_ = dhType, - }; + HidumpCompInfo info (GetDeviceIdByUUID(uuid), dhType, dhId); + + std::lock_guard lock(compInfosMutex_); auto it = compInfoSet_.find(info); if (it != compInfoSet_.end()) { compInfoSet_.erase(it); @@ -42,6 +41,7 @@ void EnabledCompsDump::DumpDisabledComp(const DHType dhType, const std::string & void EnabledCompsDump::Dump(std::set &compInfoSet) { + std::lock_guard lock(compInfosMutex_); compInfoSet = compInfoSet_; } } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 523682f6..e2daaaf8 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -93,7 +93,7 @@ int32_t HidumpHelper::Dump(const std::vector& args, std::string &re auto flag = MAP_ARGS.find(args[0]); if ((args.size() > 1) || (flag == MAP_ARGS.end())) { - errCode = ProcessDump(HidumpFlag::UNKNOW, result); + errCode = ProcessDump(HidumpFlag::UNKNOWN, result); } else { errCode = ProcessDump(flag->second, result); } @@ -138,8 +138,8 @@ int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) { DHLOGI("Dump all loaded compTypes."); - std::set loadedCompSource; - std::set loadedCompSink; + std::set loadedCompSource {}; + std::set loadedCompSink {}; ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink); result.append("Local loaded components:\n{"); @@ -167,10 +167,14 @@ int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) { DHLOGI("Dump all enabled comps."); - std::set compInfoSet; + std::set compInfoSet {}; EnabledCompsDump::GetInstance().Dump(compInfoSet); result.append("All enabled components:"); + if (compInfoSet.empty()) { + return DH_FWK_SUCCESS; + } + for (auto info : compInfoSet) { result.append("\n{"); result.append("\n DHType : "); @@ -186,23 +190,29 @@ int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) { DHLOGI("Dump all task infos."); - std::unordered_map> tasks; - TaskBoard::GetInstance().DumpAllTasks(tasks); + std::vector taskInfos {}; + TaskBoard::GetInstance().DumpAllTasks(taskInfos); result.append("All task infos:"); - for (auto task : tasks) { + if (taskInfos.empty()) { + return DH_FWK_SUCCESS; + } + + for (auto taskInfo : taskInfos) { result.append("\n{"); + result.append("\n TaskId : "); + result.append(taskInfo.id); result.append("\n TaskType : "); - result.append(g_mapTaskType[task.second->GetTaskType()]); + result.append(g_mapTaskType[taskInfo.taskType]); result.append("\n DHType : "); - result.append(g_mapDhTypeName[task.second->GetDhType()]); + result.append(g_mapDhTypeName[taskInfo.taskParm.dhType]); result.append("\n DHId : "); - result.append(GetAnonyString(task.second->GetDhId())); + result.append(GetAnonyString(taskInfo.taskParm.dhId)); result.append("\n TaskState : "); - result.append(g_mapTaskState[task.second->GetTaskState()]); + result.append(g_mapTaskState[taskInfo.taskState]); result.append("\n TaskStep : [ "); - std::vector taskStep = task.second->GetTaskSteps(); - for (auto step : taskStep) { + std::vector taskSteps = taskInfo.taskSteps; + for (auto step : taskSteps) { result.append(g_mapTaskStep[step]); result.append(" "); } @@ -216,24 +226,28 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) { DHLOGI("Dump all capability infos."); - CapabilityInfoMap capInfoMap; - CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfoMap); + std::vector capInfos; + CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos); result.append("All capability infos:"); - for (auto info : capInfoMap) { + if (capInfos.empty()) { + return DH_FWK_SUCCESS; + } + + for (auto info : capInfos) { result.append("\n{"); result.append("\n DeviceName : "); - result.append(GetAnonyString(info.second->GetDeviceName())); + result.append(GetAnonyString(info.GetDeviceName())); result.append("\n DeviceId : "); - result.append(GetAnonyString(info.second->GetDeviceId())); + result.append(GetAnonyString(info.GetDeviceId())); result.append("\n DeviceType : "); - result.append(std::to_string(info.second->GetDeviceType())); + result.append(std::to_string(info.GetDeviceType())); result.append("\n DHType : "); - result.append(g_mapDhTypeName[info.second->GetDHType()]); + result.append(g_mapDhTypeName[info.GetDHType()]); result.append("\n DHId : "); - result.append(GetAnonyString(info.second->GetDHId())); + result.append(GetAnonyString(info.GetDHId())); result.append("\n DHAttrs :\n"); - result.append(info.second->GetDHAttrs()); + result.append(info.GetDHAttrs()); result.append("\n},"); } result.replace(result.size() - 1, 1, "\n"); diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index c5300983..65073144 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -536,9 +536,13 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, return DH_FWK_SUCCESS; } -void CapabilityInfoManager::DumpCapabilityInfos(CapabilityInfoMap &capInfoMap) +void CapabilityInfoManager::DumpCapabilityInfos(std::vector &capInfos) { - capInfoMap = globalCapInfoMap_; + for (auto info : globalCapInfoMap_) { + CapabilityInfo capInfo; + capInfo = *(info.second); + capInfos.emplace_back(capInfo); + } } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp index 230092cf..59b635b7 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -86,9 +86,21 @@ void TaskBoard::RemoveTaskInner(std::string taskId) tasks_.erase(taskId); } -void TaskBoard::DumpAllTasks(std::unordered_map> &tasks) +void TaskBoard::DumpAllTasks(std::vector &taskInfos) { - tasks = tasks_; + std::lock_guard lock(tasksMtx_); + for (auto t : tasks_) { + TaskDump taskInfo = { + .id = t.second->GetId(), + .taskType = t.second->GetTaskType(), + .taskParm.networkId = t.second->GetNetworkId(), + .taskParm.uuid = t.second->GetUUID(), + .taskParm.dhId = t.second->GetDhId(), + .taskParm.dhType = t.second->GetDhType(), + .taskSteps = t.second->GetTaskSteps() + }; + taskInfos.emplace_back(taskInfo); + } } } // namespace DistributedHardware } // namespace OHOS -- Gitee From 868d74977e76746085eb68c35068d5bce1fa195b Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 20 May 2022 12:28:06 +0800 Subject: [PATCH 19/24] add dumper Signed-off-by: wanderer-dl122 --- .../include/hidumphelper/enabled_comps_dump.h | 4 ++-- .../src/resourcemanager/capability_info_manager.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h index dc9371df..9094ece4 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -30,8 +30,8 @@ struct HidumpCompInfo { std::string dhId_; DHType dhType_; - HidumpCompInfo(std::string deviceId, DHType dhType, std::string dhId) : - deviceId_(deviceId), dhId_(dhId), dhType_(dhType) {} + HidumpCompInfo(std::string deviceId, DHType dhType, std::string dhId) + : deviceId_(deviceId), dhId_(dhId), dhType_(dhType) {} bool operator < (const HidumpCompInfo &other) const { diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index 65073144..50b518fd 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -539,8 +539,7 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, void CapabilityInfoManager::DumpCapabilityInfos(std::vector &capInfos) { for (auto info : globalCapInfoMap_) { - CapabilityInfo capInfo; - capInfo = *(info.second); + CapabilityInfo capInfo = *(info.second); capInfos.emplace_back(capInfo); } } -- Gitee From 7030ab958e04dfb6ee2494a77db12dfcc0bf41bc Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 20 May 2022 15:58:48 +0800 Subject: [PATCH 20/24] add dumper Signed-off-by: wanderer-dl122 --- .../src/hidumphelper/hidump_helper.cpp | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index e2daaaf8..c1e7cdfa 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -144,21 +144,25 @@ int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) result.append("Local loaded components:\n{"); result.append("\n Source : ["); - for (auto compSource : loadedCompSource) { - result.append(" "); - result.append(g_mapDhTypeName[compSource]); - result.append(","); + if (!loadedCompSource.empty()) { + for (auto compSource : loadedCompSource) { + result.append(" "); + result.append(g_mapDhTypeName[compSource]); + result.append(","); + } + result.replace(result.size() - 1, 1, " "); } - result.replace(result.size() - 1, 1, " "); result.append("]"); result.append("\n Sink : ["); - for (auto compSink : loadedCompSink) { - result.append(" "); - result.append(g_mapDhTypeName[compSink]); - result.append(","); + if (!loadedCompSource.empty()) { + for (auto compSink : loadedCompSink) { + result.append(" "); + result.append(g_mapDhTypeName[compSink]); + result.append(","); + } + result.replace(result.size() - 1, 1, " "); } - result.replace(result.size() - 1, 1, " "); result.append("]"); result.append("\n}\n"); return DH_FWK_SUCCESS; @@ -177,6 +181,8 @@ int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) for (auto info : compInfoSet) { result.append("\n{"); + result.append("\n DeviceId : "); + result.append(GetAnonyString(info.deviceId_)); result.append("\n DHType : "); result.append(g_mapDhTypeName[info.dhType_]); result.append("\n DHId : "); @@ -200,7 +206,7 @@ int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) for (auto taskInfo : taskInfos) { result.append("\n{"); - result.append("\n TaskId : "); + result.append("\n TaskId : "); result.append(taskInfo.id); result.append("\n TaskType : "); result.append(g_mapTaskType[taskInfo.taskType]); @@ -229,7 +235,7 @@ int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) std::vector capInfos; CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos); - result.append("All capability infos:"); + result.append("All capability info of online components :"); if (capInfos.empty()) { return DH_FWK_SUCCESS; } @@ -267,7 +273,7 @@ int32_t HidumpHelper::ShowHelp(std::string &result) result.append(" -t "); result.append(": Show all tasks\n"); result.append(" -c "); - result.append(": Show all capability infos\n\n"); + result.append(": Show all Capability info of online components\n\n"); return DH_FWK_SUCCESS; } -- Gitee From 3b6cdbd84cdb14de7e914d49fbd95ffd88628ba4 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 20 May 2022 16:47:39 +0800 Subject: [PATCH 21/24] add dumper Signed-off-by: wanderer-dl122 --- common/utils/include/distributed_hardware_errno.h | 2 +- .../include/accessmanager/access_manager.h | 2 +- .../include/distributed_hardware_manager_factory.h | 2 +- .../include/distributed_hardware_service.h | 2 +- .../src/distributed_hardware_manager_factory.cpp | 2 +- .../src/distributed_hardware_service.cpp | 2 +- services/distributedhardwarefwkserviceimpl/BUILD.gn | 2 +- .../include/distributed_hardware_manager.h | 2 +- .../include/hidumphelper/enabled_comps_dump.h | 2 +- .../include/hidumphelper/hidump_helper.h | 2 +- .../include/resourcemanager/capability_info_manager.h | 2 +- .../include/utils/impl_utils.h | 2 +- .../src/componentloader/component_loader.cpp | 2 +- .../src/distributed_hardware_manager.cpp | 2 +- .../src/hidumphelper/enabled_comps_dump.cpp | 2 +- .../src/hidumphelper/hidump_helper.cpp | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 7e71cf69..96a88bfe 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h index 9e30b5fa..48f18c22 100644 --- a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h +++ b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index fd0271b8..fe37f6a1 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index 4b20930c..21c671f5 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 534122a7..7f801b21 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index a5acfbd9..6c130aa7 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/BUILD.gn b/services/distributedhardwarefwkserviceimpl/BUILD.gn index 550fad7e..6e3b3a20 100644 --- a/services/distributedhardwarefwkserviceimpl/BUILD.gn +++ b/services/distributedhardwarefwkserviceimpl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h index e7ea10f9..a94c3e00 100644 --- a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h index 9094ece4..d99cd0f2 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h index 31049086..a89a5952 100644 --- a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h index c5e384e3..5806980a 100644 --- a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h index 3dfc2a3d..992cc601 100644 --- a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp index 39567703..86a00f59 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp index e9862ca4..17359412 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp index 931ff547..feeb4fe5 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index c1e7cdfa..0a6819a6 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 -- Gitee From 77f40c2165428197301e1602f99f2ffd0c35911d Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 20 May 2022 16:55:28 +0800 Subject: [PATCH 22/24] add dumper Signed-off-by: wanderer-dl122 --- common/utils/include/idistributed_hardware_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index 1f7bd43f..46dcd6ad 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 -- Gitee From 67c17e67177723697409fe3f27d7cd7e95f9f44d Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 20 May 2022 16:58:56 +0800 Subject: [PATCH 23/24] add dumper Signed-off-by: wanderer-dl122 --- .../src/hidumphelper/hidump_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp index 0a6819a6..03ab7272 100644 --- a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -155,7 +155,7 @@ int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) result.append("]"); result.append("\n Sink : ["); - if (!loadedCompSource.empty()) { + if (!loadedCompSink.empty()) { for (auto compSink : loadedCompSink) { result.append(" "); result.append(g_mapDhTypeName[compSink]); -- Gitee From f3b0ee6e97733098e983041abf80a9de11ce4c78 Mon Sep 17 00:00:00 2001 From: zhangpengpeng Date: Tue, 24 May 2022 10:24:44 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E7=8B=AC=E7=AB=8Buid=E5=8F=8A=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangpengpeng --- sa_profile/dhardware.cfg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sa_profile/dhardware.cfg b/sa_profile/dhardware.cfg index 0efd2864..0bd3bf15 100644 --- a/sa_profile/dhardware.cfg +++ b/sa_profile/dhardware.cfg @@ -2,8 +2,9 @@ "services" : [{ "name" : "dhardware", "path" : ["/system/bin/sa_main", "/system/profile/dhardware.xml"], - "uid" : "root", - "gid" : ["system", "uhid", "root"], + "uid" : "dhardware", + "gid" : ["dhardware"], + "caps" : ["DAC_READ_SEARCH", "DAC_OVERRIDE"], "ondemand" : true }] } \ No newline at end of file -- Gitee