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

            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/ServiceAnnouncerTask.h"
      12              : 
      13              : #include "someip/ServiceDescription.h"
      14              : #include "someip/SomeIpConstants.h"
      15              : 
      16              : namespace someip
      17              : {
      18           31 : ServiceAnnouncerTask::ServiceAnnouncerTask()
      19              : : ::etl::forward_link<0>()
      20           31 : , _timestamp()
      21           31 : , _endpoint()
      22          124 : , _destination()
      23           31 : , _ttl()
      24           31 : , _minorVersion()
      25           31 : , _serviceId()
      26           31 : , _instanceId()
      27           31 : , _eventgroup()
      28           31 : , _majorVersion()
      29           31 : , _proto()
      30           31 : , _type()
      31           31 : , _unicast()
      32              : {
      33           31 :     clear();
      34           31 : }
      35              : 
      36           34 : void ServiceAnnouncerTask::clear()
      37              : {
      38           34 :     _timestamp = 0U;
      39           34 :     _endpoint.clear();
      40              : #ifdef PLATFORM_SUPPORT_IPV6
      41              :     _destination = ::ip::make_ip6(0U);
      42              : #else
      43           34 :     _destination = ::ip::make_ip4(0U);
      44              : #endif
      45           34 :     _minorVersion = minor_version::INVALID;
      46           34 :     _ttl          = ttl::INVALID;
      47           34 :     _serviceId    = service_id::INVALID;
      48           34 :     _instanceId   = instance_id::ANY;
      49           34 :     _eventgroup   = eventgroup_id::ALL;
      50           34 :     _majorVersion = major_version::INVALID;
      51           34 :     _proto        = SomeIpConstants::INVALID_PROTO;
      52           34 :     _type         = TaskType::TASK_IDLE;
      53           34 :     _unicast      = false;
      54           34 : }
      55              : 
      56           11 : ServiceAnnouncerTask& ServiceAnnouncerTask::operator=(ServiceAnnouncerTask const& rhs)
      57              : {
      58           11 :     if (this != &rhs)
      59              :     {
      60           10 :         _timestamp    = rhs._timestamp;
      61           10 :         _endpoint     = rhs._endpoint;
      62           10 :         _destination  = rhs._destination;
      63           10 :         _minorVersion = rhs._minorVersion;
      64           10 :         _ttl          = rhs._ttl;
      65           10 :         _serviceId    = rhs._serviceId;
      66           10 :         _instanceId   = rhs._instanceId;
      67           10 :         _eventgroup   = rhs._eventgroup;
      68           10 :         _majorVersion = rhs._majorVersion;
      69           10 :         _proto        = rhs._proto;
      70           10 :         _type         = rhs._type;
      71           10 :         _unicast      = rhs._unicast;
      72              :     }
      73              : 
      74           11 :     return *this;
      75              : }
      76              : 
      77           21 : void ServiceAnnouncerTask::init(
      78              :     service_id::type const serviceId,
      79              :     instance_id::type const instanceId,
      80              :     eventgroup_id::type const eventgroup,
      81              :     ttl::type const ttl,
      82              :     major_version::type const majorVersion,
      83              :     minor_version::type const minorVersion)
      84              : {
      85           21 :     _serviceId    = serviceId;
      86           21 :     _instanceId   = instanceId;
      87           21 :     _eventgroup   = eventgroup;
      88           21 :     _ttl          = ttl;
      89           21 :     _majorVersion = majorVersion;
      90           21 :     _minorVersion = minorVersion;
      91           21 : }
      92              : 
      93            6 : void ServiceAnnouncerTask::setEndpoint(::ip::IPAddress const& address, uint16_t const port)
      94              : {
      95            6 :     _endpoint.setAddress(address);
      96            6 :     _endpoint.setPort(port);
      97            6 : }
      98              : 
      99            4 : void ServiceAnnouncerTask::initFrom(
     100              :     ServiceDescription const& service,
     101              :     ::ip::IPAddress const& address,
     102              :     bool const unicast,
     103              :     uint64_t const timestamp,
     104              :     TaskType const type)
     105              : {
     106            4 :     _serviceId    = service.serviceId;
     107            4 :     _instanceId   = service.instanceId;
     108            4 :     _eventgroup   = service.eventGroup;
     109            4 :     _ttl          = service.ttl;
     110            4 :     _majorVersion = service.majorVersion;
     111            4 :     _minorVersion = service.minorVersion;
     112            4 :     _proto        = service.proto;
     113            4 :     _destination  = address;
     114            4 :     _endpoint.setAddress(service.ipAddress);
     115            4 :     _endpoint.setPort(service.port);
     116            4 :     _unicast   = unicast;
     117            4 :     _timestamp = timestamp;
     118            4 :     _type      = type;
     119            4 : }
     120              : 
     121            4 : void ServiceAnnouncerTask::copyTo(ServiceDescription& service) const
     122              : {
     123            4 :     service.serviceId    = _serviceId;
     124            4 :     service.instanceId   = _instanceId;
     125            4 :     service.eventGroup   = _eventgroup;
     126            4 :     service.ttl          = _ttl;
     127            4 :     service.majorVersion = _majorVersion;
     128            4 :     service.minorVersion = _minorVersion;
     129            4 :     service.ipAddress    = _endpoint.getAddress();
     130            4 :     service.port         = _endpoint.getPort();
     131            4 :     service.proto        = _proto;
     132            4 : }
     133              : 
     134           20 : bool ServiceAnnouncerTask::isSame(ServiceDescription const& service) const
     135              : {
     136           20 :     bool const majorVersionOk
     137           20 :         = ((_majorVersion == major_version::ANY) || (_majorVersion == service.majorVersion));
     138           20 :     bool const minorVersionOk
     139           20 :         = ((_minorVersion == minor_version::ANY) || (_minorVersion == service.minorVersion));
     140              : 
     141              :     return (
     142           20 :         (_serviceId == service.serviceId)
     143           17 :         && ((_instanceId == service.instanceId) || (_instanceId == instance_id::ANY))
     144           37 :         && majorVersionOk && minorVersionOk);
     145              : }
     146              : 
     147            3 : bool ServiceAnnouncerTask::containsEventGroup() const
     148              : {
     149            3 :     return (_eventgroup != eventgroup_id::ALL);
     150              : }
     151              : 
     152              : } // namespace someip
        

Generated by: LCOV version 2.0-1