Open Lighting Architecture  Latest Git
AsyncUsbSender.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  * AsyncUsbSender.h
17  * An Asynchronous DMX USB sender.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_ASYNCUSBSENDER_H_
22 #define PLUGINS_USBDMX_ASYNCUSBSENDER_H_
23 
24 #include <libusb.h>
25 
26 #include "AsyncUsbTransceiverBase.h"
27 #include "libs/usb/LibUsbAdaptor.h"
28 #include "ola/DmxBuffer.h"
29 #include "ola/base/Macro.h"
30 #include "ola/thread/Mutex.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace usbdmx {
35 
43  public:
50  libusb_device *usb_device);
51 
55  virtual ~AsyncUsbSender();
56 
62  bool SendDMX(const DmxBuffer &buffer);
63 
69  void TransferComplete(struct libusb_transfer *transfer);
70 
71  protected:
81  virtual bool PerformTransfer(const DmxBuffer &buffer) = 0;
82 
89  virtual void PostTransferHook() {}
90 
95  bool TransferPending() const { return m_pending_tx; }
96 
97  private:
98  DmxBuffer m_tx_buffer; // GUARDED_BY(m_mutex);
99  bool m_pending_tx; // GUARDED_BY(m_mutex);
100 
101  DISALLOW_COPY_AND_ASSIGN(AsyncUsbSender);
102 };
103 } // namespace usbdmx
104 } // namespace plugin
105 } // namespace ola
106 #endif // PLUGINS_USBDMX_ASYNCUSBSENDER_H_
A base class that send DMX data asynchronously to a libusb_device.
Definition: AsyncUsbSender.h:42
virtual void PostTransferHook()
Called when the transfer completes.
Definition: AsyncUsbSender.h:89
A base class that implements common functionality to send or receive DMX asynchronously to a libusb_d...
Definition: AsyncUsbTransceiverBase.h:39
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A class used to hold a single universe of DMX data.
bool SendDMX(const DmxBuffer &buffer)
Send one frame of DMX data.
Definition: AsyncUsbSender.cpp:42
virtual ~AsyncUsbSender()
Destructor.
Definition: AsyncUsbSender.cpp:38
AsyncUsbSender(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device)
Create a new AsyncUsbSender.
Definition: AsyncUsbSender.cpp:32
bool TransferPending() const
Check if there is a pending transfer.
Definition: AsyncUsbSender.h:95
void TransferComplete(struct libusb_transfer *transfer)
Called from the libusb callback when the asynchronous transfer completes.
Definition: AsyncUsbSender.cpp:59
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
virtual bool PerformTransfer(const DmxBuffer &buffer)=0
Perform the DMX transfer.
Wraps calls to libusb so we can test the code.
Definition: LibUsbAdaptor.h:36