From e76cf7290d5b0dbf5fe7ce4553680e28a65c7f9f Mon Sep 17 00:00:00 2001 From: wangzhen Date: Thu, 14 Dec 2023 16:00:35 +0800 Subject: [PATCH] =?UTF-8?q?AddConnection/RemoveConnection=E5=8A=A0?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhen --- .../abilitymgr/include/connection_state_item.h | 4 ++-- .../include/connection_state_manager.h | 8 ++++---- .../abilitymgr/src/connection_state_item.cpp | 17 ++++++++++------- .../abilitymgr/src/connection_state_manager.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/services/abilitymgr/include/connection_state_item.h b/services/abilitymgr/include/connection_state_item.h index 63226fd0b5..6a158817d8 100644 --- a/services/abilitymgr/include/connection_state_item.h +++ b/services/abilitymgr/include/connection_state_item.h @@ -63,7 +63,7 @@ public: * @param data output relationship data. * @return Returns true if need report relationship. */ - bool AddConnection(const std::shared_ptr &record, AbilityRuntime::ConnectionData &data); + bool AddConnection(std::shared_ptr record, AbilityRuntime::ConnectionData &data); /** * remove a connection to target extension. @@ -72,7 +72,7 @@ public: * @param data output relationship data. * @return Returns true if need report relationship. */ - bool RemoveConnection(const std::shared_ptr &record, AbilityRuntime::ConnectionData &data); + bool RemoveConnection(std::shared_ptr record, AbilityRuntime::ConnectionData &data); /** * add a connection to target data ability. diff --git a/services/abilitymgr/include/connection_state_manager.h b/services/abilitymgr/include/connection_state_manager.h index 16a3d56dfc..918a5e95a4 100644 --- a/services/abilitymgr/include/connection_state_manager.h +++ b/services/abilitymgr/include/connection_state_manager.h @@ -71,7 +71,7 @@ public: * * @param connectionRecord connection record info. */ - void AddConnection(const std::shared_ptr &connectionRecord); + void AddConnection(std::shared_ptr connectionRecord); /** * remove an connection. @@ -79,7 +79,7 @@ public: * @param connectionRecord connection record info. * @param isCallerDied whether caller was died. */ - void RemoveConnection(const std::shared_ptr &connectionRecord, bool isCallerDied); + void RemoveConnection(std::shared_ptr connectionRecord, bool isCallerDied); /** * add a data ability acquired information to manager. @@ -189,9 +189,9 @@ private: ProcessDiedHandler handler_; }; - bool AddConnectionInner(const std::shared_ptr &connectionRecord, + bool AddConnectionInner(std::shared_ptr connectionRecord, AbilityRuntime::ConnectionData &data); - bool RemoveConnectionInner(const std::shared_ptr &connectionRecord, + bool RemoveConnectionInner(std::shared_ptr connectionRecord, AbilityRuntime::ConnectionData &data); bool AddDataAbilityConnectionInner(const DataAbilityCaller &caller, const std::shared_ptr &record, AbilityRuntime::ConnectionData &data); diff --git a/services/abilitymgr/src/connection_state_item.cpp b/services/abilitymgr/src/connection_state_item.cpp index 0946fdbc0f..3652891109 100644 --- a/services/abilitymgr/src/connection_state_item.cpp +++ b/services/abilitymgr/src/connection_state_item.cpp @@ -25,7 +25,7 @@ namespace AAFwk { */ class ConnectedExtension : public std::enable_shared_from_this { public: - static std::shared_ptr CreateConnectedExtension(const std::shared_ptr &record) + static std::shared_ptr CreateConnectedExtension(std::shared_ptr record) { if (!record) { return nullptr; @@ -44,7 +44,7 @@ public: extensionType_ = AppExecFwk::ExtensionAbilityType::UNSPECIFIED; } - explicit ConnectedExtension(const std::shared_ptr &target) + explicit ConnectedExtension(std::shared_ptr target) { if (!target) { return; @@ -59,24 +59,25 @@ public: virtual ~ConnectedExtension() = default; - bool AddConnection(const sptr &connection) + bool AddConnection(sptr connection) { if (!connection) { return false; } + std::lock_guard guard(connectionsMutex_); bool needNotify = connections_.empty(); connections_.emplace(connection); return needNotify; } - bool RemoveConnection(const sptr &connection) + bool RemoveConnection(sptr connection) { if (!connection) { return false; } - + std::lock_guard guard(connectionsMutex_); connections_.erase(connection); return connections_.empty(); } @@ -98,6 +99,8 @@ private: std::string extensionModuleName_; std::string extensionName_; AppExecFwk::ExtensionAbilityType extensionType_; + + std::mutex connectionsMutex_; std::set> connections_; // remote object of IAbilityConnection }; @@ -251,7 +254,7 @@ std::shared_ptr ConnectionStateItem::CreateConnectionStateI dataCaller.callerPid, dataCaller.callerName); } -bool ConnectionStateItem::AddConnection(const std::shared_ptr &record, +bool ConnectionStateItem::AddConnection(std::shared_ptr record, AbilityRuntime::ConnectionData &data) { if (!record) { @@ -295,7 +298,7 @@ bool ConnectionStateItem::AddConnection(const std::shared_ptr return needNotify; } -bool ConnectionStateItem::RemoveConnection(const std::shared_ptr &record, +bool ConnectionStateItem::RemoveConnection(std::shared_ptr record, AbilityRuntime::ConnectionData &data) { if (!record) { diff --git a/services/abilitymgr/src/connection_state_manager.cpp b/services/abilitymgr/src/connection_state_manager.cpp index 3ae54326d8..74d676dd2c 100644 --- a/services/abilitymgr/src/connection_state_manager.cpp +++ b/services/abilitymgr/src/connection_state_manager.cpp @@ -92,7 +92,7 @@ int ConnectionStateManager::UnregisterObserver(const sptr &connectionRecord) +void ConnectionStateManager::AddConnection(std::shared_ptr connectionRecord) { std::shared_ptr controller = observerController_; if (!controller) { @@ -112,7 +112,7 @@ void ConnectionStateManager::AddConnection(const std::shared_ptrNotifyExtensionConnected(connectionData); } -void ConnectionStateManager::RemoveConnection(const std::shared_ptr &connectionRecord, +void ConnectionStateManager::RemoveConnection(std::shared_ptr connectionRecord, bool isCallerDied) { std::shared_ptr controller = observerController_; @@ -320,7 +320,7 @@ void ConnectionStateManager::GetConnectionData(std::vector &connectionRecord, +bool ConnectionStateManager::AddConnectionInner(std::shared_ptr connectionRecord, AbilityRuntime::ConnectionData &data) { std::shared_ptr targetItem = nullptr; @@ -344,7 +344,7 @@ bool ConnectionStateManager::AddConnectionInner(const std::shared_ptrAddConnection(connectionRecord, data); } -bool ConnectionStateManager::RemoveConnectionInner(const std::shared_ptr &connectionRecord, +bool ConnectionStateManager::RemoveConnectionInner(std::shared_ptr connectionRecord, AbilityRuntime::ConnectionData &data) { auto callerPid = connectionRecord->GetCallerPid();