Open Lighting Architecture  Latest Git
ThreadedUsbReceiver.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * ThreadedUsbReceiver.h
17  * Receive DMX data over USB from a dedicated thread.
18  * Copyright (C) 2015 Stefan Krupop
19  */
20 
21 #ifndef PLUGINS_USBDMX_THREADEDUSBRECEIVER_H_
22 #define PLUGINS_USBDMX_THREADEDUSBRECEIVER_H_
23 
24 #include <libusb.h>
25 #include <memory>
26 #include "ola/base/Macro.h"
27 #include "ola/Callback.h"
28 #include "ola/DmxBuffer.h"
29 #include "ola/thread/Thread.h"
30 #include "olad/PluginAdaptor.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace usbdmx {
35 
50  public:
59  ThreadedUsbReceiver(libusb_device *usb_device,
60  libusb_device_handle *usb_handle,
61  PluginAdaptor *plugin_adaptor,
62  int interface_number = 0);
63  virtual ~ThreadedUsbReceiver();
64 
69  bool Start();
70 
75  void *Run();
76 
82  m_receive_callback.reset(callback);
83  }
84 
89  const DmxBuffer &GetDmxInBuffer() const {
90  return m_buffer;
91  }
92 
93  protected:
104  virtual bool ReceiveBuffer(libusb_device_handle *handle,
105  DmxBuffer *buffer,
106  bool *buffer_updated) = 0;
107 
108  private:
109  bool m_term;
110  libusb_device* const m_usb_device;
111  libusb_device_handle* const m_usb_handle;
112  int const m_interface_number;
113  PluginAdaptor* const m_plugin_adaptor;
114  std::auto_ptr<Callback0<void> > m_receive_callback;
115  DmxBuffer m_buffer;
116  ola::thread::Mutex m_data_mutex;
117  ola::thread::Mutex m_term_mutex;
118 
119  DISALLOW_COPY_AND_ASSIGN(ThreadedUsbReceiver);
120 };
121 } // namespace usbdmx
122 } // namespace plugin
123 } // namespace ola
124 #endif // PLUGINS_USBDMX_THREADEDUSBRECEIVER_H_
const DmxBuffer & GetDmxInBuffer() const
Get DMX Buffer.
Definition: ThreadedUsbReceiver.h:89
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
bool Start()
Start the new thread.
Definition: ThreadedUsbReceiver.cpp:52
Receive DMX data using libusb, from a separate thread.
Definition: ThreadedUsbReceiver.h:49
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A class used to hold a single universe of DMX data.
Definition: Thread.h:52
Definition: PluginAdaptor.h:41
virtual bool ReceiveBuffer(libusb_device_handle *handle, DmxBuffer *buffer, bool *buffer_updated)=0
Perform the DMX transfer.
void * Run()
Entry point for the new thread.
Definition: ThreadedUsbReceiver.cpp:63
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
void SetReceiveCallback(Callback0< void > *callback)
Set the callback to be called when the receive buffer is updated.
Definition: ThreadedUsbReceiver.h:81
ThreadedUsbReceiver(libusb_device *usb_device, libusb_device_handle *usb_handle, PluginAdaptor *plugin_adaptor, int interface_number=0)
Create a new ThreadedUsbReceiver.
Definition: ThreadedUsbReceiver.cpp:30
Definition: Mutex.h:41