Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | List of all members
ola::usb::HotplugAgent Class Reference

Detailed Description

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

typedef ola::Callback2< void,
EventType, struct
libusb_device * > 
 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...
AsynchronousLibUsbAdaptorGetUSBAdaptor () const
 Get the AsynchronousLibUsbAdaptor to use. More...
bool Init ()
 Initialize the hotplug agent. More...
bool Start ()
 Start the hotplug agent. More...
void HaltNotifications ()
 Prevent any further notifications from occurring. More...
bool Stop ()
 Stop the HotplugAgent. More...

Member Typedef Documentation

Called when a USB device has been added or removed.

Template Parameters
EventTypeThe type of the event.
Thelibusb 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.

Member Enumeration Documentation


The device was added.


The device ws removed.

Constructor & Destructor Documentation

ola::usb::HotplugAgent::HotplugAgent ( NotificationCallback notification_cb,
int  debug_level 

Create a new HotplugAgent.

notification_cbThe callback to run when the device is added or removed. Ownership is transferred.
debug_levelThe libusb debug level.
ola::usb::HotplugAgent::~HotplugAgent ( )


This will stop the HotplugAgent if it's still running.

Member Function Documentation

AsynchronousLibUsbAdaptor * ola::usb::HotplugAgent::GetUSBAdaptor ( ) const

Get the AsynchronousLibUsbAdaptor to use.

An AsynchronousLibUsbAdaptor, ownership is not transferred.
Must be called after Init()

The adaptor is valid until the call to Stop().

void ola::usb::HotplugAgent::HaltNotifications ( )

Prevent any further notifications from occurring.

Once this returns, the NotificationCallback will not be called.

bool ola::usb::HotplugAgent::Init ( )

Initialize the hotplug agent.

true if the agent started correctly, false otherwise.
bool ola::usb::HotplugAgent::Start ( )

Start the hotplug agent.

true if the agent started correctly, false otherwise.
Init() has been called and returned true.
bool ola::usb::HotplugAgent::Stop ( )

Stop the HotplugAgent.

true if stopped correctly, false otherwise.

Stop() may result in notifications being run, however once Stop() returns, no further calls to the notification callback will be made.

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