Matter SDK Coverage Report
Current view: top level - transport - SessionHolder.cpp (source / functions) Coverage Total Hit
Test: SHA:e98a48c2e59f85a25417956e1d105721433aa5d1 Lines: 82.4 % 51 42
Test Date: 2026-01-09 16:53:50 Functions: 80.0 % 10 8

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2021 Project CHIP Authors
       3              :  *
       4              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       5              :  *    you may not use this file except in compliance with the License.
       6              :  *    You may obtain a copy of the License at
       7              :  *
       8              :  *        http://www.apache.org/licenses/LICENSE-2.0
       9              :  *
      10              :  *    Unless required by applicable law or agreed to in writing, software
      11              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      12              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13              :  *    See the License for the specific language governing permissions and
      14              :  *    limitations under the License.
      15              :  */
      16              : 
      17              : #include <transport/SessionHolder.h>
      18              : 
      19              : #include <transport/SecureSession.h>
      20              : #include <transport/Session.h>
      21              : 
      22              : namespace chip {
      23              : 
      24        10338 : SessionHolder::~SessionHolder()
      25              : {
      26        10338 :     Release();
      27        10338 : }
      28              : 
      29           63 : SessionHolder::SessionHolder(const SessionHolder & that) : IntrusiveListNodeBase()
      30              : {
      31           63 :     mSession = that.mSession;
      32           63 :     if (mSession.HasValue())
      33              :     {
      34           63 :         mSession.Value()->AddHolder(*this);
      35              :     }
      36           63 : }
      37              : 
      38            0 : SessionHolder::SessionHolder(SessionHolder && that) : IntrusiveListNodeBase()
      39              : {
      40            0 :     mSession = that.mSession;
      41            0 :     if (mSession.HasValue())
      42              :     {
      43            0 :         mSession.Value()->AddHolder(*this);
      44              :     }
      45              : 
      46            0 :     that.Release();
      47            0 : }
      48              : 
      49          303 : SessionHolder & SessionHolder::operator=(const SessionHolder & that)
      50              : {
      51          303 :     Release();
      52              : 
      53          303 :     mSession = that.mSession;
      54          303 :     if (mSession.HasValue())
      55              :     {
      56          303 :         mSession.Value()->AddHolder(*this);
      57              :     }
      58              : 
      59          303 :     return *this;
      60              : }
      61              : 
      62           10 : SessionHolder & SessionHolder::operator=(SessionHolder && that)
      63              : {
      64           10 :     Release();
      65              : 
      66           10 :     mSession = that.mSession;
      67           10 :     if (mSession.HasValue())
      68              :     {
      69           10 :         mSession.Value()->AddHolder(*this);
      70              :     }
      71              : 
      72           10 :     that.Release();
      73              : 
      74           10 :     return *this;
      75              : }
      76              : 
      77           58 : bool SessionHolder::GrabPairingSession(const SessionHandle & session)
      78              : {
      79           58 :     Release();
      80              : 
      81           58 :     if (!session->IsSecureSession())
      82            0 :         return false;
      83              : 
      84           58 :     if (!session->AsSecureSession()->IsEstablishing())
      85            0 :         return false;
      86              : 
      87           58 :     GrabUnchecked(session);
      88           58 :     return true;
      89              : }
      90              : 
      91        10171 : bool SessionHolder::Grab(const SessionHandle & session)
      92              : {
      93        10171 :     Release();
      94              : 
      95        10171 :     if (!session->IsActiveSession())
      96            0 :         return false;
      97              : 
      98        10171 :     GrabUnchecked(session);
      99        10171 :     return true;
     100              : }
     101              : 
     102        10231 : void SessionHolder::GrabUnchecked(const SessionHandle & session)
     103              : {
     104        10231 :     VerifyOrDie(!mSession.HasValue());
     105        10231 :     mSession.Emplace(session.mSession);
     106        10231 :     session->AddHolder(*this);
     107        10231 : }
     108              : 
     109        23021 : void SessionHolder::Release()
     110              : {
     111        23021 :     if (mSession.HasValue())
     112              :     {
     113        10607 :         mSession.Value()->RemoveHolder(*this);
     114        10607 :         mSession.ClearValue();
     115              :     }
     116        23021 : }
     117              : 
     118              : } // namespace chip
        

Generated by: LCOV version 2.0-1