Open Lighting Architecture  0.9.3
 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 
37 class UsbDmxPlugin: public ola::Plugin {
38  public:
39  explicit UsbDmxPlugin(PluginAdaptor *plugin_adaptor)
40  : Plugin(plugin_adaptor),
41  m_anyma_devices_missing_serial_numbers(false) {
42  }
43 
44  std::string Name() const { return PLUGIN_NAME; }
45  std::string Description() const;
46  ola_plugin_id Id() const { return OLA_PLUGIN_USBDMX; }
47  std::string PluginPrefix() const { return PLUGIN_PREFIX; }
48 
49  bool AddDeviceDescriptor(int fd);
50  bool RemoveDeviceDescriptor(int fd);
51  void SocketReady();
52 
53  private:
54  struct USBDeviceInformation {
55  std::string manufacturer;
56  std::string product;
57  std::string serial;
58  };
59 
60  bool m_anyma_devices_missing_serial_numbers;
61  std::vector<class UsbDevice*> m_devices; // list of our devices
62  std::vector<ola::io::DeviceDescriptor*> m_descriptors;
63  std::set<std::pair<uint8_t, uint8_t> > m_registered_devices;
64 
65  bool StartHook();
66  bool LoadFirmware();
67  void FindDevices();
68  bool StopHook();
69  bool SetDefaultPreferences();
70  class UsbDevice* NewAnymaDevice(
71  struct libusb_device *usb_device,
72  const struct libusb_device_descriptor &device_descriptor);
73 
74  void GetDeviceInfo(
75  struct libusb_device_handle *usb_handle,
76  const struct libusb_device_descriptor &device_descriptor,
77  USBDeviceInformation *device_info);
78  bool MatchManufacturer(const std::string &expected,
79  const std::string &actual);
80  bool MatchProduct(const std::string &expected, const std::string &actual);
81 
82  static const char PLUGIN_NAME[];
83  static const char PLUGIN_PREFIX[];
84  static const char LIBUSB_DEBUG_LEVEL_KEY[];
85  static int LIBUSB_DEFAULT_DEBUG_LEVEL;
86  static int LIBUSB_MAX_DEBUG_LEVEL;
87 };
88 } // namespace usbdmx
89 } // namespace plugin
90 } // namespace ola
91 #endif // PLUGINS_USBDMX_USBDMXPLUGIN_H_