MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InputBackend.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6
7/**
8 * @brief Callback signature for input events
9 */
10using InputCallback = std::function<void(const InputValue&)>;
11
12/**
13 * @brief Callback signature for device connection/disconnection events
14 */
15using DeviceCallback = std::function<void(const InputDeviceInfo&, bool connected)>;
16
17/**
18 * @class IInputBackend
19 * @brief Abstract interface for input device backends
20 *
21 * Follows the same pattern as IAudioBackend and IGraphicsBackend.
22 * Each concrete implementation (HID, MIDI, OSC, Serial) provides:
23 * - Device enumeration
24 * - Connection lifecycle management
25 * - Input event delivery via callbacks
26 *
27 * Unlike audio (which has separate AudioDevice/AudioStream classes),
28 * input backends unify device management and data flow since input
29 * devices are typically simpler and don't require the same level of
30 * configuration as audio streams.
31 */
32class MAYAFLUX_API IInputBackend {
33public:
34 virtual ~IInputBackend() = default;
35
36 // ─────────────────────────────────────────────────────────────────────
37 // Lifecycle
38 // ─────────────────────────────────────────────────────────────────────
39
40 /**
41 * @brief Initialize the input backend
42 * @return true if initialization succeeded
43 *
44 * Should discover available devices but not start polling/listening.
45 */
46 virtual bool initialize() = 0;
47
48 /**
49 * @brief Start listening for input events
50 *
51 * Begins polling/callback registration for all opened devices.
52 * Input events will be delivered via registered callbacks.
53 */
54 virtual void start() = 0;
55
56 /**
57 * @brief Stop listening for input events
58 *
59 * Pauses input delivery without closing devices.
60 */
61 virtual void stop() = 0;
62
63 /**
64 * @brief Shutdown and release all resources
65 *
66 * Closes all devices and releases backend resources.
67 * After this call, initialize() must be called again to use the backend.
68 */
69 virtual void shutdown() = 0;
70
71 /**
72 * @brief Check if backend is initialized
73 */
74 [[nodiscard]] virtual bool is_initialized() const = 0;
75
76 /**
77 * @brief Check if backend is actively listening
78 */
79 [[nodiscard]] virtual bool is_running() const = 0;
80
81 // ─────────────────────────────────────────────────────────────────────
82 // Device Management
83 // ─────────────────────────────────────────────────────────────────────
84
85 /**
86 * @brief Get list of available devices
87 * @return Vector of device info structures
88 *
89 * Returns cached device list. Call refresh_devices() to update.
90 */
91 [[nodiscard]] virtual std::vector<InputDeviceInfo> get_devices() const = 0;
92
93 /**
94 * @brief Refresh the device list
95 * @return Number of devices found
96 *
97 * Re-enumerates available devices. May trigger device callbacks
98 * for newly connected or disconnected devices.
99 */
100 virtual size_t refresh_devices() = 0;
101
102 /**
103 * @brief Open a device for input
104 * @param device_id Device identifier from get_devices()
105 * @return true if device was opened successfully
106 */
107 virtual bool open_device(uint32_t device_id) = 0;
108
109 /**
110 * @brief Close a previously opened device
111 * @param device_id Device identifier
112 */
113 virtual void close_device(uint32_t device_id) = 0;
114
115 /**
116 * @brief Check if a device is currently open
117 */
118 [[nodiscard]] virtual bool is_device_open(uint32_t device_id) const = 0;
119
120 /**
121 * @brief Get list of currently open device IDs
122 */
123 [[nodiscard]] virtual std::vector<uint32_t> get_open_devices() const = 0;
124
125 // ─────────────────────────────────────────────────────────────────────
126 // Callbacks
127 // ─────────────────────────────────────────────────────────────────────
128
129 /**
130 * @brief Register callback for input values
131 * @param callback Function to call when input arrives
132 *
133 * The callback may be called from a backend-specific thread.
134 * Implementations should document their threading model.
135 */
136 virtual void set_input_callback(InputCallback callback) = 0;
137
138 /**
139 * @brief Register callback for device connect/disconnect events
140 * @param callback Function to call when device state changes
141 */
142 virtual void set_device_callback(DeviceCallback callback) = 0;
143
144 // ─────────────────────────────────────────────────────────────────────
145 // Backend Information
146 // ─────────────────────────────────────────────────────────────────────
147
148 /**
149 * @brief Get backend type
150 */
151 [[nodiscard]] virtual InputType get_type() const = 0;
152
153 /**
154 * @brief Get backend name/identifier string
155 */
156 [[nodiscard]] virtual std::string get_name() const = 0;
157
158 /**
159 * @brief Get backend version string
160 */
161 [[nodiscard]] virtual std::string get_version() const = 0;
162};
163
164} // namespace MayaFlux::Core
virtual bool is_initialized() const =0
Check if backend is initialized.
virtual std::vector< InputDeviceInfo > get_devices() const =0
Get list of available devices.
virtual bool is_device_open(uint32_t device_id) const =0
Check if a device is currently open.
virtual void set_device_callback(DeviceCallback callback)=0
Register callback for device connect/disconnect events.
virtual InputType get_type() const =0
Get backend type.
virtual std::string get_name() const =0
Get backend name/identifier string.
virtual bool open_device(uint32_t device_id)=0
Open a device for input.
virtual void set_input_callback(InputCallback callback)=0
Register callback for input values.
virtual void stop()=0
Stop listening for input events.
virtual bool initialize()=0
Initialize the input backend.
virtual std::vector< uint32_t > get_open_devices() const =0
Get list of currently open device IDs.
virtual ~IInputBackend()=default
virtual void start()=0
Start listening for input events.
virtual void shutdown()=0
Shutdown and release all resources.
virtual size_t refresh_devices()=0
Refresh the device list.
virtual std::string get_version() const =0
Get backend version string.
virtual bool is_running() const =0
Check if backend is actively listening.
virtual void close_device(uint32_t device_id)=0
Close a previously opened device.
Abstract interface for input device backends.
InputType
Input backend type enumeration.
std::function< void(const InputValue &)> InputCallback
Callback signature for input events.
std::function< void(const InputDeviceInfo &, bool connected)> DeviceCallback
Callback signature for device connection/disconnection events.
Information about a connected input device.
Generic input value container.