Matter SDK Coverage Report
Current view: top level - transport - Session.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 74.5 % 47 35
Test Date: 2025-01-17 19:00:11 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       352928 : SecureSession * Session::AsSecureSession()
      26              : {
      27       352928 :     VerifyOrDie(GetSessionType() == SessionType::kSecure);
      28       352928 :     return static_cast<SecureSession *>(this);
      29              : }
      30              : 
      31        27480 : const SecureSession * Session::AsConstSecureSession() const
      32              : {
      33        27480 :     VerifyOrDie(GetSessionType() == SessionType::kSecure);
      34        27480 :     return static_cast<const SecureSession *>(this);
      35              : }
      36              : 
      37          549 : UnauthenticatedSession * Session::AsUnauthenticatedSession()
      38              : {
      39          549 :     VerifyOrDie(GetSessionType() == SessionType::kUnauthenticated);
      40          549 :     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         6520 : System::Clock::Timeout Session::ComputeRoundTripTimeout(System::Clock::Timeout upperlayerProcessingTimeout)
      68              : {
      69         6520 :     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         6519 :     return GetAckTimeout() + upperlayerProcessingTimeout + GetMessageReceiptTimeout(System::SystemClock().GetMonotonicTimestamp());
      77              : }
      78              : 
      79        27756 : uint16_t Session::SessionIdForLogging() const
      80              : {
      81        27756 :     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        27480 :     case Session::SessionType::kSecure:
      88        27480 :         return AsConstSecureSession()->GetLocalSessionId();
      89          275 :     case Session::SessionType::kUnauthenticated:
      90          275 :         return 0;
      91            0 :     default:
      92            0 :         VerifyOrDie(false);
      93              :         return 0;
      94              :     }
      95              : }
      96              : 
      97        27750 : const char * GetSessionTypeString(const SessionHandle & session)
      98              : {
      99        27750 :     switch (session->GetSessionType())
     100              :     {
     101            1 :     case Session::SessionType::kGroupIncoming:
     102              :     case Session::SessionType::kGroupOutgoing:
     103            1 :         return "G";
     104        27474 :     case Session::SessionType::kSecure:
     105        27474 :         return "S";
     106          275 :     case Session::SessionType::kUnauthenticated:
     107          275 :         return "U";
     108            0 :     default:
     109            0 :         return "?";
     110              :     }
     111              : }
     112              : 
     113              : } // namespace Transport
     114              : } // namespace chip
        

Generated by: LCOV version 2.0-1