Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UsbDmxPlugin.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * UsbDmxPlugin.h
17  * Interface for the usbdmx plugin class
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_USBDMXPLUGIN_H_
22 #define PLUGINS_USBDMX_USBDMXPLUGIN_H_
23 
24 #include <set>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 #include "ola/plugin_id.h"
29 #include "olad/Plugin.h"
30 #include "ola/io/Descriptor.h"
31 
32 namespace ola {
33 namespace plugin {
34 
35 namespace usbdmx {
36 
38 
39 class UsbDmxPlugin: public ola::Plugin {
40  public:
41  explicit UsbDmxPlugin(PluginAdaptor *plugin_adaptor):
42  Plugin(plugin_adaptor),
43  m_anyma_devices_missing_serial_numbers(false) {
44  }
45 
46  string Name() const { return PLUGIN_NAME; }
47  string Description() const;
48  ola_plugin_id Id() const { return OLA_PLUGIN_USBDMX; }
49  string PluginPrefix() const { return PLUGIN_PREFIX; }
50 
51  bool AddDeviceDescriptor(int fd);
52  bool RemoveDeviceDescriptor(int fd);
53  void SocketReady();
54 
55  private:
56  struct USBDeviceInformation {
57  string manufacturer;
58  string product;
59  string serial;
60  };
61 
62  bool m_anyma_devices_missing_serial_numbers;
63  vector<class UsbDevice*> m_devices; // list of our devices
64  vector<ola::io::DeviceDescriptor*> m_descriptors;
65  set<std::pair<uint8_t, uint8_t> > m_registered_devices;
66 
67  bool StartHook();
68  bool LoadFirmware();
69  void FindDevices();
70  bool StopHook();
71  bool SetDefaultPreferences();
72  class UsbDevice* NewAnymaDevice(
73  struct libusb_device *usb_device,
74  const struct libusb_device_descriptor &device_descriptor);
75 
76  void GetDeviceInfo(
77  struct libusb_device_handle *usb_handle,
78  const struct libusb_device_descriptor &device_descriptor,
79  USBDeviceInformation *device_info);
80  bool MatchManufacturer(const string &expected, const string &actual);
81  bool MatchProduct(const string &expected, const string &actual);
82  bool GetDescriptorString(libusb_device_handle *usb_handle,
83  uint8_t desc_index,
84  string *data);
85 
86  static const char PLUGIN_NAME[];
87  static const char PLUGIN_PREFIX[];
88  static const char LIBUSB_DEBUG_LEVEL_KEY[];
89  static int LIBUSB_DEFAULT_DEBUG_LEVEL;
90  static int LIBUSB_MAX_DEBUG_LEVEL;
91 };
92 } // namespace usbdmx
93 } // namespace plugin
94 } // namespace ola
95 #endif // PLUGINS_USBDMX_USBDMXPLUGIN_H_