diff --git a/README_ZH.md b/README_ZH.md index 8ec44bb343dec13834301c52b64c1baeaf60965d..7196a75c6b8d3785b8a4cf386f609fffeea113d6 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -28,13 +28,13 @@ ├── sa_profile # 分布式硬件管理框架的SA配置信息 ├── services # 分布式硬件管理框架的SA具体实现 │   └── distributedhardwarefwkservice # 分布式硬件管理框架的服务层 -│   └── AccessManager # 硬件接入管理 +│   └── accessmanager # 硬件接入管理 │ └── distributedhardwarefwkserviceimpl # 分布式硬件管理框架的服务实现层 -│ ├── ResourceManager # 硬件资源管理 -│ ├── ComponentManager # 分布式硬件部件管理 -│ ├── LocalHardwareManager # 本地硬件信息管理 -│ ├── ComponentLoader # 部件加载管理 -│ └── VersionManager # 版本管理 +│ ├── resourcemanager # 硬件资源管理 +│ ├── componentmanager # 分布式硬件部件管理 +│ ├── localhardwaremanager # 本地硬件信息管理 +│ ├── componentloader # 部件加载管理 +│ └── versionmanager # 版本管理 └── utils # 分布式硬件管理框架为各个部件提供的工具类 ``` diff --git a/common/utils/include/device_type.h b/common/utils/include/device_type.h index d5bdef799f6c58c2b3b79c2b0697e8005a3daba4..f4b8a9cc25f18e63df62ce85944bf08202d0269c 100644 --- a/common/utils/include/device_type.h +++ b/common/utils/include/device_type.h @@ -36,12 +36,13 @@ enum class DHType : uint32_t { }; struct DeviceInfo { + std::string uuid; std::string deviceId; std::string deviceName; uint16_t deviceType; - explicit DeviceInfo(std::string deviceId, std::string deviceName, uint16_t deviceType) - : deviceId(deviceId), deviceName(deviceName), deviceType(deviceType) {} + explicit DeviceInfo(std::string uuid, std::string deviceId, std::string deviceName, uint16_t deviceType) + : uuid(uuid), deviceId(deviceId), deviceName(deviceName), deviceType(deviceType) {} }; } } diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 478616bfe5c745e20e356783ad9fbf9b39fc1ca6..beb2e5427fe5d67144ed3b665f6f06302ec1e2a4 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -42,7 +42,8 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT = -10305; constexpr int32_t ERR_DH_FWK_COMPONENT_REGISTER_FAILED = -10306; constexpr int32_t ERR_DH_FWK_COMPONENT_UNREGISTER_FAILED = -10007; - constexpr int32_t DH_FWK_COMPONENT_GET_REMOTE_SA_FAILED = -10008; + constexpr int32_t ERR_DH_FWK_COMPONENT_GET_REMOTE_SA_FAILED = -10008; + constexpr int32_t ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED = -10009; /* ResourceManager errno, range: [-10400, -10499] */ constexpr int32_t ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL = -10400; @@ -80,6 +81,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_SERVICE_IPC_READ_PARA_FAIL = -10802; constexpr int32_t ERR_DH_FWK_SERVICE_STRING_IS_EMPTY = -10803; constexpr int32_t ERR_DH_FWK_SERVICE_LOCAL_VERSION_NOT_EXIST = -10804; + constexpr int32_t ERR_DH_FWK_SERVICE_WRITE_TOKEN_FAIL = -10805; /* AccessManager errno, range: [-10900, -10999] */ constexpr int32_t ERR_DH_FWK_ACCESS_INIT_DM_FAILED = -10900; diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index a7b34807c8a67e036fee9e55b8c9210fa6d9faed..016689beb091d8ed86ca9d5eab86a22a3b8d6ab8 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -28,9 +28,9 @@ public: virtual ~IDistributedHardwareManager() {}; virtual int32_t Initialize() = 0; virtual int32_t Release() = 0; - virtual int32_t SendOnLineEvent(const std::string &networkId, const std::string &deviceId, + virtual int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) = 0; - virtual int32_t SendOffLineEvent(const std::string &networkId, const std::string &deviceId, + virtual int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) = 0; virtual size_t GetOnLineCount() = 0; virtual int32_t GetComponentVersion(std::unordered_map &versionMap) = 0; diff --git a/common/utils/include/idistributed_hardware_source.h b/common/utils/include/idistributed_hardware_source.h index 2b7d926314dcfbca845d3895ff861fcd373833a8..00a326852426ea7c447baa879fd547b8da5953c9 100644 --- a/common/utils/include/idistributed_hardware_source.h +++ b/common/utils/include/idistributed_hardware_source.h @@ -24,13 +24,13 @@ namespace DistributedHardware { const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler"; class RegisterCallback { public: - virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, + virtual int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, const std::string &data) = 0; }; class UnregisterCallback { public: - virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, + virtual int32_t OnUnregisterResult(const std::string &uuid, const std::string &dhId, int32_t status, const std::string &data) = 0; }; @@ -43,11 +43,11 @@ class IDistributedHardwareSource { public: virtual int32_t InitSource(const std::string ¶ms) = 0; virtual int32_t ReleaseSource() = 0; - virtual int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, + virtual int32_t RegisterDistributedHardware(const std::string &uuid, const std::string &dhId, const EnableParam ¶m, std::shared_ptr callback) = 0; - virtual int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, + virtual int32_t UnregisterDistributedHardware(const std::string &uuid, const std::string &dhId, std::shared_ptr callback) = 0; - virtual int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, + virtual int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, const std::string &value) = 0; }; extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler(); diff --git a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h index 04731b8a5365a343e79c143478a4b3819f4532aa..8d670a44639c255f23b99094ffe267d29c238a29 100644 --- a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h +++ b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h @@ -41,7 +41,7 @@ public: static std::shared_ptr GetInstance(); int32_t Init(); int32_t UnInit(); - bool IsDeviceOnline(const std::string &deviceId); + bool IsDeviceOnline(const std::string &uuid); virtual void OnRemoteDied() override; virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override; virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index f91144280744d888999861761ec394d83aef9cda..850a5f27e81557900ab355d80093058ef7bf2f43 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -28,8 +28,8 @@ class DistributedHardwareManagerFactory { public: bool IsInit(); - int32_t SendOnLineEvent(const std::string &networkId, const std::string &deviceId, uint16_t deviceType); - int32_t SendOffLineEvent(const std::string &networkId, const std::string &deviceId, uint16_t deviceType); + int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); + int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t GetComponentVersion(std::unordered_map &versionMap); private: diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 031c6680a9eae6d42a1e77b03ced2cd41904bd94..190ea5b13f92ad89f9b65ec3ad9f99777d43a498 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -117,11 +117,11 @@ void AccessManager::OnDeviceOnline(const DmDeviceInfo &deviceInfo) deviceInfo.deviceName, deviceInfo.deviceTypeId); auto networkId = std::string(deviceInfo.deviceId); // deviceId of DM actually is networkId - auto deviceId = GetUUIDByNetworkId(networkId); + auto uuid = GetUUIDByNetworkId(networkId); auto ret = - DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, deviceId, deviceInfo.deviceTypeId); - DHLOGI("online result = %d, networkId = %s, deviceId = %s", ret, GetAnonyString(networkId).c_str(), - GetAnonyString(deviceId).c_str()); + DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, deviceInfo.deviceTypeId); + DHLOGI("online result = %d, networkId = %s, uuid = %s", ret, GetAnonyString(networkId).c_str(), + GetAnonyString(uuid).c_str()); } void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) @@ -131,11 +131,11 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) deviceInfo.deviceName, deviceInfo.deviceTypeId); auto networkId = std::string(deviceInfo.deviceId); // deviceId of DM actually is networkId - auto deviceId = GetUUIDByNetworkId(networkId); + auto uuid = GetUUIDByNetworkId(networkId); auto ret = - DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId, deviceId, deviceInfo.deviceTypeId); - DHLOGI("offline result = %d, networkId = %s, deviceId = %s", ret, GetAnonyString(networkId).c_str(), - GetAnonyString(deviceId).c_str()); + DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId, uuid, deviceInfo.deviceTypeId); + DHLOGI("offline result = %d, networkId = %s, uuid = %s", ret, GetAnonyString(networkId).c_str(), + GetAnonyString(uuid).c_str()); } void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) @@ -154,10 +154,10 @@ void AccessManager::SendTrustedDeviceOnline() DeviceManager::GetInstance().GetTrustedDeviceList(DH_FWK_PKG_NAME, "", deviceList); for (const auto &deviceInfo : deviceList) { const auto networkId = std::string(deviceInfo.deviceId); - const auto deviceId = GetUUIDByNetworkId(networkId); - DHLOGI("Send trusted device online, networkId = %s, deviceId = %s", GetAnonyString(networkId).c_str(), - GetAnonyString(deviceId).c_str()); - DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, deviceId, deviceInfo.deviceTypeId); + const auto uuid = GetUUIDByNetworkId(networkId); + DHLOGI("Send trusted device online, networkId = %s, uuid = %s", GetAnonyString(networkId).c_str(), + GetAnonyString(uuid).c_str()); + DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, deviceInfo.deviceTypeId); } } } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index c4f8a927e2a393cdc0a4f97c65e31fbd154079c7..0a4dda09cc318de297f170377fb7272522521c62 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -74,7 +74,7 @@ bool DistributedHardwareManagerFactory::IsInit() return true; } -int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &networkId, const std::string &deviceId, +int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) { if (networkId.empty()) { @@ -82,8 +82,8 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne return ERR_DH_FWK_REMOTE_NETWORK_ID_IS_EMPTY; } - if (deviceId.empty()) { - DHLOGE("deviceId is empty"); + if (uuid.empty()) { + DHLOGE("uuid is empty"); return ERR_DH_FWK_REMOTE_DEVICE_ID_IS_EMPTY; } @@ -93,7 +93,7 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne return ERR_DH_FWK_HARDWARE_MANAGER_LOAD_IMPL_FAILED; } - auto onlineResult = distributedHardwareMgrPtr_->SendOnLineEvent(networkId, deviceId, deviceType); + auto onlineResult = distributedHardwareMgrPtr_->SendOnLineEvent(networkId, uuid, deviceType); if (onlineResult != DH_FWK_SUCCESS) { DHLOGE("online failed, errCode = %d", onlineResult); return onlineResult; @@ -101,7 +101,7 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne return DH_FWK_SUCCESS; } -int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &networkId, const std::string &deviceId, +int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) { if (networkId.empty()) { @@ -109,8 +109,8 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n return ERR_DH_FWK_REMOTE_NETWORK_ID_IS_EMPTY; } - if (deviceId.empty()) { - DHLOGE("deviceId is empty"); + if (uuid.empty()) { + DHLOGE("uuid is empty"); return ERR_DH_FWK_REMOTE_DEVICE_ID_IS_EMPTY; } @@ -120,7 +120,7 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n return ERR_DH_FWK_HARDWARE_MANAGER_LOAD_IMPL_FAILED; } - auto offlineResult = distributedHardwareMgrPtr_->SendOffLineEvent(networkId, deviceId, deviceType); + auto offlineResult = distributedHardwareMgrPtr_->SendOffLineEvent(networkId, uuid, deviceType); if (offlineResult != DH_FWK_SUCCESS) { DHLOGE("offline failed, errCode = %d", offlineResult); return offlineResult; diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp index f49c11a71d3053729c70409dd007fed83be519d2..0ebbe34a14ca20f9f59494fef29e997fdecaece0 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_stub.cpp @@ -28,6 +28,10 @@ namespace DistributedHardware { int32_t DistributedHardwareStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + if (data.ReadInterfaceToken() != GetDescriptor()) { + DHLOGE("ReadInterfaceToken fail!"); + return ERR_INVALID_DATA; + } switch (code) { case QUERY_SINK_VERSION: { std::unordered_map versionMap; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp index 1f75dc9ee6cc23dd117e63488c504785ae584be5..b0553fa7777956377ad2e34ab03261a04e561bc5 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp @@ -36,7 +36,7 @@ enum class Status : uint32_t { constexpr int32_t INTERVAL_TIME_MS = 1; constexpr uint16_t TEST_DEV_TYPE_PAD = 0x11; -/* save networkId and deviceId */ +/* save networkId and uuid */ const std::vector> TEST_DEVICES = { { "11111111111111111111111111111111", "22222222222222222222222222222222" }, { "33333333333333333333333333333333", "44444444444444444444444444444444" }, @@ -202,18 +202,18 @@ HWTEST_F(AccessManagerTest, SendOffLineEvent_002, TestSize.Level1) */ HWTEST_F(AccessManagerTest, SendOffLineEvent_003, TestSize.Level0) { - auto handler = [this](Status status, std::string networkId, std::string devId, int32_t expect) { + auto handler = [this](Status status, std::string networkId, std::string uuid, int32_t expect) { if (status == Status::DEVICE_ONLINE) { std::lock_guard lock(testAccessMutex_); std::this_thread::sleep_for(std::chrono::milliseconds(100)); auto onlineResult = - DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, devId, TEST_DEV_TYPE_PAD); + DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, TEST_DEV_TYPE_PAD); EXPECT_EQ(expect, onlineResult); } else { std::lock_guard lock(testAccessMutex_); std::this_thread::sleep_for(std::chrono::milliseconds(90)); auto offlineResult = - DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId, devId, TEST_DEV_TYPE_PAD); + DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(networkId, uuid, TEST_DEV_TYPE_PAD); EXPECT_EQ(expect, offlineResult); } }; diff --git a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_enable.h b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_enable.h index bcb1d9f06ccbc9fc582341a984f1149ef870b1a0..83a0602c1d08135fa07cd14b7ce37d3ec448f3bc 100644 --- a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_enable.h +++ b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_enable.h @@ -27,9 +27,9 @@ class ComponentEnable : public std::enable_shared_from_this, pu public: ComponentEnable(); virtual ~ComponentEnable(); - int32_t Enable(const std::string &devId, const std::string &dhId, const EnableParam ¶m, + int32_t Enable(const std::string &uuid, const std::string &dhId, const EnableParam ¶m, IDistributedHardwareSource *handler); - int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, + int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, const std::string &data) override; private: diff --git a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h index 420e949bf3c31539be695b61763ba8b2b79e1f48..463f123f5b29e51ba3351c442cc66e3fbe929afd 100644 --- a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h @@ -39,8 +39,8 @@ public: public: int32_t Init(); int32_t UnInit(); - int32_t Enable(const std::string &networkId, const std::string &devId, const std::string &dhId); - int32_t Disable(const std::string &networkId, const std::string &devId, const std::string &dhId); + int32_t Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId); + int32_t Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId); private: enum class Action : int32_t { @@ -52,7 +52,7 @@ private: using ActionResult = std::unordered_map>; - DHType GetDHType(const std::string &devId, const std::string &dhId) const; + DHType GetDHType(const std::string &uuid, const std::string &dhId) const; bool InitCompSource(); bool InitCompSink(); ActionResult StartSource(); @@ -60,11 +60,11 @@ private: ActionResult StartSink(); ActionResult StopSink(); bool WaitForResult(const Action &action, ActionResult result); - int32_t GetEnableParam(const std::string &networkId, const std::string &devId, const std::string &dhId, + int32_t GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, DHType dhType, EnableParam ¶m); - std::string GetSinkVersion(const std::string &networkId, const std::string &devId, DHType dhType); - std::string GetVersionFromCache(const std::string &devId, DHType dhType); - int32_t UpdateVersionCache(const std::string &networkId, const std::string &devId); + std::string GetSinkVersion(const std::string &networkId, const std::string &uuid, DHType dhType); + std::string GetVersionFromCache(const std::string &uuid, DHType dhType); + int32_t UpdateVersionCache(const std::string &networkId, const std::string &uuid); sptr GetRemoteDHMS(const std::string &networkId) const; private: diff --git a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h index 718ab866fa527d6c7d6b2829d22cc2b2ca24f9a9..07bec4f887f2643afc48dbfafa993839c77df22f 100644 --- a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h @@ -27,8 +27,8 @@ DECLARE_SINGLE_INSTANCE(DistributedHardwareManager); public: int32_t Initialize() override; int32_t Release() override; - int32_t SendOnLineEvent(const std::string &networkId, const std::string &deviceId, uint16_t deviceType) override; - int32_t SendOffLineEvent(const std::string &networkId, const std::string &deviceId, uint16_t deviceType) override; + int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; + 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; }; diff --git a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h index a1e190085dd25e26f5f44b333a2584b6363f926b..c9154d172aee49030ea9ac831029b2954d07cea6 100644 --- a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h @@ -32,8 +32,6 @@ #include "event_sender.h" #include "single_instance.h" -using OHOS::DistributedKv::Entry; - class DBAdapter; namespace OHOS { namespace DistributedHardware { @@ -88,8 +86,6 @@ public: void RemoveManualSyncCount(const std::string &deviceId); /* Actively synchronizes data */ int32_t ManualSync(const std::string &networkId); - /* Manual sync notify */ - void NotifySyncCompleted(); /* Database data changes callback */ virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification) override; virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification, @@ -99,14 +95,12 @@ public: private: CapabilityInfoManager(); - void HandleCapabilityAddChange(const std::vector &insertRecords); - void HandleCapabilityUpdateChange(const std::vector &updateRecords); - void HandleCapabilityDeleteChange(const std::vector &deleteRecords); + void HandleCapabilityAddChange(const std::vector &insertRecords); + void HandleCapabilityUpdateChange(const std::vector &updateRecords); + void HandleCapabilityDeleteChange(const std::vector &deleteRecords); private: mutable std::mutex capInfoMgrMutex_; - int32_t manualSyncResult_; - std::condition_variable manualSyncCondVar_; std::shared_ptr dbAdapterPtr_; CapabilityInfoMap globalCapInfoMap_; }; diff --git a/services/distributedhardwarefwkserviceimpl/include/task/disable_task.h b/services/distributedhardwarefwkserviceimpl/include/task/disable_task.h index 2f7f1c7b461ec68ad0cd1e072e8baf56ebd93847..83276ac73026ea0d5a4b1a4fc2bed9da358313b4 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/disable_task.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/disable_task.h @@ -23,13 +23,14 @@ namespace DistributedHardware { class DisableTask : public Task { public: DisableTask() = delete; - DisableTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + DisableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); virtual ~DisableTask(); virtual void DoTask(); private: /* synchronous function for unregister distributed hardware, return on asynchronous unregister finish */ int32_t UnRegisterHardware(); + void DoTaskInner(); }; } } diff --git a/services/distributedhardwarefwkserviceimpl/include/task/enable_task.h b/services/distributedhardwarefwkserviceimpl/include/task/enable_task.h index 9b9ff62534c43fb384e1d912a3d654c5ff874e82..8c2aae9988eaebe17ffa5ec70c7648e87acf9bde 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/enable_task.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/enable_task.h @@ -23,13 +23,14 @@ namespace DistributedHardware { class EnableTask : public Task { public: EnableTask() = delete; - EnableTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + EnableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); virtual ~EnableTask(); virtual void DoTask(); private: /* synchronous function for register distributed hardware, return on asynchronous register finish */ int32_t RegisterHardware(); + void DoTaskInner(); }; } } diff --git a/services/distributedhardwarefwkserviceimpl/include/task/offline_task.h b/services/distributedhardwarefwkserviceimpl/include/task/offline_task.h index 15bc0865a9aa63911711b205dfb4afc8cc1fd2c4..18d06c346dd762bc7ee82ac3a2b5a58810f8b394 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/offline_task.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/offline_task.h @@ -26,7 +26,7 @@ namespace DistributedHardware { class OffLineTask : public Task { public: OffLineTask() = delete; - OffLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + OffLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); virtual ~OffLineTask(); virtual void DoTask(); diff --git a/services/distributedhardwarefwkserviceimpl/include/task/online_task.h b/services/distributedhardwarefwkserviceimpl/include/task/online_task.h index b9a59887458114f384c7affcd5108efa8db7215e..d21d47b62486ee1fb45b981df59095eeca1f4618 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/online_task.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/online_task.h @@ -23,7 +23,7 @@ namespace DistributedHardware { class OnLineTask : public Task { public: OnLineTask() = delete; - OnLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + OnLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); virtual ~OnLineTask(); virtual void DoTask(); diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task.h b/services/distributedhardwarefwkserviceimpl/include/task/task.h index 8e432a53e620d8423d2717c6d7449fe8dbd230ed..de9117c24dc9b9af9e8e86cae47809dceff947c5 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task.h @@ -29,13 +29,13 @@ namespace DistributedHardware { class Task : public std::enable_shared_from_this { public: Task() = delete; - Task(const std::string &networkId, const std::string &devId, const std::string &dhId); + Task(const std::string &networkId, const std::string &uuid, const std::string &dhId); virtual ~Task(); virtual void DoTask() = 0; std::string GetId(); std::string GetNetworkId(); - std::string GetDevId(); + std::string GetUUID(); std::string GetDhId(); TaskType GetTaskType(); void SetTaskType(TaskType taskType); @@ -54,7 +54,7 @@ public: private: std::string id_; std::string networkId_; - std::string devId_; + std::string uuid_; std::string dhId_; TaskType taskType_ { TaskType::UNKNOWN }; std::vector taskSteps_; diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_factory.h b/services/distributedhardwarefwkserviceimpl/include/task/task_factory.h index b5368e4dd387143d2acb891477d9e3bfb178e834..957d820e3885767683eb378d25467f01472779c4 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_factory.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_factory.h @@ -26,7 +26,7 @@ namespace DistributedHardware { class TaskFactory { DECLARE_SINGLE_INSTANCE(TaskFactory); public: - std::shared_ptr CreateTask(TaskType taskType, const std::string &networkId, const std::string &devId, + std::shared_ptr CreateTask(TaskType taskType, const std::string &networkId, const std::string &uuid, const std::string &dhId, std::shared_ptr fatherTask); }; } diff --git a/services/distributedhardwarefwkserviceimpl/include/utils/dh_context.h b/services/distributedhardwarefwkserviceimpl/include/utils/dh_context.h index 51b2dfe4d634503881a5d549e63fb8dbf51039d7..42b1c825f54618cac51218bd0caedda21c8eab9d 100644 --- a/services/distributedhardwarefwkserviceimpl/include/utils/dh_context.h +++ b/services/distributedhardwarefwkserviceimpl/include/utils/dh_context.h @@ -36,19 +36,25 @@ public: const DeviceInfo& GetDeviceInfo(); /* Save online device UUID and networkId when devices online */ - void AddOnlineDevice(const std::string &devId, const std::string &networkId); - void RemoveOnlineDevice(const std::string &devId); - bool IsDeviceOnline(const std::string &devId); + void AddOnlineDevice(const std::string &uuid, const std::string &networkId); + void RemoveOnlineDevice(const std::string &uuid); + bool IsDeviceOnline(const std::string &uuid); size_t GetOnlineCount(); - std::string GetNetworkIdByUUID(const std::string &devId); + std::string GetNetworkIdByUUID(const std::string &uuid); + + /* DeviceId is which is hashed by sha256 */ + std::string GetUUIDByDeviceId(const std::string &deviceId); private: std::shared_ptr eventBus_; - DeviceInfo devInfo_ { "", "", 0 }; + DeviceInfo devInfo_ { "", "", "", 0 }; std::mutex devMutex_; - /* Save online device UUID and networkId */ + /* Save online device uuid and networkId */ std::unordered_map onlineDeviceMap_; + + /* Save online device hashed uuid and uuid */ + std::unordered_map deviceIdUUIDMap_; std::shared_mutex onlineDevMutex_; }; } diff --git a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h index b5daf2f58cabdc9fd40ab1cebdd2a43e960bbd1f..c29fd75c8a306581afac31b559ae2be4167614b8 100644 --- a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h @@ -56,7 +56,7 @@ struct CompVersion { }; struct DHVersion { - std::string devId; + std::string uuid; std::string dhVersion; std::unordered_map compVersions; }; diff --git a/services/distributedhardwarefwkserviceimpl/include/versionmanager/version_manager.h b/services/distributedhardwarefwkserviceimpl/include/versionmanager/version_manager.h index 6bb78c652bb957787d283bada67362babc47ba03..4071074a2be20716f8524d5e825508bdaf55566d 100644 --- a/services/distributedhardwarefwkserviceimpl/include/versionmanager/version_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/versionmanager/version_manager.h @@ -36,10 +36,10 @@ public: ~VersionManager() {} int32_t Init(); void UnInit(); - int32_t AddDHVersion(const std::string &devId, const DHVersion &dhVersion); - int32_t RemoveDHVersion(const std::string &devId); - int32_t GetDHVersion(const std::string &devId, DHVersion &dhVersion); - int32_t GetCompVersion(const std::string &devId, const DHType dhType, CompVersion &compVersion); + int32_t AddDHVersion(const std::string &uuid, const DHVersion &dhVersion); + int32_t RemoveDHVersion(const std::string &uuid); + int32_t GetDHVersion(const std::string &uuid, DHVersion &dhVersion); + int32_t GetCompVersion(const std::string &uuid, const DHType dhType, CompVersion &compVersion); std::string GetLocalDeviceVersion(); void ShowLocalVersion(const DHVersion &dhVersion) const; diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index e0f33d384db4c5bd63f3290d4135a0087b99ac24..0e4271a97545a6d7b4eb697295a3cde000de741e 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_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "ipc_object_stub.h" @@ -39,6 +40,11 @@ namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(ComponentManager); +namespace { + constexpr int32_t ENABLE_RETRY_MAX_TIMES = 30; + constexpr int32_t DISABLE_RETRY_MAX_TIMES = 30; +} + ComponentManager::~ComponentManager() { DHLOGD("start."); @@ -99,10 +105,10 @@ ComponentManager::ActionResult ComponentManager::StartSource() { DHLOGI("start."); std::unordered_map> futures; - std::string devId = DHContext::GetInstance().GetDeviceInfo().deviceId; + std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; for (const auto &item : compSource_) { CompVersion compversion; - VersionManager::GetInstance().GetCompVersion(devId, item.first, compversion); + VersionManager::GetInstance().GetCompVersion(uuid, item.first, compversion); auto params = compversion.sourceVersion; auto future = std::async(std::launch::async, [item, params]() { return item.second->InitSource(params); }); futures.emplace(item.first, future.share()); @@ -114,10 +120,10 @@ ComponentManager::ActionResult ComponentManager::StartSink() { DHLOGI("start."); std::unordered_map> futures; - std::string devId = DHContext::GetInstance().GetDeviceInfo().deviceId; + std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid; for (const auto &item : compSink_) { CompVersion compversion; - VersionManager::GetInstance().GetCompVersion(devId, item.first, compversion); + VersionManager::GetInstance().GetCompVersion(uuid, item.first, compversion); auto params = compversion.sinkVersion; auto future = std::async(std::launch::async, [item, params]() { return item.second->InitSink(params); }); futures.emplace(item.first, future.share()); @@ -201,31 +207,45 @@ bool ComponentManager::InitCompSink() return !compSink_.empty(); } -int32_t ComponentManager::Enable(const std::string &networkId, const std::string &devId, const std::string &dhId) +int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId) { DHLOGI("start."); - auto dhType = GetDHType(devId, dhId); + auto dhType = GetDHType(uuid, dhId); auto find = compSource_.find(dhType); if (find == compSource_.end()) { DHLOGE("can not find handler for dhId = %s.", dhId.c_str()); return ERR_DH_FWK_PARA_INVALID; } EnableParam param; - auto ret = GetEnableParam(networkId, devId, dhId, dhType, param); + auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param); if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetEnableParam failed, devId = %s, dhId = %s, errCode = %d", GetAnonyString(devId).c_str(), + DHLOGE("GetEnableParam failed, uuid = %s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), dhId.c_str(), ret); return ret; } auto compEnable = std::make_shared(); auto result = compEnable->Enable(networkId, dhId, param, find->second); - DHLOGI("enable result is %d, devId = %s, dhId = %s", result, GetAnonyString(devId).c_str(), dhId.c_str()); + if (result != DH_FWK_SUCCESS) { + for (int retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { + if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGW("device is already offline, no need try enable, uuid = %s", GetAnonyString(uuid).c_str()); + return result; + } + if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { + DHLOGI("enable success, retryCount = %d", retryCount); + return DH_FWK_SUCCESS; + } + DHLOGE("enable failed, retryCount = %d", retryCount); + } + return result; + } + DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), dhId.c_str()); return result; } -int32_t ComponentManager::Disable(const std::string &networkId, const std::string &devId, const std::string &dhId) +int32_t ComponentManager::Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId) { - auto dhType = GetDHType(devId, dhId); + auto dhType = GetDHType(uuid, dhId); auto find = compSource_.find(dhType); if (find == compSource_.end()) { DHLOGE("can not find handler for dhId = %s.", dhId.c_str()); @@ -233,84 +253,102 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } auto compDisable = std::make_shared(); auto result = compDisable->Disable(networkId, dhId, find->second); - DHLOGI("disable result is %d, devId = %s, dhId = %s", result, GetAnonyString(devId).c_str(), dhId.c_str()); + if (result != DH_FWK_SUCCESS) { + for (int retryCount = 0; retryCount < DISABLE_RETRY_MAX_TIMES; retryCount++) { + if (DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGW("device is already online, no need try disable, uuid = %s", GetAnonyString(uuid).c_str()); + return result; + } + if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { + DHLOGI("disable success, retryCount = %d", retryCount); + return DH_FWK_SUCCESS; + } + DHLOGE("disable failed, retryCount = %d", retryCount); + } + return result; + } + DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), dhId.c_str()); return result; } -DHType ComponentManager::GetDHType(const std::string &devId, const std::string &dhId) const +DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &dhId) const { std::shared_ptr capability = nullptr; - auto ret = CapabilityInfoManager::GetInstance()->GetCapability(devId, dhId, capability); + auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { return capability->GetDHType(); } - DHLOGE("get dhType failed, devId = %s, dhId = %s", GetAnonyString(devId).c_str(), dhId.c_str()); + DHLOGE("get dhType failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), dhId.c_str()); return DHType::UNKNOWN; } -int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std::string &devId, +int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, DHType dhType, EnableParam ¶m) { std::shared_ptr capability = nullptr; - auto ret = CapabilityInfoManager::GetInstance()->GetCapability(devId, dhId, capability); + auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability); if ((ret != DH_FWK_SUCCESS) || (capability == nullptr)) { - DHLOGE("GetCapability failed, devId =%s, dhId = %s, errCode = %d", GetAnonyString(devId).c_str(), dhId.c_str(), + DHLOGE("GetCapability failed, uuid =%s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), dhId.c_str(), ret); return ret; } param.attrs = capability->GetDHAttrs(); - param.version = GetSinkVersion(networkId, devId, dhType); + 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()); + return ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED; + } - DHLOGI("success. devId =%s, dhId = %s, version = %s", GetAnonyString(devId).c_str(), dhId.c_str(), + DHLOGI("success. uuid =%s, dhId = %s, version = %s", GetAnonyString(uuid).c_str(), dhId.c_str(), param.version.c_str()); return DH_FWK_SUCCESS; } -std::string ComponentManager::GetSinkVersion(const std::string &networkId, const std::string &devId, DHType dhType) +std::string ComponentManager::GetSinkVersion(const std::string &networkId, const std::string &uuid, DHType dhType) { - DHLOGI("networkId = %s ", networkId.c_str()); - auto sinkVersion = GetVersionFromCache(devId, dhType); + DHLOGI("networkId = %s ", GetAnonyString(networkId).c_str()); + auto sinkVersion = GetVersionFromCache(uuid, dhType); if (!sinkVersion.empty()) { - DHLOGI("GetVersionFromCache success, sinkVersion = %s, devId = %s, dhType = %#X", sinkVersion.c_str(), - GetAnonyString(devId).c_str(), dhType); + DHLOGI("GetVersionFromCache success, sinkVersion = %s, uuid = %s, dhType = %#X", sinkVersion.c_str(), + GetAnonyString(uuid).c_str(), dhType); return sinkVersion; } - auto updateResult = UpdateVersionCache(networkId, devId); + auto updateResult = UpdateVersionCache(networkId, uuid); if (updateResult != DH_FWK_SUCCESS) { - DHLOGE("UpdateVersionCache failed, devId = %s, errCode = %d", GetAnonyString(devId).c_str(), updateResult); + DHLOGE("UpdateVersionCache failed, uuid = %s, errCode = %d", GetAnonyString(uuid).c_str(), updateResult); return ""; } - sinkVersion = GetVersionFromCache(devId, dhType); + sinkVersion = GetVersionFromCache(uuid, dhType); return sinkVersion; } -std::string ComponentManager::GetVersionFromCache(const std::string &devId, DHType dhType) +std::string ComponentManager::GetVersionFromCache(const std::string &uuid, DHType dhType) { std::lock_guard lock(sinkVersionMutex_); - auto iter = sinkVersions_.find(devId); + auto iter = sinkVersions_.find(uuid); if (iter == sinkVersions_.end()) { - DHLOGE("can not find component version for devId = %s", GetAnonyString(devId).c_str()); + DHLOGE("can not find component version for uuid = %s", GetAnonyString(uuid).c_str()); return ""; } auto find = iter->second.find(dhType); if (find == iter->second.end()) { - DHLOGE("can not find component version for devId = %s, dhType = %#X", devId.c_str(), dhType); + DHLOGE("can not find component version for uuid = %s, dhType = %#X", uuid.c_str(), dhType); return ""; } return find->second; } -int32_t ComponentManager::UpdateVersionCache(const std::string &networkId, const std::string &devId) +int32_t ComponentManager::UpdateVersionCache(const std::string &networkId, const std::string &uuid) { sptr dhms = GetRemoteDHMS(networkId); if (dhms == nullptr) { DHLOGI("GetRemoteDHMS failed, networkId = %s", GetAnonyString(networkId).c_str()); - return DH_FWK_COMPONENT_GET_REMOTE_SA_FAILED; + return ERR_DH_FWK_COMPONENT_GET_REMOTE_SA_FAILED; } std::unordered_map versions; @@ -321,7 +359,7 @@ int32_t ComponentManager::UpdateVersionCache(const std::string &networkId, const } { std::lock_guard lock(sinkVersionMutex_); - sinkVersions_.emplace(devId, versions); + sinkVersions_.emplace(uuid, versions); } DHLOGI("QuerySinkVersion success"); return DH_FWK_SUCCESS; diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp index 938cca7f711740ba26119bb15017139aedaf3257..cce91398367c86ebbc743a28d43281dd056536ce 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp @@ -81,7 +81,7 @@ int32_t DistributedHardwareManager::Release() return DH_FWK_SUCCESS; } -int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId, const std::string &deviceId, +int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) { (void)deviceType; @@ -90,27 +90,27 @@ int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId DHLOGE("networkId is empty"); return ERR_DH_FWK_REMOTE_NETWORK_ID_IS_EMPTY; } - if (deviceId.empty()) { - DHLOGE("deviceId is empty, networkId = %s", GetAnonyString(networkId).c_str()); + if (uuid.empty()) { + DHLOGE("uuid is empty, networkId = %s", GetAnonyString(networkId).c_str()); return ERR_DH_FWK_REMOTE_DEVICE_ID_IS_EMPTY; } - DHLOGI("networkId = %s, deviceId = %s", GetAnonyString(networkId).c_str(), GetAnonyString(deviceId).c_str()); + DHLOGI("networkId = %s, uuid = %s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); - if (DHContext::GetInstance().IsDeviceOnline(deviceId)) { - DHLOGW("device is already online, deviceId = %s", GetAnonyString(deviceId).c_str()); + if (DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGW("device is already online, uuid = %s", GetAnonyString(uuid).c_str()); return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_ONLINE; } - auto task = TaskFactory::GetInstance().CreateTask(TaskType::ON_LINE, networkId, deviceId, "", nullptr); + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ON_LINE, networkId, uuid, "", nullptr); TaskExecutor::GetInstance().PushTask(task); - DHContext::GetInstance().AddOnlineDevice(deviceId, networkId); - CapabilityInfoManager::GetInstance()->CreateManualSyncCount(deviceId); + DHContext::GetInstance().AddOnlineDevice(uuid, networkId); + CapabilityInfoManager::GetInstance()->CreateManualSyncCount(GetDeviceIdByUUID(uuid)); return DH_FWK_SUCCESS; } -int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkId, const std::string &deviceId, +int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) { (void)deviceType; @@ -119,23 +119,23 @@ int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkI DHLOGE("networkId is empty"); return ERR_DH_FWK_REMOTE_NETWORK_ID_IS_EMPTY; } - if (deviceId.empty()) { - DHLOGE("deviceId is empty, networkId = %s", GetAnonyString(networkId).c_str()); + if (uuid.empty()) { + DHLOGE("uuid is empty, networkId = %s", GetAnonyString(networkId).c_str()); return ERR_DH_FWK_REMOTE_DEVICE_ID_IS_EMPTY; } - DHLOGI("networkId = %s, deviceId = %s", GetAnonyString(networkId).c_str(), GetAnonyString(deviceId).c_str()); + DHLOGI("networkId = %s, uuid = %s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); - if (!DHContext::GetInstance().IsDeviceOnline(deviceId)) { - DHLOGW("device is already offline, deviceId = %s", GetAnonyString(deviceId).c_str()); + if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGW("device is already offline, uuid = %s", GetAnonyString(uuid).c_str()); return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_OFFLINE; } - auto task = TaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, networkId, deviceId, "", nullptr); + auto task = TaskFactory::GetInstance().CreateTask(TaskType::OFF_LINE, networkId, uuid, "", nullptr); TaskExecutor::GetInstance().PushTask(task); - DHContext::GetInstance().RemoveOnlineDevice(deviceId); - CapabilityInfoManager::GetInstance()->RemoveManualSyncCount(deviceId); + DHContext::GetInstance().RemoveOnlineDevice(uuid); + CapabilityInfoManager::GetInstance()->RemoveManualSyncCount(GetDeviceIdByUUID(uuid)); return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_proxy.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_proxy.cpp index 7a94a7b6c677ea0a616c5acdd189581e2bcac65a..c74cde00b7c5a261e6bdfc79fd2ed5766bfff6e4 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_proxy.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_proxy.cpp @@ -39,6 +39,10 @@ int32_t DistributedHardwareProxy::QuerySinkVersion(std::unordered_mapSendRequest(QUERY_SINK_VERSION, data, reply, option); if (error != NO_ERROR) { DHLOGE("SendRequest failed, errCode = %d", error); diff --git a/services/distributedhardwarefwkserviceimpl/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/localhardwaremanager/local_hardware_manager.cpp index b309d82dee759d7c757baa52ad1e6528ed9ebb87..c84599794ffc83f4f04ea69f63a63134bf80d34c 100644 --- a/services/distributedhardwarefwkserviceimpl/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/localhardwaremanager/local_hardware_manager.cpp @@ -85,6 +85,7 @@ void LocalHardwareManager::QueryLocalHardware(const DHType dhType, IHardwareHand void LocalHardwareManager::AddLocalCapabilityInfo(const std::vector &dhItems, const DHType dhType) { + DHLOGI("start!"); std::vector> capabilityInfos; std::string deviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; std::string devName = DHContext::GetInstance().GetDeviceInfo().deviceName; diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index b6510fb3264ec33fb0ebf62f5ef932913dc4e78c..d3e6e9d83f2016819c099424adaf37528d1f125d 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -33,15 +33,12 @@ #include "task_executor.h" #include "task_factory.h" -using OHOS::DistributedKv::Entry; - namespace OHOS { namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "CapabilityInfoManager" -CapabilityInfoManager::CapabilityInfoManager() - : manualSyncResult_(ERR_DH_FWK_RESOURCE_DB_MANUAL_SYNC_FAIL), dbAdapterPtr_(nullptr) +CapabilityInfoManager::CapabilityInfoManager() : dbAdapterPtr_(nullptr) {} CapabilityInfoManager::~CapabilityInfoManager() @@ -301,22 +298,11 @@ int32_t CapabilityInfoManager::ManualSync(const std::string &networkId) DHLOGE("dbAdapterPtr_ is null"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; } - manualSyncResult_ = ERR_DH_FWK_RESOURCE_DB_MANUAL_SYNC_FAIL; if (dbAdapterPtr_->ManualSync(networkId) != DH_FWK_SUCCESS) { DHLOGE("ManualSync failed"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - manualSyncCondVar_.wait_for(lock, std::chrono::seconds(MANUAL_SYNC_TIMEOUT), - [this] { return this->manualSyncResult_ == DH_FWK_SUCCESS; }); - return manualSyncResult_; -} - -void CapabilityInfoManager::NotifySyncCompleted() -{ - DHLOGI("CapabilityInfoManager SyncCompleted NotifySyncCompleted"); - std::lock_guard lock(capInfoMgrMutex_); - manualSyncResult_ = DH_FWK_SUCCESS; - manualSyncCondVar_.notify_one(); + return DH_FWK_SUCCESS; } void CapabilityInfoManager::OnChange(const DistributedKv::ChangeNotification &changeNotification) @@ -352,7 +338,7 @@ void CapabilityInfoManager::OnEvent(CapabilityInfoEvent &ev) } } -void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &insertRecords) +void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &insertRecords) { std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : insertRecords) { @@ -365,19 +351,19 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector & const auto keyString = capPtr->GetKey(); DHLOGI("Add capability key: %s", capPtr->GetAnonymousKey().c_str()); globalCapInfoMap_[keyString] = capPtr; - std::string deviceId = capPtr->GetDeviceId(); - std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(deviceId); + std::string uuid = DHContext::GetInstance().GetUUIDByDeviceId(capPtr->GetDeviceId()); + std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(uuid); if (networkId.empty()) { - DHLOGI("Find network failed and never enable, deviceId: %s", GetAnonyString(deviceId).c_str()); + DHLOGI("Find network failed and never enable, deviceId: %s", GetAnonyString(uuid).c_str()); continue; } - auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, networkId, deviceId, + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, networkId, uuid, capPtr->GetDHId(), nullptr); TaskExecutor::GetInstance().PushTask(task); } } -void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &updateRecords) +void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &updateRecords) { std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : updateRecords) { @@ -393,7 +379,7 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &deleteRecords) +void CapabilityInfoManager::HandleCapabilityDeleteChange(const std::vector &deleteRecords) { std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : deleteRecords) { diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/db_adapter.cpp index 70ba5b4854ed8cab3886a26912df17fea64535c4..a44192bb1049f6faa73a8cee5b3396341f7a17c2 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/db_adapter.cpp @@ -18,6 +18,8 @@ #include #include +#include "kvstore_observer.h" + #include "anonymous_string.h" #include "capability_info.h" #include "capability_info_manager.h" @@ -28,16 +30,6 @@ #include "distributed_hardware_log.h" #include "event_bus.h" -using OHOS::DistributedKv::Entry; -using OHOS::DistributedKv::Key; -using OHOS::DistributedKv::KvStoreDeathRecipient; -using OHOS::DistributedKv::KvStoreType; -using OHOS::DistributedKv::Options; -using OHOS::DistributedKv::SingleKvStore; -using OHOS::DistributedKv::Status; -using OHOS::DistributedKv::SubscribeType; -using OHOS::DistributedKv::Value; - namespace OHOS { namespace DistributedHardware { #undef DH_LOG_TAG @@ -57,14 +49,14 @@ DBAdapter::~DBAdapter() DHLOGI("DBAdapter Destruction"); } -Status DBAdapter::GetKvStorePtr() +DistributedKv::Status DBAdapter::GetKvStorePtr() { - Options options = { + DistributedKv::Options options = { .createIfMissing = true, .encrypt = false, .autoSync = true, - .securityLevel = DistributedKv::SecurityLevel::S2, - .kvStoreType = KvStoreType::SINGLE_VERSION + .securityLevel = DistributedKv::SecurityLevel::S1, + .kvStoreType = DistributedKv::KvStoreType::SINGLE_VERSION }; return kvDataMgr_.GetSingleKvStore(options, appId_, storeId_, kvStoragePtr_); } @@ -75,8 +67,8 @@ int32_t DBAdapter::Init() std::lock_guard lock(dbAdapterMutex_); int32_t tryTimes = MAX_INIT_RETRY_TIMES; while (tryTimes > 0) { - Status status = GetKvStorePtr(); - if (status == Status::SUCCESS && kvStoragePtr_) { + DistributedKv::Status status = GetKvStorePtr(); + if (status == DistributedKv::Status::SUCCESS && kvStoragePtr_) { DHLOGI("Init KvStorePtr Success"); RegisterManualSyncListener(); RegisterChangeListener(); @@ -118,8 +110,8 @@ int32_t DBAdapter::ReInit() } UnRegisterManualSyncListener(); kvStoragePtr_.reset(); - Status status = GetKvStorePtr(); - if (status != Status::SUCCESS || !kvStoragePtr_) { + DistributedKv::Status status = GetKvStorePtr(); + if (status != DistributedKv::Status::SUCCESS || !kvStoragePtr_) { DHLOGW("Get kvStoragePtr_ failed, status: %d", status); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } @@ -141,7 +133,6 @@ void DBAdapter::SyncCompleted(const std::map } DHLOGI("ManualSyncCallback::SyncCompleted, retryCount: %d", manualSyncCountMap_[deviceId]); if (result.second == DistributedKv::Status::SUCCESS) { - CapabilityInfoManager::GetInstance()->NotifySyncCompleted(); manualSyncCountMap_[deviceId] = 0; } else { manualSyncCountMap_[deviceId]++; @@ -166,10 +157,10 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) DHLOGE("kvStoragePtr_ is null"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - Key kvKey(key); - Value kvValue; - Status status = kvStoragePtr_->Get(kvKey, kvValue); - if (status != Status::SUCCESS) { + DistributedKv::Key kvKey(key); + DistributedKv::Value kvValue; + DistributedKv::Status status = kvStoragePtr_->Get(kvKey, kvValue); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("Query from db failed, key: %s", GetAnonyString(key).c_str()); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } @@ -187,10 +178,10 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< } // if prefix is empty, get all entries. - Key allEntryKeyPrefix(keyPrefix); - std::vector allEntries; - Status status = kvStoragePtr_->GetEntries(allEntryKeyPrefix, allEntries); - if (status != Status::SUCCESS) { + DistributedKv::Key allEntryKeyPrefix(keyPrefix); + std::vector allEntries; + DistributedKv::Status status = kvStoragePtr_->GetEntries(allEntryKeyPrefix, allEntries); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("Query data by keyPrefix failed, prefix: %s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; @@ -208,10 +199,10 @@ int32_t DBAdapter::PutData(const std::string &key, std::string &value) DHLOGE("kvStoragePtr_ is null"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - Key kvKey(key); - Value kvValue(value); - Status status = kvStoragePtr_->Put(kvKey, kvValue); - if (status == Status::IPC_ERROR) { + DistributedKv::Key kvKey(key); + DistributedKv::Value kvValue(value); + DistributedKv::Status status = kvStoragePtr_->Put(kvKey, kvValue); + if (status == DistributedKv::Status::IPC_ERROR) { DHLOGE("Put kv to db failed, ret: %d", status); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } @@ -229,15 +220,15 @@ int32_t DBAdapter::PutDataBatch(const std::vector &keys, const std: DHLOGE("Param invalid"); return ERR_DH_FWK_PARA_INVALID; } - std::vector entries; + std::vector entries; for (unsigned long i = 0; i < keys.size(); i++) { - Entry entry; + DistributedKv::Entry entry; entry.key = keys[i]; entry.value = values[i]; entries.push_back(entry); } - Status status = kvStoragePtr_->PutBatch(entries); - if (status != Status::SUCCESS) { + DistributedKv::Status status = kvStoragePtr_->PutBatch(entries); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("Put kv batch to db failed, ret: %d", status); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } @@ -266,8 +257,8 @@ int32_t DBAdapter::ManualSync(const std::string &networkId) return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } std::vector devList = { networkId }; - Status status = kvStoragePtr_->Sync(devList, DistributedKv::SyncMode::PULL); - if (status != Status::SUCCESS) { + DistributedKv::Status status = kvStoragePtr_->Sync(devList, DistributedKv::SyncMode::PULL); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("ManualSync Data failed, networkId: %s", GetAnonyString(networkId).c_str()); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } @@ -288,8 +279,9 @@ int32_t DBAdapter::RegisterChangeListener() DHLOGE("kvStoragePtr_ is null"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - Status status = kvStoragePtr_->SubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_REMOTE, dataChangeListener_); - if (status == Status::IPC_ERROR) { + DistributedKv::Status status = kvStoragePtr_->SubscribeKvStore(DistributedKv::SubscribeType::SUBSCRIBE_TYPE_REMOTE, + dataChangeListener_); + if (status == DistributedKv::Status::IPC_ERROR) { DHLOGE("Register db data change listener failed, ret: %d", status); return ERR_DH_FWK_RESOURCE_REGISTER_DB_FAILED; } @@ -303,8 +295,9 @@ int32_t DBAdapter::UnRegisterChangeListener() DHLOGE("kvStoragePtr_ is null"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - Status status = kvStoragePtr_->UnSubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_REMOTE, dataChangeListener_); - if (status == Status::IPC_ERROR) { + DistributedKv::Status status = kvStoragePtr_->UnSubscribeKvStore( + DistributedKv::SubscribeType::SUBSCRIBE_TYPE_REMOTE, dataChangeListener_); + if (status == DistributedKv::Status::IPC_ERROR) { DHLOGE("UnRegister db data change listener failed, ret: %d", status); return ERR_DH_FWK_RESOURCE_UNREGISTER_DB_FAILED; } @@ -350,7 +343,7 @@ void DBAdapter::OnRemoteDied() int32_t times = 0; while (times < DIED_CHECK_MAX_TIMES) { // init kvStore. - if (this->ReInit() != DH_FWK_SUCCESS) { + if (this->ReInit() == DH_FWK_SUCCESS) { // register data change listener again. this->RegisterChangeListener(); this->SyncDBForRecover(); @@ -368,8 +361,8 @@ void DBAdapter::OnRemoteDied() void DBAdapter::DeleteKvStore() { std::lock_guard lock(dbAdapterMutex_); - Status status = kvDataMgr_.DeleteKvStore(appId_, storeId_); - if (status != Status::SUCCESS) { + DistributedKv::Status status = kvDataMgr_.DeleteKvStore(appId_, storeId_); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("DeleteKvStore error, appId: %s, storeId: %s, status: %d", appId_.appId.c_str(), storeId_.storeId.c_str(), status); return; @@ -384,8 +377,8 @@ int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) DHLOGE("kvStoragePtr_ is null"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - Status status = kvStoragePtr_->RemoveDeviceData(deviceId); - if (status != Status::SUCCESS) { + DistributedKv::Status status = kvStoragePtr_->RemoveDeviceData(deviceId); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("Remove device data failed, deviceId: %s", GetAnonyString(deviceId).c_str()); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } @@ -400,9 +393,9 @@ int32_t DBAdapter::RemoveDataByKey(const std::string &key) DHLOGE("kvStoragePtr_ is null"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - Key kvKey(key); - Status status = kvStoragePtr_->Delete(kvKey); - if (status != Status::SUCCESS) { + DistributedKv::Key kvKey(key); + DistributedKv::Status status = kvStoragePtr_->Delete(kvKey); + if (status != DistributedKv::Status::SUCCESS) { DHLOGE("Remove data by key failed"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } diff --git a/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp index 8bf53b64e94a4e773e7503a60dca5e4bd74b0edc..c852ad28fefcd7ef5a1eee7181c702e0778ceee0 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp @@ -27,22 +27,27 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "DisableTask" -DisableTask::DisableTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : Task(networkId, devId, dhId) +DisableTask::DisableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : Task(networkId, uuid, dhId) { SetTaskType(TaskType::DISABLE); SetTaskSteps(std::vector { TaskStep::DO_DISABLE }); - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(devId).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(uuid).c_str()); } DisableTask::~DisableTask() { - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); } void DisableTask::DoTask() { - DHLOGD("id = %s, devId = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str(), GetDhId().c_str()); + std::thread(&DisableTask::DoTaskInner, this).detach(); +} + +void DisableTask::DoTaskInner() +{ + DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str()); SetTaskState(TaskState::RUNNING); /* trigger Unregister Distributed Hardware Task, sync function */ @@ -63,9 +68,9 @@ void DisableTask::DoTask() int32_t DisableTask::UnRegisterHardware() { - auto result = ComponentManager::GetInstance().Disable(GetNetworkId(), GetDevId(), GetDhId()); - DHLOGI("disable task %s, id = %s, devId = %s, dhId = %s", (result == DH_FWK_SUCCESS) ? "success" : "failed", - GetId().c_str(), GetAnonyString(GetDevId()).c_str(), GetDhId().c_str()); + auto result = ComponentManager::GetInstance().Disable(GetNetworkId(), GetUUID(), GetDhId()); + 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()); return result; } } diff --git a/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp index 02715a71c651e03b108b75a81a09a896e61a3036..4c21c324e8ce75ec5160286988ae59765474b709 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp @@ -29,22 +29,27 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "EnableTask" -EnableTask::EnableTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : Task(networkId, devId, dhId) +EnableTask::EnableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : Task(networkId, uuid, dhId) { SetTaskType(TaskType::ENABLE); SetTaskSteps(std::vector { TaskStep::DO_ENABLE }); - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(devId).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(uuid).c_str()); } EnableTask::~EnableTask() { - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); } void EnableTask::DoTask() { - DHLOGD("id = %s, devId = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str(), GetDhId().c_str()); + std::thread(&EnableTask::DoTaskInner, this).detach(); +} + +void EnableTask::DoTaskInner() +{ + DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str()); SetTaskState(TaskState::RUNNING); auto result = RegisterHardware(); auto state = (result == DH_FWK_SUCCESS) ? TaskState::SUCCESS : TaskState::FAIL; @@ -55,9 +60,9 @@ void EnableTask::DoTask() int32_t EnableTask::RegisterHardware() { - auto result = ComponentManager::GetInstance().Enable(GetNetworkId(), GetDevId(), GetDhId()); - DHLOGI("enable task %s, id = %s, devId = %s, dhId = %s", (result == DH_FWK_SUCCESS) ? "success" : "failed", - GetId().c_str(), GetAnonyString(GetDevId()).c_str(), GetDhId().c_str()); + auto result = ComponentManager::GetInstance().Enable(GetNetworkId(), GetUUID(), GetDhId()); + 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()); return result; } } diff --git a/services/distributedhardwarefwkserviceimpl/src/task/offline_task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/offline_task.cpp index 7925a1b0abd7996dbf0eeea71ab34e2b6e24f27a..c0c431481d375a6961d804befae2f68faa1a9024 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/offline_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/offline_task.cpp @@ -19,6 +19,7 @@ #include "anonymous_string.h" #include "capability_info_manager.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "task_board.h" @@ -30,18 +31,18 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "OffLineTask" -OffLineTask::OffLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : Task(networkId, devId, dhId) +OffLineTask::OffLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : Task(networkId, uuid, dhId) { this->SetTaskType(TaskType::OFF_LINE); this->SetTaskSteps({TaskStep::UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE, TaskStep::WAIT_UNREGISTGER_COMPLETE, TaskStep::CLEAR_OFFLINE_INFO}); - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(devId).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(uuid).c_str()); } OffLineTask::~OffLineTask() { - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); } void OffLineTask::DoTask() @@ -51,7 +52,7 @@ void OffLineTask::DoTask() void OffLineTask::DoTaskInner() { - DHLOGD("start offline task, id = %s, devId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGD("start offline task, id = %s, uuid = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); this->SetTaskState(TaskState::RUNNING); for (auto& step : this->GetTaskSteps()) { switch (step) { @@ -80,11 +81,11 @@ void OffLineTask::DoTaskInner() void OffLineTask::CreateDisableTask() { - DHLOGI("networkId = %s, devId = %s", GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGI("networkId = %s, uuid = %s", GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetUUID()).c_str()); std::vector> capabilityInfos; - CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(GetDevId(), capabilityInfos); + CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(GetDeviceIdByUUID(GetUUID()), capabilityInfos); if (capabilityInfos.empty()) { - DHLOGE("capabilityInfos is empty, can not create disableTask, devId = %s", GetAnonyString(GetDevId()).c_str()); + DHLOGE("capabilityInfos is empty, can not create disableTask, uuid = %s", GetAnonyString(GetUUID()).c_str()); return; } for (const auto &iter : capabilityInfos) { @@ -92,7 +93,7 @@ void OffLineTask::CreateDisableTask() DHLOGE("capabilityInfo is null"); continue; } - auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, GetNetworkId(), GetDevId(), + auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, GetNetworkId(), GetUUID(), iter->GetDHId(), shared_from_this()); TaskExecutor::GetInstance().PushTask(task); } @@ -108,10 +109,10 @@ void OffLineTask::WaitDisableTaskFinish() void OffLineTask::ClearOffLineInfo() { - DHLOGI("start clear resource when device offline, devId = %s", GetAnonyString(GetDevId()).c_str()); - auto ret = CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoInMem(GetDevId()); + DHLOGI("start clear resource when device offline, uuid = %s", GetAnonyString(GetUUID()).c_str()); + auto ret = CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoInMem(GetDeviceIdByUUID(GetUUID())); if (ret != DH_FWK_SUCCESS) { - DHLOGE("RemoveCapabilityInfoInMem failed, devId = %s, errCode = %d", GetAnonyString(GetDevId()).c_str(), ret); + DHLOGE("RemoveCapabilityInfoInMem failed, uuid = %s, errCode = %d", GetAnonyString(GetUUID()).c_str(), ret); } } diff --git a/services/distributedhardwarefwkserviceimpl/src/task/online_task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/online_task.cpp index 8142264cd00ea74687b6315e67afdfff18a051bd..52f9b5403358d68b24337c74f512faac73ce0e75 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/online_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/online_task.cpp @@ -17,6 +17,7 @@ #include "anonymous_string.h" #include "capability_info_manager.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "task_board.h" @@ -28,22 +29,22 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "OnLineTask" -OnLineTask::OnLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : Task(networkId, devId, dhId) +OnLineTask::OnLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : Task(networkId, uuid, dhId) { SetTaskType(TaskType::ON_LINE); SetTaskSteps(std::vector { TaskStep::SYNC_ONLINE_INFO, TaskStep::REGISTER_ONLINE_DISTRIBUTED_HARDWARE }); - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(devId).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(uuid).c_str()); } OnLineTask::~OnLineTask() { - DHLOGD("id = %s, devId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGD("id = %s, uuid = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); } void OnLineTask::DoTask() { - DHLOGD("start online task, id = %s, devId = %s", GetId().c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGD("start online task, id = %s, uuid = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); this->SetTaskState(TaskState::RUNNING); for (auto& step : this->GetTaskSteps()) { switch (step) { @@ -67,25 +68,25 @@ void OnLineTask::DoTask() void OnLineTask::DoSyncInfo() { - DHLOGI("start sync resource when device online, devId = %s", GetAnonyString(GetDevId()).c_str()); + DHLOGI("start sync resource when device online, uuid = %s", GetAnonyString(GetUUID()).c_str()); auto ret = CapabilityInfoManager::GetInstance()->ManualSync(GetNetworkId()); if (ret != DH_FWK_SUCCESS) { - DHLOGW("ManualSync failed, devId = %s, errCode = %d", GetAnonyString(GetDevId()).c_str(), ret); + DHLOGW("ManualSync failed, uuid = %s, errCode = %d", GetAnonyString(GetUUID()).c_str(), ret); } - ret = CapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(GetDevId()); + ret = CapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(GetDeviceIdByUUID(GetUUID())); if (ret != DH_FWK_SUCCESS) { - DHLOGE("SyncDeviceInfoFromDB failed, devId = %s, errCode = %d", GetAnonyString(GetDevId()).c_str(), ret); + DHLOGE("SyncDeviceInfoFromDB failed, uuid = %s, errCode = %d", GetAnonyString(GetUUID()).c_str(), ret); return; } } void OnLineTask::CreateEnableTask() { - DHLOGI("networkId = %s, devId = %s", GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetDevId()).c_str()); + DHLOGI("networkId = %s, uuid = %s", GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetUUID()).c_str()); std::vector> capabilityInfos; - CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(GetDevId(), capabilityInfos); + CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(GetDeviceIdByUUID(GetUUID()), capabilityInfos); if (capabilityInfos.empty()) { - DHLOGE("capabilityInfos is empty, can not create enableTask, devId = %s", GetAnonyString(GetDevId()).c_str()); + DHLOGE("capabilityInfos is empty, can not create enableTask, uuid = %s", GetAnonyString(GetUUID()).c_str()); return; } for (const auto &iter : capabilityInfos) { @@ -93,7 +94,7 @@ void OnLineTask::CreateEnableTask() DHLOGE("capabilityInfo is null"); continue; } - auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, GetNetworkId(), GetDevId(), + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, GetNetworkId(), GetUUID(), iter->GetDHId(), shared_from_this()); TaskExecutor::GetInstance().PushTask(task); } diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task.cpp index 6d4b6fa05f5f6aa81d9ba3e4edf30ba41f9c88bf..349f645c9251bd29d937dacee7bd4da349ecc4e5 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task.cpp @@ -20,8 +20,8 @@ namespace OHOS { namespace DistributedHardware { -Task::Task(const std::string &networkId, const std::string &devId, const std::string &dhId) - : id_(DH_TASK_NAME_PREFIX + GetRandomID()), networkId_(networkId), devId_(devId), dhId_(dhId) +Task::Task(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : id_(DH_TASK_NAME_PREFIX + GetRandomID()), networkId_(networkId), uuid_(uuid), dhId_(dhId) {} Task::~Task() @@ -39,9 +39,9 @@ std::string Task::GetNetworkId() return this->networkId_; } -std::string Task::GetDevId() +std::string Task::GetUUID() { - return this->devId_; + return this->uuid_; } std::string Task::GetDhId() diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp index 89b7083f5a8633b07dd911fadecfb968bc679fbe..ba13f0f371c926f7363a0701a5c194fc4caaeb42 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp @@ -29,27 +29,27 @@ namespace DistributedHardware { #define DH_LOG_TAG "TaskFactory" IMPLEMENT_SINGLE_INSTANCE(TaskFactory); -std::shared_ptr TaskFactory::CreateTask(TaskType taskType, const std::string &networkId, const std::string &devId, +std::shared_ptr TaskFactory::CreateTask(TaskType taskType, const std::string &networkId, const std::string &uuid, const std::string &dhId, std::shared_ptr fatherTask) { - DHLOGI("taskType = %d, networkId = %s, devId = %s, dhId = %s", static_cast(taskType), - GetAnonyString(networkId).c_str(), GetAnonyString(devId).c_str(), dhId.c_str()); + DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s", static_cast(taskType), + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), dhId.c_str()); std::shared_ptr task = nullptr; switch (taskType) { case TaskType::ENABLE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } case TaskType::DISABLE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } case TaskType::ON_LINE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } case TaskType::OFF_LINE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } default: { diff --git a/services/distributedhardwarefwkserviceimpl/src/utils/dh_context.cpp b/services/distributedhardwarefwkserviceimpl/src/utils/dh_context.cpp index 9f920ee22f1e0b53c352c80ca775beee64809b37..06e71cd186513ae9f376fea6e460f50c34af7808 100644 --- a/services/distributedhardwarefwkserviceimpl/src/utils/dh_context.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/utils/dh_context.cpp @@ -40,34 +40,36 @@ std::shared_ptr DHContext::GetEventBus() const DeviceInfo& DHContext::GetDeviceInfo() { std::lock_guard lock(devMutex_); - if (!devInfo_.deviceId.empty()) { + if (!devInfo_.uuid.empty()) { return devInfo_; } devInfo_ = GetLocalDeviceInfo(); return devInfo_; } -void DHContext::AddOnlineDevice(const std::string &devId, const std::string &networkId) +void DHContext::AddOnlineDevice(const std::string &uuid, const std::string &networkId) { std::unique_lock lock(onlineDevMutex_); - if (!devId.empty() && !networkId.empty()) { - onlineDeviceMap_[devId] = networkId; + if (!uuid.empty() && !networkId.empty()) { + onlineDeviceMap_[uuid] = networkId; + deviceIdUUIDMap_[GetDeviceIdByUUID(uuid)] = uuid; } } -void DHContext::RemoveOnlineDevice(const std::string &devId) +void DHContext::RemoveOnlineDevice(const std::string &uuid) { std::unique_lock lock(onlineDevMutex_); - auto iter = onlineDeviceMap_.find(devId); + auto iter = onlineDeviceMap_.find(uuid); if (iter != onlineDeviceMap_.end()) { onlineDeviceMap_.erase(iter); + deviceIdUUIDMap_.erase(GetDeviceIdByUUID(uuid)); } } -bool DHContext::IsDeviceOnline(const std::string &devId) +bool DHContext::IsDeviceOnline(const std::string &uuid) { std::shared_lock lock(onlineDevMutex_); - return onlineDeviceMap_.find(devId) != onlineDeviceMap_.end(); + return onlineDeviceMap_.find(uuid) != onlineDeviceMap_.end(); } size_t DHContext::GetOnlineCount() @@ -76,14 +78,24 @@ size_t DHContext::GetOnlineCount() return onlineDeviceMap_.size(); } -std::string DHContext::GetNetworkIdByUUID(const std::string &devId) +std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) { std::unique_lock lock(onlineDevMutex_); - if (onlineDeviceMap_.find(devId) == onlineDeviceMap_.end()) { - DHLOGE("Can not find networkId in onlineDeviceMap_: %s", GetAnonyString(devId).c_str()); + if (onlineDeviceMap_.find(uuid) == onlineDeviceMap_.end()) { + DHLOGE("Can not find networkId, uuid: %s", GetAnonyString(uuid).c_str()); return ""; } - return onlineDeviceMap_[devId]; + return onlineDeviceMap_[uuid]; +} + +std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) +{ + std::unique_lock lock(onlineDevMutex_); + if (deviceIdUUIDMap_.find(deviceId) == deviceIdUUIDMap_.end()) { + DHLOGE("Can not find uuid, deviceId: %s", GetAnonyString(deviceId).c_str()); + return ""; + } + return deviceIdUUIDMap_[deviceId]; } } } diff --git a/services/distributedhardwarefwkserviceimpl/src/versionmanager/version_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/versionmanager/version_manager.cpp index 66df996dded1b02993a2d6f3ffe22a9996dd3519..febd7d55375e2ecb8a1bf0281734a3d1f73d7262 100644 --- a/services/distributedhardwarefwkserviceimpl/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/versionmanager/version_manager.cpp @@ -37,8 +37,8 @@ int32_t VersionManager::Init() } dhVersion.dhVersion = DH_LOCAL_VERSION; ShowLocalVersion(dhVersion); - std::string strDevID = DHContext::GetInstance().GetDeviceInfo().deviceId; - AddDHVersion(strDevID, dhVersion); + std::string strUUID = DHContext::GetInstance().GetDeviceInfo().uuid; + AddDHVersion(strUUID, dhVersion); return DH_FWK_SUCCESS; } @@ -57,47 +57,47 @@ void VersionManager::ShowLocalVersion(const DHVersion &dhVersion) const } } -int32_t VersionManager::AddDHVersion(const std::string &devId, const DHVersion &dhVersion) +int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &dhVersion) { - DHLOGI("devId: %s", GetAnonyString(devId).c_str()); + DHLOGI("uuid: %s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); - dhVersions_.insert(std::pair(devId, dhVersion)); + dhVersions_.insert(std::pair(uuid, dhVersion)); return DH_FWK_SUCCESS; } -int32_t VersionManager::RemoveDHVersion(const std::string &devId) +int32_t VersionManager::RemoveDHVersion(const std::string &uuid) { - DHLOGI("devId: %s", GetAnonyString(devId).c_str()); + DHLOGI("uuid: %s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); - std::unordered_map::iterator iter = dhVersions_.find(devId); + std::unordered_map::iterator iter = dhVersions_.find(uuid); if (iter == dhVersions_.end()) { - DHLOGE("there is no devId: %s, remove fail", GetAnonyString(devId).c_str()); + DHLOGE("there is no uuid: %s, remove fail", GetAnonyString(uuid).c_str()); return ERR_DH_FWK_VERSION_DEVICE_ID_NOT_EXIST; } dhVersions_.erase(iter); return DH_FWK_SUCCESS; } -int32_t VersionManager::GetDHVersion(const std::string &devId, DHVersion &dhVersion) +int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersion) { - DHLOGI("devId: %s", GetAnonyString(devId).c_str()); + DHLOGI("uuid: %s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); - std::unordered_map::iterator iter = dhVersions_.find(devId); + std::unordered_map::iterator iter = dhVersions_.find(uuid); if (iter == dhVersions_.end()) { - DHLOGE("there is no devId: %s, get version fail", GetAnonyString(devId).c_str()); + DHLOGE("there is no uuid: %s, get version fail", GetAnonyString(uuid).c_str()); return ERR_DH_FWK_VERSION_DEVICE_ID_NOT_EXIST; } else { - dhVersion = dhVersions_[devId]; + dhVersion = dhVersions_[uuid]; return DH_FWK_SUCCESS; } } -int32_t VersionManager::GetCompVersion(const std::string &devId, const DHType dhType, CompVersion &compVersion) +int32_t VersionManager::GetCompVersion(const std::string &uuid, const DHType dhType, CompVersion &compVersion) { DHVersion dhVersion; - int32_t ret = GetDHVersion(devId, dhVersion); + int32_t ret = GetDHVersion(uuid, dhVersion); if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetDHVersion fail, devId: %s", GetAnonyString(devId).c_str()); + DHLOGE("GetDHVersion fail, uuid: %s", GetAnonyString(uuid).c_str()); return ret; } if (dhVersion.compVersions.find(dhType) == dhVersion.compVersions.end()) { diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentloader/src/component_loader_test.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentloader/src/component_loader_test.cpp index fddb7a3da64827e421122c0a848cebbdb6a79653..4b47f1fbb364edb2560524455d98bd97229dc44a 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentloader/src/component_loader_test.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentloader/src/component_loader_test.cpp @@ -78,7 +78,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_002, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(ComponentLoaderTest, component_loader_test_004, TestSize.Level0) +HWTEST_F(ComponentLoaderTest, component_loader_test_003, TestSize.Level0) { for (const auto &iter : g_compHandlerMap) { IDistributedHardwareSource *sourcePtr = nullptr; @@ -94,7 +94,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_004, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(ComponentLoaderTest, component_loader_test_005, TestSize.Level0) +HWTEST_F(ComponentLoaderTest, component_loader_test_004, TestSize.Level0) { for (const auto &iter : g_compHandlerMap) { IDistributedHardwareSink *sinkPtr = nullptr; @@ -110,7 +110,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_005, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(ComponentLoaderTest, component_loader_test_006, TestSize.Level0) +HWTEST_F(ComponentLoaderTest, component_loader_test_005, TestSize.Level0) { for (const auto &iter : g_compHandlerMap) { auto ret = ComponentLoader::GetInstance().ReleaseHardwareHandler(iter.first); @@ -125,7 +125,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_006, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(ComponentLoaderTest, component_loader_test_007, TestSize.Level0) +HWTEST_F(ComponentLoaderTest, component_loader_test_006, TestSize.Level0) { for (const auto &iter : g_compHandlerMap) { auto ret = ComponentLoader::GetInstance().ReleaseSource(iter.first); @@ -140,7 +140,7 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_007, TestSize.Level0) * @tc.type: FUNC * @tc.require: AR000GHSK3 */ -HWTEST_F(ComponentLoaderTest, component_loader_test_008, TestSize.Level0) +HWTEST_F(ComponentLoaderTest, component_loader_test_007, TestSize.Level0) { for (const auto &iter : g_compHandlerMap) { auto ret = ComponentLoader::GetInstance().ReleaseSink(iter.first); diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/include/mock_idistributed_hardware_source.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/include/mock_idistributed_hardware_source.h index 381e031c1b815d5e59ae257d83b89438569c6f70..cd7a35c9f78f6a9c0a8698a545d8c1f20b21d609 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/include/mock_idistributed_hardware_source.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/include/mock_idistributed_hardware_source.h @@ -28,12 +28,12 @@ public: virtual ~MockIDistributedHardwareSource() {} MOCK_METHOD1(InitSource, int32_t(const std::string ¶ms)); MOCK_METHOD0(ReleaseSource, int32_t()); - MOCK_METHOD4(RegisterDistributedHardware, int32_t(const std::string &devId, const std::string &dhId, + MOCK_METHOD4(RegisterDistributedHardware, int32_t(const std::string &uuid, const std::string &dhId, const EnableParam ¶meters, std::shared_ptr callback)); MOCK_METHOD3(UnregisterDistributedHardware, - int32_t(const std::string &devId, const std::string &dhId, std::shared_ptr callback)); + int32_t(const std::string &uuid, const std::string &dhId, std::shared_ptr callback)); - int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, + int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, const std::string &value) { return 0; diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/src/component_manager_test.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/src/component_manager_test.cpp index 217fe99819a1361f5e7000f17a0bc3505d73cc36..9c7714cf9d6f985c17bac9ed5f39259e1d24114b 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/componentmanager/src/component_manager_test.cpp @@ -61,11 +61,11 @@ int32_t ComponentManagerTest::Enable(int32_t timeout, int32_t status) auto compEnable = std::make_shared(); EnableParam parameters; std::future future; - auto handler = [&future, timeout, status, compEnable](std::string devId, std::string dhId, + auto handler = [&future, timeout, status, compEnable](std::string uuid, std::string dhId, const EnableParam ¶meters, std::shared_ptr callback) { - future = std::async(std::launch::async, [timeout, compEnable, devId, dhId, status]() { + future = std::async(std::launch::async, [timeout, compEnable, uuid, dhId, status]() { std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); - return compEnable->OnRegisterResult(devId, dhId, status, ""); + return compEnable->OnRegisterResult(uuid, dhId, status, ""); }); return DH_FWK_SUCCESS; }; @@ -87,11 +87,11 @@ int32_t ComponentManagerTest::Disable(int32_t timeout, int32_t status) auto compDisable = std::make_shared(); std::future future; - auto handler = [&future, timeout, status, compDisable](std::string devId, std::string dhId, + auto handler = [&future, timeout, status, compDisable](std::string uuid, std::string dhId, std::shared_ptr callback) { - future = std::async(std::launch::async, [timeout, compDisable, devId, dhId, status]() { + future = std::async(std::launch::async, [timeout, compDisable, uuid, dhId, status]() { std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); - return compDisable->OnUnregisterResult(devId, dhId, status, ""); + return compDisable->OnUnregisterResult(uuid, dhId, status, ""); }); return DH_FWK_SUCCESS; }; diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/distributed_hardware_manager_test.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/distributed_hardware_manager_test.cpp index af2d9c2453cad862c09be1698669c66806007778..c01bae52b3d16074f545b0b7c485bcbb3f39c5ce 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/distributed_hardware_manager_test.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/distributed_hardware_manager_test.cpp @@ -30,7 +30,7 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { -/* save networkId and deviceId */ +/* save networkId and uuid */ const std::vector> TEST_DEVICES = { { "11111111111111111111111111111111", "22222222222222222222222222222222" }, { "33333333333333333333333333333333", "44444444444444444444444444444444" }, @@ -88,7 +88,7 @@ HWTEST_F(DistributedHardwareManagerTest, sendOnLineEvent_test_002, TestSize.Leve /** * @tc.name: sendOnLineEvent_test_003 - * @tc.desc: Verify the SendOnLineEvent failed for deviceId is empty + * @tc.desc: Verify the SendOnLineEvent failed for uuid is empty * @tc.type: FUNC * @tc.require: AR000GHSJM */ @@ -151,7 +151,7 @@ HWTEST_F(DistributedHardwareManagerTest, sendOffLineEvent_test_002, TestSize.Lev /** * @tc.name: sendOffLineEvent_test_003 - * @tc.desc: Verify the SendOffLineEvent failed for deviceId is empty + * @tc.desc: Verify the SendOffLineEvent failed for uuid is empty * @tc.type: FUNC * @tc.require: AR000GHSJM */ diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 8b0a8e8e34afc772823fe756b60715d213db9730..5a68c343340966e0ff9e216a08bbb9e6906ae868 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -334,7 +334,26 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_012, TestSize.Level0) HWTEST_F(ResourceManagerTest, resource_manager_test_013, TestSize.Level0) { CapabilityInfoMap capMap; - EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(EMPTY_PREFIX, capMap), DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_0->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_1->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_2->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_3->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_4->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_5->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_6->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_7->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_8->GetDeviceId(), capMap), + DH_FWK_SUCCESS); + EXPECT_EQ(CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(CAP_INFO_9->GetDeviceId(), capMap), + DH_FWK_SUCCESS); EXPECT_EQ(capMap.size(), TEST_SIZE_10); } } diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_disable_task.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_disable_task.h index 8aaf3a695436d017113b73ae86e32d271ad85ffd..39c45b3409032b425c7464df70d06c9b3d6136be 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_disable_task.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_disable_task.h @@ -23,7 +23,7 @@ namespace DistributedHardware { class MockDisableTask : public DisableTask { public: MockDisableTask() = delete; - MockDisableTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + MockDisableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); private: /* synchronous function for unregister distributed hardware, return on asynchronous unregister finish */ diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_enable_task.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_enable_task.h index 04ffd779bca2dc7de92d535b40b0cf2b4d95e6df..abb35352689f1a956a3c8e7a24f9c59adcda9beb 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_enable_task.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_enable_task.h @@ -23,7 +23,7 @@ namespace DistributedHardware { class MockEnableTask : public EnableTask { public: MockEnableTask() = delete; - MockEnableTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + MockEnableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); private: /* synchronous function for register distributed hardware, return on asynchronous register finish */ diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_offline_task.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_offline_task.h index 5a17042c10e22f19d79ed82b8beb52c6c3c81b65..8f99e84607a1a30dea521e0bf7171172d9e84e6f 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_offline_task.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_offline_task.h @@ -24,7 +24,7 @@ namespace DistributedHardware { class MockOffLineTask : public OffLineTask { public: MockOffLineTask() = delete; - MockOffLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + MockOffLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); void SetOffLineDevInfos(std::vector offLineDevInfos); private: diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_online_task.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_online_task.h index 8551649af885bc537e5d18c478c27a498812bf5c..47cda4917f46fe1c76a3b61f79f9a8ef8797aef2 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_online_task.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_online_task.h @@ -26,7 +26,7 @@ namespace DistributedHardware { class MockOnLineTask : public OnLineTask { public: MockOnLineTask() = delete; - MockOnLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId); + MockOnLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId); void SetOnLineDevInfos(std::vector devInfos); private: diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_factory.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_factory.h index 47524a5d7b27812ce708d75a46c03cabf89c8a9e..f97b9f9c43c08adb33dbddb6c4b015288b3eaa7e 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_factory.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_factory.h @@ -26,7 +26,7 @@ namespace DistributedHardware { class MockTaskFactory { DECLARE_SINGLE_INSTANCE(MockTaskFactory); public: - std::shared_ptr CreateTask(TaskType taskType, const std::string &networkId, const std::string &devId, + std::shared_ptr CreateTask(TaskType taskType, const std::string &networkId, const std::string &uuid, const std::string &dhId, std::shared_ptr fatherTask); }; } diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_utils.h b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_utils.h index 628efa1ccc18b8edee6030c2351a22d358bf17db..36fa6036d46fbe29ee28ee41ea349edf4a574d42 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_utils.h +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/include/mock_task_utils.h @@ -22,7 +22,7 @@ namespace OHOS { namespace DistributedHardware { struct MockDevInfo { std::string networkId; - std::string devId; + std::string uuid; std::string dhId; }; } diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_disable_task.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_disable_task.cpp index ca9e6137a3efbe9e13bb6c46865bd0f25c2f59d9..35a54724c90b1dd98043710086534c43a7355426 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_disable_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_disable_task.cpp @@ -23,8 +23,8 @@ namespace OHOS { namespace DistributedHardware { -MockDisableTask::MockDisableTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : DisableTask(networkId, devId, dhId) +MockDisableTask::MockDisableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : DisableTask(networkId, uuid, dhId) {} int32_t MockDisableTask::UnRegisterHardware() diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_enable_task.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_enable_task.cpp index 6646eb062d25737bfd0fcd997433621bb06f230d..dea92cc5ef97d1488727f453cbca631db46392c1 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_enable_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_enable_task.cpp @@ -22,8 +22,8 @@ namespace OHOS { namespace DistributedHardware { -MockEnableTask::MockEnableTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : EnableTask(networkId, devId, dhId) +MockEnableTask::MockEnableTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : EnableTask(networkId, uuid, dhId) {} int32_t MockEnableTask::RegisterHardware() diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_offline_task.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_offline_task.cpp index c20d9e28325edda04673a889089ddb1c38890a10..db577a7fb281ba2cd15e424a0286709be9bf6114 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_offline_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_offline_task.cpp @@ -24,15 +24,15 @@ namespace OHOS { namespace DistributedHardware { -MockOffLineTask::MockOffLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : OffLineTask(networkId, devId, dhId) +MockOffLineTask::MockOffLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : OffLineTask(networkId, uuid, dhId) {} void MockOffLineTask::CreateDisableTask() { for (auto &devInfo : offLineDevInfos) { std::shared_ptr disableTask = MockTaskFactory::GetInstance().CreateTask(TaskType::DISABLE, - devInfo.networkId, devInfo.devId, devInfo.dhId, shared_from_this()); + devInfo.networkId, devInfo.uuid, devInfo.dhId, shared_from_this()); TaskExecutor::GetInstance().PushTask(disableTask); } } diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_online_task.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_online_task.cpp index 1ac00bfe49a7d3a1815e5e5351865519fb23483d..815b00e4ede4a59211644340e23e0a2dee42c34a 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_online_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_online_task.cpp @@ -24,8 +24,8 @@ namespace OHOS { namespace DistributedHardware { -MockOnLineTask::MockOnLineTask(const std::string &networkId, const std::string &devId, const std::string &dhId) - : OnLineTask(networkId, devId, dhId) +MockOnLineTask::MockOnLineTask(const std::string &networkId, const std::string &uuid, const std::string &dhId) + : OnLineTask(networkId, uuid, dhId) { DHLOGI("Ctor MockOnLineTask: %s, type: %d", this->GetId().c_str(), this->GetTaskType()); } @@ -41,7 +41,7 @@ void MockOnLineTask::CreateEnableTask() { for (const auto& devInfo : onLineDevInfos) { std::shared_ptr enableTask = MockTaskFactory::GetInstance().CreateTask(TaskType::ENABLE, - devInfo.networkId, devInfo.devId, devInfo.dhId, shared_from_this()); + devInfo.networkId, devInfo.uuid, devInfo.dhId, shared_from_this()); TaskExecutor::GetInstance().PushTask(enableTask); } } diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_task_factory.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_task_factory.cpp index eabe6a5bb20692e4264f2d4da44eb5d57e7aa3b5..d0a9d08c8def63571e7beb6967e7d5d385829fbf 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_task_factory.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/task/src/mock_task_factory.cpp @@ -26,24 +26,24 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(MockTaskFactory); std::shared_ptr MockTaskFactory::CreateTask(TaskType taskType, const std::string &networkId, - const std::string &devId, const std::string &dhId, std::shared_ptr fatherTask) + const std::string &uuid, const std::string &dhId, std::shared_ptr fatherTask) { std::shared_ptr task = nullptr; switch (taskType) { case TaskType::ENABLE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } case TaskType::DISABLE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } case TaskType::ON_LINE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } case TaskType::OFF_LINE: { - task = std::make_shared(networkId, devId, dhId); + task = std::make_shared(networkId, uuid, dhId); break; } default: { diff --git a/services/distributedhardwarefwkserviceimpl/test/unittest/common/versionmanager/src/version_manager_test.cpp b/services/distributedhardwarefwkserviceimpl/test/unittest/common/versionmanager/src/version_manager_test.cpp index 692a4e1141a74e320bb8976eb748c42ce71700ea..12b68af18ed404402b6d7e1d5ff6ea11c2cadce8 100644 --- a/services/distributedhardwarefwkserviceimpl/test/unittest/common/versionmanager/src/version_manager_test.cpp +++ b/services/distributedhardwarefwkserviceimpl/test/unittest/common/versionmanager/src/version_manager_test.cpp @@ -96,15 +96,15 @@ HWTEST_F(VersionManagerTest, version_manager_test_002, TestSize.Level0) CompVersion cVs3; CompVersionGetValue(cVs3, TEST_COMPONENT_NAME_3, DHType::MIC, TEST_HANDLER_VERSION_3, TEST_SOURCE_VERSION_3, TEST_SINK_VERSION_3); - dhVersion.devId = TEST_DEVICE_ID_1; + dhVersion.uuid = TEST_DEVICE_ID_1; dhVersion.dhVersion = TEST_DH_VERSION; dhVersion.compVersions.insert(std::make_pair(cVs1.dhType, cVs1)); dhVersion.compVersions.insert(std::make_pair(cVs2.dhType, cVs2)); dhVersion.compVersions.insert(std::make_pair(cVs3.dhType, cVs3)); - int32_t ret = VersionManager::GetInstance().AddDHVersion(dhVersion.devId, dhVersion); + int32_t ret = VersionManager::GetInstance().AddDHVersion(dhVersion.uuid, dhVersion); EXPECT_EQ(DH_FWK_SUCCESS, ret); - dhVersion.devId = TEST_DEVICE_ID_2; - ret = VersionManager::GetInstance().AddDHVersion(dhVersion.devId, dhVersion); + dhVersion.uuid = TEST_DEVICE_ID_2; + ret = VersionManager::GetInstance().AddDHVersion(dhVersion.uuid, dhVersion); EXPECT_EQ(DH_FWK_SUCCESS, ret); } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index ce60423d44af145693dd0128366fc08d513d57ef..49d4ddee72060124ae6439b71337f020db7eb4c1 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -12,10 +12,12 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedhardwarefwk/distributedhardwarefwk.gni") +import( + "//foundation/distributedhardware/distributedhardwarefwk/distributedhardwarefwk.gni") ohos_shared_library("distributedhardwareutils") { include_dirs = [ + "//third_party/openssl:libcrypto_static", "//utils/native/base/include", "//utils/system/safwk/native/include", "${common_path}/log/include", @@ -27,11 +29,14 @@ ohos_shared_library("distributedhardwareutils") { sources = [ "src/anonymous_string.cpp", + "src/dh_utils_tool.cpp", "src/log/dh_log.cpp", - "src/dh_utils_tool.cpp" ] - deps = [ "//utils/native/base:utils" ] + deps = [ + "//third_party/openssl:libcrypto_static", + "//utils/native/base:utils", + ] defines = [ "HI_LOG_ENABLE", @@ -42,9 +47,9 @@ ohos_shared_library("distributedhardwareutils") { external_deps = [ "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "dsoftbus_standard:softbus_client", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", - "dsoftbus_standard:softbus_client", ] subsystem_name = "distributedhardware" diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index 00198874cefdf1c92f5ed37653a8c0480088680d..0fdf5b9ebbe89ca81ff9f7612261a0184b280587 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -36,6 +36,9 @@ std::string GetRandomID(); std::string GetUUIDByNetworkId(const std::string &networkId); DeviceInfo GetLocalDeviceInfo(); + +/* Convert uuid to deviceId by sha256 encode */ +std::string GetDeviceIdByUUID(const std::string &uuid); } } #endif \ No newline at end of file diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 05f178a96ed0efa78a1a11d3457afa02cf7203ec..ab5c3aecadc3fa9be83821321ae98f8820922b9e 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -20,6 +20,7 @@ #include #include +#include "openssl/sha.h" #include "softbus_bus_center.h" #include "constants.h" @@ -77,16 +78,39 @@ std::string GetUUIDByNetworkId(const std::string &networkId) return (ret == DH_FWK_SUCCESS) ? std::string(uuid) : ""; } +std::string GetDeviceIdByUUID(const std::string &uuid) +{ + unsigned char hash[SHA256_DIGEST_LENGTH * 2 + 1] = {0}; + SHA256_CTX ctx; + SHA256_Init(&ctx); + SHA256_Update(&ctx, uuid.data(), uuid.size()); + SHA256_Final(&hash[SHA256_DIGEST_LENGTH], &ctx); + // here we translate sha256 hash to hexadecimal. each 8-bit char will be presented by two characters([0-9a-f]) + constexpr int32_t WIDTH = 4; + constexpr unsigned char MASK = 0x0F; + const char* hexCode = "0123456789abcdef"; + constexpr int32_t DOUBLE_TIMES = 2; + for (int32_t i = 0; i < SHA256_DIGEST_LENGTH; ++i) { + unsigned char value = hash[SHA256_DIGEST_LENGTH + i]; + // uint8_t is 2 digits in hexadecimal. + hash[i * DOUBLE_TIMES] = hexCode[(value >> WIDTH) & MASK]; + hash[i * DOUBLE_TIMES + 1] = hexCode[value & MASK]; + } + hash[SHA256_DIGEST_LENGTH * DOUBLE_TIMES] = 0; + return reinterpret_cast(hash); +} + DeviceInfo GetLocalDeviceInfo() { - DeviceInfo devInfo { "", "", 0 }; + DeviceInfo devInfo { "", "", "", 0 }; auto info = std::make_unique(); auto ret = GetLocalNodeDeviceInfo(DH_FWK_PKG_NAME.c_str(), info.get()); if (ret != DH_FWK_SUCCESS) { DHLOGE("GetLocalNodeDeviceInfo failed, errCode = %d", ret); return devInfo; } - devInfo.deviceId = GetUUIDByNetworkId(info->networkId); + devInfo.uuid = GetUUIDByNetworkId(info->networkId); + devInfo.deviceId = GetDeviceIdByUUID(devInfo.uuid); devInfo.deviceName = info->deviceName; devInfo.deviceType = info->deviceTypeId; return devInfo;