MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Core::SerialInputBackend Class Reference

The serial devices of the input system, one SerialDevice per open port. More...

#include <SerialInputBackend.hpp>

Inheritance diagram for MayaFlux::Core::SerialInputBackend:
Collaboration diagram for MayaFlux::Core::SerialInputBackend:

Classes

struct  Config
struct  Entry
struct  ReaderRecord
struct  Roster

Public Types

using ReaderCallback = std::function<void(const InputValue&)>

Public Member Functions

uint32_t add_port (const SerialPortConfig &port)
 List a port that was not configured, or update one that was while it is closed.
uint64_t add_reader (uint32_t device_id, SerialSpec spec, ReaderCallback callback)
 Read a device's bytes a second way and hand the values to callback.
uint32_t add_view (uint32_t device_id, SerialSpec spec)
 List a second way of reading a device, as a device of its own.
void close_device (uint32_t device_id) override
 Close a previously opened device.
std::shared_ptr< SerialDevice > get_device (uint32_t device_id) const
 The open device, or null.
std::vector< InputDeviceInfo > get_devices () const override
 Get list of available devices.
std::string get_name () const override
 Get backend name/identifier string.
std::vector< uint32_t > get_open_devices () const override
 Get list of currently open device IDs.
InputType get_type () const override
 Get backend type.
std::string get_version () const override
 Get backend version string.
bool initialize () override
 Initialize the input backend.
bool is_device_open (uint32_t device_id) const override
 Check if a device is currently open.
bool is_initialized () const override
 Check if backend is initialized.
bool is_running () const override
 Check if backend is actively listening.
bool open_device (uint32_t device_id) override
 Open a device for input.
SerialInputBackend & operator= (const SerialInputBackend &)=delete
SerialInputBackend & operator= (SerialInputBackend &&)=delete
size_t refresh_devices () override
 Refresh the device list.
void remove_reader (uint64_t token)
 Stop a reader.
 SerialInputBackend (Config config)
 SerialInputBackend (const SerialInputBackend &)=delete
 SerialInputBackend (SerialInputBackend &&)=delete
void set_device_callback (DeviceCallback callback) override
 Register callback for device connect/disconnect events.
bool set_device_spec (uint32_t device_id, SerialSpec spec)
 Give a device its spec, before it is opened.
void set_input_callback (InputCallback callback) override
 Register callback for input values.
void shutdown () override
 Shutdown and release all resources.
void start () override
 Start listening for input events.
void stop () override
 Stop listening for input events.
int write (uint32_t device_id, std::span< const uint8_t > data) override
 Send an output report to an open device, for rumble, LEDs or commands.
 ~SerialInputBackend () override
Public Member Functions inherited from MayaFlux::Core::IInputBackend
virtual int send_feature_report (uint32_t, std::span< const uint8_t >)
 Send a feature report to an open device.
virtual ~IInputBackend ()=default

Private Types

using DeviceEvent = std::pair<InputDeviceInfo, bool>

Private Member Functions

uint64_t add_record (uint32_t device_id, uint32_t stamp, SerialSpec spec, ReaderCallback callback)
void attach_readers (uint32_t device_id, const std::shared_ptr< SerialDevice > &device)
void detach_view (uint32_t view_id)
void notify_device (const InputDeviceInfo &info, bool connected) const
void notify_input (const InputValue &value) const
void on_link_state (uint32_t device_id, EndpointState previous, EndpointState current)

Static Private Member Functions

static uint32_t id_for (Roster &roster, const std::string &key)
static Entry make_entry (uint32_t id, const std::string &path, const std::string &name, const SerialLineSettings &line, const SerialProtocolSettings &protocol, bool configured)

Private Attributes

Config m_config
Memory::SnapshotCell< DeviceCallback > m_device_callback
std::atomic< bool > m_initialized { false }
Memory::SnapshotCell< InputCallback > m_input_callback
std::atomic< uint64_t > m_next_reader { 1 }
std::mutex m_reader_mutex
std::vector< ReaderRecord > m_records
Memory::SnapshotCell< Roster > m_roster
std::atomic< bool > m_running { false }

Detailed Description

The serial devices of the input system, one SerialDevice per open port.

Devices come from the configured ports and, with enumerate_ports, from the ports the system exposes. A device keeps its id for as long as the backend lives, found again by the path it was configured with or the path the enumerator gave it, which is the stable /dev/serial/by-id link where the system has one, so a replug does not change it. Every value a device parses is delivered to the input callback, from the network io thread, once the backend is started.

Ports are opened through the NetworkService, which must have the serial transport enabled in GlobalNetworkConfig, and that endpoint does the reconnecting. The device callback reports a device as connected while its port is open and as disconnected when it leaves OPEN. A device uses the default spec, one line per message read as numbers, unless set_device_spec gave it another before it was opened.

write() sends the bytes as they are. A caller that wants requests and replies takes the device from get_device().

Definition at line 35 of file SerialInputBackend.hpp.


The documentation for this class was generated from the following files: