Add a network backend.
Only one backend per NetworkTransport type is permitted.
219{
220 if (!backend) {
221 return false;
222 }
223
225
227
230 "Network backend {} already registered", backend->get_name());
231 return false;
232 }
233
234 if (!backend->initialize()) {
236 "Failed to initialize network backend: {}", backend->get_name());
237 return false;
238 }
239
240 backend->set_receive_callback(
241 [
this](uint64_t
id,
const uint8_t* data,
size_t size, std::string_view addr) {
243 });
244
245 backend->set_state_callback(
248 });
249
250 if (auto* tcp = dynamic_cast<TCPBackend*>(backend.get())) {
251 tcp->set_endpoint_id_allocator([this]() -> uint64_t {
253 });
254 }
255
257 "Added network backend: {}", backend->get_name());
258
260 return true;
261}
#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.