Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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
32namespace ola {
33namespace plugin {
34namespace 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
120 const ThreadedUsbReceiver &operator=(const ThreadedUsbReceiver &) = delete;
121};
122} // namespace usbdmx
123} // namespace plugin
124} // namespace ola
125#endif // PLUGINS_USBDMX_THREADEDUSBRECEIVER_H_
A class used to hold a single universe of DMX data.
Helper macros.
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
Definition PluginAdaptor.h:41
Receive DMX data using libusb, from a separate thread.
Definition ThreadedUsbReceiver.h:49
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
void SetReceiveCallback(Callback0< void > *callback)
Set the callback to be called when the receive buffer is updated.
Definition ThreadedUsbReceiver.h:81
const DmxBuffer & GetDmxInBuffer() const
Get DMX Buffer.
Definition ThreadedUsbReceiver.h:89
bool Start()
Start the new thread.
Definition ThreadedUsbReceiver.cpp:52
void * Run()
Entry point for the new thread.
Definition ThreadedUsbReceiver.cpp:63
virtual bool ReceiveBuffer(libusb_device_handle *handle, DmxBuffer *buffer, bool *buffer_updated)=0
Perform the DMX transfer.
Definition Mutex.h:41
Definition Thread.h:52
The namespace containing all OLA symbols.
Definition Credentials.cpp:44