From 2fe5fffee625f497d4af321788f0a343102bae30 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Mon, 19 Feb 2024 20:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E6=AD=A5=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=BC=95=E8=B5=B7=E5=81=B6=E7=8E=B0crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../src/distributed_input_source_manager.cpp | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 8f89121..9bf8c8c 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -1201,15 +1201,22 @@ void DistributedInputSourceManager::RunRelayPrepareCallback(const std::string &s { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK); std::lock_guard lock(prepareMutex_); + bool isCbRun = false; + sptr cb = nullptr; for (auto iter = relayPreCallbacks_.begin(); iter != relayPreCallbacks_.end(); ++iter) { if (iter->srcId == srcId && iter->sinkId == sinkId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI"); - iter->preCallback->OnResult(sinkId, status); + cb = iter->preCallback; relayPreCallbacks_.erase(iter); - return; + isCbRun = true; + break; } } - DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI relayPreCallbacks_ is null."); + if (isCbRun && cb != nullptr) { + cb->OnResult(sinkId, status); + } else { + DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI relayPreCallbacks_ is null."); + } } void DistributedInputSourceManager::RunRelayUnprepareCallback(const std::string &srcId, const std::string &sinkId, @@ -1217,15 +1224,22 @@ void DistributedInputSourceManager::RunRelayUnprepareCallback(const std::string { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK); std::lock_guard lock(prepareMutex_); + bool isCbRun = false; + sptr cb = nullptr; for (auto iter = relayUnpreCallbacks_.begin(); iter != relayUnpreCallbacks_.end(); ++iter) { if (iter->srcId == srcId && iter->sinkId == sinkId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI"); - iter->unpreCallback->OnResult(sinkId, status); + cb = iter->unpreCallback; relayUnpreCallbacks_.erase(iter); - return; + isCbRun = true; + break; } } - DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI relayUnpreCallbacks_ is null."); + if (isCbRun && cb != nullptr) { + cb->OnResult(sinkId, status); + } else { + DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI relayUnpreCallbacks_ is null."); + } } void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devId, const int32_t &status) @@ -1330,18 +1344,20 @@ void DistributedInputSourceManager::RunRelayStartDhidCallback(const std::string DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI dhIds:%s, vec-size:%d", dhids.c_str(), dhidsVec.size()); bool isCbRun = false; - for (std::vector::iterator iter = relayStaDhidCallbacks_.begin(); - iter != relayStaDhidCallbacks_.end(); ++iter) { + sptr cb = nullptr; + for (auto iter = relayStaDhidCallbacks_.begin(); iter != relayStaDhidCallbacks_.end(); ++iter) { if (iter->srcId != srcId || iter->sinkId != sinkId || !IsStringDataSame(iter->dhIds, dhidsVec)) { continue; } DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI call OnResultDhids"); - iter->callback->OnResultDhids(sinkId, status); + cb = iter->callback; relayStaDhidCallbacks_.erase(iter); isCbRun = true; break; } - if (!isCbRun) { + if (isCbRun && cb != nullptr) { + cb->OnResultDhids(sinkId, status); + } else { DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI relayStaDhidCallbacks_ is null."); } } @@ -1352,18 +1368,20 @@ void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string & std::vector dhidsVec; SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec); bool isCbRun = false; - for (std::vector::iterator iter = relayStpDhidCallbacks_.begin(); - iter != relayStpDhidCallbacks_.end(); ++iter) { + sptr cb = nullptr; + for (auto iter = relayStpDhidCallbacks_.begin(); iter != relayStpDhidCallbacks_.end(); ++iter) { if (iter->srcId != srcId || iter->sinkId != sinkId || !IsStringDataSame(iter->dhIds, dhidsVec)) { continue; } DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI call OnResultDhids"); - iter->callback->OnResultDhids(sinkId, status); + cb = iter->callback; relayStpDhidCallbacks_.erase(iter); isCbRun = true; break; } - if (!isCbRun) { + if (isCbRun && cb != nullptr) { + cb->OnResultDhids(sinkId, status); + } else { DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI relayStpDhidCallbacks_ is null."); } } -- Gitee