Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:
54  ThreadedUsbSender(libusb_device *usb_device,
55  libusb_device_handle *usb_handle);
56  virtual ~ThreadedUsbSender();
57 
62  bool Start();
63 
68  void *Run();
69 
76  bool SendDMX(const DmxBuffer &buffer);
77 
78  protected:
87  virtual bool TransmitBuffer(libusb_device_handle *handle,
88  const DmxBuffer &buffer) = 0;
89 
90  private:
91  bool m_term;
92  libusb_device* const m_usb_device;
93  libusb_device_handle* const m_usb_handle;
94  DmxBuffer m_buffer;
95  ola::thread::Mutex m_data_mutex;
96  ola::thread::Mutex m_term_mutex;
97 
98  DISALLOW_COPY_AND_ASSIGN(ThreadedUsbSender);
99 };
100 } // namespace usbdmx
101 } // namespace plugin
102 } // namespace ola
103 #endif // PLUGINS_USBDMX_THREADEDUSBSENDER_H_