Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
AsyncUsbReceiver.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 * AsyncUsbReceiver.h
17 * An Asynchronous DMX USB receiver.
18 * Copyright (C) 2015 Stefan Krupop
19 */
20
21#ifndef PLUGINS_USBDMX_ASYNCUSBRECEIVER_H_
22#define PLUGINS_USBDMX_ASYNCUSBRECEIVER_H_
23
24#include <libusb.h>
25#include <memory>
26
27#include "AsyncUsbTransceiverBase.h"
28#include "libs/usb/LibUsbAdaptor.h"
29#include "ola/Callback.h"
30#include "ola/DmxBuffer.h"
31#include "ola/base/Macro.h"
32#include "ola/thread/Mutex.h"
33#include "olad/PluginAdaptor.h"
34
35namespace ola {
36namespace plugin {
37namespace usbdmx {
38
47 public:
55 libusb_device *usb_device,
56 PluginAdaptor *plugin_adaptor);
57
61 virtual ~AsyncUsbReceiver();
62
67 bool Init();
68
74 bool Init(libusb_device_handle* handle);
75
80 bool Start();
81
87 m_receive_callback.reset(callback);
88 }
89
94 void GetDmx(DmxBuffer *buffer) {
95 ola::thread::MutexLocker locker(&m_mutex);
96 buffer->Set(m_rx_buffer);
97 }
98
104 void TransferComplete(struct libusb_transfer *transfer);
105
106 protected:
115 virtual bool PerformTransfer() = 0;
116
123 virtual bool TransferCompleted(DmxBuffer *buffer, int transferred_size) = 0;
124
125 private:
126 PluginAdaptor* const m_plugin_adaptor;
127 bool m_inited_with_handle;
128
129 DmxBuffer m_rx_buffer; // GUARDED_BY(m_mutex);
130 std::auto_ptr<Callback0<void> > m_receive_callback;
131
132 AsyncUsbReceiver(const AsyncUsbReceiver &) = delete;
133 const AsyncUsbReceiver &operator=(const AsyncUsbReceiver &) = delete;
134};
135} // namespace usbdmx
136} // namespace plugin
137} // namespace ola
138#endif // PLUGINS_USBDMX_ASYNCUSBRECEIVER_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
bool Set(const uint8_t *data, unsigned int length)
Set the contents of this DmxBuffer.
Definition DmxBuffer.cpp:137
Definition PluginAdaptor.h:41
A base class that receives DMX data asynchronously from a libusb_device.
Definition AsyncUsbReceiver.h:46
bool Init()
Initialize the receiver.
Definition AsyncUsbReceiver.cpp:43
void GetDmx(DmxBuffer *buffer)
Get DMX Buffer.
Definition AsyncUsbReceiver.h:94
AsyncUsbReceiver(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device, PluginAdaptor *plugin_adaptor)
Create a new AsyncUsbReceiver.
Definition AsyncUsbReceiver.cpp:29
void SetReceiveCallback(Callback0< void > *callback)
Set the callback to be called when the receive buffer is updated.
Definition AsyncUsbReceiver.h:86
virtual ~AsyncUsbReceiver()
Destructor.
Definition AsyncUsbReceiver.cpp:37
void TransferComplete(struct libusb_transfer *transfer)
Called from the libusb callback when the asynchronous transfer completes.
Definition AsyncUsbReceiver.cpp:64
bool Start()
Start receiving DMX.
Definition AsyncUsbReceiver.cpp:55
virtual bool TransferCompleted(DmxBuffer *buffer, int transferred_size)=0
Called when the transfer completes.
virtual bool PerformTransfer()=0
Start the request of data from the widget.
A base class that implements common functionality to send or receive DMX asynchronously to a libusb_d...
Definition AsyncUsbTransceiverBase.h:39
Definition Mutex.h:64
Wraps calls to libusb so we can test the code.
Definition LibUsbAdaptor.h:36
The namespace containing all OLA symbols.
Definition Credentials.cpp:44