Open Lighting Architecture  Latest Git
ThreadedUsbSender.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  * ThreadedUsbSender.h
17  * Send DMX data over USB from a dedicated thread.
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_THREADEDUSBSENDER_H_
22 #define PLUGINS_USBDMX_THREADEDUSBSENDER_H_
23 
24 #include <libusb.h>
25 #include "ola/base/Macro.h"
26 #include "ola/DmxBuffer.h"
27 #include "ola/thread/Thread.h"
28 
29 namespace ola {
30 namespace plugin {
31 namespace usbdmx {
32 
47  public:
55  ThreadedUsbSender(libusb_device *usb_device,
56  libusb_device_handle *usb_handle,
57  int interface_number = 0);
58  virtual ~ThreadedUsbSender();
59 
64  bool Start();
65 
70  void *Run();
71 
78  bool SendDMX(const DmxBuffer &buffer);
79 
80  protected:
89  virtual bool TransmitBuffer(libusb_device_handle *handle,
90  const DmxBuffer &buffer) = 0;
91 
92  private:
93  bool m_term;
94  libusb_device* const m_usb_device;
95  libusb_device_handle* const m_usb_handle;
96  int const m_interface_number;
97  DmxBuffer m_buffer;
98  ola::thread::Mutex m_data_mutex;
99  ola::thread::Mutex m_term_mutex;
100 
101  DISALLOW_COPY_AND_ASSIGN(ThreadedUsbSender);
102 };
103 } // namespace usbdmx
104 } // namespace plugin
105 } // namespace ola
106 #endif // PLUGINS_USBDMX_THREADEDUSBSENDER_H_
bool SendDMX(const DmxBuffer &buffer)
Buffer a DMX frame for sending.
Definition: ThreadedUsbSender.cpp:92
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A class used to hold a single universe of DMX data.
Definition: Thread.h:52
ThreadedUsbSender(libusb_device *usb_device, libusb_device_handle *usb_handle, int interface_number=0)
Create a new ThreadedUsbSender.
Definition: ThreadedUsbSender.cpp:30
bool Start()
Start the new thread.
Definition: ThreadedUsbSender.cpp:49
Helper macros.
Send DMX data using libusb, from a separate thread.
Definition: ThreadedUsbSender.h:46
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
virtual bool TransmitBuffer(libusb_device_handle *handle, const DmxBuffer &buffer)=0
Perform the DMX transfer.
void * Run()
Entry point for the new thread.
Definition: ThreadedUsbSender.cpp:60
Definition: Mutex.h:41