LCOV - code coverage report
Current view: top level - libs/bsw/cpp2someip/src - RebootTracker.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 35 35
Test Date: 2026-09-11 12:05:06 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /********************************************************************************
       2              :  * Copyright (c) 2026 Accenture
       3              :  *
       4              :  * This program and the accompanying materials are made available under the
       5              :  * terms of the Apache License Version 2.0 which is available at
       6              :  * https://www.apache.org/licenses/LICENSE-2.0
       7              :  *
       8              :  * SPDX-License-Identifier: Apache-2.0
       9              :  ********************************************************************************/
      10              : 
      11              : #include "someip/RebootTracker.h"
      12              : 
      13              : #include "someip/logger.h"
      14              : 
      15              : // Logger API uses printf-style varargs for fixed diagnostic messages in this module.
      16              : // NOLINTBEGIN(cppcoreguidelines-pro-type-vararg)
      17              : 
      18              : namespace someip
      19              : {
      20              : using ::ip::IPAddress;
      21              : using ::util::logger::SOMEIP;
      22              : 
      23              : // protected
      24           33 : RebootTracker::RebootTracker(EndpointMap& endpointMap) : _endpoints(endpointMap) {}
      25              : 
      26            9 : void RebootTracker::init() { _endpoints.clear(); }
      27              : 
      28           72 : bool RebootTracker::evaluate(SessionInfo const& session) const
      29              : {
      30           72 :     EndpointMap::iterator const iter = _endpoints.find(session.remoteIp);
      31              : 
      32           72 :     if ((iter != nullptr) && (iter != _endpoints.end()))
      33              :     {
      34           30 :         RebootTrackerEndpoint& endpoint = iter->second;
      35           30 :         if (session.isMulticast)
      36              :         {
      37            2 :             return endpoint.getMulticastRebootValue(session.sessionId, session.rebootFlag);
      38              :         }
      39              : 
      40           28 :         return endpoint.getUnicastRebootValue(session.sessionId, session.rebootFlag);
      41              :     }
      42              : 
      43           42 :     if (session.rebootFlag == false)
      44              :     {
      45            1 :         return false;
      46              :     }
      47              : 
      48           41 :     return 0 >= session.sessionId;
      49              : }
      50              : 
      51           64 : void RebootTracker::apply(SessionInfo const& session)
      52              : {
      53           64 :     EndpointMap::iterator const iter = addEndpoint(session.remoteIp);
      54           64 :     if (_endpoints.end() == iter)
      55              :     {
      56            2 :         WARN_LOG(SOMEIP, "RebootTracker: unable to add endpoint");
      57              :     }
      58              :     else
      59              :     {
      60           62 :         RebootTrackerEndpoint& endpoint = iter->second;
      61           62 :         bool reboot                     = false;
      62              : 
      63           62 :         if (session.isMulticast)
      64              :         {
      65            4 :             reboot = endpoint.getMulticastRebootValue(session.sessionId, session.rebootFlag);
      66            4 :             endpoint.setMulticast(session.sessionId, session.rebootFlag);
      67              :         }
      68              :         else
      69              :         {
      70           58 :             reboot = endpoint.getUnicastRebootValue(session.sessionId, session.rebootFlag);
      71           58 :             endpoint.setUnicast(session.sessionId, session.rebootFlag);
      72              :         }
      73              : 
      74           62 :         if (reboot)
      75              :         {
      76           31 :             (void)_endpoints.erase(session.remoteIp);
      77              :         }
      78              :     }
      79           64 : }
      80              : 
      81           64 : RebootTracker::EndpointMap::iterator RebootTracker::addEndpoint(IPAddress const& remoteIp)
      82              : {
      83           64 :     EndpointMap::iterator const iter = _endpoints.find(remoteIp);
      84           64 :     if (iter != _endpoints.end())
      85              :     {
      86           24 :         return iter; // endpoint already added
      87              :     }
      88              : 
      89           40 :     if (_endpoints.full() == true)
      90              :     {
      91            2 :         return _endpoints.end();
      92              :     }
      93              : 
      94           38 :     RebootTrackerEndpoint& endpoint = _endpoints[remoteIp];
      95           38 :     endpoint.initActiveReboot();
      96              : 
      97           38 :     return _endpoints.find(remoteIp);
      98              : }
      99              : 
     100              : } // namespace someip
     101              : 
     102              : // NOLINTEND(cppcoreguidelines-pro-type-vararg)
        

Generated by: LCOV version 2.0-1