MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NetworkSink.cpp
Go to the documentation of this file.
1#include "NetworkSink.hpp"
2
7
9
10namespace {
11
12 Core::NetworkTransport resolve_transport(NetworkTransportHint hint, StreamProfile profile)
13 {
14 switch (hint) {
22 switch (profile) {
25 default:
27 }
28 }
30 }
31
32} // namespace
33
35 : m_name(config.name)
36{
39
40 if (!svc) {
42 "NetworkSink '{}': NetworkService not available", m_name);
43 return;
44 }
45
46 m_service = svc;
47
49 info.transport = resolve_transport(config.transport, config.profile);
51 info.remote_address = config.endpoint.address;
52 info.remote_port = config.endpoint.port;
53 info.local_port = config.endpoint.local_port;
54 info.label = config.name;
55
56 m_endpoint_id = svc->open_endpoint(info);
57
58 if (m_endpoint_id == 0) {
60 "NetworkSink '{}': endpoint open failed", m_name);
61 return;
62 }
63
65 "NetworkSink '{}' opened endpoint {}", m_name, m_endpoint_id);
66}
67
75
77 : m_name(std::move(other.m_name))
78 , m_endpoint_id(other.m_endpoint_id)
79 , m_service(other.m_service)
80{
81 other.m_endpoint_id = 0;
82 other.m_service = nullptr;
83}
84
86{
87 if (this != &other) {
88 if (m_endpoint_id != 0 && m_service) {
89 m_service->close_endpoint(m_endpoint_id);
90 }
91 m_name = std::move(other.m_name);
92 m_endpoint_id = other.m_endpoint_id;
93 m_service = other.m_service;
94 other.m_endpoint_id = 0;
95 other.m_service = nullptr;
96 }
97 return *this;
98}
99
101{
102 if (m_endpoint_id == 0 || !m_service) {
103 return false;
104 }
105 return m_service->send(m_endpoint_id, data.data(), data.size());
106}
107
108bool NetworkSink::send_to(ByteView data, const std::string& address, uint16_t port) const
109{
110 if (m_endpoint_id == 0 || !m_service) {
111 return false;
112 }
113 return m_service->send_to(m_endpoint_id, data.data(), data.size(), address, port);
114}
115
116} // namespace MayaFlux::Portal::Network
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Registry::Service::NetworkService * m_service
NetworkSink(const StreamConfig &config)
Open a send endpoint from a StreamConfig.
bool send(ByteView data) const
Send bytes through this sink's endpoint.
~NetworkSink()
Close the endpoint and release resources.
NetworkSink & operator=(const NetworkSink &)=delete
bool send_to(ByteView data, const std::string &address, uint16_t port) const
Send bytes to an explicit address, overriding the config target.
Owned handle for sending data through a network stream.
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
NetworkTransport
Identifies the transport protocol a backend implements.
@ Networking
Network operations (data transfer, protocol handling)
@ Portal
High-level user-facing API layer.
NetworkTransportHint
Portal-level transport hint, independent of Core::NetworkTransport.
@ SHARED_MEMORY
Zero-copy IPC on the same machine.
@ TCP
Reliable ordered byte stream. Bulk data, session-oriented.
@ AUTO
Let NetworkFoundry pick based on StreamProfile.
@ UDP
Low-latency, unordered datagrams. OSC, control, sparse streams.
std::span< const uint8_t > ByteView
Convenience alias for a read-only byte view.
StreamProfile
Data characteristics that drive transport and framing selection.
@ ORDERED_BULK
Large payloads, loss-intolerant, ordering required.
Describes one logical send/receive endpoint managed by a backend.
Full configuration for an outbound or bidirectional stream.
uint16_t port
Remote port (send) or local port (receive).
uint16_t local_port
Explicit local bind port. 0 = OS-assigned.
std::string address
Remote address. Empty = listen only.
std::function< bool(uint64_t endpoint_id, const uint8_t *data, size_t size)> send
Send data through an endpoint.
std::function< bool(uint64_t endpoint_id, const uint8_t *data, size_t size, const std::string &address, uint16_t port)> send_to
Send data to a specific address through an endpoint.
std::function< void(uint64_t endpoint_id)> close_endpoint
Close an endpoint.
Backend network transport service interface.