Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AsyncUsbTransceiverBase.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  * AsyncUsbTransceiverBase.h
17  * An Asynchronous DMX USB transceiver.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
22 #define PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
23 
24 #include <libusb.h>
25 
26 #include "libs/usb/LibUsbAdaptor.h"
27 #include "ola/DmxBuffer.h"
28 #include "ola/base/Macro.h"
29 #include "ola/thread/Mutex.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace usbdmx {
34 
40  public:
47  libusb_device *usb_device);
48 
52  virtual ~AsyncUsbTransceiverBase();
53 
58  bool Init();
59 
65  virtual void TransferComplete(struct libusb_transfer *transfer) = 0;
66 
71  libusb_device_handle *GetHandle() { return m_usb_handle; }
72 
73  protected:
78 
82  libusb_device* const m_usb_device;
83 
89  virtual libusb_device_handle* SetupHandle() = 0;
90 
97  virtual void PostTransferHook() {}
98 
102  void CancelTransfer();
103 
109  void FillControlTransfer(unsigned char *buffer, unsigned int timeout);
110 
114  void FillBulkTransfer(unsigned char endpoint, unsigned char *buffer,
115  int length, unsigned int timeout);
116 
120  void FillInterruptTransfer(unsigned char endpoint, unsigned char *buffer,
121  int length, unsigned int timeout);
122 
127  int SubmitTransfer();
128 
129  enum TransferState {
130  IDLE,
131  IN_PROGRESS,
132  DISCONNECTED,
133  };
134 
135  libusb_device_handle *m_usb_handle;
136  bool m_suppress_continuation;
137  struct libusb_transfer *m_transfer;
138 
139  TransferState m_transfer_state; // GUARDED_BY(m_mutex);
140  ola::thread::Mutex m_mutex;
141 
142  private:
144 };
145 } // namespace usbdmx
146 } // namespace plugin
147 } // namespace ola
148 #endif // PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
libusb_device_handle * GetHandle()
Get the libusb_device_handle of an already opened widget.
Definition: AsyncUsbTransceiverBase.h:71
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
virtual ~AsyncUsbTransceiverBase()
Destructor.
Definition: AsyncUsbTransceiverBase.cpp:58
void FillControlTransfer(unsigned char *buffer, unsigned int timeout)
Fill a control transfer.
Definition: AsyncUsbTransceiverBase.cpp:93
libusb_device *const m_usb_device
The libusb_device passed in the constructor.
Definition: AsyncUsbTransceiverBase.h:82
ola::usb::LibUsbAdaptor *const m_adaptor
The LibUsbAdaptor passed in the constructor.
Definition: AsyncUsbTransceiverBase.h:77
virtual void TransferComplete(struct libusb_transfer *transfer)=0
Called from the libusb callback when the asynchronous transfer completes.
A base class that implements common functionality to send or receive DMX asynchronously to a libusb_d...
Definition: AsyncUsbTransceiverBase.h:39
A class used to hold a single universe of DMX data.
bool Init()
Initialize the transceiver.
Definition: AsyncUsbTransceiverBase.cpp:64
void FillBulkTransfer(unsigned char endpoint, unsigned char *buffer, int length, unsigned int timeout)
Fill a bulk transfer.
Definition: AsyncUsbTransceiverBase.cpp:99
virtual libusb_device_handle * SetupHandle()=0
Open the device handle.
void FillInterruptTransfer(unsigned char endpoint, unsigned char *buffer, int length, unsigned int timeout)
Fill an interrupt transfer.
Definition: AsyncUsbTransceiverBase.cpp:107
AsyncUsbTransceiverBase(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device)
Create a new AsyncUsbTransceiverBase.
Definition: AsyncUsbTransceiverBase.cpp:47
void CancelTransfer()
Cancel any pending transfers.
Definition: AsyncUsbTransceiverBase.cpp:69
int SubmitTransfer()
Submit the transfer for tx.
Definition: AsyncUsbTransceiverBase.cpp:115
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
virtual void PostTransferHook()
Called when the transfer completes.
Definition: AsyncUsbTransceiverBase.h:97
Definition: Mutex.h:35
Wraps calls to libusb so we can test the code.
Definition: LibUsbAdaptor.h:36