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 <ip/IPAddress.h>
14 :
15 : #include <etl/flat_map.h>
16 : #include <cstdint>
17 :
18 : namespace someip
19 : {
20 : namespace internal
21 : {
22 : uint16_t const INITIAL_SESSION_ID = 1U;
23 : uint16_t const MAX_SESSION_ID = 0xFFFFU;
24 :
25 : class SessionEntry
26 : {
27 : public:
28 : SessionEntry();
29 : void clear();
30 : void increment();
31 :
32 : uint16_t _sessionId;
33 : bool _rebootFlag;
34 : };
35 :
36 : class SessionEndpoint : public SessionEntry
37 : {
38 : public:
39 : SessionEndpoint();
40 : void clear();
41 : };
42 :
43 : } // namespace internal
44 :
45 : class SessionManager
46 : {
47 : public:
48 : void init();
49 :
50 : void getSessionInfoForNextMulticastMessage(uint16_t& sessionId, bool& rebootFlag);
51 :
52 : void getSessionInfoForNextUnicastMessage(
53 : ::ip::IPAddress const& ipAddress, uint16_t& sessionId, bool& rebootFlag);
54 :
55 : protected:
56 : using EndpointMap
57 : = ::etl::iflat_map<::ip::IPAddress, internal::SessionEndpoint, ::ip::IPAddressCompareLess>;
58 :
59 : explicit SessionManager(EndpointMap& map);
60 :
61 : private:
62 : EndpointMap::iterator addEndpoint(::ip::IPAddress const& ipAddress);
63 :
64 : EndpointMap& _endpoints;
65 : internal::SessionEntry _multicast;
66 : };
67 :
68 : namespace declare
69 : {
70 : template<uint16_t NUM_ENDPOINTS>
71 : class SessionManager : public ::someip::SessionManager
72 : {
73 : public:
74 : SessionManager();
75 :
76 : private:
77 : ::etl::flat_map<
78 : ::ip::IPAddress,
79 : internal::SessionEndpoint,
80 : NUM_ENDPOINTS,
81 : ::ip::IPAddressCompareLess>
82 : _endpointMap;
83 : };
84 :
85 : template<uint16_t NUM_ENDPOINTS>
86 27 : inline SessionManager<NUM_ENDPOINTS>::SessionManager()
87 27 : : ::someip::SessionManager(_endpointMap), _endpointMap()
88 27 : {}
89 :
90 : } // namespace declare
91 : } // namespace someip
|