Add a network backend.
Only one backend per NetworkTransport type is permitted.
200{
201 if (!backend) {
202 return false;
203 }
204
206
208
211 "Network backend {} already registered", backend->get_name());
212 return false;
213 }
214
215 if (!backend->initialize()) {
217 "Failed to initialize network backend: {}", backend->get_name());
218 return false;
219 }
220
221 backend->set_receive_callback(
222 [this](uint64_t id, const uint8_t* data, size_t size, std::string_view addr) {
224 });
225
226 backend->set_state_callback(
229 });
230
231 if (auto* tcp = dynamic_cast<TCPBackend*>(backend.get())) {
232 tcp->set_endpoint_id_allocator([this]() -> uint64_t {
234 });
235 }
236
238 "Added network backend: {}", backend->get_name());
239
241 return true;
242}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::shared_mutex m_backends_mutex
std::atomic< uint64_t > m_next_endpoint_id
Global endpoint id counter shared across all backends.
void on_backend_state_change(const EndpointInfo &info, EndpointState previous, EndpointState current)
Wired as the state callback on each backend.
void on_backend_receive(uint64_t endpoint_id, const uint8_t *data, size_t size, std::string_view sender_addr)
Wired as the receive callback on each backend.
std::unordered_map< NetworkTransport, std::unique_ptr< INetworkBackend > > m_backends
EndpointState
Observable connection state for an endpoint.
NetworkTransport
Identifies the transport protocol a backend implements.
@ NetworkSubsystem
Network subsystem operations (endpoint management, data routing)
@ Core
Core engine, backend, subsystems.