Open Lighting Architecture  Latest Git
Public Member Functions | Protected Member Functions | List of all members
ola::usb::LibUsbThread Class Referenceabstract

Detailed Description

The base class for the dedicated libusb thread.

Asynchronous I/O for libusb requires either i) a dedicated thread ii) integration with the i/o event loop. From the libusb documentation, i) has the advantage that it works on Windows, so we do that.

However, there is no easy way to interrupt libusb_handle_events(). Instead we use either libusb_close (for the non-hotplug case) or libusb_hotplug_deregister_callback() (for the hotplug case) to wake libusb_handle_events().

Both these techniques have require care to avoid deadlocks / race conditions. For the non-hotplug case, it's imperative that libusb_open() and libusb_close() are paired with calls to OpenHandle() and CloseHandle(). covers both approaches.

Inheritance diagram for ola::usb::LibUsbThread:
Inheritance graph
Collaboration diagram for ola::usb::LibUsbThread:
Collaboration graph

Public Member Functions

 LibUsbThread (libusb_context *context)
 Base constructor. More...
virtual ~LibUsbThread ()
virtual bool Init ()
 Initialize the thread.
virtual void Shutdown ()
 Shutdown the thread.
void * Run ()
 The entry point to the libusb thread. More...
virtual void OpenHandle ()=0
 This must be called whenever libusb_open() is called.
virtual void CloseHandle (libusb_device_handle *handle)=0
 This must be called whenever libusb_close() is called.

Protected Member Functions

void SetTerminate ()
 Indicate that the libusb thread should terminate. More...
void LaunchThread ()
 Start the libusb thread.
void JoinThread ()
 Join the libusb thread.
libusb_context * Context () const
 Return the libusb_context this thread uses. More...

Constructor & Destructor Documentation

◆ LibUsbThread()

ola::usb::LibUsbThread::LibUsbThread ( libusb_context *  context)

Base constructor.

contextthe libusb context to use.

Member Function Documentation

◆ Context()

libusb_context* ola::usb::LibUsbThread::Context ( ) const

Return the libusb_context this thread uses.

A libusb_context.

◆ Run()

void * ola::usb::LibUsbThread::Run ( )

The entry point to the libusb thread.

Don't call this directly. It's executed when the thread starts.

Implements ola::thread::Thread.

◆ SetTerminate()

void ola::usb::LibUsbThread::SetTerminate ( )

Indicate that the libusb thread should terminate.

This doesn't wake up libusb_handle_events(), it simply sets m_term to true.

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