From 73b87bd5f0fc046aaa5c4ebe819a1ff817fb1eb1 Mon Sep 17 00:00:00 2001 From: yangli Date: Sat, 6 May 2023 16:13:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E7=AB=9E=E4=BA=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli --- .../include/callback/dscreen_source_callback.h | 3 +++ .../screen_source/src/callback/dscreen_source_callback.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback.h b/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback.h index 1a463157..633c1084 100644 --- a/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback.h +++ b/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "idistributed_hardware_source.h" @@ -42,6 +43,8 @@ public: void PopUnregisterCallback(const std::string &reqId); private: + std::mutex registerMutex_; + std::mutex unregisterMutex_; std::map> registerCallbackMap_; std::map> unregisterCallbackMap_; }; diff --git a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp index 1b551704..2af5d905 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp @@ -26,6 +26,7 @@ int32_t DScreenSourceCallback::OnNotifyRegResult(const std::string &devId, const { DHLOGI("DScreenSourceCallback OnNotifyRegResult devId: %s dhId: %s status: %" PRId32, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status); + std::lock_guard lock(registerMutex_); const auto iter = registerCallbackMap_.find(reqId); if (iter != registerCallbackMap_.end()) { if (iter->second == nullptr) { @@ -45,6 +46,7 @@ int32_t DScreenSourceCallback::OnNotifyUnregResult(const std::string &devId, con { DHLOGI("DScreenSourceCallback OnNotifyUnregResult devId: %s dhId: %s status: %" PRId32, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status); + std::lock_guard lock(unregisterMutex_); const auto iter = unregisterCallbackMap_.find(reqId); if (iter != unregisterCallbackMap_.end()) { if (iter->second == nullptr) { @@ -63,12 +65,14 @@ void DScreenSourceCallback::PushRegRegisterCallback(const std::string &reqId, const std::shared_ptr &callback) { DHLOGD("PushRegRegisterCallback"); + std::lock_guard lock(registerMutex_); registerCallbackMap_.emplace(reqId, callback); } void DScreenSourceCallback::PopRegRegisterCallback(const std::string &reqId) { DHLOGD("PopRegRegisterCallback"); + std::lock_guard lock(registerMutex_); registerCallbackMap_.erase(reqId); } @@ -76,12 +80,14 @@ void DScreenSourceCallback::PushUnregisterCallback(const std::string &reqId, const std::shared_ptr &callback) { DHLOGD("PushUnregisterCallback"); + std::lock_guard lock(unregisterMutex_); unregisterCallbackMap_.emplace(reqId, callback); } void DScreenSourceCallback::PopUnregisterCallback(const std::string &reqId) { DHLOGD("PopUnregisterCallback"); + std::lock_guard lock(unregisterMutex_); unregisterCallbackMap_.erase(reqId); } } -- Gitee From 9a4941b02a079feb196f118ed2da58eca70a2c42 Mon Sep 17 00:00:00 2001 From: yangli Date: Mon, 8 May 2023 17:19:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangli --- .../screensourcetest/src/dscreen_source_handler_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp index 7022c6c5..63ae0089 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp @@ -84,6 +84,7 @@ HWTEST_F(DScreenSourceHandlerTest, RegisterDistributedHardware_001, TestSize.Lev param.version = "1.0"; param.attrs = "attrs"; std::string callbackParam = "callbackParam"; + DScreenSourceHandler::GetInstance().InitSource("DScreenSourceHandlerTest"); sptr loadCallback = new DScreenSourceLoadCallback(callbackParam); loadCallback->OnLoadSystemAbilitySuccess(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, nullptr); std::shared_ptr callback = std::make_shared(); -- Gitee