Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SyncPluginImpl.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  * SyncPluginImpl.h
17  * The synchronous implementation of the USB DMX plugin.
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_SYNCPLUGINIMPL_H_
22 #define PLUGINS_USBDMX_SYNCPLUGINIMPL_H_
23 
24 #include <libusb.h>
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include "ola/base/Macro.h"
32 #include "plugins/usbdmx/LibUsbAdaptor.h"
33 #include "plugins/usbdmx/PluginImplInterface.h"
34 #include "plugins/usbdmx/WidgetFactory.h"
35 
36 namespace ola {
37 
38 class Device;
39 
40 namespace plugin {
41 namespace usbdmx {
42 
52  public:
61  SyncPluginImpl(PluginAdaptor *plugin_adaptor,
62  Plugin *plugin,
63  unsigned int debug_level);
64 
65  ~SyncPluginImpl();
66 
67  bool Start();
68  bool Stop();
69 
70  bool NewWidget(class AnymauDMX *widget);
71  bool NewWidget(class EurolitePro *widget);
72  bool NewWidget(class ScanlimeFadecandy *widget);
73  bool NewWidget(class Sunlite *widget);
74  bool NewWidget(class VellemanK8062 *widget);
75 
76  void WidgetRemoved(OLA_UNUSED class AnymauDMX *widget) {}
77  void WidgetRemoved(OLA_UNUSED class EurolitePro *widget) {}
79  void WidgetRemoved(OLA_UNUSED class Sunlite *widget) {}
80  void WidgetRemoved(OLA_UNUSED class VellemanK8062 *widget) {}
81 
82  private:
83  typedef std::vector<class WidgetFactory*> WidgetFactories;
84  typedef std::map<class Widget*, Device*> WidgetToDeviceMap;
85 
86  PluginAdaptor* const m_plugin_adaptor;
87  Plugin* const m_plugin;
88  const unsigned int m_debug_level;
89  SyncronousLibUsbAdaptor m_usb_adaptor;
90  WidgetFactories m_widget_factories;
91 
92  libusb_context *m_context;
93 
94  WidgetToDeviceMap m_devices;
95  std::set<std::pair<uint8_t, uint8_t> > m_registered_devices;
96 
97  unsigned int ScanForDevices();
98  void ReScanForDevices();
99  bool CheckDevice(libusb_device *device);
100 
101  bool StartAndRegisterDevice(class Widget *widget, Device *device);
102 
103  DISALLOW_COPY_AND_ASSIGN(SyncPluginImpl);
104 };
105 } // namespace usbdmx
106 } // namespace plugin
107 } // namespace ola
108 #endif // PLUGINS_USBDMX_SYNCPLUGINIMPL_H_