CreatorCreator
Home
Getting Started
  • 中文简体
  • English
Home
Getting Started
  • 中文简体
  • English
  • Creator

    • Getting Started
  • Stream Dock

    • Plugin SDK
    • Icon Pack

      • Overview
      • Terminology
      • Creating an Icon Pack
      • Icon Specifications
    • Scene Configuration

      • What is a Scenario Configuration?
      • Exporting
      • Use Cases
  • mPanel

    • Plugin SDK
  • Cpp SDK

    • Overview
    • Dependency Installation
    • Device Manager
    • StreamDock Base Class
    • Communication Transport
    • Example
    • API Reference
    • Source Code
  • Python SDK

    • Overview
    • Dependency Installation
    • Device Manager
    • StreamDock Base Class
    • API Reference
    • Examples
    • Source Code
  • Windows-WebSocket SDK

    • Overview
    • Getting Started
    • Events Sent
    • Events Received
    • Source Code
  • Support

    • Help and Bug Reporting

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

PlatformFileFunctionLocationPurpose
Windowsdevicemanager_win.cppWindowProcDBT_DEVICEARRIVAL branchDevice insertion handling
Windowsdevicemanager_win.cppWindowProcDBT_DEVICEREMOVECOMPLETE branchDevice removal handling
Linuxdevicemanager_linux.cpplistenaction == "add" branchDevice insertion handling
Linuxdevicemanager_linux.cpplistenaction == "remove" branchDevice removal handling

Note: When adding processing logic, pay attention to:

  1. Maintain thread safety (use existing streamdocksMutex_)
  2. Avoid blocking the event loop
  3. Exception handling should wrap existing logic
Last Updated:
Contributors: JKWTCN
Prev
Dependency Installation
Next
StreamDock Base Class