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

            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/NetworkChannel.h"
      14              : #include "someip/SomeIpConstants.h"
      15              : 
      16              : #include <etl/expected.h>
      17              : #include <etl/optional.h>
      18              : #include <etl/vector.h>
      19              : #include <cstdint>
      20              : 
      21              : namespace someip
      22              : {
      23              : class INetworkListener;
      24              : 
      25              : /**
      26              :  * Responsible for the network resources.
      27              :  */
      28              : class INetwork
      29              : {
      30              : protected:
      31          151 :     INetwork() = default;
      32              : 
      33              : public:
      34              :     INetwork(INetwork const&)            = delete;
      35              :     INetwork& operator=(INetwork const&) = delete;
      36              : 
      37          151 :     virtual ~INetwork() = default;
      38              : 
      39              :     /**
      40              :      * Pure virtual fuction that sets listener for SD.
      41              :      *
      42              :      * \pre network is stopped.
      43              :      */
      44              :     virtual void setSdListener(INetworkListener& listener) = 0;
      45              : 
      46              :     /**
      47              :      * Pure virtual function that sets listener for RPC.
      48              :      *
      49              :      * \pre network is stopped.
      50              :      */
      51              :     virtual void setRpcListener(INetworkListener& listener) = 0;
      52              : 
      53              :     /**
      54              :      * Pure virtual function that configures a SD port.
      55              :      *
      56              :      * \pre network is stopped.
      57              :      *
      58              :      * \return true on success
      59              :      */
      60              :     virtual bool initSdPort(uint16_t port) = 0;
      61              : 
      62              :     /**
      63              :      * Pure virtual function that configures a UDP port.
      64              :      *
      65              :      * If stopped, the port will be configured for being opened on start.
      66              :      * If started, the port will be opened immediately.
      67              :      *
      68              :      * \return true on success
      69              :      */
      70              :     virtual bool initUdpPort(uint16_t port) = 0;
      71              : 
      72              :     /**
      73              :      * Pure virtual function that closes a UDP port.
      74              :      *
      75              :      * \pre network is started.
      76              :      */
      77              :     virtual void shutdownUdpPort(uint16_t port) = 0;
      78              : 
      79              :     /**
      80              :      * Pure virtual function that configures a TCP port.
      81              :      *
      82              :      * If stopped, the port will be configured for being opened on start.
      83              :      * If started, the port will be opened immediately.
      84              :      *
      85              :      * \return true on success
      86              :      */
      87              :     virtual bool initTcpPort(uint16_t port) = 0;
      88              : 
      89              :     /**
      90              :      * Pure virtual function that configures
      91              :      * a TCP port with external buffering for reassembling received data.
      92              :      *
      93              :      * The quantity of buffers shall be equal to the max number of expected clients for the
      94              :      * particular 'port'.
      95              :      * If stopped, the port will be configured for being opened on start.
      96              :      * If started, the port will be opened immediately.
      97              :      *
      98              :      * \return true on success
      99              :      */
     100              :     virtual bool
     101              :     initTcpPortWithExternalBuffers(uint16_t port, ::etl::ivector<::etl::span<uint8_t>>& buffers)
     102              :         = 0;
     103              : 
     104              :     /**
     105              :      * Pure virtual function that closes a TCP port.
     106              :      *
     107              :      * \pre network is started.
     108              :      */
     109              :     virtual void shutdownTcpPort(uint16_t port) = 0;
     110              : 
     111              :     /**
     112              :      * Pure virtual function that provides information whether
     113              :      * the network is started.
     114              :      */
     115              :     virtual bool isStarted() const = 0;
     116              : 
     117              :     /**
     118              :      * Pure virtual function that starts the network by opening all
     119              :      * configured network resources.
     120              :      *
     121              :      * Opens all configured network resources.
     122              :      *
     123              :      * \return true on success
     124              :      */
     125              :     virtual bool start() = 0;
     126              : 
     127              :     /**
     128              :      * Pure virtual function that stops the network by stopping all
     129              :      * configured network resources.
     130              :      */
     131              :     virtual void stop() = 0;
     132              : 
     133              :     /**
     134              :      * Pure virtual function that returns multicast ip.
     135              :      */
     136              :     virtual ::ip::IPAddress const& getMulticastIp() const = 0;
     137              : 
     138              :     /**
     139              :      * Pure virtual function that returns local ip.
     140              :      */
     141              :     virtual ::ip::IPAddress const& getLocalIp() const = 0;
     142              : 
     143              :     /**
     144              :      * Pure virtual function that returns subnet id.
     145              :      */
     146              :     virtual uint8_t getSubnetId() const = 0;
     147              : 
     148              :     /**
     149              :      * Pure virtual function that returns SD port.
     150              :      */
     151              :     virtual ::etl::expected<uint16_t, PortError> getSdPort(bool multicast = true) const = 0;
     152              : 
     153              :     /**
     154              :      * Pure virtual function that returns a SD channel.
     155              :      *
     156              :      * \note Succeeds if a SD proxy is preconfigured and open for this localPort.
     157              :      *
     158              :      * \param localPort the channel is associated with.
     159              :      * \param remoteEndpoint the channel is associated with.
     160              :      *
     161              :      * \return an optional channel.
     162              :      */
     163              :     virtual ::etl::optional<NetworkChannel>
     164              :     getSdChannel(uint16_t localPort, ::ip::IPEndpoint const& remoteEndpoint) const = 0;
     165              : 
     166              :     /**
     167              :      * Pure virtual function that opens a RPC channel for a remoteEndpoint.
     168              :      *
     169              :      * \note Succeeds if a RPC proxy is currently open and associated with this localPort.
     170              :      *
     171              :      * \param localPort the channel is associated with.
     172              :      * \param remoteEndpoint the channel is associated with.
     173              :      * \param proto the protocol used for this channel.
     174              :      *
     175              :      * \return an optional channel.
     176              :      */
     177              :     virtual ::etl::optional<NetworkChannel>
     178              :     getRpcChannel(uint16_t localPort, ::ip::IPEndpoint const& remoteEndpoint, uint8_t proto) const
     179              :         = 0;
     180              : 
     181              :     /**
     182              :      * Pure virtual function that opens a UDP RPC channel for a remoteEndpoint.
     183              :      *
     184              :      * \note Succeeds if a UDP RPC proxy is already open and associated with this localPort or a new
     185              :      * one could be opened.
     186              :      *
     187              :      * \param localPort the channel is associated with.
     188              :      * \param remoteEndpoint the channel is associated with.
     189              :      *
     190              :      * \return an optional channel.
     191              :      */
     192              :     virtual ::etl::optional<NetworkChannel>
     193              :     openUdpChannel(uint16_t localPort, ::ip::IPEndpoint const& remoteEndpoint) = 0;
     194              : 
     195              :     /**
     196              :      * Pure virtual function that opens a TCP RPC channel for a remoteEndpoint.
     197              :      *
     198              :      * \note Succeeds if a new TCP RPC proxy could be opened for the remoteEndpoint.
     199              :      *
     200              :      * \param localPort the channel is associated with.
     201              :      * \param remoteEndpoint the channel is associated with.
     202              :      *
     203              :      * \return an optional channel, which will be associated with the remote port if successfully.
     204              :      */
     205              :     virtual ::etl::optional<NetworkChannel>
     206              :     openTcpChannel(uint16_t localPort, ::ip::IPEndpoint const& remoteEndpoint) = 0;
     207              : 
     208              :     /**
     209              :      * Pure virtual function that opens a TCP RPC channel for a remoteEndpoint.
     210              :      *
     211              :      * \note Succeeds if a new TCP RPC proxy could be opened for the remoteEndpoint.
     212              :      *
     213              :      * \param localPort the channel is associated with.
     214              :      * \param remoteEndpoint the channel is associated with.
     215              :      * \param buffer the external buffer to be used for an incoming tcp data.
     216              :      *
     217              :      * \return an optional channel, which will be associated with the remote port if successfully.
     218              :      */
     219              :     virtual ::etl::optional<NetworkChannel> openTcpChannelWithExternalReassembleBuffer(
     220              :         uint16_t localPort, ::ip::IPEndpoint const& remoteEndpoint, ::etl::span<uint8_t> buffer)
     221              :         = 0;
     222              : 
     223              :     // INTERFACE_END
     224              : };
     225              : 
     226              : } // namespace someip
        

Generated by: LCOV version 2.0-1