From 31c0a2e55703ffe454b81185a9b519ba6991e83c Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Mon, 19 May 2025 12:00:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B9=BF=E6=92=AD=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- .../relationship_sync_mgr.h | 2 +- .../relationship_sync_mgr.cpp | 83 ++++++++++--------- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index 9ad048763..1c9279a69 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -90,7 +90,7 @@ struct RelationShipChangeMsg { bool FromDelUserPayLoad(const cJSON *payloadJson); bool FromStopUserPayLoad(const cJSON *payloadJson); bool FromShareUnbindPayLoad(const cJSON *payloadJson); - void GetBroadCastId(const cJSON *payloadJson, uint32_t userIdNum); + bool GetBroadCastId(const cJSON *payloadJson, uint32_t userIdNum); std::string ToJson() const; bool FromJson(const std::string &msgJson); diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index e0dbb9dd3..428531518 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -16,6 +16,7 @@ #include "relationship_sync_mgr.h" #include +#include #include "dm_anonymous.h" #include "dm_log.h" @@ -38,8 +39,8 @@ namespace { const int32_t DEVICE_UNBIND_PAYLOAD_LEN = 3; /** * @brief app unbind payload length 6 bytes - * | 2 bytes | 4 bytes | 1 bytes | - * | userid lower 2 bytes | token id lower 4 bytes | broadcastId | + * | 2 bytes | 4 bytes | 4 bytes | 1 bytes | + * | userid lower 2 bytes | token id lower 4 bytes | peertoken id lower 4 bytes | broadcastId | */ const int32_t APP_UNBIND_PAYLOAD_LEN = 11; /** @@ -558,14 +559,15 @@ bool RelationShipChangeMsg::FromServiceUnbindPayLoad(const cJSON *payloadJson) return FromAppUnbindPayLoad(payloadJson); } -void RelationShipChangeMsg::GetBroadCastId(const cJSON *payloadJson, uint32_t userIdNum) +bool RelationShipChangeMsg::GetBroadCastId(const cJSON *payloadJson, uint32_t userIdNum) { broadCastId = 0; cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, userIdNum * USERID_BYTES + 1); - CHECK_NULL_VOID(payloadItem); + CHECK_NULL_RETURN(payloadItem, true); if (cJSON_IsNumber(payloadItem)) { broadCastId |= static_cast(payloadItem->valueint); } + return true; } bool RelationShipChangeMsg::FromSyncFrontOrBackUserIdPayLoad(const cJSON *payloadJson) @@ -621,8 +623,7 @@ bool RelationShipChangeMsg::FromSyncFrontOrBackUserIdPayLoad(const cJSON *payloa isForegroundUser = false; } } - GetBroadCastId(payloadJson, userIdNum); - return true; + return GetBroadCastId(payloadJson, userIdNum); } bool RelationShipChangeMsg::FromDelUserPayLoad(const cJSON *payloadJson) @@ -819,19 +820,19 @@ bool RelationShipChangeMsg::FromJson(const std::string &msgJson) const std::string RelationShipChangeMsg::ToMapKey() const { - std::string ret; + std::ostringstream ret; std::string isNewEventStr = isNewEvent ? "true" : "false"; - ret += "_" + std::to_string(static_cast(type)); - ret += "_" + isNewEventStr; - ret += "_" + std::to_string(userId); - ret += "_" + GetAnonyString(accountId); - ret += "_" + GetAnonyString(peerUdid); - ret += "_" + std::to_string(tokenId); - ret += "_" + std::to_string(peerTokenId); - ret += "_" + GetUserIdInfoList(userIdInfos); - ret += "_" + std::to_string(syncUserIdFlag); - ret += "_" + credId; - return ret; + ret << "_" << std::to_string(static_cast(type)); + ret << "_" << isNewEventStr; + ret << "_" << std::to_string(userId); + ret << "_" << GetAnonyString(accountId); + ret << "_" << GetAnonyString(peerUdid); + ret << "_" << std::to_string(tokenId); + ret << "_" << std::to_string(peerTokenId); + ret << "_" << GetUserIdInfoList(userIdInfos); + ret << "_" << std::to_string(syncUserIdFlag); + ret << "_" << credId; + return ret.str(); } void ReleationShipSyncMgr::HandleRecvBroadCastTimeout(const std::string &key) @@ -845,13 +846,15 @@ void ReleationShipSyncMgr::HandleRecvBroadCastTimeout(const std::string &key) bool ReleationShipSyncMgr::GetCurrentTimeSec(int32_t &sec) { - time_t now = time(0); - tm *ltm = localtime(&now); - if (ltm == nullptr) { + time_t now; + time(&now); + struct tm ltm; + struct tm *res = localtime_r(&now, <m); + if (res == nullptr) { LOGE("get current time failed."); return false; } - sec = ltm->tm_sec % CURRENT_TIME_SEC_FLAG; + sec = ltm.tm_sec % CURRENT_TIME_SEC_FLAG; return true; } @@ -897,34 +900,36 @@ bool ReleationShipSyncMgr::IsNewBroadCastId(const RelationShipChangeMsg &msg) ReleationShipSyncMgr::HandleRecvBroadCastTimeout(key); }); return true; + } else { + return false; } return false; } const std::string RelationShipChangeMsg::ToString() const { - std::string ret; + std::ostringstream ret; std::string isNewEventStr = isNewEvent ? "true" : "false"; - ret += "{ MsgType: " + std::to_string(static_cast(type)); - ret += "{ isNewEvent: " + isNewEventStr; - ret += ", userId: " + std::to_string(userId); - ret += ", accountId: " + GetAnonyString(accountId); - ret += ", tokenId: " + std::to_string(tokenId); - ret += ", peerUdids: " + GetAnonyStringList(peerUdids); - ret += ", peerUdid: " + GetAnonyString(peerUdid); - ret += ", accountName: " + GetAnonyString(accountName); - ret += ", syncUserIdFlag: " + std::to_string(syncUserIdFlag); - ret += ", userIds: " + GetUserIdInfoList(userIdInfos); - ret += ", broadCastId: " + std::to_string(broadCastId) + " }"; - return ret; + ret << "{ MsgType: " << std::to_string(static_cast(type)); + ret << "{ isNewEvent: " << isNewEventStr; + ret << ", userId: " << std::to_string(userId); + ret << ", accountId: " << GetAnonyString(accountId); + ret << ", tokenId: " << std::to_string(tokenId); + ret << ", peerUdids: " << GetAnonyStringList(peerUdids); + ret << ", peerUdid: " << GetAnonyString(peerUdid); + ret << ", accountName: " << GetAnonyString(accountName); + ret << ", syncUserIdFlag: " << std::to_string(syncUserIdFlag); + ret << ", userIds: " << GetUserIdInfoList(userIdInfos); + ret << ", broadCastId: " << std::to_string(broadCastId) << " }"; + return ret.str(); } const std::string UserIdInfo::ToString() const { - std::string ret; - ret += "{ " + std::to_string(this->isForeground); - ret += ", userId: " + std::to_string(this->userId) + " }"; - return ret; + std::ostringstream ret; + ret << "{ " << std::to_string(this->isForeground); + ret << ", userId: " << std::to_string(this->userId) << " }"; + return ret.str(); } const std::string GetUserIdInfoList(const std::vector &list) -- Gitee