mirror of
https://github.com/openharmony/distributed_hardware_fwk.git
synced 2026-07-19 21:53:41 -04:00
@@ -86,12 +86,13 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map<DHType,
|
||||
int DistributedHardwareService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DistributedHardwareService Dump.");
|
||||
std::string result;
|
||||
std::vector<std::string> argsStr;
|
||||
|
||||
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);
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+11
-5
@@ -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 <cstdint>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
@@ -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<HidumpCompInfo> &compInfoSet);
|
||||
|
||||
@@ -48,6 +53,7 @@ private:
|
||||
~EnabledCompsDump() = default;
|
||||
|
||||
private:
|
||||
std::mutex compInfosMutex_;
|
||||
std::set<HidumpCompInfo> compInfoSet_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ public:
|
||||
/* EventBus async processing callback */
|
||||
void OnEvent(CapabilityInfoEvent &e) override;
|
||||
|
||||
void DumpCapabilityInfos(CapabilityInfoMap &capInfoMap);
|
||||
void DumpCapabilityInfos(std::vector<CapabilityInfo> &capInfos);
|
||||
|
||||
private:
|
||||
CapabilityInfoManager();
|
||||
|
||||
@@ -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<std::string, std::shared_ptr<Task>> &tasks);
|
||||
void DumpAllTasks(std::vector<TaskDump> &taskInfos);
|
||||
|
||||
private:
|
||||
void RemoveTaskInner(std::string taskId);
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -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<std::mutex> 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<std::mutex> 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<HidumpCompInfo> &compInfoSet)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(compInfosMutex_);
|
||||
compInfoSet = compInfoSet_;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -93,7 +93,7 @@ int32_t HidumpHelper::Dump(const std::vector<std::string>& 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<DHType> loadedCompSource;
|
||||
std::set<DHType> loadedCompSink;
|
||||
std::set<DHType> loadedCompSource {};
|
||||
std::set<DHType> 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<HidumpCompInfo> compInfoSet;
|
||||
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 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<std::string, std::shared_ptr<Task>> tasks;
|
||||
TaskBoard::GetInstance().DumpAllTasks(tasks);
|
||||
std::vector<TaskDump> 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> taskStep = task.second->GetTaskSteps();
|
||||
for (auto step : taskStep) {
|
||||
std::vector<TaskStep> 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<CapabilityInfo> 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");
|
||||
|
||||
+7
-3
@@ -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<CapabilityInfo> &capInfos)
|
||||
{
|
||||
capInfoMap = globalCapInfoMap_;
|
||||
for (auto info : globalCapInfoMap_) {
|
||||
CapabilityInfo capInfo;
|
||||
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
|
||||
@@ -86,9 +86,21 @@ void TaskBoard::RemoveTaskInner(std::string taskId)
|
||||
tasks_.erase(taskId);
|
||||
}
|
||||
|
||||
void TaskBoard::DumpAllTasks(std::unordered_map<std::string, std::shared_ptr<Task>> &tasks)
|
||||
void TaskBoard::DumpAllTasks(std::vector<TaskDump> &taskInfos)
|
||||
{
|
||||
tasks = tasks_;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user