Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Protected Member Functions | List of all members
ola::plugin::usbdmx::ThreadedUsbReceiver Class Referenceabstract

Detailed Description

Receive DMX data using libusb, from a separate thread.

The synchronous libusb calls can sometimes take a while to complete, I've seen cases of up to 21ms.

To avoid blocking the main thread, we need to perform the libusb transfer calls in a separate thread. This class contains all the thread management code, leaving the subclass to implement ReceiveBuffer(), which performs the actual transfer.

ThreadedUsbReceiver can be used as a building block for synchronous widgets.

Inheritance diagram for ola::plugin::usbdmx::ThreadedUsbReceiver:
Inheritance graph
Collaboration diagram for ola::plugin::usbdmx::ThreadedUsbReceiver:
Collaboration graph

Public Member Functions

 ThreadedUsbReceiver (libusb_device *usb_device, libusb_device_handle *usb_handle, PluginAdaptor *plugin_adaptor, int interface_number=0)
 Create a new ThreadedUsbReceiver. More...
bool Start ()
 Start the new thread. More...
void * Run ()
 Entry point for the new thread. More...
void SetReceiveCallback (Callback0< void > *callback)
 Set the callback to be called when the receive buffer is updated. More...
const DmxBufferGetDmxInBuffer () const
 Get DMX Buffer. More...

Protected Member Functions

virtual bool ReceiveBuffer (libusb_device_handle *handle, DmxBuffer *buffer, bool *buffer_updated)=0
 Perform the DMX transfer. More...

Constructor & Destructor Documentation

ola::plugin::usbdmx::ThreadedUsbReceiver::ThreadedUsbReceiver ( libusb_device *  usb_device,
libusb_device_handle *  usb_handle,
PluginAdaptor plugin_adaptor,
int  interface_number = 0 

Create a new ThreadedUsbReceiver.

usb_deviceThe usb_device to use. The ThreadedUsbReceiver takes a ref on the device, while the ThreadedUsbReceiver object exists.
usb_handleThe handle to use for the DMX transfer.
plugin_adaptorthe PluginAdaptor used to execute callbacks
interface_numberthe USB interface number of the widget. Defaults to 0.

Member Function Documentation

const DmxBuffer& ola::plugin::usbdmx::ThreadedUsbReceiver::GetDmxInBuffer ( ) const

Get DMX Buffer.

DmxBuffer with current input values.
virtual bool ola::plugin::usbdmx::ThreadedUsbReceiver::ReceiveBuffer ( libusb_device_handle *  handle,
DmxBuffer buffer,
bool *  buffer_updated 
protectedpure virtual

Perform the DMX transfer.

handlethe libusb_device_handle to use for the transfer.
bufferThe DmxBuffer to be updated.
buffer_updatedset to true when buffer was updated (=data received)
true if the transfer was completed, false otherwise.

This is called from the receiver thread.

void * ola::plugin::usbdmx::ThreadedUsbReceiver::Run ( )

Entry point for the new thread.


Implements ola::thread::Thread.

void ola::plugin::usbdmx::ThreadedUsbReceiver::SetReceiveCallback ( Callback0< void > *  callback)

Set the callback to be called when the receive buffer is updated.

callbackThe callback to call.
bool ola::plugin::usbdmx::ThreadedUsbReceiver::Start ( )

Start the new thread.

true if the thread is running, false otherwise.

Reimplemented from ola::thread::Thread.

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