Open Lighting Architecture
0.10.4
|
Detects when USB devices are added or removed.
The HotplugAgent will run a callback when a USB device is added or removed. On systems with libusb >= 1.0.16 which also support hotplug we'll use the Hotplug API, otherwise we'll periodically check for devices.
Public Types | |
enum | EventType { DEVICE_ADDED, DEVICE_REMOVED } |
typedef ola::Callback2< void, EventType, struct libusb_device * > | NotificationCallback |
Called when a USB device has been added or removed. More... | |
Public Member Functions | |
HotplugAgent (NotificationCallback *notification_cb, int debug_level) | |
Create a new HotplugAgent. More... | |
~HotplugAgent () | |
Destructor. More... | |
AsyncronousLibUsbAdaptor * | GetUSBAdaptor () const |
Get the AsyncronousLibUsbAdaptor to use. More... | |
bool | Init () |
Initialize the hotplug agent. More... | |
bool | Start () |
Start the hotplug agent. More... | |
void | HaltNotifications () |
Prevent any further notifications from occuring. More... | |
bool | Stop () |
Stop the HotplugAgent. More... | |
typedef ola::Callback2<void, EventType, struct libusb_device*> ola::usb::HotplugAgent::NotificationCallback |
Called when a USB device has been added or removed.
EventType | The type of the event. |
The | libusb device for this event. |
The callback can be run in either the thread calling Start() or from an internal hotplug thread. However it won't be called from both at once.
ola::usb::HotplugAgent::HotplugAgent | ( | NotificationCallback * | notification_cb, |
int | debug_level | ||
) |
Create a new HotplugAgent.
notification_cb | The callback to run when the device is added or removed. Ownership is transferred. |
debug_level | The libusb debug level. |
ola::usb::HotplugAgent::~HotplugAgent | ( | ) |
Destructor.
This will stop the HotplugAgent if it's still running.
AsyncronousLibUsbAdaptor * ola::usb::HotplugAgent::GetUSBAdaptor | ( | ) | const |
Get the AsyncronousLibUsbAdaptor to use.
The adaptor is valid until the call to Stop().
void ola::usb::HotplugAgent::HaltNotifications | ( | ) |
Prevent any further notifications from occuring.
Once this returns, the NotificationCallback will not be called.
bool ola::usb::HotplugAgent::Init | ( | ) |
Initialize the hotplug agent.
bool ola::usb::HotplugAgent::Start | ( | ) |
Start the hotplug agent.
bool ola::usb::HotplugAgent::Stop | ( | ) |
Stop the HotplugAgent.
Stop() may result in notifications being run, however once Stop() returns, no further calls to the notification callback will be made.