LCOV - code coverage report
Current view: top level - libs/bsw/cpp2someip/include/someip - ServiceManager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-09-11 12:05:06 Functions: 100.0 % 3 3

            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              : #pragma once
      12              : 
      13              : #include "someip/ProvidedService.h"
      14              : 
      15              : #include <etl/flat_set.h>
      16              : #include <cstdint>
      17              : 
      18              : namespace someip
      19              : {
      20              : class IServiceAnnouncer;
      21              : class ServiceAnnouncerTask;
      22              : 
      23              : /**
      24              :  * Responsible to maintain a list of provided services.
      25              :  */
      26              : class ServiceManager
      27              : {
      28              : public:
      29              :     enum class FindServiceResult : uint8_t
      30              :     {
      31              :         FIND_SERVICE_OK,
      32              :         FIND_SERVICE_UNKNOWN,
      33              :         FIND_SERVICE_WRONG_MAJOR_VERSION
      34              :     };
      35              : 
      36              :     void wire(IServiceAnnouncer* serviceAnnouncer);
      37              : 
      38              :     /**
      39              :      * Initialize registered services.
      40              :      */
      41              :     void start();
      42              : 
      43              :     /**
      44              :      * Shutdown registered services.
      45              :      */
      46              :     void stop();
      47              : 
      48              :     /**
      49              :      * Register a service.
      50              :      *
      51              :      * \post service will be initialized.
      52              :      *
      53              :      * \return true if service was registered.
      54              :      */
      55              :     bool registerService(ProvidedService& service);
      56              : 
      57              :     /**
      58              :      * Unregister a service.
      59              :      *
      60              :      * \post service will be removed asynchronous.
      61              :      *
      62              :      * \return true if service was removed.
      63              :      */
      64              :     bool unregisterService(ProvidedService& service);
      65              : 
      66              :     /**
      67              :      * Answers if given service is registered.
      68              :      */
      69              :     bool hasService(ProvidedService& service) const;
      70              : 
      71              :     /**
      72              :      * Answers if there is a service/eventgroup registered with a given ServiceDescription.
      73              :      */
      74              :     bool hasServiceDescription(ServiceDescription const& service) const;
      75              : 
      76              :     /**
      77              :      * Runs lifecycle on services
      78              :      */
      79              :     void updateServices(uint64_t time);
      80              : 
      81              :     /**
      82              :      * Find the instance ID of a service based on the given ServiceDescription.
      83              :      *
      84              :      * The search is performed based on:
      85              :      * - serviceId
      86              :      * - majorVersion
      87              :      * - port
      88              :      *
      89              :      * \return The instance ID of the service if found, or instance_id::any
      90              :      * if not found.
      91              :      */
      92              :     instance_id::type getInstanceId(ServiceDescription const& service) const;
      93              : 
      94              :     /**
      95              :      * Find a service identified by:
      96              :      *
      97              :      * - serviceId
      98              :      * - instanceId
      99              :      * - majorVersion
     100              :      *
     101              :      * \return service pointer if successful, or 0L otherwise.
     102              :      */
     103              :     ProvidedService const* getService(ServiceDescription const& service) const;
     104              : 
     105              :     /**
     106              :      * Find a eventgroup identified by:
     107              :      *
     108              :      * - serviceId
     109              :      * - instanceId
     110              :      * - majorVersion
     111              :      * - eventgroupId
     112              :      *
     113              :      * \return service pointer if successful, or 0L otherwise.
     114              :      */
     115              :     ProvidedService const* getEventGroup(ServiceDescription const& service) const;
     116              : 
     117              :     /**
     118              :      * Find a handler identified by:
     119              :      *
     120              :      * - serviceId
     121              :      * - majorVersion
     122              :      * - port
     123              :      * - proto
     124              :      *
     125              :      * \post result of search will be set.
     126              :      *
     127              :      * \return handler pointer if successful, or 0L otherwise.
     128              :      */
     129              :     ServiceHandler* getHandler(ServiceDescription const& service, FindServiceResult& result) const;
     130              : 
     131              :     /**
     132              :      * Trigger offers for a service-announcer task.
     133              :      */
     134              :     void triggerOffers(ServiceAnnouncerTask const& task) const;
     135              : 
     136              :     /**
     137              :      * Trigger stop offers after being stopped.
     138              :      *
     139              :      * \note should be called after stop,- calls stop implicitly otherwise.
     140              :      */
     141              :     void triggerStopOffers();
     142              : 
     143              :     uint16_t getNumberOfServices() const;
     144              :     uint16_t getMaxNumberOfServices() const;
     145              : 
     146              : protected:
     147              :     struct ServiceIdComparator
     148              :     {
     149              :         bool operator()(ProvidedService const* lhs, uint16_t rhs) const;
     150              :     };
     151              : 
     152              :     struct LessThanComparator
     153              :     {
     154              :         bool operator()(ProvidedService const* lhs, ProvidedService const* rhs) const;
     155              :     };
     156              : 
     157              :     using ServiceList = ::etl::iflat_set<ProvidedService*, LessThanComparator>;
     158              : 
     159              :     explicit ServiceManager(ServiceList& serviceList);
     160              : 
     161              : private:
     162              :     void removeServices();
     163              : 
     164              :     ServiceList& _services;
     165              :     IServiceAnnouncer* _pServiceAnnouncer;
     166              : 
     167              :     bool _stopCalled;
     168              : };
     169              : 
     170              : namespace declare
     171              : {
     172              : template<uint16_t NUM_SERVICES>
     173              : class ServiceManager : public ::someip::ServiceManager
     174              : {
     175              : public:
     176              :     ServiceManager();
     177              : 
     178              : private:
     179              :     ::etl::flat_set<ProvidedService*, NUM_SERVICES, LessThanComparator> _services;
     180              : };
     181              : 
     182              : template<uint16_t NUM_SERVICES>
     183           99 : inline ServiceManager<NUM_SERVICES>::ServiceManager()
     184           99 : : ::someip::ServiceManager(_services), _services()
     185              : 
     186           99 : {}
     187              : 
     188              : } // namespace declare
     189              : } // namespace someip
        

Generated by: LCOV version 2.0-1