MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlobalNetworkConfig.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6
7/**
8 * @enum NetworkTransport
9 * @brief Identifies the transport protocol a backend implements
10 */
11enum class NetworkTransport : uint8_t {
12 UDP,
13 TCP,
15};
16
17/**
18 * @enum EndpointRole
19 * @brief Whether an endpoint sends, receives, or both
20 */
21enum class EndpointRole : uint8_t {
22 SEND,
23 RECEIVE,
25};
26
27/**
28 * @enum EndpointState
29 * @brief Observable connection state for an endpoint
30 */
31enum class EndpointState : uint8_t {
32 CLOSED,
33 OPENING,
34 OPEN,
35 ERROR,
37};
38
39/**
40 * @struct EndpointInfo
41 * @brief Describes one logical send/receive endpoint managed by a backend
42 *
43 * Analogous to InputDeviceInfo for InputSubsystem. An endpoint is the
44 * network equivalent of a device: something you open, send/receive
45 * through, and close.
46 */
47struct MAYAFLUX_API EndpointInfo {
48 uint64_t id {};
49 NetworkTransport transport { NetworkTransport::UDP };
50 EndpointRole role { EndpointRole::BIDIRECTIONAL };
51 EndpointState state { EndpointState::CLOSED };
52 std::string label;
53 std::string remote_address;
54 uint16_t remote_port {};
55 uint16_t local_port {};
56};
57
58/**
59 * @struct NetworkMessage
60 * @brief A received datagram or framed message with sender metadata
61 *
62 * Passed to receive callbacks. Also the natural return type for a
63 * future NetworkAwaiter (Kriya::NetworkReceive) if condition-driven
64 * coroutine support is added later, following the EventAwaiter model.
65 */
67 uint64_t endpoint_id {};
68 std::vector<uint8_t> data;
69 std::string sender_address;
70};
71
72// ─────────────────────────────────────────────────────────────────────────────
73// Per-backend configuration structs
74// ─────────────────────────────────────────────────────────────────────────────
75
76/**
77 * @struct UDPBackendInfo
78 * @brief Configuration for the UDP transport backend
79 *
80 * UDP handles connectionless datagrams. OSC, simple parameter
81 * broadcast, and low-latency control messages ride on top of this.
82 */
83struct MAYAFLUX_API UDPBackendInfo {
84 bool enabled { false };
85 uint16_t default_receive_port { 8000 };
86 uint16_t default_send_port { 9000 };
87 std::string default_send_address { "127.0.0.1" };
88 size_t receive_buffer_size { 65536 };
89 bool enable_broadcast { false };
90 bool enable_multicast { false };
91 std::string multicast_group;
92
93 static constexpr auto describe()
94 {
95 return std::make_tuple(
96 IO::member("enabled", &UDPBackendInfo::enabled),
97 IO::member("default_receive_port", &UDPBackendInfo::default_receive_port),
98 IO::member("default_send_port", &UDPBackendInfo::default_send_port),
99 IO::member("default_send_address", &UDPBackendInfo::default_send_address),
100 IO::member("receive_buffer_size", &UDPBackendInfo::receive_buffer_size),
101 IO::member("enable_broadcast", &UDPBackendInfo::enable_broadcast),
102 IO::member("enable_multicast", &UDPBackendInfo::enable_multicast),
103 IO::member("multicast_group", &UDPBackendInfo::multicast_group));
104 }
105};
106
107/**
108 * @struct TCPBackendInfo
109 * @brief Configuration for the TCP transport backend
110 *
111 * TCP handles reliable, ordered byte streams. Bulk audio/video/tensor
112 * data, model weight transfer, and any payload where completeness
113 * matters more than latency.
114 */
115struct MAYAFLUX_API TCPBackendInfo {
116 bool enabled { false };
117 uint16_t listen_port { 0 };
118 size_t receive_buffer_size { 1048576 };
119 bool auto_reconnect { true };
120 uint32_t reconnect_interval_ms { 2000 };
121 uint32_t connect_timeout_ms { 5000 };
122
123 static constexpr auto describe()
124 {
125 return std::make_tuple(
126 IO::member("enabled", &TCPBackendInfo::enabled),
127 IO::member("listen_port", &TCPBackendInfo::listen_port),
128 IO::member("receive_buffer_size", &TCPBackendInfo::receive_buffer_size),
129 IO::member("auto_reconnect", &TCPBackendInfo::auto_reconnect),
130 IO::member("reconnect_interval_ms", &TCPBackendInfo::reconnect_interval_ms),
131 IO::member("connect_timeout_ms", &TCPBackendInfo::connect_timeout_ms));
132 }
133};
134
135/**
136 * @struct SharedMemoryBackendInfo
137 * @brief Configuration for local inter-process shared memory transport
138 *
139 * Zero-copy data exchange between processes on the same machine.
140 * Useful for multi-instance MayaFlux, bridging to Python inference
141 * servers without serialization overhead, or DAW plugin hosting.
142 */
143struct MAYAFLUX_API SharedMemoryBackendInfo {
144 bool enabled { false };
145 std::string segment_name { "mayaflux_shm" };
146 size_t segment_size { 16 * 1024 * 1024 };
147
148 static constexpr auto describe()
149 {
150 return std::make_tuple(
151 IO::member("enabled", &SharedMemoryBackendInfo::enabled),
152 IO::member("segment_name", &SharedMemoryBackendInfo::segment_name),
153 IO::member("segment_size", &SharedMemoryBackendInfo::segment_size));
154 }
155};
156
157// ─────────────────────────────────────────────────────────────────────────────
158// Global configuration
159// ─────────────────────────────────────────────────────────────────────────────
160
161/**
162 * @struct GlobalNetworkConfig
163 * @brief Configuration for the NetworkSubsystem
164 *
165 * Passed to NetworkSubsystem during construction. Mirrors the pattern
166 * established by GlobalInputConfig for InputSubsystem.
167 *
168 * @code
169 * GlobalNetworkConfig net_config;
170 * net_config.udp.enabled = true;
171 * net_config.udp.default_receive_port = 7000;
172 * net_config.tcp.enabled = true;
173 * auto net_subsystem = std::make_unique<NetworkSubsystem>(net_config);
174 * @endcode
175 */
176struct MAYAFLUX_API GlobalNetworkConfig {
180
181 static GlobalNetworkConfig with_udp(uint16_t recv_port = 8000, uint16_t send_port = 9000)
182 {
183 GlobalNetworkConfig config;
184 config.udp.enabled = true;
185 config.udp.default_receive_port = recv_port;
186 config.udp.default_send_port = send_port;
187 return config;
188 }
189
190 static GlobalNetworkConfig with_tcp(uint16_t listen_port = 0)
191 {
192 GlobalNetworkConfig config;
193 config.tcp.enabled = true;
194 config.tcp.listen_port = listen_port;
195 return config;
196 }
197
198 static GlobalNetworkConfig with_osc(uint16_t recv_port = 8000, uint16_t send_port = 9000)
199 {
200 return with_udp(recv_port, send_port);
201 }
202
203 [[nodiscard]] bool any_enabled() const
204 {
205 return udp.enabled || tcp.enabled || shared_memory.enabled;
206 }
207
208 static constexpr auto describe()
209 {
210 return std::make_tuple(
211 IO::member("udp", &GlobalNetworkConfig::udp),
212 IO::member("tcp", &GlobalNetworkConfig::tcp),
213 IO::member("shared_memory", &GlobalNetworkConfig::shared_memory));
214 }
215};
216
217} // namespace MayaFlux::Core
EndpointState
Observable connection state for an endpoint.
NetworkTransport
Identifies the transport protocol a backend implements.
EndpointRole
Whether an endpoint sends, receives, or both.
Describes one logical send/receive endpoint managed by a backend.
static GlobalNetworkConfig with_tcp(uint16_t listen_port=0)
static GlobalNetworkConfig with_udp(uint16_t recv_port=8000, uint16_t send_port=9000)
static GlobalNetworkConfig with_osc(uint16_t recv_port=8000, uint16_t send_port=9000)
Configuration for the NetworkSubsystem.
A received datagram or framed message with sender metadata.
Configuration for local inter-process shared memory transport.
Configuration for the TCP transport backend.
Configuration for the UDP transport backend.