Matter SDK Coverage Report
Current view: top level - app - OperationalSessionSetupPool.h (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 8.3 % 24 2
Test Date: 2025-01-17 19:00:11 Functions: 9.1 % 22 2

            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/OperationalSessionSetup.h>
      21              : #include <lib/support/Pool.h>
      22              : #include <transport/Session.h>
      23              : 
      24              : namespace chip {
      25              : 
      26              : class OperationalSessionSetupPoolDelegate
      27              : {
      28              : public:
      29              :     virtual OperationalSessionSetup * Allocate(const CASEClientInitParams & params, CASEClientPoolDelegate * clientPool,
      30              :                                                ScopedNodeId peerId, OperationalSessionReleaseDelegate * releaseDelegate) = 0;
      31              : 
      32              :     virtual void Release(OperationalSessionSetup * device) = 0;
      33              : 
      34              :     virtual OperationalSessionSetup * FindSessionSetup(ScopedNodeId peerId, bool forAddressUpdate) = 0;
      35              : 
      36              :     virtual void ReleaseAllSessionSetupsForFabric(FabricIndex fabricIndex) = 0;
      37              : 
      38              :     virtual void ReleaseAllSessionSetup() = 0;
      39              : 
      40            1 :     virtual ~OperationalSessionSetupPoolDelegate() {}
      41              : };
      42              : 
      43              : template <size_t N>
      44              : class OperationalSessionSetupPool : public OperationalSessionSetupPoolDelegate
      45              : {
      46              : public:
      47            1 :     ~OperationalSessionSetupPool() override { mSessionSetupPool.ReleaseAll(); }
      48              : 
      49            0 :     OperationalSessionSetup * Allocate(const CASEClientInitParams & params, CASEClientPoolDelegate * clientPool,
      50              :                                        ScopedNodeId peerId, OperationalSessionReleaseDelegate * releaseDelegate) override
      51              :     {
      52            0 :         return mSessionSetupPool.CreateObject(params, clientPool, peerId, releaseDelegate);
      53              :     }
      54              : 
      55            0 :     void Release(OperationalSessionSetup * device) override { mSessionSetupPool.ReleaseObject(device); }
      56              : 
      57            0 :     OperationalSessionSetup * FindSessionSetup(ScopedNodeId peerId, bool forAddressUpdate) override
      58              :     {
      59            0 :         OperationalSessionSetup * foundDevice = nullptr;
      60            0 :         mSessionSetupPool.ForEachActiveObject([&](auto * activeSetup) {
      61            0 :             if (activeSetup->GetPeerId() == peerId && activeSetup->IsForAddressUpdate() == forAddressUpdate)
      62              :             {
      63            0 :                 foundDevice = activeSetup;
      64            0 :                 return Loop::Break;
      65              :             }
      66            0 :             return Loop::Continue;
      67              :         });
      68              : 
      69            0 :         return foundDevice;
      70              :     }
      71              : 
      72            0 :     void ReleaseAllSessionSetupsForFabric(FabricIndex fabricIndex) override
      73              :     {
      74            0 :         mSessionSetupPool.ForEachActiveObject([&](auto * activeSetup) {
      75            0 :             if (activeSetup->GetFabricIndex() == fabricIndex)
      76              :             {
      77            0 :                 Release(activeSetup);
      78              :             }
      79            0 :             return Loop::Continue;
      80              :         });
      81            0 :     }
      82              : 
      83            0 :     void ReleaseAllSessionSetup() override
      84              :     {
      85            0 :         mSessionSetupPool.ForEachActiveObject([&](auto * activeSetup) {
      86            0 :             Release(activeSetup);
      87            0 :             return Loop::Continue;
      88              :         });
      89            0 :     }
      90              : 
      91              : private:
      92              :     ObjectPool<OperationalSessionSetup, N> mSessionSetupPool;
      93              : };
      94              : 
      95              : }; // namespace chip
        

Generated by: LCOV version 2.0-1