Open Lighting Architecture  Latest Git
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...
 
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

◆ NotificationCallback

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

◆ EventType

Enumerator
DEVICE_ADDED 

The device was added.

DEVICE_REMOVED 

The device ws removed.

Constructor & Destructor Documentation

◆ HotplugAgent()

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.

◆ ~HotplugAgent()

ola::usb::HotplugAgent::~HotplugAgent ( )

Destructor.

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

Member Function Documentation

◆ GetUSBAdaptor()

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

Get the AsynchronousLibUsbAdaptor to use.

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

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

◆ HaltNotifications()

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

Prevent any further notifications from occurring.

Once this returns, the NotificationCallback will not be called.

◆ Init()

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

Initialize the hotplug agent.

Returns
true if the agent started correctly, false otherwise.

◆ Start()

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.

◆ Stop()

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: