Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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().

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

Inheritance diagram for ola::usb::LibUsbThread:
Inheritance graph
[legend]
Collaboration diagram for ola::usb::LibUsbThread:
Collaboration graph
[legend]

Public Member Functions

 LibUsbThread (libusb_context *context)
 Base constructor. More...
 
virtual ~LibUsbThread ()
 Destructor.
 
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

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

Base constructor.

Parameters
contextthe libusb context to use.

Member Function Documentation

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

Return the libusb_context this thread uses.

Returns
A libusb_context.
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.

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: