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/ISubscriptionManager.h"
14 :
15 : #include <etl/flat_set.h>
16 : #include <etl/ipool.h>
17 :
18 : namespace someip
19 : {
20 : namespace internal
21 : {
22 :
23 : using EndpointPool = ::etl::ipool;
24 : using EventGroupPool = ::etl::ipool;
25 :
26 : class FindEventGroupCondition
27 : {
28 : public:
29 : explicit FindEventGroupCondition(SubscribedEventGroup const& eventgroup);
30 :
31 : bool isValid() const;
32 : bool operator()(SubscribedEventGroup const* eventgroup) const;
33 :
34 : private:
35 : SubscribedEventGroup const& _eventgroup;
36 : };
37 :
38 : class RemoveExpiredTtlCondition
39 : {
40 : public:
41 : RemoveExpiredTtlCondition(
42 : EndpointPool& endpoints, uint32_t ticks, internal::EventGroupPool& groupPool);
43 :
44 : bool operator()(SubscribedEventGroup* eventgroup) const;
45 :
46 : private:
47 : EndpointPool& _endpoints;
48 : uint32_t const _ticks;
49 : internal::EventGroupPool& _groupPool;
50 : };
51 :
52 : } // namespace internal
53 :
54 : class SubscriptionManager : public ISubscriptionManager
55 : {
56 : public:
57 : void stop();
58 :
59 : InternalSubscribeResult addSubscription(
60 : service_id::type serviceId,
61 : major_version::type majorVersion,
62 : instance_id::type instanceId,
63 : eventgroup_id::type eventgroupId,
64 : ttl::type ttl,
65 : ::ip::IPAddress const& ipAddress,
66 : uint16_t port) override;
67 :
68 : void removeSubscription(
69 : service_id::type serviceId,
70 : major_version::type majorVersion,
71 : instance_id::type instanceId,
72 : eventgroup_id::type eventgroupId,
73 : ::ip::IPAddress const& ipAddress,
74 : uint16_t port) override;
75 :
76 : void removeSubscriptions(
77 : service_id::type serviceId,
78 : major_version::type majorVersion,
79 : instance_id::type instanceId,
80 : eventgroup_id::type eventgroupId) override;
81 :
82 : void removeSubscriptions(::ip::IPAddress const& ipAddress) override;
83 :
84 : void updateTTLs(uint32_t expiredSeconds) override;
85 :
86 : SubscriptionEndpointList*
87 : getSubscriptions(SubscribedEventGroup const& eventgroup) const override;
88 :
89 : uint16_t getCurrentNumberOfSubscriptions() const override;
90 : uint16_t getMaximumNumberOfSubscriptions() const override;
91 :
92 : protected:
93 : struct LessThanComparator
94 : {
95 : bool operator()(SubscribedEventGroup const* lhs, SubscribedEventGroup const* rhs) const;
96 : };
97 :
98 : class RemoveIpCondition
99 : {
100 : public:
101 : RemoveIpCondition(
102 : internal::EndpointPool& endpoints,
103 : ::ip::IPAddress const& ipAddr,
104 : internal::EventGroupPool& groupPool);
105 :
106 : bool operator()(SubscribedEventGroup* eventgroup) const;
107 :
108 : private:
109 : internal::EndpointPool& _endpoints;
110 : ::ip::IPAddress const& _ip;
111 : internal::EventGroupPool& _groupPool;
112 : };
113 :
114 : using EventGroupList = ::etl::iflat_set<SubscribedEventGroup*, LessThanComparator>;
115 :
116 : SubscriptionManager(
117 : EventGroupList& groupList,
118 : internal::EventGroupPool& groupPool,
119 : internal::EndpointPool& endpointPool);
120 :
121 : private:
122 : void clear();
123 :
124 : EventGroupList& _eventgroups;
125 : internal::EventGroupPool& _groupPool;
126 : internal::EndpointPool& _endpoints;
127 : };
128 :
129 : namespace declare
130 : {
131 : template<uint16_t NUM_SUBSCRIPTIONS>
132 : class SubscriptionManager : public ::someip::SubscriptionManager
133 : {
134 : public:
135 : SubscriptionManager();
136 :
137 : private:
138 : ::etl::flat_set<SubscribedEventGroup*, NUM_SUBSCRIPTIONS, LessThanComparator> _eventgroupList;
139 :
140 : ::etl::pool<SubscribedEventGroup, NUM_SUBSCRIPTIONS> _eventGroupPool;
141 : ::etl::pool<SubscriptionEndpoint, NUM_SUBSCRIPTIONS> _endpointPool;
142 : };
143 :
144 : template<uint16_t NUM_SUBSCRIPTIONS>
145 20 : inline SubscriptionManager<NUM_SUBSCRIPTIONS>::SubscriptionManager()
146 20 : : ::someip::SubscriptionManager(_eventgroupList, _eventGroupPool, _endpointPool)
147 20 : {}
148 :
149 : } // namespace declare
150 : } // namespace someip
|