From 1dcea0ecb58692bfe364b4b597d7bb779a50f89a Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 16:27:04 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../dependency/softbus/softbus_connector.cpp | 38 +++++++++++++++---- .../devicestate/dm_device_state_manager.cpp | 2 - 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 4ece01e32..93f77db92 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -17,6 +17,8 @@ #include #include +#include +#include #include "dm_anonymous.h" #include "dm_constants.h" @@ -47,6 +49,30 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeOffline = SoftbusConnector::OnSoftbusDeviceOffline, .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; +void DeviceOnLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo) +{ + LOGI("Device on line start"); + std::mutex lockDeviceOnLine; + std::lock_guard lock(lockDeviceOnLine); + for (auto &iter : stateCallbackMap) { + iter.second->OnDeviceOnline(iter.first, deviceInfo); + } + LOGI("Device on line end"); +} + +void DeviceOffLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo) +{ + LOGI("Device off line start"); + std::mutex lockDeviceOffLine; + std::lock_guard lock(lockDeviceOffLine); + for (auto &iter : stateCallbackMap) { + iter.second->OnDeviceOffline(iter.first, deviceInfo); + } + LOGI("Device off line end"); +} + SoftbusConnector::SoftbusConnector() { softbusSession_ = std::make_shared(); @@ -445,9 +471,8 @@ void SoftbusConnector::OnSoftBusDeviceOnline(NodeBasicInfo *info) DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); - for (auto &iter : stateCallbackMap_) { - iter.second->OnDeviceOnline(iter.first, dmDeviceInfo); - } + std::thread deviceOnLine(DeviceOnLine, stateCallbackMap_, dmDeviceInfo); + deviceOnLine.detach(); if (discoveryDeviceInfoMap_.empty()) { return; @@ -473,9 +498,8 @@ void SoftbusConnector::OnSoftbusDeviceOffline(NodeBasicInfo *info) } DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); - for (auto &iter : stateCallbackMap_) { - iter.second->OnDeviceOffline(iter.first, dmDeviceInfo); - } + std::thread deviceOffLine(DeviceOffLine, stateCallbackMap_, dmDeviceInfo); + deviceOffLine.detach(); } void SoftbusConnector::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) @@ -556,4 +580,4 @@ void SoftbusConnector::OnParameterChgCallback(const char *key, const char *value } } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 98ba3c7f2..9318bd0ab 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -87,8 +87,6 @@ void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmD if (profileAdapter == nullptr) { LOGE("OnDeviceOffline profile adapter is null"); } else { - std::string uuid; - SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); if (iter == remoteDeviceInfos_.end()) { } else { -- Gitee From b1d1ee1c8c8b3767674d083afbca4b6a47a32da9 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 16:48:14 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 93f77db92..5d6d2e480 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; @@ -62,7 +62,7 @@ void DeviceOnLine(std::map> } void DeviceOffLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device off line start"); std::mutex lockDeviceOffLine; -- Gitee From d1443587fe5a9f68d4c839e2a51e41b67b2a3521 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 16:54:23 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 5d6d2e480..ab6b70fff 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; @@ -62,7 +62,7 @@ void DeviceOnLine(std::map> } void DeviceOffLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device off line start"); std::mutex lockDeviceOffLine; -- Gitee From cd460218ddd002aea7a2d03afa53e57aadd79548 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 17:12:03 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index ab6b70fff..530938ab2 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; -- Gitee From b76158e998bddc9614a409035eee29917acada3b Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 17:19:12 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 530938ab2..f3278fe8e 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; @@ -62,7 +62,7 @@ void DeviceOnLine(std::map> } void DeviceOffLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device off line start"); std::mutex lockDeviceOffLine; -- Gitee From 1c7714886b3619ad8f677d114730e24e1512e0a0 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 19:04:23 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=B5=8B=E8=AF=95stop=20?= =?UTF-8?q?timer=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/authentication/dm_auth_manager.cpp | 17 ++++++++------- .../src/dependency/timer/dm_timer.cpp | 21 ++++++------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index e759e8c4b..4188f510d 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -176,7 +176,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) { LOGI("DmAuthManager::VerifyAuthentication"); std::shared_ptr ptr; - if (authenticationMap_.find(1) == authenticationMap_.end() && timerMap_[INPUT_TIMEOUT_TASK] == nullptr) { + if (authenticationMap_.find(1) == authenticationMap_.end() + || timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return DM_FAILED; } @@ -270,7 +271,7 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) switch (authResponseContext_->msgType) { case MSG_TYPE_NEGOTIATE: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT - && timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] != nullptr) { + && timerMap_.find(WAIT_NEGOTIATE_TIMEOUT_TASK) != timerMap_.end()) { timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseState_->TransitionTo(std::make_shared()); } else { @@ -279,7 +280,7 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) break; case MSG_TYPE_REQ_AUTH: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE - && timerMap_[WAIT_REQUEST_TIMEOUT_TASK] != nullptr) { + && timerMap_.find(WAIT_REQUEST_TIMEOUT_TASK) != timerMap_.end()) { timerMap_[WAIT_REQUEST_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseState_->TransitionTo(std::make_shared()); } else { @@ -339,7 +340,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) { LOGE("DmAuthManager OnMemberJoin start"); - if (authRequestState_ != nullptr && timerMap_[ADD_TIMEOUT_TASK] != nullptr) { + if (authRequestState_ != nullptr && timerMap_.find(ADD_TIMEOUT_TASK) != timerMap_.end()) { timerMap_[ADD_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (status != DM_OK || authResponseContext_->requestId != requestId) { if (authRequestState_ != nullptr) { @@ -446,7 +447,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) void DmAuthManager::SendAuthRequest(const int32_t &sessionId) { LOGE("DmAuthManager::EstablishAuthChannel session id"); - if (timerMap_[NEGOTIATE_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(NEGOTIATE_TIMEOUT_TASK) == timerMap_.end()) { return; } timerMap_[NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); @@ -484,7 +485,7 @@ int32_t DmAuthManager::StartAuthProcess(const int32_t &action) void DmAuthManager::StartRespAuthProcess() { LOGI("DmAuthManager::StartRespAuthProcess StartRespAuthProcess", authResponseContext_->sessionId); - if (timerMap_[CONFIRM_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(CONFIRM_TIMEOUT_TASK) == timerMap_.end()) { return; } timerMap_[CONFIRM_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); @@ -543,7 +544,7 @@ std::string DmAuthManager::GetConnectAddr(std::string deviceId) int32_t DmAuthManager::JoinNetwork() { LOGE("DmAuthManager JoinNetwork start"); - if (timerMap_[AUTHENTICATE_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(AUTHENTICATE_TIMEOUT_TASK) == timerMap_.end()) { return DM_FAILED; } timerMap_[AUTHENTICATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); @@ -798,7 +799,7 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) { LOGI("DmAuthManager::VerifyPinAuthAuthentication"); - if (timerMap_[INPUT_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { return; } timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index 329ee54b9..897800efe 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -92,7 +92,6 @@ void DmTimer::Stop(int32_t code) } LOGI("DmTimer %s Stop success", mTimerName_.c_str()); } - return; } @@ -107,14 +106,8 @@ void DmTimer::WaitForTimeout() int32_t nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); if (nfds < 0) { LOGE("DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno); - if (errno == EINTR) { - LOGI("DmTimer is stop"); - return; - } - } - - char event = 0; - if (nfds > 0) { + } else if (nfds > 0) { + char event = 0; if (mEvents_[0].events & EPOLLIN) { int num = read(mTimeFd_[0], &event, 1); if (num > 0) { @@ -124,13 +117,11 @@ void DmTimer::WaitForTimeout() } } Release(); - return; + } else { + mHandle_(mHandleData_, *this); + Release(); + LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); } - - mHandle_(mHandleData_, *this); - Release(); - - LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); return; } -- Gitee