From d3af6d9d511050ff842c7f89e6da6b3d6e0b9213 Mon Sep 17 00:00:00 2001 From: "xiaocong.ran" Date: Tue, 1 Mar 2022 18:01:26 +0800 Subject: [PATCH] timer Signed-off-by: xiaocong.ran Change-Id: I3b96d1b47ad3bdecc35652fff0078ef39cca5209 --- .../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