![]() |
Open Lighting Architecture 0.10.9
|
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.
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. | |
|
inlineexplicit |
Base constructor.
| context | the libusb context to use. |
|
pure virtual |
This must be called whenever libusb_close() is called.
Implemented in ola::usb::LibUsbSimpleThread.
|
inlineprotected |
Return the libusb_context this thread uses.
|
pure virtual |
This must be called whenever libusb_open() is called.
Implemented in ola::usb::LibUsbSimpleThread.
|
virtual |
The entry point to the libusb thread.
Don't call this directly. It's executed when the thread starts.
Implements ola::thread::Thread.
|
inlineprotected |
Indicate that the libusb thread should terminate.
This doesn't wake up libusb_handle_events(), it simply sets m_term to true.