Matter SDK Coverage Report
Current view: top level - transport - Session.cpp (source / functions) Coverage Total Hit
Test: SHA:f84fe08d06f240e801b5d923f8a938a9938ca110 Lines: 74.5 % 47 35
Test Date: 2025-02-22 08:08:07 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/GroupSession.h>
      18              : #include <transport/SecureSession.h>
      19              : #include <transport/Session.h>
      20              : #include <transport/UnauthenticatedSessionTable.h>
      21              : 
      22              : namespace chip {
      23              : namespace Transport {
      24              : 
      25       352202 : SecureSession * Session::AsSecureSession()
      26              : {
      27       352202 :     VerifyOrDie(GetSessionType() == SessionType::kSecure);
      28       352202 :     return static_cast<SecureSession *>(this);
      29              : }
      30              : 
      31        28439 : const SecureSession * Session::AsConstSecureSession() const
      32              : {
      33        28439 :     VerifyOrDie(GetSessionType() == SessionType::kSecure);
      34        28439 :     return static_cast<const SecureSession *>(this);
      35              : }
      36              : 
      37          559 : UnauthenticatedSession * Session::AsUnauthenticatedSession()
      38              : {
      39          559 :     VerifyOrDie(GetSessionType() == SessionType::kUnauthenticated);
      40          559 :     return static_cast<UnauthenticatedSession *>(this);
      41              : }
      42              : 
      43            0 : IncomingGroupSession * Session::AsIncomingGroupSession()
      44              : {
      45            0 :     VerifyOrDie(GetSessionType() == SessionType::kGroupIncoming);
      46            0 :     return static_cast<IncomingGroupSession *>(this);
      47              : }
      48              : 
      49            0 : const IncomingGroupSession * Session::AsConstIncomingGroupSession() const
      50              : {
      51            0 :     VerifyOrDie(GetSessionType() == SessionType::kGroupIncoming);
      52            0 :     return static_cast<const IncomingGroupSession *>(this);
      53              : }
      54              : 
      55            2 : OutgoingGroupSession * Session::AsOutgoingGroupSession()
      56              : {
      57            2 :     VerifyOrDie(GetSessionType() == SessionType::kGroupOutgoing);
      58            2 :     return static_cast<OutgoingGroupSession *>(this);
      59              : }
      60              : 
      61            1 : const OutgoingGroupSession * Session::AsConstOutgoingGroupSession() const
      62              : {
      63            1 :     VerifyOrDie(GetSessionType() == SessionType::kGroupOutgoing);
      64            1 :     return static_cast<const OutgoingGroupSession *>(this);
      65              : }
      66              : 
      67         6720 : System::Clock::Timeout Session::ComputeRoundTripTimeout(System::Clock::Timeout upperlayerProcessingTimeout)
      68              : {
      69         6720 :     if (IsGroupSession())
      70              :     {
      71            1 :         return System::Clock::kZero;
      72              :     }
      73              : 
      74              :     // Treat us as active for purposes of GetMessageReceiptTimeout(), since the
      75              :     // other side would be responding to our message.
      76         6719 :     return GetAckTimeout() + upperlayerProcessingTimeout + GetMessageReceiptTimeout(System::SystemClock().GetMonotonicTimestamp());
      77              : }
      78              : 
      79        28720 : uint16_t Session::SessionIdForLogging() const
      80              : {
      81        28720 :     switch (GetSessionType())
      82              :     {
      83            0 :     case Session::SessionType::kGroupIncoming:
      84            0 :         return AsConstIncomingGroupSession()->GetGroupId();
      85            1 :     case Session::SessionType::kGroupOutgoing:
      86            1 :         return AsConstOutgoingGroupSession()->GetGroupId();
      87        28439 :     case Session::SessionType::kSecure:
      88        28439 :         return AsConstSecureSession()->GetLocalSessionId();
      89          280 :     case Session::SessionType::kUnauthenticated:
      90          280 :         return 0;
      91            0 :     default:
      92            0 :         VerifyOrDie(false);
      93              :         return 0;
      94              :     }
      95              : }
      96              : 
      97        28714 : const char * GetSessionTypeString(const SessionHandle & session)
      98              : {
      99        28714 :     switch (session->GetSessionType())
     100              :     {
     101            1 :     case Session::SessionType::kGroupIncoming:
     102              :     case Session::SessionType::kGroupOutgoing:
     103            1 :         return "G";
     104        28433 :     case Session::SessionType::kSecure:
     105        28433 :         return "S";
     106          280 :     case Session::SessionType::kUnauthenticated:
     107          280 :         return "U";
     108            0 :     default:
     109            0 :         return "?";
     110              :     }
     111              : }
     112              : 
     113              : } // namespace Transport
     114              : } // namespace chip
        

Generated by: LCOV version 2.0-1