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