From acbb6ddb5c4c963adcbef28222ccbf78e072b06c Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Thu, 28 Apr 2022 11:10:39 +0800 Subject: [PATCH] =?UTF-8?q?DM=E4=B8=8A=E7=BA=BF=E5=8A=A8=E6=80=81=E6=8B=89?= =?UTF-8?q?=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F=E6=A1=86=E6=9E=B6SA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- common/include/dm_constants.h | 1 + .../devicestate/dm_device_state_manager.cpp | 1 - .../lite/dm_distributed_hardware_load.h | 4 +- .../standard/dm_distributed_hardware_load.h | 4 +- .../lite/dm_distributed_hardware_load.cpp | 2 +- .../standard/dm_distributed_hardware_load.cpp | 51 ++++++++++--------- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index db66982b..c4aaf136 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -41,6 +41,7 @@ const int32_t MIN_PIN_CODE = 100000; const int32_t MAX_PIN_CODE = 999999; const int32_t DISCOVER_STATUS_LEN = 20; const int32_t COMMON_CALLBACK_MAX_SIZE = 200; +const uint32_t MAX_LOAD_VAVLUE = 3; enum { DM_OK = 0, diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index ab10937c..3088141e 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -129,7 +129,6 @@ void DmDeviceStateManager::PostDeviceOffline(const std::string &pkgName, const D void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { - DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); LOGI("OnDeviceOnline function is called back with pkgName: %s", pkgName.c_str()); RegisterOffLineTimer(info); diff --git a/utils/include/fwkload/lite/dm_distributed_hardware_load.h b/utils/include/fwkload/lite/dm_distributed_hardware_load.h index 7a2d54c2..bcfa6732 100644 --- a/utils/include/fwkload/lite/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/lite/dm_distributed_hardware_load.h @@ -24,9 +24,9 @@ class DmDistributedHardwareLoad { public: void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); - uint32_t getDistributedHardwareLoadCount(void); + uint32_t GetDistributedHardwareLoadCount(void); private: - uint32_t nLoadCount_; + uint32_t distributedHardwareLoadCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/fwkload/standard/dm_distributed_hardware_load.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h index 3f47ffd0..ca3aed65 100644 --- a/utils/include/fwkload/standard/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -34,9 +34,9 @@ class DmDistributedHardwareLoad { public: void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); - uint32_t getDistributedHardwareLoadCount(void); + uint32_t GetDistributedHardwareLoadCount(void); private: - uint32_t nLoadCount_; + uint32_t distributedHardwareLoadCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp index bdc2a89d..1662a20d 100644 --- a/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/lite/dm_distributed_hardware_load.cpp @@ -27,7 +27,7 @@ void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { return; } -uint32_t DmDistributedHardwareLoad::getDistributedHardwareLoadCount(void) +uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount(void) { return 0; } diff --git a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp index c349c7de..5a9e019d 100644 --- a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -19,26 +19,6 @@ namespace OHOS { namespace DistributedHardware { -void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - LOGI("DmDistributedHhardware Load SA success, systemAbilityId:%d, remoteObject result:%s", - systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); - if (remoteObject == nullptr) { - LOGE("remoteObject is nullptr"); - return; - } -} -void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - LOGE("DmDistributedHhardware Load SA failed, systemAbilityId:%d", systemAbilityId); - uint32_t maxLoadValue = 3; - if (DmDistributedHardwareLoad::GetInstance().getDistributedHardwareLoadCount() < maxLoadValue) { - DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); - } - return; -} - IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) { @@ -47,7 +27,7 @@ void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) if (samgr == nullptr) { LOGE("failed to get system ability mgr."); } - nLoadCount_++; + distributedHardwareLoadCount_++; sptr distributedHardwareLoadCallback_ = new DistributedHardwareLoadCallback(); int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SA_ID, distributedHardwareLoadCallback_); if (ret != DM_OK) { @@ -58,11 +38,34 @@ void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) } void DmDistributedHardwareLoad::InitDistributedHardwareLoadCount(void) { - nLoadCount_ = 0; + distributedHardwareLoadCount_ = 0; } -uint32_t DmDistributedHardwareLoad::getDistributedHardwareLoadCount() +uint32_t DmDistributedHardwareLoad::GetDistributedHardwareLoadCount() { - return nLoadCount_; + return distributedHardwareLoadCount_; +} + +void DistributedHardwareLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + LOGI("DmDistributedHhardware Load SA success, systemAbilityId:%d, remoteObject result:%s", + systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (remoteObject == nullptr) { + LOGE("remoteObject is nullptr"); + return; + } + DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); +} +void DistributedHardwareLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + LOGE("DmDistributedHhardware Load SA failed, systemAbilityId:%d", systemAbilityId); + + if (DmDistributedHardwareLoad::GetInstance().GetDistributedHardwareLoadCount() < MAX_LOAD_VAVLUE) { + DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk(); + } else { + DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount(); + } + return; } } // namespace DistributedHardware } // namespace OHOS