LCOV - code coverage report
Current view: top level - transport - Session.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 35 47 74.5 %
Date: 2024-02-15 08:20:41 Functions: 8 10 80.0 %

          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      317688 : SecureSession * Session::AsSecureSession()
      26             : {
      27      317688 :     VerifyOrDie(GetSessionType() == SessionType::kSecure);
      28      317688 :     return static_cast<SecureSession *>(this);
      29             : }
      30             : 
      31       18863 : const SecureSession * Session::AsConstSecureSession() const
      32             : {
      33       18863 :     VerifyOrDie(GetSessionType() == SessionType::kSecure);
      34       18863 :     return static_cast<const SecureSession *>(this);
      35             : }
      36             : 
      37         459 : UnauthenticatedSession * Session::AsUnauthenticatedSession()
      38             : {
      39         459 :     VerifyOrDie(GetSessionType() == SessionType::kUnauthenticated);
      40         459 :     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        6366 : System::Clock::Timeout Session::ComputeRoundTripTimeout(System::Clock::Timeout upperlayerProcessingTimeout)
      68             : {
      69        6366 :     if (IsGroupSession())
      70             :     {
      71           1 :         return System::Clock::kZero;
      72             :     }
      73        6365 :     return GetAckTimeout() + upperlayerProcessingTimeout;
      74             : }
      75             : 
      76       19058 : uint16_t Session::SessionIdForLogging() const
      77             : {
      78       19058 :     switch (GetSessionType())
      79             :     {
      80           0 :     case Session::SessionType::kGroupIncoming:
      81           0 :         return AsConstIncomingGroupSession()->GetGroupId();
      82           1 :     case Session::SessionType::kGroupOutgoing:
      83           1 :         return AsConstOutgoingGroupSession()->GetGroupId();
      84       18863 :     case Session::SessionType::kSecure:
      85       18863 :         return AsConstSecureSession()->GetLocalSessionId();
      86         194 :     case Session::SessionType::kUnauthenticated:
      87         194 :         return 0;
      88           0 :     default:
      89           0 :         VerifyOrDie(false);
      90             :         return 0;
      91             :     }
      92             : }
      93             : 
      94       19058 : const char * GetSessionTypeString(const SessionHandle & session)
      95             : {
      96       19058 :     switch (session->GetSessionType())
      97             :     {
      98           1 :     case Session::SessionType::kGroupIncoming:
      99             :     case Session::SessionType::kGroupOutgoing:
     100           1 :         return "G";
     101       18863 :     case Session::SessionType::kSecure:
     102       18863 :         return "S";
     103         194 :     case Session::SessionType::kUnauthenticated:
     104         194 :         return "U";
     105           0 :     default:
     106           0 :         return "?";
     107             :     }
     108             : }
     109             : 
     110             : } // namespace Transport
     111             : } // namespace chip

Generated by: LCOV version 1.14