Add a network backend.
Only one backend per NetworkTransport type is permitted.
225{
226 if (!backend) {
227 return false;
228 }
229
231
233
236 "Network backend {} already registered", backend->get_name());
237 return false;
238 }
239
240 if (!backend->initialize()) {
242 "Failed to initialize network backend: {}", backend->get_name());
243 return false;
244 }
245
246 backend->set_receive_callback(
247 [this](uint64_t id, const uint8_t* data, size_t size, std::string_view addr) {
249 });
250
251 backend->set_state_callback(
254 });
255
256 if (auto* tcp = dynamic_cast<TCPBackend*>(backend.get())) {
257 tcp->set_endpoint_id_allocator([this]() -> uint64_t {
259 });
260 }
261
263 "Added network backend: {}", backend->get_name());
264
266 return true;
267}
#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.