LCOV - code coverage report
Current view: top level - app - OperationalSessionSetupPool.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 2 24 8.3 %
Date: 2024-02-15 08:20:41 Functions: 2 22 9.1 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2021 Project CHIP Authors
       4             :  *
       5             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6             :  *    you may not use this file except in compliance with the License.
       7             :  *    You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  *    Unless required by applicable law or agreed to in writing, software
      12             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  *    See the License for the specific language governing permissions and
      15             :  *    limitations under the License.
      16             :  */
      17             : 
      18             : #pragma once
      19             : 
      20             : #include <app/CASESessionManager.h>
      21             : #include <app/OperationalSessionSetup.h>
      22             : #include <lib/support/Pool.h>
      23             : #include <transport/Session.h>
      24             : 
      25             : namespace chip {
      26             : 
      27             : class OperationalSessionSetupPoolDelegate
      28             : {
      29             : public:
      30             :     virtual OperationalSessionSetup * Allocate(const CASEClientInitParams & params, CASEClientPoolDelegate * clientPool,
      31             :                                                ScopedNodeId peerId, OperationalSessionReleaseDelegate * releaseDelegate) = 0;
      32             : 
      33             :     virtual void Release(OperationalSessionSetup * device) = 0;
      34             : 
      35             :     virtual OperationalSessionSetup * FindSessionSetup(ScopedNodeId peerId, bool forAddressUpdate) = 0;
      36             : 
      37             :     virtual void ReleaseAllSessionSetupsForFabric(FabricIndex fabricIndex) = 0;
      38             : 
      39             :     virtual void ReleaseAllSessionSetup() = 0;
      40             : 
      41           1 :     virtual ~OperationalSessionSetupPoolDelegate() {}
      42             : };
      43             : 
      44             : template <size_t N>
      45             : class OperationalSessionSetupPool : public OperationalSessionSetupPoolDelegate
      46             : {
      47             : public:
      48           1 :     ~OperationalSessionSetupPool() override { mSessionSetupPool.ReleaseAll(); }
      49             : 
      50           0 :     OperationalSessionSetup * Allocate(const CASEClientInitParams & params, CASEClientPoolDelegate * clientPool,
      51             :                                        ScopedNodeId peerId, OperationalSessionReleaseDelegate * releaseDelegate) override
      52             :     {
      53           0 :         return mSessionSetupPool.CreateObject(params, clientPool, peerId, releaseDelegate);
      54             :     }
      55             : 
      56           0 :     void Release(OperationalSessionSetup * device) override { mSessionSetupPool.ReleaseObject(device); }
      57             : 
      58           0 :     OperationalSessionSetup * FindSessionSetup(ScopedNodeId peerId, bool forAddressUpdate) override
      59             :     {
      60           0 :         OperationalSessionSetup * foundDevice = nullptr;
      61           0 :         mSessionSetupPool.ForEachActiveObject([&](auto * activeSetup) {
      62           0 :             if (activeSetup->GetPeerId() == peerId && activeSetup->IsForAddressUpdate() == forAddressUpdate)
      63             :             {
      64           0 :                 foundDevice = activeSetup;
      65           0 :                 return Loop::Break;
      66             :             }
      67           0 :             return Loop::Continue;
      68             :         });
      69             : 
      70           0 :         return foundDevice;
      71             :     }
      72             : 
      73           0 :     void ReleaseAllSessionSetupsForFabric(FabricIndex fabricIndex) override
      74             :     {
      75           0 :         mSessionSetupPool.ForEachActiveObject([&](auto * activeSetup) {
      76           0 :             if (activeSetup->GetFabricIndex() == fabricIndex)
      77             :             {
      78           0 :                 Release(activeSetup);
      79             :             }
      80           0 :             return Loop::Continue;
      81             :         });
      82           0 :     }
      83             : 
      84           0 :     void ReleaseAllSessionSetup() override
      85             :     {
      86           0 :         mSessionSetupPool.ForEachActiveObject([&](auto * activeSetup) {
      87           0 :             Release(activeSetup);
      88           0 :             return Loop::Continue;
      89             :         });
      90           0 :     }
      91             : 
      92             : private:
      93             :     ObjectPool<OperationalSessionSetup, N> mSessionSetupPool;
      94             : };
      95             : 
      96             : }; // namespace chip

Generated by: LCOV version 1.14