Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | List of all members
ola::plugin::usbdmx::LibUsbThread Class Reference

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::plugin::usbdmx::LibUsbThread:
ola::thread::Thread ola::plugin::usbdmx::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.

Additional Inherited Members

- Private Member Functions inherited from ola::thread::Thread
 Thread (const Options &options=Options())
 Create a new thread with the specified thread options.
virtual ~Thread ()
 Destructor.
virtual bool Start ()
 Start the thread and wait for the thread to be running.
virtual bool FastStart ()
 Start the thread and return immediately.
virtual bool Join (void *ptr=NULL)
 Join this thread.
bool IsRunning ()
 Check if the thread is running.
ThreadId Id () const
 Return the thread id.
std::string Name () const
 Return the thread name.
virtual void * Run ()=0
 The entry point for the new thread.
- Static Private Member Functions inherited from ola::thread::Thread
static ThreadId Self ()
 Returns the current thread's id.

Constructor & Destructor Documentation

ola::plugin::usbdmx::LibUsbThread::LibUsbThread ( libusb_context *  context)
inlineexplicit

Base constructor.

Parameters
contextthe libusb context to use.

Member Function Documentation

libusb_context* ola::plugin::usbdmx::LibUsbThread::Context ( ) const
inlineprotected

Return the libusb_context this thread uses.

Returns
A libusb_context.
void * ola::plugin::usbdmx::LibUsbThread::Run ( )

The entry point to the libusb thread.

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

void ola::plugin::usbdmx::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: