Open Lighting Architecture  0.10.4
 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

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...
 
AsyncronousLibUsbAdaptorGetUSBAdaptor () 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...
 

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

Enumerator
DEVICE_ADDED 

The device was added.

DEVICE_REMOVED 

The device ws removed.

Constructor & Destructor Documentation

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

Create a new HotplugAgent.

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

Destructor.

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

Member Function Documentation

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

Get the AsyncronousLibUsbAdaptor to use.

Returns
An AsyncronousLibUsbAdaptor, ownership is not transferred.
Precondition
Must be called after Init()

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.

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

Start the hotplug agent.

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

Stop the HotplugAgent.

Returns
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: