From ba7d71aa10dd3fb516525b9f0ee3f25e010bfeb6 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Thu, 2 Dec 2021 01:46:51 +0800 Subject: [PATCH] Use Loop::Break/Continue instead of bool in visitor of ForEachActiveObject --- src/app/CASESessionManager.cpp | 8 ++--- src/app/InteractionModelEngine.cpp | 4 +-- src/channel/Manager.cpp | 4 +-- src/channel/Manager.h | 6 ++-- src/controller/CHIPDeviceController.cpp | 8 ++--- src/inet/InetLayer.h | 8 ++--- src/inet/TCPEndPoint.cpp | 12 ++++--- src/lib/support/Pool.cpp | 19 +++++----- src/lib/support/Pool.h | 40 ++++++++++++--------- src/lib/support/PoolWrapper.h | 13 +++---- src/lib/support/tests/TestPool.cpp | 16 ++++----- src/messaging/ExchangeMgr.cpp | 10 +++--- src/messaging/ReliableMessageMgr.cpp | 32 ++++++++--------- src/messaging/ReliableMessageMgr.h | 2 +- src/transport/SecureSessionTable.h | 8 ++--- src/transport/SessionManager.cpp | 20 +++++------ src/transport/SessionManager.h | 12 +++---- src/transport/UnauthenticatedSessionTable.h | 6 ++-- src/transport/raw/TCP.cpp | 6 ++-- 19 files changed, 123 insertions(+), 111 deletions(-) diff --git a/src/app/CASESessionManager.cpp b/src/app/CASESessionManager.cpp index f5c76239b2a04c..19cc27dc31c4fd 100644 --- a/src/app/CASESessionManager.cpp +++ b/src/app/CASESessionManager.cpp @@ -125,9 +125,9 @@ OperationalDeviceProxy * CASESessionManager::FindSession(SessionHandle session) if (activeSession->MatchesSession(session)) { foundSession = activeSession; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundSession; @@ -140,9 +140,9 @@ OperationalDeviceProxy * CASESessionManager::FindExistingSession(NodeId id) if (activeSession->GetDeviceId() == id) { foundSession = activeSession; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundSession; diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 2546c646e38b62..2916c60429ab6f 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -81,7 +81,7 @@ void InteractionModelEngine::Shutdown() // Increase magic number to invalidate all Handle-s. mMagic++; - mCommandHandlerObjs.ForEachActiveObject([this](CommandHandler * obj) -> bool { + mCommandHandlerObjs.ForEachActiveObject([this](CommandHandler * obj) -> Loop { // Modifying the pool during iteration is generally frowned upon. // This is almost safe since mCommandHandlerObjs is a BitMapObjectPool which won't malfunction when modifying the inner // record while during traversal. But this behavior is not guranteed, so we should fix this by implementing DeallocateAll. @@ -92,7 +92,7 @@ void InteractionModelEngine::Shutdown() // TODO(@kghost, #10332) Implement DeallocateAll and replace this. mCommandHandlerObjs.Deallocate(obj); - return true; + return Loop::Continue; }); for (auto & readClient : mReadClients) diff --git a/src/channel/Manager.cpp b/src/channel/Manager.cpp index e821ce2071d2ef..8cba97bd83b405 100644 --- a/src/channel/Manager.cpp +++ b/src/channel/Manager.cpp @@ -29,9 +29,9 @@ ChannelHandle ChannelManager::EstablishChannel(const ChannelBuilder & builder, C if (context->MatchesBuilder(builder)) { channelContext = context; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); if (channelContext == nullptr) diff --git a/src/channel/Manager.h b/src/channel/Manager.h index 588fa099834292..d44e6df872d93a 100644 --- a/src/channel/Manager.h +++ b/src/channel/Manager.h @@ -57,7 +57,7 @@ class DLL_EXPORT ChannelManager : public SessionCreationDelegate mChannelHandles.ForEachActiveObject([&](ChannelContextHandleAssociation * association) { if (association->mChannelContext == channel) event(association->mChannelDelegate); - return true; + return Loop::Continue; }); } @@ -67,9 +67,9 @@ class DLL_EXPORT ChannelManager : public SessionCreationDelegate if (context->MatchesSession(session, mExchangeManager->GetSessionManager())) { context->OnNewConnection(session); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index c5331f37b53324..05bfd31ba6a260 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -641,9 +641,9 @@ CommissioneeDeviceProxy * DeviceCommissioner::FindCommissioneeDevice(SessionHand if (deviceProxy->MatchesSession(session)) { foundDevice = deviceProxy; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundDevice; @@ -656,9 +656,9 @@ CommissioneeDeviceProxy * DeviceCommissioner::FindCommissioneeDevice(NodeId id) if (deviceProxy->GetDeviceId() == id) { foundDevice = deviceProxy; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundDevice; diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index 8200ec060e8f21..a028a76eee979a 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -50,7 +50,7 @@ class EndPointManager { public: using EndPoint = EndPointType; - using EndPointVisitor = bool (*)(EndPoint *); + using EndPointVisitor = Loop (*)(EndPoint *); EndPointManager() {} virtual ~EndPointManager() {} @@ -83,7 +83,7 @@ class EndPointManager virtual EndPoint * CreateEndPoint() = 0; virtual void DeleteEndPoint(EndPoint * endPoint) = 0; - virtual bool ForEachEndPoint(const EndPointVisitor visitor) = 0; + virtual Loop ForEachEndPoint(const EndPointVisitor visitor) = 0; private: System::Layer * mSystemLayer; @@ -101,9 +101,9 @@ class EndPointManagerImplPool : public EndPointManager(endPoint)); } - bool ForEachEndPoint(const typename Manager::EndPointVisitor visitor) override + Loop ForEachEndPoint(const typename Manager::EndPointVisitor visitor) override { - return sEndPointPool.ForEachActiveObject([&](EndPoint * endPoint) -> bool { return visitor(endPoint); }); + return sEndPointPool.ForEachActiveObject([&](EndPoint * endPoint) -> Loop { return visitor(endPoint); }); } private: diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp index 1eb693ef833b4d..d5f2428a66c33b 100644 --- a/src/inet/TCPEndPoint.cpp +++ b/src/inet/TCPEndPoint.cpp @@ -2522,11 +2522,11 @@ void TCPEndPoint::HandleIdleTimer(chip::System::Layer * aSystemLayer, void * aAp auto & endPointManager = *reinterpret_cast *>(aAppState); bool lTimerRequired = IsIdleTimerRunning(endPointManager); - endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) -> bool { + endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) -> Loop { if (!lEndPoint->IsConnected()) - return true; + return Loop::Continue; if (lEndPoint->mIdleTimeout == 0) - return true; + return Loop::Continue; if (lEndPoint->mRemainingIdleTime == 0) { @@ -2537,7 +2537,7 @@ void TCPEndPoint::HandleIdleTimer(chip::System::Layer * aSystemLayer, void * aAp --lEndPoint->mRemainingIdleTime; } - return true; + return Loop::Continue; }); if (lTimerRequired) @@ -2550,7 +2550,9 @@ void TCPEndPoint::HandleIdleTimer(chip::System::Layer * aSystemLayer, void * aAp bool TCPEndPoint::IsIdleTimerRunning(EndPointManager & endPointManager) { // See if there are any TCP connections with the idle timer check in use. - return !endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) { return (lEndPoint->mIdleTimeout == 0); }); + return Loop::Break == endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) { + return (lEndPoint->mIdleTimeout == 0) ? Loop::Continue : Loop::Break; + }); } #endif // INET_TCP_IDLE_CHECK_INTERVAL > 0 diff --git a/src/lib/support/Pool.cpp b/src/lib/support/Pool.cpp index ddb574a3bec0e1..a874da637b6212 100644 --- a/src/lib/support/Pool.cpp +++ b/src/lib/support/Pool.cpp @@ -84,7 +84,8 @@ size_t StaticAllocatorBitmap::IndexOf(void * element) return index; } -bool StaticAllocatorBitmap::ForEachActiveObjectInner(void * context, bool lambda(void * context, void * object)) +using Lambda = Loop(*)(void *, void *); +Loop StaticAllocatorBitmap::ForEachActiveObjectInner(void * context, Lambda lambda) { for (size_t word = 0; word * kBitChunkSize < Capacity(); ++word) { @@ -94,12 +95,12 @@ bool StaticAllocatorBitmap::ForEachActiveObjectInner(void * context, bool lambda { if ((value & (kBit1 << offset)) != 0) { - if (!lambda(context, At(word * kBitChunkSize + offset))) - return false; + if (lambda(context, At(word * kBitChunkSize + offset)) == Loop::Break) + return Loop::Break; } } } - return true; + return Loop::Finish; } #if CHIP_SYSTEM_CONFIG_POOL_USE_HEAP @@ -116,20 +117,20 @@ HeapObjectListNode * HeapObjectList::FindNode(void * object) const return nullptr; } -using Lambda = bool (*)(void *, void *); -bool HeapObjectList::ForEachNode(void * context, bool lambda(void * context, void * object)) +using Lambda = Loop(*)(void *, void *); +Loop HeapObjectList::ForEachNode(void * context, Lambda lambda) { ++mIterationDepth; - bool result = true; + Loop result = Loop::Finish; bool anyReleased = false; HeapObjectListNode * p = mNext; while (p != this) { if (p->mObject != nullptr) { - if (!lambda(context, p->mObject)) + if (lambda(context, p->mObject) == Loop::Break) { - result = false; + result = Loop::Break; break; } } diff --git a/src/lib/support/Pool.h b/src/lib/support/Pool.h index ec9540756af73f..6134be93409e37 100644 --- a/src/lib/support/Pool.h +++ b/src/lib/support/Pool.h @@ -32,6 +32,13 @@ namespace chip { +enum class Loop : uint8_t +{ + Continue, + Break, + Finish, +}; + namespace internal { class Statistics @@ -87,7 +94,7 @@ class StaticAllocatorBitmap : public internal::StaticAllocatorBase void * At(size_t index) { return static_cast(mElements) + mElementSize * index; } size_t IndexOf(void * element); - bool ForEachActiveObjectInner(void * context, bool lambda(void * context, void * object)); + Loop ForEachActiveObjectInner(void * context, Loop lambda(void * context, void * object)); private: void * mElements; @@ -112,7 +119,7 @@ class LambdaProxy { public: LambdaProxy(Function && function) : mFunction(std::move(function)) {} - static bool Call(void * context, void * target) + static Loop Call(void * context, void * target) { return static_cast(context)->mFunction(static_cast(target)); } @@ -150,7 +157,7 @@ struct HeapObjectList : HeapObjectListNode HeapObjectListNode * FindNode(void * object) const; - bool ForEachNode(void * context, bool lambda(void * context, void * object)); + Loop ForEachNode(void * context, Loop lambda(void * context, void * object)); size_t mIterationDepth; }; @@ -178,8 +185,8 @@ struct HeapObjectList : HeapObjectListNode * * @fn ForEachActiveObject * @memberof ObjectPool - * @param visitor A function that takes a T* and returns true to continue iterating or false to stop iterating. - * @returns false if a visitor call returned false, true otherwise. + * @param visitor A function that takes a T* and returns Loop::Continue to continue iterating or Loop::Break to stop iterating. + * @returns Loop::Break if a visitor call returned Loop::Break, Loop::Finish otherwise. * * Iteration may be nested. ReleaseObject() can be called during iteration, on the current object or any other. * CreateObject() can be called, but it is undefined whether or not a newly created object will be visited. @@ -226,25 +233,26 @@ class BitMapObjectPool : public internal::StaticAllocatorBitmap, public internal * @brief * Run a functor for each active object in the pool * - * @param function The functor of type `bool (*)(T*)`, return false to break the iteration - * @return bool Returns false if broke during iteration + * @param function The functor of type `Loop (*)(T*)`, return Loop::Break to break the iteration + * @return Loop Returns Break or Finish according to the iteration * * caution * this function is not thread-safe, make sure all usage of the * pool is protected by a lock, or else avoid using this function */ template - bool ForEachActiveObject(Function && function) + Loop ForEachActiveObject(Function && function) { + static_assert(std::is_same()))>::value, "The function must take T* and return Loop"); internal::LambdaProxy proxy(std::forward(function)); return ForEachActiveObjectInner(&proxy, &internal::LambdaProxy::Call); } private: - static bool ReleaseObject(void * context, void * object) + static Loop ReleaseObject(void * context, void * object) { static_cast(context)->ReleaseObject(static_cast(object)); - return true; + return Loop::Continue; } std::atomic mUsage[(N + kBitChunkSize - 1) / kBitChunkSize]; @@ -314,22 +322,22 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon< * @brief * Run a functor for each active object in the pool * - * @param function The functor of type `bool (*)(T*)`, return false to break the iteration - * @return bool Returns false if broke during iteration + * @param function The functor of type `Loop (*)(T*)`, return Loop::Break to break the iteration + * @return Loop Returns Break or Finish according to the iteration */ template - bool ForEachActiveObject(Function && function) + Loop ForEachActiveObject(Function && function) { - // return ForEachNode([function](void *object) { return function(static_cast(object)); }); + static_assert(std::is_same()))>::value, "The function must take T* and return Loop"); internal::LambdaProxy proxy(std::forward(function)); return mObjects.ForEachNode(&proxy, &internal::LambdaProxy::Call); } private: - static bool ReleaseObject(void * context, void * object) + static Loop ReleaseObject(void * context, void * object) { static_cast(context)->ReleaseObject(static_cast(object)); - return true; + return Loop::Continue; } internal::HeapObjectList mObjects; diff --git a/src/lib/support/PoolWrapper.h b/src/lib/support/PoolWrapper.h index 9bd3699ae769fc..b00a936e0991fe 100644 --- a/src/lib/support/PoolWrapper.h +++ b/src/lib/support/PoolWrapper.h @@ -38,16 +38,17 @@ class PoolInterface virtual void ResetObject(U * element, ConstructorArguments &&... args) = 0; template - bool ForEachActiveObject(Function && function) + Loop ForEachActiveObject(Function && function) { - auto proxy = [&](U * target) -> bool { return function(target); }; + static_assert(std::is_same()))>::value, "The function must take T* and return Loop"); + auto proxy = [&](U * target) -> Loop { return function(target); }; return ForEachActiveObjectInner( - &proxy, [](void * context, U * target) -> bool { return (*static_cast(context))(target); }); + &proxy, [](void * context, U * target) -> Loop { return (*static_cast(context))(target); }); } protected: - using Lambda = bool (*)(void *, U *); - virtual bool ForEachActiveObjectInner(void * context, Lambda lambda) = 0; + using Lambda = Loop (*)(void *, U *); + virtual Loop ForEachActiveObjectInner(void * context, Lambda lambda) = 0; }; template @@ -75,7 +76,7 @@ class PoolProxy> : public PoolInter } protected: - virtual bool ForEachActiveObjectInner(void * context, + virtual Loop ForEachActiveObjectInner(void * context, typename PoolInterface::Lambda lambda) override { return Impl().ForEachActiveObject([&](T * target) { return lambda(context, static_cast(target)); }); diff --git a/src/lib/support/tests/TestPool.cpp b/src/lib/support/tests/TestPool.cpp index 2245a9322baf9a..c9242d054cad1b 100644 --- a/src/lib/support/tests/TestPool.cpp +++ b/src/lib/support/tests/TestPool.cpp @@ -39,7 +39,7 @@ size_t GetNumObjectsInUse(POOL & pool) size_t count = 0; pool.ForEachActiveObject([&count](void *) { ++count; - return true; + return Loop::Continue; }); return count; } @@ -240,17 +240,17 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) objIds.erase(object->mId); ++count; sum += object->mId; - return true; + return Loop::Continue; }); NL_TEST_ASSERT(inSuite, count == kSize); NL_TEST_ASSERT(inSuite, sum == kSize * (kSize - 1) / 2); NL_TEST_ASSERT(inSuite, objIds.size() == 0); - // Verify that returning false stops iterating. + // Verify that returning Loop::Break stops iterating. count = 0; pool.ForEachActiveObject([&](S * object) { objIds.insert(object->mId); - return ++count != kSize / 2; + return ++count != kSize / 2 ? Loop::Continue : Loop::Break; }); NL_TEST_ASSERT(inSuite, count == kSize / 2); NL_TEST_ASSERT(inSuite, objIds.size() == kSize / 2); @@ -269,10 +269,10 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) { ++count; } - return true; + return Loop::Continue; }); } - return true; + return Loop::Continue; }); NL_TEST_ASSERT(inSuite, count == (kSize - 1) * kSize / 2); NL_TEST_ASSERT(inSuite, objIds.size() == 0); @@ -289,7 +289,7 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) { objIds.insert(object->mId); } - return true; + return Loop::Continue; }); NL_TEST_ASSERT(inSuite, count == kSize); NL_TEST_ASSERT(inSuite, objIds.size() == kSize / 2); @@ -316,7 +316,7 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) objArray[id] = pool.CreateObject(id); NL_TEST_ASSERT(inSuite, objArray[id] != nullptr); } - return true; + return Loop::Continue; }); for (size_t i = 0; i < kSize; ++i) { diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index 0826c118b71b5c..bf592c9af2363c 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -101,7 +101,7 @@ CHIP_ERROR ExchangeManager::Shutdown() mContextPool.ForEachActiveObject([](auto * ec) { // There should be no active object in the pool VerifyOrDie(false); - return true; + return Loop::Continue; }); if (mSessionManager != nullptr) @@ -226,9 +226,9 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const // Matched ExchangeContext; send to message handler. ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, source, msgFlags, std::move(msgBuf)); found = true; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); if (found) @@ -322,7 +322,7 @@ void ExchangeManager::ExpireExchangesForSession(SessionHandle session) // Continue to iterate because there can be multiple exchanges // associated with the connection. } - return true; + return Loop::Continue; }); } @@ -338,7 +338,7 @@ void ExchangeManager::CloseAllContextsForDelegate(const ExchangeDelegate * deleg ec->SetDelegate(nullptr); ec->Close(); } - return true; + return Loop::Continue; }); } diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp index 8594d080bdadda..dc0c31a516d3d0 100644 --- a/src/messaging/ReliableMessageMgr.cpp +++ b/src/messaging/ReliableMessageMgr.cpp @@ -70,7 +70,7 @@ void ReliableMessageMgr::Shutdown() // Clear the retransmit table mRetransTable.ForEachActiveObject([&](auto * entry) { ClearRetransTable(*entry); - return true; + return Loop::Continue; }); mSystemLayer = nullptr; @@ -95,7 +95,7 @@ void ReliableMessageMgr::TicklessDebugDumpRetransTable(const char * log) ChipLogDetail(ExchangeManager, "EC:" ChipLogFormatExchange " MessageCounter:" ChipLogFormatMessageCounter " NextRetransTimeCtr:%04" PRIX16, ChipLogValueExchange(&entry->ec.Get()), entry->retainedBuf.GetMessageCounter(), entry->nextRetransTimeTick); - return true; + return Loop::Continue; }); } #else @@ -133,7 +133,7 @@ void ReliableMessageMgr::ExecuteActions() CHIP_ERROR err = CHIP_NO_ERROR; if (entry->nextRetransTimeTick != 0) - return true; + return Loop::Continue; if (entry->retainedBuf.IsNull()) { @@ -143,7 +143,7 @@ void ReliableMessageMgr::ExecuteActions() // // If that were to happen, we would crash in the code below. Guard against it, just in case. ClearRetransTable(*entry); - return true; + return Loop::Continue; } uint8_t sendCount = entry->sendCount; @@ -178,7 +178,7 @@ void ReliableMessageMgr::ExecuteActions() #endif } - return true; + return Loop::Continue; }); TicklessDebugDumpRetransTable("ReliableMessageMgr::ExecuteActions Dumping mRetransTable entries after processing"); @@ -228,7 +228,7 @@ void ReliableMessageMgr::ExpireTicks() #if defined(RMP_TICKLESS_DEBUG) ChipLogDetail(ExchangeManager, "ReliableMessageMgr::ExpireTicks set nextRetransTimeTick to %u", entry->nextRetransTimeTick); #endif - return true; + return Loop::Continue; }); // Re-Adjust the base time stamp to the most recent tick boundary @@ -293,9 +293,9 @@ void ReliableMessageMgr::PauseRetransmision(ReliableMessageContext * rc, uint32_ { entry->nextRetransTimeTick = static_cast(entry->nextRetransTimeTick + (PauseTimeMillis >> mTimerIntervalShift)); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -305,9 +305,9 @@ void ReliableMessageMgr::ResumeRetransmision(ReliableMessageContext * rc) if (entry->ec->GetReliableMessageContext() == rc) { entry->nextRetransTimeTick = 0; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -327,9 +327,9 @@ bool ReliableMessageMgr::CheckAndRemRetransTable(ReliableMessageContext * rc, ui ackMessageCounter, ChipLogValueExchange(rc->GetExchangeContext())); #endif removed = true; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return removed; @@ -390,9 +390,9 @@ void ReliableMessageMgr::ClearRetransTable(ReliableMessageContext * rc) if (entry->ec->GetReliableMessageContext() == rc) { result = entry; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); if (result != nullptr) { @@ -442,7 +442,7 @@ void ReliableMessageMgr::StartTimer() ChipLogDetail(ExchangeManager, "ReliableMessageMgr::StartTimer RetransTime %" PRIu64, nextWakeTimeTick); #endif } - return true; + return Loop::Continue; }); if (foundWake) @@ -503,7 +503,7 @@ int ReliableMessageMgr::TestGetCountRetransTable() int count = 0; mRetransTable.ForEachActiveObject([&](auto * entry) { count++; - return true; + return Loop::Continue; }); return count; } diff --git a/src/messaging/ReliableMessageMgr.h b/src/messaging/ReliableMessageMgr.h index 617007a2f81b45..4c4bc5724c5fd9 100644 --- a/src/messaging/ReliableMessageMgr.h +++ b/src/messaging/ReliableMessageMgr.h @@ -240,7 +240,7 @@ class ReliableMessageMgr { mContextPool.ForEachActiveObject([&](auto * ec) { function(ec->GetReliableMessageContext()); - return true; + return Loop::Continue; }); } diff --git a/src/transport/SecureSessionTable.h b/src/transport/SecureSessionTable.h index 62a2429e172a5f..d40e6626b6789a 100644 --- a/src/transport/SecureSessionTable.h +++ b/src/transport/SecureSessionTable.h @@ -69,7 +69,7 @@ class SecureSessionTable void ReleaseSession(SecureSession * session) { mEntries.ReleaseObject(session); } template - bool ForEachSession(Function && function) + Loop ForEachSession(Function && function) { return mEntries.ForEachActiveObject(std::forward(function)); } @@ -89,9 +89,9 @@ class SecureSessionTable if (session->GetLocalSessionId() == localSessionId) { result = session; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return result; } @@ -115,7 +115,7 @@ class SecureSessionTable callback(*session); ReleaseSession(session); } - return true; + return Loop::Continue; }); } diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index e2f4ac7d843f1e..87be4943ed0369 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -261,7 +261,7 @@ void SessionManager::ExpireAllPairings(NodeId peerNodeId, FabricIndex fabric) HandleConnectionExpired(*session); mSecureSessions.ReleaseSession(session); } - return true; + return Loop::Continue; }); } @@ -274,7 +274,7 @@ void SessionManager::ExpireAllPairingsForFabric(FabricIndex fabric) HandleConnectionExpired(*session); mSecureSessions.ReleaseSession(session); } - return true; + return Loop::Continue; }); } @@ -319,7 +319,7 @@ CHIP_ERROR SessionManager::NewPairing(const Optional & p SessionHandle sessionHandle(session->GetPeerNodeId(), session->GetLocalSessionId(), session->GetPeerSessionId(), fabric); mSessionCreationDelegates.ForEachActiveObject([&](std::reference_wrapper * cb) { cb->get().OnNewSession(sessionHandle); - return true; + return Loop::Continue; }); return CHIP_NO_ERROR; @@ -369,7 +369,7 @@ void SessionManager::RegisterRecoveryDelegate(SessionRecoveryDelegate & cb) #ifndef NDEBUG mSessionRecoveryDelegates.ForEachActiveObject([&](std::reference_wrapper * i) { VerifyOrDie(std::addressof(cb) != std::addressof(i->get())); - return true; + return Loop::Continue; }); #endif std::reference_wrapper * slot = mSessionRecoveryDelegates.CreateObject(cb); @@ -382,9 +382,9 @@ void SessionManager::UnregisterRecoveryDelegate(SessionRecoveryDelegate & cb) if (std::addressof(cb) == std::addressof(i->get())) { mSessionRecoveryDelegates.ReleaseObject(i); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -392,7 +392,7 @@ void SessionManager::RefreshSessionOperationalData(const SessionHandle & session { mSessionRecoveryDelegates.ForEachActiveObject([&](std::reference_wrapper * cb) { cb->get().OnFirstMessageDeliveryFailed(sessionHandle); - return true; + return Loop::Continue; }); } @@ -595,7 +595,7 @@ void SessionManager::HandleConnectionExpired(const Transport::SecureSession & se session.GetFabricIndex()); mSessionReleaseDelegates.ForEachActiveObject([&](std::reference_wrapper * cb) { cb->get().OnSessionReleased(sessionHandle); - return true; + return Loop::Continue; }); mTransportMgr->Disconnect(session.GetPeerAddress()); @@ -632,9 +632,9 @@ SessionHandle SessionManager::FindSecureSessionForNode(NodeId peerNodeId) if (session->GetPeerNodeId() == peerNodeId) { found = session; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); VerifyOrDie(found != nullptr); diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index 3cd472ff49f6be..6e8ec58a7fbd7e 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -154,7 +154,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate #ifndef NDEBUG mSessionCreationDelegates.ForEachActiveObject([&](std::reference_wrapper * i) { VerifyOrDie(std::addressof(cb) != std::addressof(i->get())); - return true; + return Loop::Continue; }); #endif std::reference_wrapper * slot = mSessionCreationDelegates.CreateObject(cb); @@ -167,9 +167,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate if (std::addressof(cb) == std::addressof(i->get())) { mSessionCreationDelegates.ReleaseObject(i); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -179,7 +179,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate #ifndef NDEBUG mSessionReleaseDelegates.ForEachActiveObject([&](std::reference_wrapper * i) { VerifyOrDie(std::addressof(cb) != std::addressof(i->get())); - return true; + return Loop::Continue; }); #endif std::reference_wrapper * slot = mSessionReleaseDelegates.CreateObject(cb); @@ -192,9 +192,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate if (std::addressof(cb) == std::addressof(i->get())) { mSessionReleaseDelegates.ReleaseObject(i); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } diff --git a/src/transport/UnauthenticatedSessionTable.h b/src/transport/UnauthenticatedSessionTable.h index c265d43fe249e7..032f19e2a919f1 100644 --- a/src/transport/UnauthenticatedSessionTable.h +++ b/src/transport/UnauthenticatedSessionTable.h @@ -159,9 +159,9 @@ class UnauthenticatedSessionTable if (MatchPeerAddress(entry->GetPeerAddress(), address)) { result = entry; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return result; } @@ -177,7 +177,7 @@ class UnauthenticatedSessionTable result = entry; oldestTime = entry->GetLastActivityTime(); } - return true; + return Loop::Continue; }); return result; diff --git a/src/transport/raw/TCP.cpp b/src/transport/raw/TCP.cpp index 82b8a7c0274197..d8db200488d718 100644 --- a/src/transport/raw/TCP.cpp +++ b/src/transport/raw/TCP.cpp @@ -213,9 +213,9 @@ CHIP_ERROR TCPBase::SendAfterConnect(const PeerAddress & addr, System::PacketBuf // same destination exists. alreadyConnecting = true; pending->mPacketBuffer->AddToEnd(std::move(msg)); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); // If already connecting, buffer was just enqueued for more sending @@ -378,7 +378,7 @@ void TCPBase::OnConnectionComplete(Inet::TCPEndPoint * endPoint, CHIP_ERROR inet err = endPoint->Send(std::move(buffer)); } } - return true; + return Loop::Continue; }); if (err == CHIP_NO_ERROR)