From 3ce22dbe245731220d7968cf92a60c0e82b4949c Mon Sep 17 00:00:00 2001 From: tangfan Date: Sun, 10 Dec 2023 12:00:13 +0800 Subject: [PATCH 1/2] fix sync bug Signed-off-by: tangfan --- .../include/subscribemanager/profile_event_handler.h | 1 + .../src/subscribemanager/profile_sync_handler.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/old/services/core/include/subscribemanager/profile_event_handler.h b/old/services/core/include/subscribemanager/profile_event_handler.h index 8ab79eaf..0dd48146 100644 --- a/old/services/core/include/subscribemanager/profile_event_handler.h +++ b/old/services/core/include/subscribemanager/profile_event_handler.h @@ -50,6 +50,7 @@ public: virtual int32_t Subscribe(const SubscribeInfo& subscribeInfo, const sptr& profileEventNotifier); int32_t Unsubscribe(const sptr& profileEventNotifier); + int32_t Unsubscribe(ProfileEvent profileEvent, const sptr& profileEventNotifier); void OnSubscriberDied(const sptr& profileEventNotifier); protected: diff --git a/old/services/core/src/subscribemanager/profile_sync_handler.cpp b/old/services/core/src/subscribemanager/profile_sync_handler.cpp index 99f6d943..227c3e68 100644 --- a/old/services/core/src/subscribemanager/profile_sync_handler.cpp +++ b/old/services/core/src/subscribemanager/profile_sync_handler.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "profile_sync_handler.h" #include "device_profile_log.h" @@ -62,13 +63,16 @@ void ProfileSyncHandler::NotifySyncCompleted(const SyncResult& syncResults) } { std::lock_guard autoLock(notifierLock_); - for (const auto& [notifier, _] : profileEventSubscribeInfos_) { - sptr profileEventNotifier = iface_cast(notifier); + auto iter = profileEventSubscribeInfos_.begin(); + while (iter != profileEventSubscribeInfos_.end()) { + sptr profileEventNotifier = iface_cast(iter->first); if (profileEventNotifier == nullptr) { HILOGE("cast to IProfileEventNotifier failed"); - continue; + iter++; + } else { + profileEventNotifier->OnSyncCompleted(syncResults); + profileEventSubscribeInfos_.erase(iter++); } - profileEventNotifier->OnSyncCompleted(syncResults); } } DeviceProfileStorageManager::GetInstance().NotifySyncCompleted(); -- Gitee From 9446f2df926169636bb91642ed2fc26180a68c30 Mon Sep 17 00:00:00 2001 From: tangfan Date: Sun, 10 Dec 2023 12:07:11 +0800 Subject: [PATCH 2/2] fix sync bug Signed-off-by: tangfan --- .../core/include/subscribemanager/profile_event_handler.h | 1 - old/services/core/src/subscribemanager/profile_sync_handler.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/old/services/core/include/subscribemanager/profile_event_handler.h b/old/services/core/include/subscribemanager/profile_event_handler.h index 0dd48146..8ab79eaf 100644 --- a/old/services/core/include/subscribemanager/profile_event_handler.h +++ b/old/services/core/include/subscribemanager/profile_event_handler.h @@ -50,7 +50,6 @@ public: virtual int32_t Subscribe(const SubscribeInfo& subscribeInfo, const sptr& profileEventNotifier); int32_t Unsubscribe(const sptr& profileEventNotifier); - int32_t Unsubscribe(ProfileEvent profileEvent, const sptr& profileEventNotifier); void OnSubscriberDied(const sptr& profileEventNotifier); protected: diff --git a/old/services/core/src/subscribemanager/profile_sync_handler.cpp b/old/services/core/src/subscribemanager/profile_sync_handler.cpp index 227c3e68..16c76790 100644 --- a/old/services/core/src/subscribemanager/profile_sync_handler.cpp +++ b/old/services/core/src/subscribemanager/profile_sync_handler.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include #include "profile_sync_handler.h" #include "device_profile_log.h" -- Gitee