Open Lighting Architecture: plugins/usbdmx/AsyncUsbReceiver.h Source File

| 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
46 class AsyncUsbReceiver: public AsyncUsbTransceiverBase {
47 public:
54 AsyncUsbReceiver(ola::usb::LibUsbAdaptor* const adaptor,
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
86 void SetReceiveCallback(Callback0<void> *callback) {
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_
Callback.h
DmxBuffer.h
A class used to hold a single universe of DMX data.
Macro.h
Helper macros.
PluginAdaptor.h
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
ola::Callback0
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::DmxBuffer::Set
bool Set(const uint8_t *data, unsigned int length)
Set the contents of this DmxBuffer.
Definition DmxBuffer.cpp:137
ola::PluginAdaptor
Definition PluginAdaptor.h:41
ola::plugin::usbdmx::AsyncUsbReceiver::Init
bool Init()
Initialize the receiver.
Definition AsyncUsbReceiver.cpp:43
ola::plugin::usbdmx::AsyncUsbReceiver::GetDmx
void GetDmx(DmxBuffer *buffer)
Get DMX Buffer.
Definition AsyncUsbReceiver.h:94
ola::plugin::usbdmx::AsyncUsbReceiver::AsyncUsbReceiver
AsyncUsbReceiver(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device, PluginAdaptor *plugin_adaptor)
Create a new AsyncUsbReceiver.
Definition AsyncUsbReceiver.cpp:29
ola::plugin::usbdmx::AsyncUsbReceiver::SetReceiveCallback
void SetReceiveCallback(Callback0< void > *callback)
Set the callback to be called when the receive buffer is updated.
Definition AsyncUsbReceiver.h:86
ola::plugin::usbdmx::AsyncUsbReceiver::~AsyncUsbReceiver
virtual ~AsyncUsbReceiver()
Destructor.
Definition AsyncUsbReceiver.cpp:37
ola::plugin::usbdmx::AsyncUsbReceiver::TransferComplete
void TransferComplete(struct libusb_transfer *transfer)
Called from the libusb callback when the asynchronous transfer completes.
Definition AsyncUsbReceiver.cpp:64
ola::plugin::usbdmx::AsyncUsbReceiver::Start
bool Start()
Start receiving DMX.
Definition AsyncUsbReceiver.cpp:55
ola::plugin::usbdmx::AsyncUsbReceiver::TransferCompleted
virtual bool TransferCompleted(DmxBuffer *buffer, int transferred_size)=0
Called when the transfer completes.
ola::plugin::usbdmx::AsyncUsbReceiver::PerformTransfer
virtual bool PerformTransfer()=0
Start the request of data from the widget.
ola::plugin::usbdmx::AsyncUsbTransceiverBase::AsyncUsbTransceiverBase
AsyncUsbTransceiverBase(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device)
Create a new AsyncUsbTransceiverBase.
Definition AsyncUsbTransceiverBase.cpp:47
ola::thread::MutexLocker
Definition Mutex.h:64
ola::usb::LibUsbAdaptor
Wraps calls to libusb so we can test the code.
Definition LibUsbAdaptor.h:36
ola::plugin::usbdmx
The plugin for hardware using libusb.
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44