DeviceManager
Central device manager for enumerating all connected StreamDock devices. An instance of this class must be created to detect and use StreamDock devices.
Getting Device Manager Instance
DeviceManager uses the singleton pattern. Get the instance as follows:
DeviceManager &manager = DeviceManager::instance();
enumerate()
Detects connected StreamDock devices.
Returns a map containing all connected StreamDock devices, where the key is the device path and the value is the device object.
manager.enumerator();
auto streamDocks = manager.getStreamDocks();
listen()
Listens for new device connections or disconnections.
On Linux platform, this method uses libudev to monitor device plug/unplug events.
On Windows platform, this method uses Windows message mechanism (WM_DEVICECHANGE) to monitor device plug/unplug events.
stopListen()
Stops the device listening thread.
manager.stopListen();
getStreamDocks()
Gets all currently connected StreamDock devices.
auto& streamDocks = manager.getStreamDocks();
for (const auto& device : streamDocks) {
// device.first is the device path
// device.second is the device object
auto devicePath = device.first;
auto streamDock = device.second;
}
Asynchronous Event Processing
// Start device read loop
device->reader()->startReadLoop();
// Register key event callback
device->reader()->registerReadCallback(1, []() {
std::cout << "Key 1 pressed" << std::endl;
}, RegisterEvent::KeyPress);
// Register knob event callback
device->reader()->registerReadCallback(16, []() {
std::cout << "Knob left rotation" << std::endl;
}, RegisterEvent::KnobLeft);
Device Hot-plug Monitoring and Callbacks
| Platform | File | Function | Location | Purpose |
|---|---|---|---|---|
| Windows | devicemanager_win.cpp | WindowProc | DBT_DEVICEARRIVAL branch | Device insertion handling |
| Windows | devicemanager_win.cpp | WindowProc | DBT_DEVICEREMOVECOMPLETE branch | Device removal handling |
| Linux | devicemanager_linux.cpp | listen | action == "add" branch | Device insertion handling |
| Linux | devicemanager_linux.cpp | listen | action == "remove" branch | Device removal handling |
Note: When adding processing logic, pay attention to:
- Maintain thread safety (use existing
streamdocksMutex_) - Avoid blocking the event loop
- Exception handling should wrap existing logic
