MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

bool MayaFlux::Core::NetworkSerialLink::open ( const std::string & path,
const SerialLineSettings & line )
overridevirtual

Open the port at path with line.

Returns
false when it cannot be opened. A link that reconnects returns true for a port that is not there yet and reports the wait as RECONNECTING.

Implements MayaFlux::Core::ISerialLink.

Definition at line 32 of file NetworkSerialLink.cpp.

33{
34 if (!m_service || !m_service->open_endpoint || !m_service->set_endpoint_receive_callback) {
36 "Serial link {} needs a NetworkService", path);
37 return false;
38 }
39
40 close();
41
42 auto shared = std::make_shared<Shared>();
43 shared->chunk = m_chunk;
44 shared->state = m_state;
45
46 EndpointInfo info;
47 info.transport = NetworkTransport::SERIAL;
49 info.framing = FramingPolicy::NONE;
50 info.remote_path = path;
51 info.label = path;
52 info.serial = line;
53
54 const uint64_t endpoint = m_service->open_endpoint(info);
55 if (endpoint == 0) {
57 "Serial link could not open {}: the port must exist, or the serial transport must be enabled in GlobalNetworkConfig and set to reconnect",
58 path);
59 return false;
60 }
61
62 m_endpoint = endpoint;
63 m_shared = shared;
64 const std::weak_ptr<Shared> weak = shared;
65
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 });
70 }
71 });
72
73 if (m_service->set_endpoint_state_callback) {
74 m_service->set_endpoint_state_callback(endpoint,
75 [weak](uint64_t, EndpointState, EndpointState current) {
76 if (const auto held = weak.lock()) {
77 held->report(current);
78 }
79 });
80 }
81
82 if (m_service->get_endpoint_state) {
83 shared->report(m_service->get_endpoint_state(endpoint));
84 }
85
86 return true;
87}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
EndpointState
Observable connection state for an endpoint.
@ InputBackend
Input device backend (HID, MIDI, OSC).
@ Core
Core engine, backend, subsystems.
Vruta::SoundRoutine line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool restartable)
Creates a continuous interpolation generator between two values over time.
Definition Tasks.cpp:60

References MayaFlux::Core::BIDIRECTIONAL, close(), MayaFlux::Journal::Core, MayaFlux::Core::EndpointInfo::framing, MayaFlux::Journal::InputBackend, MayaFlux::Core::EndpointInfo::label, m_chunk, m_endpoint, m_service, m_shared, m_state, MF_ERROR, MF_WARN, MayaFlux::Core::NONE, MayaFlux::Core::EndpointInfo::remote_path, MayaFlux::Core::EndpointInfo::role, MayaFlux::Core::SERIAL, MayaFlux::Core::EndpointInfo::serial, and MayaFlux::Core::EndpointInfo::transport.

Referenced by operator=().

Here is the call graph for this function:
Here is the caller graph for this function: