mirror of
https://github.com/openharmony/distributed_hardware_fwk.git
synced 2026-07-01 20:24:00 -04:00
@@ -118,7 +118,7 @@ void AccessManager::OnDeviceOnline(const DmDeviceInfo &deviceInfo)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(accessMutex_);
|
||||
DHLOGI("start, networkId = %s, deviceName = %s, deviceTypeId = %d", GetAnonyString(deviceInfo.deviceId).c_str(),
|
||||
deviceInfo.deviceName, deviceInfo.deviceTypeId);
|
||||
GetAnonyString(deviceInfo.deviceName).c_str(), deviceInfo.deviceTypeId);
|
||||
|
||||
auto networkId = std::string(deviceInfo.deviceId); // deviceId of DM actually is networkId
|
||||
auto uuid = GetUUIDBySoftBus(networkId);
|
||||
@@ -132,7 +132,7 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(accessMutex_);
|
||||
DHLOGI("start, networkId = %s, deviceName = %s, deviceTypeId = %d", GetAnonyString(deviceInfo.deviceId).c_str(),
|
||||
deviceInfo.deviceName, deviceInfo.deviceTypeId);
|
||||
GetAnonyString(deviceInfo.deviceName).c_str(), deviceInfo.deviceTypeId);
|
||||
|
||||
auto networkId = std::string(deviceInfo.deviceId); // deviceId of DM actually is networkId
|
||||
auto uuid = GetUUIDBySoftBus(networkId);
|
||||
|
||||
+8
-6
@@ -32,16 +32,17 @@ ComponentDisable::~ComponentDisable() {}
|
||||
int32_t ComponentDisable::Disable(const std::string &networkId, const std::string &dhId,
|
||||
IDistributedHardwareSource *handler)
|
||||
{
|
||||
DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str());
|
||||
DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str());
|
||||
if (handler == nullptr) {
|
||||
DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str());
|
||||
DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_PARA_INVALID;
|
||||
}
|
||||
|
||||
auto ret = handler->UnregisterDistributedHardware(networkId, dhId, shared_from_this());
|
||||
if (ret != DH_FWK_SUCCESS) {
|
||||
DHLOGE("UnregisterDistributedHardware failed, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(),
|
||||
dhId.c_str());
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_COMPONENT_UNREGISTER_FAILED;
|
||||
}
|
||||
|
||||
@@ -50,7 +51,8 @@ int32_t ComponentDisable::Disable(const std::string &networkId, const std::strin
|
||||
auto waitStatus = conVar_.wait_for(lock, std::chrono::milliseconds(DISABLE_TIMEOUT_MS),
|
||||
[this]() { return status_ != std::numeric_limits<int32_t>::max(); });
|
||||
if (!waitStatus) {
|
||||
DHLOGE("disable timeout, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str());
|
||||
DHLOGE("disable timeout, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT;
|
||||
}
|
||||
return (status_ == DH_FWK_SUCCESS) ? DH_FWK_SUCCESS : ERR_DH_FWK_COMPONENT_DISABLE_FAILED;
|
||||
@@ -61,10 +63,10 @@ int32_t ComponentDisable::OnUnregisterResult(const std::string &networkId, const
|
||||
{
|
||||
if (status == DH_FWK_SUCCESS) {
|
||||
DHLOGI("disable success, networkId = %s, dhId = %s, data = %s.", GetAnonyString(networkId).c_str(),
|
||||
dhId.c_str(), data.c_str());
|
||||
GetAnonyString(dhId).c_str(), data.c_str());
|
||||
} else {
|
||||
DHLOGE("disable failed, networkId = %s, dhId = %s, status = %d, data = %s.", GetAnonyString(networkId).c_str(),
|
||||
dhId.c_str(), status, data.c_str());
|
||||
GetAnonyString(dhId).c_str(), status, data.c_str());
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
+8
-6
@@ -32,16 +32,17 @@ ComponentEnable::~ComponentEnable() {}
|
||||
int32_t ComponentEnable::Enable(const std::string &networkId, const std::string &dhId, const EnableParam ¶m,
|
||||
IDistributedHardwareSource *handler)
|
||||
{
|
||||
DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str());
|
||||
DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str());
|
||||
if (handler == nullptr) {
|
||||
DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str());
|
||||
DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_PARA_INVALID;
|
||||
}
|
||||
|
||||
auto ret = handler->RegisterDistributedHardware(networkId, dhId, param, shared_from_this());
|
||||
if (ret != DH_FWK_SUCCESS) {
|
||||
DHLOGE("RegisterDistributedHardware failed, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(),
|
||||
dhId.c_str());
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_COMPONENT_REGISTER_FAILED;
|
||||
}
|
||||
|
||||
@@ -50,7 +51,8 @@ int32_t ComponentEnable::Enable(const std::string &networkId, const std::string
|
||||
auto waitStatus = conVar_.wait_for(lock, std::chrono::milliseconds(ENABLE_TIMEOUT_MS),
|
||||
[this]() { return status_ != std::numeric_limits<int32_t>::max(); });
|
||||
if (!waitStatus) {
|
||||
DHLOGE("enable timeout, networkId = %s dhId = %s", GetAnonyString(networkId).c_str(), dhId.c_str());
|
||||
DHLOGE("enable timeout, networkId = %s dhId = %s", GetAnonyString(networkId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT;
|
||||
}
|
||||
return (status_ == DH_FWK_SUCCESS) ? DH_FWK_SUCCESS : ERR_DH_FWK_COMPONENT_ENABLE_FAILED;
|
||||
@@ -61,10 +63,10 @@ int32_t ComponentEnable::OnRegisterResult(const std::string &networkId, const st
|
||||
{
|
||||
if (status == DH_FWK_SUCCESS) {
|
||||
DHLOGI("enable success, networkId = %s, dhId = %s, data = %s.", GetAnonyString(networkId).c_str(),
|
||||
dhId.c_str(), data.c_str());
|
||||
GetAnonyString(dhId).c_str(), data.c_str());
|
||||
} else {
|
||||
DHLOGE("enable failed, networkId = %s, dhId = %s, status = %d, data = %s.", GetAnonyString(networkId).c_str(),
|
||||
dhId.c_str(), status, data.c_str());
|
||||
GetAnonyString(dhId).c_str(), status, data.c_str());
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
+14
-10
@@ -225,14 +225,14 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string
|
||||
DHLOGI("start.");
|
||||
auto find = compSource_.find(dhType);
|
||||
if (find == compSource_.end()) {
|
||||
DHLOGE("can not find handler for dhId = %s.", dhId.c_str());
|
||||
DHLOGE("can not find handler for dhId = %s.", GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_PARA_INVALID;
|
||||
}
|
||||
EnableParam param;
|
||||
auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param);
|
||||
if (ret != DH_FWK_SUCCESS) {
|
||||
DHLOGE("GetEnableParam failed, uuid = %s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(),
|
||||
dhId.c_str(), ret);
|
||||
GetAnonyString(dhId).c_str(), ret);
|
||||
for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) {
|
||||
if (!DHContext::GetInstance().IsDeviceOnline(uuid)) {
|
||||
DHLOGE("device is already offline, no need try GetEnableParam, uuid = %s",
|
||||
@@ -263,7 +263,8 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string
|
||||
}
|
||||
return result;
|
||||
}
|
||||
DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), dhId.c_str());
|
||||
DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -291,7 +292,8 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin
|
||||
}
|
||||
return result;
|
||||
}
|
||||
DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), dhId.c_str());
|
||||
DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -302,7 +304,8 @@ DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &d
|
||||
if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) {
|
||||
return capability->GetDHType();
|
||||
}
|
||||
DHLOGE("get dhType failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), dhId.c_str());
|
||||
DHLOGE("get dhType failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return DHType::UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -312,20 +315,21 @@ int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std
|
||||
std::shared_ptr<CapabilityInfo> capability = nullptr;
|
||||
auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability);
|
||||
if ((ret != DH_FWK_SUCCESS) || (capability == nullptr)) {
|
||||
DHLOGE("GetCapability failed, uuid =%s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), dhId.c_str(),
|
||||
ret);
|
||||
DHLOGE("GetCapability failed, uuid =%s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(),
|
||||
GetAnonyString(dhId).c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
param.attrs = capability->GetDHAttrs();
|
||||
param.version = GetSinkVersion(networkId, uuid, dhType);
|
||||
if (param.version.empty()) {
|
||||
DHLOGI("Get Sink Version failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), dhId.c_str());
|
||||
DHLOGI("Get Sink Version failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED;
|
||||
}
|
||||
|
||||
DHLOGI("success. uuid =%s, dhId = %s, version = %s", GetAnonyString(uuid).c_str(), dhId.c_str(),
|
||||
param.version.c_str());
|
||||
DHLOGI("success. uuid =%s, dhId = %s, version = %s", GetAnonyString(uuid).c_str(),
|
||||
GetAnonyString(dhId).c_str(), param.version.c_str());
|
||||
|
||||
return DH_FWK_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ void DisableTask::DoTask()
|
||||
|
||||
void DisableTask::DoTaskInner()
|
||||
{
|
||||
DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str());
|
||||
DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(),
|
||||
GetAnonyString(GetDhId()).c_str());
|
||||
SetTaskState(TaskState::RUNNING);
|
||||
|
||||
/* trigger Unregister Distributed Hardware Task, sync function */
|
||||
@@ -69,7 +70,7 @@ int32_t DisableTask::UnRegisterHardware()
|
||||
{
|
||||
auto result = ComponentManager::GetInstance().Disable(GetNetworkId(), GetUUID(), GetDhId(), GetDhType());
|
||||
DHLOGI("disable task %s, id = %s, uuid = %s, dhId = %s", (result == DH_FWK_SUCCESS) ? "success" : "failed",
|
||||
GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str());
|
||||
GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetDhId()).c_str());
|
||||
return result;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -46,7 +46,8 @@ void EnableTask::DoTask()
|
||||
|
||||
void EnableTask::DoTaskInner()
|
||||
{
|
||||
DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str());
|
||||
DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(),
|
||||
GetAnonyString(GetDhId()).c_str());
|
||||
SetTaskState(TaskState::RUNNING);
|
||||
auto result = RegisterHardware();
|
||||
auto state = (result == DH_FWK_SUCCESS) ? TaskState::SUCCESS : TaskState::FAIL;
|
||||
@@ -59,7 +60,7 @@ int32_t EnableTask::RegisterHardware()
|
||||
{
|
||||
auto result = ComponentManager::GetInstance().Enable(GetNetworkId(), GetUUID(), GetDhId(), GetDhType());
|
||||
DHLOGI("enable task %s, id = %s, uuid = %s, dhId = %s", (result == DH_FWK_SUCCESS) ? "success" : "failed",
|
||||
GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str());
|
||||
GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetDhId()).c_str());
|
||||
return result;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -31,8 +31,9 @@ namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(TaskFactory);
|
||||
std::shared_ptr<Task> TaskFactory::CreateTask(TaskType taskType, TaskParam taskParam, std::shared_ptr<Task> fatherTask)
|
||||
{
|
||||
DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s", static_cast<int32_t>(taskType),
|
||||
GetAnonyString(taskParam.networkId).c_str(), GetAnonyString(taskParam.uuid).c_str(), taskParam.dhId.c_str());
|
||||
DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s",
|
||||
static_cast<int32_t>(taskType), GetAnonyString(taskParam.networkId).c_str(),
|
||||
GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.dhId).c_str());
|
||||
std::shared_ptr<Task> task = nullptr;
|
||||
switch (taskType) {
|
||||
case TaskType::ENABLE: {
|
||||
|
||||
Reference in New Issue
Block a user