Open Lighting Architecture  Latest Git
AsyncPluginImpl.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  * AsyncPluginImpl.h
17  * The asynchronous libusb implementation.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
22 #define PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
23 
24 #include <libusb.h>
25 
26 #if HAVE_CONFIG_H
27 #include <config.h>
28 #endif // HAVE_CONFIG_H
29 
30 #include <map>
31 #include <memory>
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 #include "libs/usb/Types.h"
37 #include "libs/usb/HotplugAgent.h"
38 
39 #include "ola/base/Macro.h"
40 #include "olad/Preferences.h"
41 #include "plugins/usbdmx/PluginImplInterface.h"
42 #include "plugins/usbdmx/SynchronizedWidgetObserver.h"
43 #include "plugins/usbdmx/WidgetFactory.h"
44 
45 namespace ola {
46 namespace usb {
47 class LibUsbThread;
48 class AsynchronousLibUsbAdaptor;
49 } // namespace usb
50 
51 class Device;
52 
53 namespace plugin {
54 namespace usbdmx {
55 
60  public:
70  AsyncPluginImpl(PluginAdaptor *plugin_adaptor,
71  Plugin *plugin,
72  unsigned int debug_level,
73  Preferences *preferences);
74  ~AsyncPluginImpl();
75 
76  bool Start();
77  bool Stop();
78 
79  // These are all run in the main SelectServer thread.
80  bool NewWidget(class AnymauDMX *widget);
81  bool NewWidget(class AVLdiyD512 *widget);
82  bool NewWidget(class DMXCProjectsNodleU1 *widget);
83  bool NewWidget(class DMXCreator512Basic *widget);
84  bool NewWidget(class EurolitePro *widget);
85  bool NewWidget(ola::usb::JaRuleWidget *widget);
86  bool NewWidget(class ScanlimeFadecandy *widget);
87  bool NewWidget(class ShowJockeyDMXU1 *widget);
88  bool NewWidget(class Sunlite *widget);
89  bool NewWidget(class VellemanK8062 *widget);
90 
91  private:
92  typedef std::vector<class WidgetFactory*> WidgetFactories;
93  typedef std::map<ola::usb::USBDeviceID, class DeviceState*> USBDeviceMap;
94 
95  PluginAdaptor* const m_plugin_adaptor;
96  Plugin* const m_plugin;
97  const unsigned int m_debug_level;
98  std::auto_ptr<ola::usb::HotplugAgent> m_agent;
99  Preferences* const m_preferences;
100 
101  SynchronizedWidgetObserver m_widget_observer;
102  ola::usb::AsynchronousLibUsbAdaptor *m_usb_adaptor; // not owned
103  WidgetFactories m_widget_factories;
104  USBDeviceMap m_device_map;
105 
106  void DeviceEvent(ola::usb::HotplugAgent::EventType event,
107  struct libusb_device *device);
108  void SetupUSBDevice(libusb_device *device);
109 
110  template <typename Widget>
111  bool StartAndRegisterDevice(Widget *widget, Device *device);
112 
113  void ShutdownDeviceState(DeviceState *state);
114 
116 };
117 } // namespace usbdmx
118 } // namespace plugin
119 } // namespace ola
120 #endif // PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
The interface for the Nodle Widgets.
Definition: DMXCProjectsNodleU1.h:43
The EurolitePro Widget.
Definition: EurolitePro.h:42
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
The asynchronous libusb implementation.
Definition: AsyncPluginImpl.h:59
Definition: Device.h:95
A Ja Rule hardware device (widget).
Definition: JaRuleWidget.h:57
The interface for the Fadecandy Widgets.
Definition: ScanlimeFadecandy.h:49
EventType
Definition: HotplugAgent.h:47
Definition: Plugin.h:118
Definition: PluginAdaptor.h:41
Definition: AsyncPluginImpl.cpp:71
The interface for the Sunlite Widgets.
Definition: Sunlite.h:40
The interface for an implementation of the USB DMX plugin.
Definition: PluginImplInterface.h:40
Transfers widget add/remove events to another thread.
Definition: SynchronizedWidgetObserver.h:40
The base class for AVLdiy Widgets.
Definition: AVLdiyD512.h:41
The interface for the Velleman Widgets.
Definition: VellemanK8062.h:41
Definition: Preferences.h:147
Helper macros.
The ShowJockey-DMX-U1 Widget.
Definition: ShowJockeyDMXU1.h:54
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Receives notifications when Widgets are added or removed.
Definition: WidgetFactory.h:49
The base class for DMXCreator512Basic Widgets.
Definition: DMXCreator512Basic.h:41
A LibUsbAdaptor for use with Asynchronous widgets.
Definition: LibUsbAdaptor.h:563
The base class for Anyma Widgets.
Definition: AnymauDMX.h:41