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/RpcServiceRegistry.h"
12 :
13 : #include "someip/ServiceQuery.h"
14 :
15 : namespace someip
16 : {
17 9 : RpcServiceRegistry::RpcServiceRegistry(
18 9 : ServiceManager& serviceManager, ServiceTracker& serviceTracker)
19 9 : : _serviceManager(serviceManager), _serviceTracker(serviceTracker)
20 9 : {}
21 :
22 7 : void RpcServiceRegistry::init() { _serviceTracker.init(*this); }
23 :
24 0 : void RpcServiceRegistry::shutdown() {}
25 :
26 : // virtual
27 2 : bool RpcServiceRegistry::registerProvidedService(ProvidedService& service)
28 : {
29 2 : return _serviceManager.registerService(service);
30 : }
31 :
32 : // virtual
33 2 : void RpcServiceRegistry::unregisterProvidedService(ProvidedService& service)
34 : {
35 2 : (void)_serviceManager.unregisterService(service);
36 2 : }
37 :
38 : // virtual
39 1 : bool RpcServiceRegistry::registerServiceQuery(ServiceQuery& /* query */)
40 : {
41 1 : return false; // not used for rpc-mode
42 : }
43 :
44 : // virtual
45 1 : void RpcServiceRegistry::unregisterServiceQuery(ServiceQuery& /* query */) {}
46 :
47 : // virtual
48 0 : QueryManager const* RpcServiceRegistry::getQueryManager() const { return nullptr; }
49 :
50 : // virtual
51 3 : instance_id::type RpcServiceRegistry::getInstanceId(
52 : uint16_t const serviceId,
53 : uint8_t const majorVersion,
54 : ::ip::IPAddress const& ipAddress,
55 : uint16_t const port,
56 : bool /*remoteProvider*/) const
57 : {
58 3 : auto service = ::someip::make<ServiceDescription>();
59 3 : service.serviceId = serviceId;
60 3 : service.majorVersion = majorVersion;
61 3 : service.ipAddress = ipAddress;
62 3 : service.port = port;
63 :
64 6 : return _serviceTracker.getInstanceId(service);
65 : }
66 :
67 : // virtual
68 1 : void RpcServiceRegistry::offerReceived(
69 : ServiceDescription const& /*receivedService*/, ::ip::IPAddress const& /*sourceAddress*/)
70 1 : {}
71 :
72 : // virtual
73 1 : IServiceRegistry::SubscriptionResult RpcServiceRegistry::subscribeReceived(
74 : uint16_t const /* serviceId */,
75 : uint16_t const /* instanceId */,
76 : uint8_t const /* majorVersion */,
77 : uint16_t const /* eventGroup */,
78 : uint32_t const /* ttl */,
79 : ::ip::IPAddress const& /* ipAddress */,
80 : uint16_t const /* port */,
81 : uint8_t const /* proto */)
82 : {
83 1 : return IServiceRegistry::SubscriptionResult::SUBSCRIBE_OK;
84 : }
85 :
86 : // virtual
87 1 : void RpcServiceRegistry::subscribeAckReceived(
88 : uint16_t const /* serviceId */,
89 : uint16_t const /* instanceId */,
90 : uint16_t const /* eventGroup */,
91 : uint8_t const /* majorVersion */,
92 : ::ip::IPEndpoint const& /* multicastEndpoint */,
93 : ::ip::IPAddress const& /* sourceAddress */)
94 1 : {}
95 :
96 : // virtual
97 0 : void RpcServiceRegistry::subscribeNackReceived(
98 : uint16_t const /* serviceId */,
99 : uint16_t const /* instanceId */,
100 : uint16_t const /* eventGroup */,
101 : uint8_t const /* majorVersion */,
102 : ::ip::IPAddress const& /* sourceAddress */)
103 0 : {}
104 :
105 : // virtual
106 1 : void RpcServiceRegistry::rebootDetected(::ip::IPAddress const& /* ipAddress */) {}
107 :
108 : // virtual
109 1 : bool RpcServiceRegistry::interestedInService(
110 : service_id::type /* serviceId */,
111 : instance_id::type /* instanceId */,
112 : major_version::type /* majorVersion */) const
113 : {
114 1 : return false;
115 : }
116 :
117 : // virtual
118 1 : bool RpcServiceRegistry::isEventgroupPort(
119 : service_id::type /*serviceId*/,
120 : instance_id::type /*instanceId*/,
121 : major_version::type /*majorVersion*/,
122 : uint16_t /*port*/) const
123 : {
124 1 : return true;
125 : }
126 :
127 : // virtual
128 1 : uint16_t RpcServiceRegistry::getCurrentNumberOfSubscriptions() const { return 0; }
129 :
130 : // virtual
131 1 : uint16_t RpcServiceRegistry::getMaximumNumberOfSubscriptions() const { return 0; }
132 :
133 : // virtual
134 3 : uint16_t RpcServiceRegistry::getCurrentNumberOfProvidedServices() const
135 : {
136 3 : return _serviceManager.getNumberOfServices();
137 : }
138 :
139 : // virtual
140 1 : uint16_t RpcServiceRegistry::getMaximumNumberOfProvidedServices() const
141 : {
142 1 : return _serviceManager.getMaxNumberOfServices();
143 : }
144 :
145 : // virtual
146 2 : uint16_t RpcServiceRegistry::getCurrentNumberOfRemoteServices() const
147 : {
148 2 : return _serviceTracker.getCurrentNumberOfServices();
149 : }
150 :
151 : // virtual
152 1 : uint16_t RpcServiceRegistry::getMaximumNumberOfRemoteServices() const
153 : {
154 1 : return _serviceTracker.getMaximumNumberOfServices();
155 : }
156 :
157 : } // namespace someip
|