Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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().

http://libusb.sourceforge.net/api-1.0/group__asyncio.html covers both approaches.

Inheritance diagram for ola::usb::LibUsbThread:
ola::thread::Thread ola::usb::LibUsbSimpleThread

Public Member Functions

 LibUsbThread (libusb_context *context)
 Base constructor.
 
virtual ~LibUsbThread ()
 Destructor.
 
virtual bool Init ()
 Initialize the thread.
 
virtual void Shutdown ()
 Shutdown the thread.
 
void * Run ()
 The entry point to the libusb thread.
 
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.
 
void LaunchThread ()
 Start the libusb thread.
 
void JoinThread ()
 Join the libusb thread.
 
libusb_context * Context () const
 Return the libusb_context this thread uses.
 

Constructor & Destructor Documentation

◆ LibUsbThread()

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

Base constructor.

Parameters
contextthe libusb context to use.

Member Function Documentation

◆ CloseHandle()

virtual void ola::usb::LibUsbThread::CloseHandle ( libusb_device_handle * handle)
pure virtual

This must be called whenever libusb_close() is called.

Implemented in ola::usb::LibUsbSimpleThread.

◆ Context()

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

Return the libusb_context this thread uses.

Returns
A libusb_context.

◆ OpenHandle()

virtual void ola::usb::LibUsbThread::OpenHandle ( )
pure virtual

This must be called whenever libusb_open() is called.

Implemented in ola::usb::LibUsbSimpleThread.

◆ Run()

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

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

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: