MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SerialSource.cpp
Go to the documentation of this file.
1#include "SerialSource.hpp"
2
7
9
10std::shared_ptr<Vruta::NetworkSource> serial_source(uint32_t device_id, const Core::SerialSpec& framing)
11{
13 if (!service || !service->add_serial_reader || !service->remove_serial_reader) {
15 "serial_source: InputService not available");
16 return nullptr;
17 }
18
19 Core::SerialSpec spec = framing;
21 spec.parser = nullptr;
22
23 auto source = std::make_shared<Vruta::NetworkSource>();
24 const std::weak_ptr<Vruta::NetworkSource> weak = source;
25
26 const uint64_t token = service->add_serial_reader(device_id, spec,
27 [weak, device_id](const Core::InputValue& value) {
28 const auto held = weak.lock();
29 const auto* bytes = value.try_bytes();
30 if (!held || !bytes) {
31 return;
32 }
34 message.endpoint_id = device_id;
35 message.data = *bytes;
36 held->signal(message);
37 });
38
39 if (token == 0) {
41 "serial_source: serial device {} is not available", device_id);
42 return nullptr;
43 }
44
45 return { source.get(), [source, token, remove = service->remove_serial_reader](Vruta::NetworkSource*) mutable {
46 remove(token);
47 source.reset();
48 } };
49}
50
51} // namespace MayaFlux::Portal::Network
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
Awaitable broadcast message stream for a network endpoint.
@ Networking
Network operations (data transfer, protocol handling).
@ Portal
High-level user-facing API layer.
std::shared_ptr< Vruta::NetworkSource > serial_source(uint32_t device_id, const Core::SerialSpec &framing)
Read a serial device as network messages, framed the way framing says.
const std::vector< uint8_t > * try_bytes() const noexcept
Safe bytes extraction.
Generic input value container.
A received datagram or framed message with sender metadata.
What a serial device is: its line setup, framing and parsing, as a plain value.
Backend input device service interface.