!80 框架添加hidumper打印信息

Merge pull request !80 from dengliang/master
This commit is contained in:
openharmony_ci
2022-05-20 09:39:31 +00:00
committed by Gitee
23 changed files with 587 additions and 18 deletions
@@ -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
@@ -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_DPRINTF_ERROR = -11002;
} // namespace DistributedHardware
} // namespace OHOS
#endif
@@ -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
@@ -34,6 +34,7 @@ public:
uint16_t deviceType) = 0;
virtual size_t GetOnLineCount() = 0;
virtual int32_t GetComponentVersion(std::unordered_map<DHType, std::string> &versionMap) = 0;
virtual int32_t Dump(const std::vector<std::string> &argsStr, std::string &result) = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -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
@@ -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<std::string> &argsStr, std::string &result);
private:
AccessManager() = default;
int32_t RegisterDevStateCallback();
@@ -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
@@ -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<DHType, std::string> &versionMap);
int Dump(const std::vector<std::string> &argsStr, std::string &result);
private:
bool Init();
void UnInit();
@@ -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,6 +35,7 @@ public:
DistributedHardwareService(int32_t saId, bool runOnCreate);
~DistributedHardwareService() = default;
int32_t QuerySinkVersion(std::unordered_map<DHType, std::string> &versionMap) override;
int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
protected:
void OnStart() override;
@@ -166,5 +166,10 @@ void AccessManager::SendTrustedDeviceOnline()
DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, deviceInfo.deviceTypeId);
}
}
int32_t AccessManager::Dump(const std::vector<std::string> &argsStr, std::string &result)
{
return DistributedHardwareManagerFactory::GetInstance().Dump(argsStr, result);
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -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
@@ -205,5 +205,14 @@ int32_t DistributedHardwareManagerFactory::GetComponentVersion(std::unordered_ma
}
return distributedHardwareMgrPtr_->GetComponentVersion(versionMap);
}
int32_t DistributedHardwareManagerFactory::Dump(const std::vector<std::string> &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
@@ -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
@@ -82,5 +82,28 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map<DHType,
(void)versionMap;
return 0;
}
int DistributedHardwareService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
DHLOGI("DistributedHardwareService Dump.");
std::vector<std::string> 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);
}
if (dprintf(fd, "%s\n", result.c_str()) < 0) {
DHLOGE("Hidump dprintf error");
ret = ERR_DH_FWK_HIDUMP_DPRINTF_ERROR;
}
return ret;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -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
@@ -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",
@@ -43,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",
@@ -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
@@ -17,6 +17,7 @@
#define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MANAGER_H
#include <map>
#include <set>
#include <unordered_map>
#include <mutex>
#include <future>
@@ -44,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<DHType> &compSourceType, std::set<DHType> &compSinkType);
private:
enum class Action : int32_t {
START_SOURCE,
@@ -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
@@ -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<DHType, std::string> &versionMap) override;
int32_t Dump(const std::vector<std::string> &argsStr, std::string &result) override;
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,61 @@
/*
* 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
*
* 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_ENABLED_COMPS_DUMP_H
#define OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_H
#include <cstdint>
#include <mutex>
#include <set>
#include <string>
#include "device_type.h"
#include "single_instance.h"
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->deviceId_ == other.deviceId_) && (this->dhId_ < other.dhId_)) ||
(this->deviceId_ < other.deviceId_));
}
};
class EnabledCompsDump {
DECLARE_SINGLE_INSTANCE_BASE(EnabledCompsDump);
public:
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<HidumpCompInfo> &compInfoSet);
private:
explicit EnabledCompsDump() = default;
~EnabledCompsDump() = default;
private:
std::mutex compInfosMutex_;
std::set<HidumpCompInfo> compInfoSet_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif
@@ -0,0 +1,56 @@
/*
* 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
*
* 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 <cstdint>
#include <set>
#include <string>
#include "enabled_comps_dump.h"
#include "device_type.h"
#include "single_instance.h"
namespace OHOS {
namespace DistributedHardware {
enum class HidumpFlag {
UNKNOWN = 0,
GET_HELP,
GET_LOADED_COMP_LIST,
GET_ENABLED_COMP_LIST,
GET_TASK_LIST,
GET_CAPABILITY_LIST,
};
class HidumpHelper {
DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper);
public:
int32_t Dump(const std::vector<std::string>& args, std::string &result);
private:
explicit HidumpHelper() = default;
~HidumpHelper() = default;
int32_t ProcessDump(const HidumpFlag &flag, 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
} // namespace OHOS
#endif
@@ -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
@@ -91,6 +91,8 @@ public:
/* EventBus async processing callback */
void OnEvent(CapabilityInfoEvent &e) override;
void DumpCapabilityInfos(std::vector<CapabilityInfo> &capInfos);
private:
CapabilityInfoManager();
void HandleCapabilityAddChange(const std::vector<DistributedKv::Entry> &insertRecords);
@@ -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,6 +35,8 @@ public:
void RemoveTask(std::string taskId);
int32_t WaitForALLTaskFinish();
void DumpAllTasks(std::vector<TaskDump> &taskInfos);
private:
void RemoveTaskInner(std::string taskId);
@@ -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
@@ -67,6 +67,14 @@ struct TaskParam {
std::string dhId;
DHType dhType;
};
struct TaskDump {
std::string id;
TaskType taskType;
TaskParam taskParm;
TaskState taskState;
std::vector<TaskStep> taskSteps;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif
@@ -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
@@ -23,6 +23,7 @@
#include "constants.h"
#include "distributed_hardware_log.h"
#include "hidump_helper.h"
using nlohmann::json;
@@ -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
@@ -28,6 +28,7 @@
#include "dh_utils_tool.h"
#include "distributed_hardware_errno.h"
#include "distributed_hardware_log.h"
#include "enabled_comps_dump.h"
#include "ipc_object_stub.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
@@ -257,6 +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(uuid, dhType, dhId);
return DH_FWK_SUCCESS;
}
DHLOGE("enable failed, retryCount = %d", retryCount);
@@ -265,6 +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(uuid, dhType, dhId);
return result;
}
@@ -286,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);
EnabledCompsDump::GetInstance().DumpDisabledComp(uuid, dhType, dhId);
return DH_FWK_SUCCESS;
}
DHLOGE("disable failed, retryCount = %d", retryCount);
@@ -294,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());
EnabledCompsDump::GetInstance().DumpDisabledComp(uuid, dhType, dhId);
return result;
}
@@ -412,5 +417,15 @@ sptr<IDistributedHardware> ComponentManager::GetRemoteDHMS(const std::string &ne
}
return iface_cast<IDistributedHardware>(object);
}
void ComponentManager::DumpLoadedComps(std::set<DHType> &compSourceType, std::set<DHType> &compSinkType)
{
for (auto compSource : compSource_) {
compSourceType.emplace(compSource.first);
}
for (auto compSink : compSink_) {
compSinkType.emplace(compSink.first);
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -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
@@ -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"
@@ -176,5 +177,10 @@ int32_t DistributedHardwareManager::GetComponentVersion(std::unordered_map<DHTyp
}
return DH_FWK_SUCCESS;
}
int32_t DistributedHardwareManager::Dump(const std::vector<std::string> &argsStr, std::string &result)
{
return HidumpHelper::GetInstance().Dump(argsStr, result);
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,48 @@
/*
* 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
*
* 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"
#include "dh_utils_tool.h"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump);
void EnabledCompsDump::DumpEnabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId)
{
HidumpCompInfo info (GetDeviceIdByUUID(uuid), dhType, dhId);
std::lock_guard<std::mutex> lock(compInfosMutex_);
compInfoSet_.emplace(info);
}
void EnabledCompsDump::DumpDisabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId)
{
HidumpCompInfo info (GetDeviceIdByUUID(uuid), dhType, dhId);
std::lock_guard<std::mutex> lock(compInfosMutex_);
auto it = compInfoSet_.find(info);
if (it != compInfoSet_.end()) {
compInfoSet_.erase(it);
}
}
void EnabledCompsDump::Dump(std::set<HidumpCompInfo> &compInfoSet)
{
std::lock_guard<std::mutex> lock(compInfosMutex_);
compInfoSet = compInfoSet_;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,289 @@
/*
* 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
*
* 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 "hidump_helper.h"
#include <unordered_map>
#include "capability_info_manager.h"
#include "component_manager.h"
#include "distributed_hardware_errno.h"
#include "distributed_hardware_log.h"
#include "task_board.h"
namespace OHOS {
namespace DistributedHardware {
IMPLEMENT_SINGLE_INSTANCE(HidumpHelper);
namespace {
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";
const std::unordered_map<std::string, HidumpFlag> MAP_ARGS = {
{ 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<DHType, std::string> g_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" },
};
std::unordered_map<TaskType, std::string> g_mapTaskType = {
{ TaskType::UNKNOWN, "UNKNOWN" },
{ TaskType::ENABLE, "ENABLE" },
{ TaskType::DISABLE, "DISABLE" },
{ TaskType::ON_LINE, "ON_LINE" },
{ TaskType::OFF_LINE, "OFF_LINE" },
};
std::unordered_map<TaskStep, std::string> 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_COMPLETE, "WAIT_UNREGISTGER_COMPLETE" },
};
std::unordered_map<TaskState, std::string> g_mapTaskState = {
{ TaskState::INIT, "INIT" },
{ TaskState::RUNNING, "RUNNING" },
{ TaskState::SUCCESS, "SUCCESS" },
{ TaskState::FAIL, "FAIL" },
};
}
int32_t HidumpHelper::Dump(const std::vector<std::string>& args, std::string &result)
{
DHLOGI("HidumpHelper dump start.");
result.clear();
int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR;
if (args.empty()) {
return ProcessDump(HidumpFlag::GET_HELP, result);
}
auto flag = MAP_ARGS.find(args[0]);
if ((args.size() > 1) || (flag == MAP_ARGS.end())) {
errCode = ProcessDump(HidumpFlag::UNKNOWN, result);
} else {
errCode = ProcessDump(flag->second, result);
}
return errCode;
}
int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result)
{
DHLOGI("Process Dump.");
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 = 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: {
errCode = ShowIllealInfomation(result);
break;
}
}
return errCode;
}
int32_t HidumpHelper::ShowAllLoadedComps(std::string &result)
{
DHLOGI("Dump all loaded compTypes.");
std::set<DHType> loadedCompSource {};
std::set<DHType> loadedCompSink {};
ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink);
result.append("Local loaded components:\n{");
result.append("\n Source : [");
if (!loadedCompSource.empty()) {
for (auto compSource : loadedCompSource) {
result.append(" ");
result.append(g_mapDhTypeName[compSource]);
result.append(",");
}
result.replace(result.size() - 1, 1, " ");
}
result.append("]");
result.append("\n Sink : [");
if (!loadedCompSink.empty()) {
for (auto compSink : loadedCompSink) {
result.append(" ");
result.append(g_mapDhTypeName[compSink]);
result.append(",");
}
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 all enabled comps.");
std::set<HidumpCompInfo> 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 DeviceId : ");
result.append(GetAnonyString(info.deviceId_));
result.append("\n DHType : ");
result.append(g_mapDhTypeName[info.dhType_]);
result.append("\n DHId : ");
result.append(GetAnonyString(info.dhId_));
result.append("\n},");
}
result.replace(result.size() - 1, 1, "\n");
return DH_FWK_SUCCESS;
}
int32_t HidumpHelper::ShowAllTaskInfos(std::string &result)
{
DHLOGI("Dump all task infos.");
std::vector<TaskDump> taskInfos {};
TaskBoard::GetInstance().DumpAllTasks(taskInfos);
result.append("All task infos:");
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[taskInfo.taskType]);
result.append("\n DHType : ");
result.append(g_mapDhTypeName[taskInfo.taskParm.dhType]);
result.append("\n DHId : ");
result.append(GetAnonyString(taskInfo.taskParm.dhId));
result.append("\n TaskState : ");
result.append(g_mapTaskState[taskInfo.taskState]);
result.append("\n TaskStep : [ ");
std::vector<TaskStep> taskSteps = taskInfo.taskSteps;
for (auto step : taskSteps) {
result.append(g_mapTaskStep[step]);
result.append(" ");
}
result.append("]\n");
result.append("},");
}
result.replace(result.size() - 1, 1, "\n");
return DH_FWK_SUCCESS;
}
int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result)
{
DHLOGI("Dump all capability infos.");
std::vector<CapabilityInfo> capInfos;
CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos);
result.append("All capability info of online components :");
if (capInfos.empty()) {
return DH_FWK_SUCCESS;
}
for (auto info : capInfos) {
result.append("\n{");
result.append("\n DeviceName : ");
result.append(GetAnonyString(info.GetDeviceName()));
result.append("\n DeviceId : ");
result.append(GetAnonyString(info.GetDeviceId()));
result.append("\n DeviceType : ");
result.append(std::to_string(info.GetDeviceType()));
result.append("\n DHType : ");
result.append(g_mapDhTypeName[info.GetDHType()]);
result.append("\n DHId : ");
result.append(GetAnonyString(info.GetDHId()));
result.append("\n DHAttrs :\n");
result.append(info.GetDHAttrs());
result.append("\n},");
}
result.replace(result.size() - 1, 1, "\n");
return DH_FWK_SUCCESS;
}
int32_t HidumpHelper::ShowHelp(std::string &result)
{
DHLOGI("Show dump help.");
result.append("DistributedHardwareFramework dump options:\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 tasks\n");
result.append(" -c ");
result.append(": Show all Capability info of online components\n\n");
return DH_FWK_SUCCESS;
}
int32_t HidumpHelper::ShowIllealInfomation(std::string &result)
{
DHLOGI("ShowIllealInfomation Dump.");
result.clear();
result.append("Unrecognized option, -h for help.");
return ERR_DH_FWK_HIDUMP_INVALID_ARGS;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -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
@@ -531,5 +531,13 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix,
}
return DH_FWK_SUCCESS;
}
void CapabilityInfoManager::DumpCapabilityInfos(std::vector<CapabilityInfo> &capInfos)
{
for (auto info : globalCapInfoMap_) {
CapabilityInfo capInfo = *(info.second);
capInfos.emplace_back(capInfo);
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -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
@@ -85,5 +85,22 @@ void TaskBoard::RemoveTaskInner(std::string taskId)
tasks_.erase(taskId);
}
void TaskBoard::DumpAllTasks(std::vector<TaskDump> &taskInfos)
{
std::lock_guard<std::mutex> 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