mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
AddConnection/RemoveConnection加锁
Signed-off-by: wangzhen <wangzhen346@huawei.com>
This commit is contained in:
parent
5ec884e124
commit
e76cf7290d
@ -63,7 +63,7 @@ public:
|
||||
* @param data output relationship data.
|
||||
* @return Returns true if need report relationship.
|
||||
*/
|
||||
bool AddConnection(const std::shared_ptr<ConnectionRecord> &record, AbilityRuntime::ConnectionData &data);
|
||||
bool AddConnection(std::shared_ptr<ConnectionRecord> 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<ConnectionRecord> &record, AbilityRuntime::ConnectionData &data);
|
||||
bool RemoveConnection(std::shared_ptr<ConnectionRecord> record, AbilityRuntime::ConnectionData &data);
|
||||
|
||||
/**
|
||||
* add a connection to target data ability.
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
*
|
||||
* @param connectionRecord connection record info.
|
||||
*/
|
||||
void AddConnection(const std::shared_ptr<ConnectionRecord> &connectionRecord);
|
||||
void AddConnection(std::shared_ptr<ConnectionRecord> 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> &connectionRecord, bool isCallerDied);
|
||||
void RemoveConnection(std::shared_ptr<ConnectionRecord> 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> &connectionRecord,
|
||||
bool AddConnectionInner(std::shared_ptr<ConnectionRecord> connectionRecord,
|
||||
AbilityRuntime::ConnectionData &data);
|
||||
bool RemoveConnectionInner(const std::shared_ptr<ConnectionRecord> &connectionRecord,
|
||||
bool RemoveConnectionInner(std::shared_ptr<ConnectionRecord> connectionRecord,
|
||||
AbilityRuntime::ConnectionData &data);
|
||||
bool AddDataAbilityConnectionInner(const DataAbilityCaller &caller,
|
||||
const std::shared_ptr<DataAbilityRecord> &record, AbilityRuntime::ConnectionData &data);
|
||||
|
@ -25,7 +25,7 @@ namespace AAFwk {
|
||||
*/
|
||||
class ConnectedExtension : public std::enable_shared_from_this<ConnectedExtension> {
|
||||
public:
|
||||
static std::shared_ptr<ConnectedExtension> CreateConnectedExtension(const std::shared_ptr<ConnectionRecord> &record)
|
||||
static std::shared_ptr<ConnectedExtension> CreateConnectedExtension(std::shared_ptr<ConnectionRecord> record)
|
||||
{
|
||||
if (!record) {
|
||||
return nullptr;
|
||||
@ -44,7 +44,7 @@ public:
|
||||
extensionType_ = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
|
||||
}
|
||||
|
||||
explicit ConnectedExtension(const std::shared_ptr<AbilityRecord> &target)
|
||||
explicit ConnectedExtension(std::shared_ptr<AbilityRecord> target)
|
||||
{
|
||||
if (!target) {
|
||||
return;
|
||||
@ -59,24 +59,25 @@ public:
|
||||
|
||||
virtual ~ConnectedExtension() = default;
|
||||
|
||||
bool AddConnection(const sptr<IRemoteObject> &connection)
|
||||
bool AddConnection(sptr<IRemoteObject> connection)
|
||||
{
|
||||
if (!connection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard guard(connectionsMutex_);
|
||||
bool needNotify = connections_.empty();
|
||||
connections_.emplace(connection);
|
||||
|
||||
return needNotify;
|
||||
}
|
||||
|
||||
bool RemoveConnection(const sptr<IRemoteObject> &connection)
|
||||
bool RemoveConnection(sptr<IRemoteObject> 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<sptr<IRemoteObject>> connections_; // remote object of IAbilityConnection
|
||||
};
|
||||
|
||||
@ -251,7 +254,7 @@ std::shared_ptr<ConnectionStateItem> ConnectionStateItem::CreateConnectionStateI
|
||||
dataCaller.callerPid, dataCaller.callerName);
|
||||
}
|
||||
|
||||
bool ConnectionStateItem::AddConnection(const std::shared_ptr<ConnectionRecord> &record,
|
||||
bool ConnectionStateItem::AddConnection(std::shared_ptr<ConnectionRecord> record,
|
||||
AbilityRuntime::ConnectionData &data)
|
||||
{
|
||||
if (!record) {
|
||||
@ -295,7 +298,7 @@ bool ConnectionStateItem::AddConnection(const std::shared_ptr<ConnectionRecord>
|
||||
return needNotify;
|
||||
}
|
||||
|
||||
bool ConnectionStateItem::RemoveConnection(const std::shared_ptr<ConnectionRecord> &record,
|
||||
bool ConnectionStateItem::RemoveConnection(std::shared_ptr<ConnectionRecord> record,
|
||||
AbilityRuntime::ConnectionData &data)
|
||||
{
|
||||
if (!record) {
|
||||
|
@ -92,7 +92,7 @@ int ConnectionStateManager::UnregisterObserver(const sptr<AbilityRuntime::IConne
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConnectionStateManager::AddConnection(const std::shared_ptr<ConnectionRecord> &connectionRecord)
|
||||
void ConnectionStateManager::AddConnection(std::shared_ptr<ConnectionRecord> connectionRecord)
|
||||
{
|
||||
std::shared_ptr<ConnectionObserverController> controller = observerController_;
|
||||
if (!controller) {
|
||||
@ -112,7 +112,7 @@ void ConnectionStateManager::AddConnection(const std::shared_ptr<ConnectionRecor
|
||||
controller->NotifyExtensionConnected(connectionData);
|
||||
}
|
||||
|
||||
void ConnectionStateManager::RemoveConnection(const std::shared_ptr<ConnectionRecord> &connectionRecord,
|
||||
void ConnectionStateManager::RemoveConnection(std::shared_ptr<ConnectionRecord> connectionRecord,
|
||||
bool isCallerDied)
|
||||
{
|
||||
std::shared_ptr<ConnectionObserverController> controller = observerController_;
|
||||
@ -320,7 +320,7 @@ void ConnectionStateManager::GetConnectionData(std::vector<AbilityRuntime::Conne
|
||||
HILOG_DEBUG("GetConnectionData: %{public}zu", connectionData.size());
|
||||
}
|
||||
|
||||
bool ConnectionStateManager::AddConnectionInner(const std::shared_ptr<ConnectionRecord> &connectionRecord,
|
||||
bool ConnectionStateManager::AddConnectionInner(std::shared_ptr<ConnectionRecord> connectionRecord,
|
||||
AbilityRuntime::ConnectionData &data)
|
||||
{
|
||||
std::shared_ptr<ConnectionStateItem> targetItem = nullptr;
|
||||
@ -344,7 +344,7 @@ bool ConnectionStateManager::AddConnectionInner(const std::shared_ptr<Connection
|
||||
return targetItem->AddConnection(connectionRecord, data);
|
||||
}
|
||||
|
||||
bool ConnectionStateManager::RemoveConnectionInner(const std::shared_ptr<ConnectionRecord> &connectionRecord,
|
||||
bool ConnectionStateManager::RemoveConnectionInner(std::shared_ptr<ConnectionRecord> connectionRecord,
|
||||
AbilityRuntime::ConnectionData &data)
|
||||
{
|
||||
auto callerPid = connectionRecord->GetCallerPid();
|
||||
|
Loading…
Reference in New Issue
Block a user