VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
someip_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 by Thun Lu. All rights reserved.
3 * Author: Thun Lu <thun.lu@zohomail.cn>
4 * Repo: https://github.com/thun-res/vlink
5 * _ __ __ _ __
6 * | | / / / / (_) ____ / /__
7 * | | / / / / / / / __ \ / //_/
8 * | |/ / / /___ / / / / / / / ,<
9 * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/**
25 * @file someip_conf.h
26 * @brief Transport configuration for the @c someip:// SOME/IP (vsomeip) backend.
27 *
28 * @details
29 * @c SomeipConf configures the SOME/IP (Scalable service-Oriented MiddlewarE over IP)
30 * transport via the vsomeip library. SOME/IP is the standard automotive middleware
31 * protocol used in AUTOSAR environments over Ethernet.
32 *
33 * @par Supported Node Types
34 * @c someip:// supports all six node types: @c kPublisher, @c kSubscriber, @c kServer,
35 * @c kClient, @c kSetter, and @c kGetter.
36 *
37 * @par SOME/IP Identifier Model
38 * SOME/IP uses a numeric identifier hierarchy rather than string topic names:
39 *
40 * | Field | Use case | Description |
41 * | ------------ | --------------- | ---------------------------------------------- |
42 * | @c service | All | SOME/IP Service ID (16-bit hex) |
43 * | @c instance | All | Service Instance ID (16-bit hex) |
44 * | @c method | RPC only | Method ID for @c kServer / @c kClient |
45 * | @c groups | Event/Field | Event group set for pub/sub and field nodes |
46 * | @c event | Event/Field | Event ID within the group |
47 * | @c field | Field only | @c true when node is a field (getter/setter) |
48 *
49 * @par URL Format
50 * @code
51 * // RPC (Server/Client):
52 * someip://<service>/<instance>?method=<method_id>
53 *
54 * // Event (Publisher/Subscriber):
55 * someip://<service>/<instance>?groups=<g1,g2,...>&event=<event_id>
56 *
57 * // Field (Setter/Getter):
58 * someip://<service>/<instance>?groups=<g1,g2,...>&event=<event_id>&field=1
59 * @endcode
60 *
61 * All numeric values are decimal. Service and instance must be non-zero.
62 *
63 * @par Example
64 * @code
65 * // RPC server on service 0x1234, instance 0x5678, method 0x0001:
66 * vlink::Server<MyReq, MyResp> server("someip://4660/22136?method=1");
67 *
68 * // Event publisher on service 0x1234, instance 0x5678, group 0x0001, event 0x0010:
69 * vlink::Publisher<MyMsg> pub("someip://4660/22136?groups=1&event=16");
70 *
71 * // Or construct directly:
72 * vlink::SomeipConf pub_conf(0x1234, 0x5678, {0x0001}, 0x0010);
73 * vlink::Publisher<MyMsg> pub(pub_conf);
74 * @endcode
75 *
76 * @par vsomeip Configuration
77 * A vsomeip JSON configuration file can be loaded at startup:
78 * @code
79 * vlink::SomeipConf::load_global_config_file("/etc/vsomeip/vsomeip.json");
80 * @endcode
81 *
82 * @note This header is compiled only when @c VLINK_SUPPORT_SOMEIP is defined.
83 * @note @c service and @c instance must both be non-zero for @c is_valid() to return @c true.
84 * @note For @c kPublisher / @c kSubscriber / @c kSetter / @c kGetter, both @c groups and
85 * @c event must be set; otherwise @c is_valid() returns @c false.
86 * @note For @c kSetter / @c kGetter, @c field must be @c true.
87 */
88
89#pragma once
90
91#ifdef VLINK_SUPPORT_SOMEIP
92
93#include <cstdint>
94#include <set>
95#include <string>
96
97#include "../impl/conf.h"
98
99namespace vlink {
100
101/**
102 * @struct SomeipConf
103 * @brief Configuration for the @c someip:// SOME/IP transport.
104 *
105 * @details
106 * Can be constructed directly with numeric identifiers or parsed from a URL string
107 * via @c Url. Two constructors are provided: one for RPC (method-based) nodes and
108 * one for event/field (group-based) nodes.
109 */
110struct VLINK_EXPORT SomeipConf final : public Conf {
111 using Groups = std::set<uint16_t>; ///< Set of SOME/IP event group IDs.
112
113 uint16_t service{0}; ///< SOME/IP Service ID; must be non-zero for a valid configuration.
114 uint16_t instance{0}; ///< SOME/IP Service Instance ID; must be non-zero.
115 uint16_t method{0}; ///< SOME/IP Method ID; used only for @c kServer / @c kClient nodes.
116 Groups groups; ///< Set of event group IDs; required for event and field nodes.
117 uint16_t event{0}; ///< SOME/IP Event ID within the group; required for event/field nodes.
118 bool field{false}; ///< @c true if this is a field node (@c kSetter / @c kGetter).
119
120 /**
121 * @brief Constructs a @c SomeipConf for an RPC node (Server or Client).
122 *
123 * @param _service SOME/IP Service ID.
124 * @param _instance Service Instance ID.
125 * @param _method Method ID for the RPC interface.
126 */
127 explicit SomeipConf(uint16_t _service, uint16_t _instance, uint16_t _method);
128
129 /**
130 * @brief Constructs a @c SomeipConf for an event or field node.
131 *
132 * @param _service SOME/IP Service ID.
133 * @param _instance Service Instance ID.
134 * @param _groups Set of event group IDs to subscribe to.
135 * @param _event SOME/IP Event ID within the group.
136 * @param _field @c true for field (getter/setter) mode; @c false for event (pub/sub).
137 */
138 explicit SomeipConf(uint16_t _service, uint16_t _instance, const Groups& _groups, uint16_t _event,
139 bool _field = false);
140
141 /**
142 * @brief Returns @c true if all fields equal those of @p conf.
143 *
144 * @param conf Configuration to compare.
145 * @return @c true if @c service, @c instance, @c method, @c groups, @c event, and
146 * @c field all match.
147 */
148 [[nodiscard]] bool operator==(const SomeipConf& conf) const noexcept;
149
150 /**
151 * @brief Returns @c true if any field differs from @p conf.
152 *
153 * @param conf Configuration to compare.
154 * @return Logical negation of @c operator==.
155 */
156 [[nodiscard]] bool operator!=(const SomeipConf& conf) const noexcept;
157
158 /**
159 * @brief Returns @c TransportType::kSomeip identifying this transport.
160 *
161 * @return @c TransportType::kSomeip.
162 */
163 [[nodiscard]] TransportType get_transport_type() const override;
164
165 /**
166 * @brief Loads a vsomeip JSON configuration file as the global vsomeip config.
167 *
168 * @details
169 * Delegates to @c SomeipFactory::load_global_config_file(). Must be called
170 * before any @c someip:// nodes are created. The file configures the vsomeip
171 * routing, application name, logging, and network bindings.
172 *
173 * @param filepath Path to the vsomeip JSON configuration file.
174 * @return @c true if the file was loaded and applied; @c false otherwise.
175 */
176 static bool load_global_config_file(const std::string& filepath);
177
178#ifndef VLINK_ENABLE_C_INTERFACE
180#endif
181 VLINK_ALLOW_IMPL_TYPE(kServer | kClient | kPublisher | kSubscriber | kSetter | kGetter)
182 VLINK_CONF_IMPL(SomeipConf)
183};
184
185////////////////////////////////////////////////////////////////
186/// Details
187////////////////////////////////////////////////////////////////
188
189inline SomeipConf::SomeipConf(uint16_t _service, uint16_t _instance, uint16_t _method)
190 : service(_service), instance(_instance), method(_method) {}
191
192inline SomeipConf::SomeipConf(uint16_t _service, uint16_t _instance, const Groups& _groups, uint16_t _event,
193 bool _field)
194 : service(_service), instance(_instance), groups(_groups), event(_event), field(_field) {}
195
196inline bool SomeipConf::operator==(const SomeipConf& conf) const noexcept {
197 return service == conf.service && instance == conf.instance && method == conf.method && groups == conf.groups &&
198 event == conf.event && field == conf.field;
199}
200
201inline bool SomeipConf::operator!=(const SomeipConf& conf) const noexcept { return !(*this == conf); }
202
203inline TransportType SomeipConf::get_transport_type() const { return TransportType::kSomeip; }
204
205} // namespace vlink
206
207#endif
Abstract transport configuration base class and associated helper macros.
#define VLINK_CONF_IMPL(classname)
Standard boilerplate for concrete Conf subclass declarations.
Definition conf.h:227
#define VLINK_DECLARE_GLOBAL_PROPERTY()
Declares per-transport global state: thread count and property storage.
Definition conf.h:292
#define VLINK_ALLOW_IMPL_TYPE(type)
Declares a static constexpr bitmask of supported ImplType values.
Definition conf.h:268
#define VLINK_EXPORT
Definition macros.h:85