OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
configuration.hpp
1#pragma once
2#include <cstdint>
3#include <optional>
4#include <string>
5#include <vector>
6
7namespace ossia::net
8{
9enum class framing
10{
11 none,
12 size_prefix, // 4-byte big-endian (backward compatible)
13 slip,
14 line_delimiter,
15 cobs,
16 stx_etx,
17 size_prefix_1byte,
18 size_prefix_2byte_be,
19 size_prefix_2byte_le,
20 size_prefix_4byte_le,
21 fixed_length
22};
23
24struct fd_configuration
25{
26 std::string fd;
27};
28
29struct send_fd_configuration : fd_configuration
30{
31};
32struct receive_fd_configuration : fd_configuration
33{
34};
35
36struct outbound_socket_configuration
37{
38 std::string host;
39 uint16_t port{};
40 bool broadcast{};
41
42 std::optional<int> multicast_ttl;
43 std::string multicast_interface{};
44 std::optional<bool> multicast_loopback;
45};
46struct inbound_socket_configuration
47{
48 std::string bind{"0.0.0.0"};
49 uint16_t port{};
50 std::string multicast_group{};
51 std::string multicast_interface{"0.0.0.0"};
52};
53
54struct double_fd_configuration
55{
56 std::optional<receive_fd_configuration> local;
57 std::optional<send_fd_configuration> remote;
58};
59
60struct double_socket_configuration
61{
62 std::optional<inbound_socket_configuration> local;
63 std::optional<outbound_socket_configuration> remote;
64};
65
66struct serial_configuration
67{
68 // the serial device name ("COM1", "/dev/ttyUSB1"...)
69 std::string port;
70
71 int baud_rate{19200};
72 int character_size{8};
73 enum
74 {
75 no_flow_control,
76 software,
77 hardware
78 } flow_control{no_flow_control};
79 enum
80 {
81 no_parity,
82 odd,
83 even
84 } parity{no_parity};
85 enum
86 {
87 one,
88 onepointfive,
89 two
90 } stop_bits{one};
91};
92
93// CAN is only implemented on top of SocketCAN for now, so ossia::net::can_socket
94// itself is Linux-only -- but the configuration is plain data and exists
95// everywhere, exactly like the POSIX-only unix socket configurations above. That
96// way the protocol layers that carry a configuration around do not have to be
97// guarded themselves, only the code that actually opens a socket.
98struct can_filter_configuration
99{
100 // Both fields are raw SocketCAN values: `id` may carry CAN_EFF_FLAG,
101 // CAN_RTR_FLAG and CAN_INV_FILTER, and the kernel keeps a frame when
102 // `received_id & mask == id & mask`.
103 uint32_t id{};
104 uint32_t mask{};
105};
106
107struct can_configuration
108{
109 // The netdev name of the CAN interface: "can0", "vcan0", "slcan0"...
110 // Not spelled `interface`: that is a macro (`struct`) on Windows, pulled in by
111 // <objbase.h> through most of the Win32 headers.
112 std::string interface_name;
113
114 // Enable CAN FD (CAN_RAW_FD_FRAMES): allows payloads of up to 64 bytes.
115 // Note that this is not a mode switch -- once enabled, classic frames and FD
116 // frames both arrive on the same socket, and the socket keeps being able to
117 // send classic frames.
118 bool fd{false};
119
120 // Kernel defaults, spelled out. Together they mean: frames written by this
121 // socket are looped back to the *other* sockets bound to the interface, but
122 // not to the socket that sent them. Disabling loopback is a per-socket switch
123 // that turns off the loopback of that socket's own frames to everyone.
124 bool loopback{true};
125 bool receive_own_messages{false};
126
127 // Receive error frames (CAN_RAW_ERR_FILTER). Those are not bus traffic: the
128 // kernel synthesizes them to report controller/bus conditions, and they are
129 // delivered with CAN_ERR_FLAG set. See can_message::error.
130 bool error_frames{false};
131
132 // Empty means "receive every frame". Note that a non-empty list is applied by
133 // the kernel per socket, so several sockets on the same interface each get
134 // their own view of the bus.
135 std::vector<can_filter_configuration> filters;
136};
137
138struct ws_client_configuration
139{
140 std::string url;
141};
142
143struct ws_server_configuration
144{
145 int port{};
146};
147
148// first / second: the unix sockets name.
149// Must be reverted between host and mirror as they are symmetrical.
150struct unix_dgram_configuration : double_fd_configuration
151{
152};
153
154struct unix_stream_configuration : fd_configuration
155{
156};
157
158struct udp_configuration : double_socket_configuration
159{
160};
161
162struct tcp_client_configuration : outbound_socket_configuration
163{
164};
165
166struct udp_server_configuration : inbound_socket_configuration
167{
168};
169struct tcp_server_configuration : inbound_socket_configuration
170{
171};
172struct unix_dgram_server_configuration : receive_fd_configuration
173{
174};
175struct unix_stream_server_configuration : receive_fd_configuration
176{
177};
178}