Open Lighting Architecture: ola::usb::HotplugAgent Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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.

## Public Member Functions
| HotplugAgent (NotificationCallback *notification_cb, int debug_level)
| Create a new HotplugAgent.
| ~HotplugAgent ()
| Destructor.
AsyncronousLibUsbAdaptor * | GetUSBAdaptor () const
| Get the AsyncronousLibUsbAdaptor to use.
bool | Init ()
| Initialize the hotplug agent.
bool | Start ()
| Start the hotplug agent.
void | HaltNotifications ()
| Prevent any further notifications from occurring.
bool | Stop ()
| Stop the HotplugAgent.

## Member Typedef Documentation

## ◆ NotificationCallback

typedef ola::Callback2<void, EventType, struct libusb_device*> ola::usb::HotplugAgent::NotificationCallback

Called when a USB device has been added or removed.

Template Parameters

  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.

## Member Enumeration Documentation

## ◆ EventType

enum ola::usb::HotplugAgent::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_cb | The callback to run when the device is added or removed. Ownership is transferred.
  debug_level | The libusb debug level.

## ◆ ~HotplugAgent()

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

Destructor.

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

## Member Function Documentation

## ◆ GetUSBAdaptor()

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

## ◆ 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:

- libs/usb/HotplugAgent.h
- libs/usb/HotplugAgent.cpp