16 if (previous != current &&
state) {
17 state(previous, current);
36 "Serial link {} needs a NetworkService", path);
42 auto shared = std::make_shared<Shared>();
54 const uint64_t endpoint =
m_service->open_endpoint(info);
57 "Serial link could not open {}: the port must exist, or the serial transport must be enabled in GlobalNetworkConfig and set to reconnect",
64 const std::weak_ptr<Shared> weak = shared;
66 m_service->set_endpoint_receive_callback(endpoint,
67 [weak](uint64_t,
const uint8_t* data,
size_t size, std::string_view) {
68 if (
const auto held = weak.lock(); held && held->chunk) {
69 held->chunk(std::span<const uint8_t> { data, size });
73 if (
m_service->set_endpoint_state_callback) {
74 m_service->set_endpoint_state_callback(endpoint,
76 if (
const auto held = weak.lock()) {
77 held->report(current);
83 shared->report(
m_service->get_endpoint_state(endpoint));
143 return m_service->post_after(delay, std::move(callback));
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::function< void(std::span< const uint8_t > bytes)> ChunkCallback
std::function< void(EndpointState previous, EndpointState current)> StateCallback
void cancel_post(TimerToken token) override
Cancel a timer.
void set_state_callback(StateCallback callback) override
size_t backlog() const override
Bytes accepted by write() and not yet sent.
~NetworkSerialLink() override
Registry::Service::NetworkService * m_service
void close() override
Close the port.
void set_chunk_callback(ChunkCallback callback) override
bool open(const std::string &path, const SerialLineSettings &line) override
Open the port at path with line.
bool write(std::span< const uint8_t > bytes) override
bool set_control_lines(std::optional< bool > dtr, std::optional< bool > rts) override
Set DTR and RTS, each optional so one can change alone.
std::shared_ptr< Shared > m_shared
EndpointState state() const override
bool send_break() override
NetworkSerialLink(Registry::Service::NetworkService *service)
TimerToken post_after(std::chrono::milliseconds delay, std::function< void()> callback) override
Run callback once after delay on the link's thread.
EndpointState
Observable connection state for an endpoint.
@ InputBackend
Input device backend (HID, MIDI, OSC).
@ Core
Core engine, backend, subsystems.
SerialLineSettings serial
Serial: the line setup applied at open. The device path is remote_path.
FramingPolicy framing
TCP and UDS: how messages are delimited.
NetworkTransport transport
std::string remote_path
UDS: socket to connect to, given the same way as local_path.
Describes one logical send/receive endpoint managed by a backend.
std::atomic< EndpointState > reported
void report(EndpointState current)
Line setup applied when a serial endpoint opens.
Backend network transport service interface.