Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "ola/thread/Future.h"
41 #include "olad/Preferences.h"
42 #include "plugins/usbdmx/PluginImplInterface.h"
43 #include "plugins/usbdmx/SyncronizedWidgetObserver.h"
44 #include "plugins/usbdmx/WidgetFactory.h"
45 
46 namespace ola {
47 namespace usb {
48 class LibUsbThread;
49 class AsyncronousLibUsbAdaptor;
50 } // namespace usb
51 
52 class Device;
53 
54 namespace plugin {
55 namespace usbdmx {
56 
61  public:
71  AsyncPluginImpl(PluginAdaptor *plugin_adaptor,
72  Plugin *plugin,
73  unsigned int debug_level,
74  Preferences *preferences);
75  ~AsyncPluginImpl();
76 
77  bool Start();
78  bool Stop();
79 
80  // These are all run in the main SelectServer thread.
81  bool NewWidget(class AnymauDMX *widget);
82  bool NewWidget(class DMXCProjectsNodleU1 *widget);
83  bool NewWidget(class EurolitePro *widget);
84  bool NewWidget(ola::usb::JaRuleWidget *widget);
85  bool NewWidget(class ScanlimeFadecandy *widget);
86  bool NewWidget(class Sunlite *widget);
87  bool NewWidget(class VellemanK8062 *widget);
88 
89  private:
90  typedef std::vector<class WidgetFactory*> WidgetFactories;
91  typedef std::map<ola::usb::USBDeviceID, class DeviceState*> USBDeviceMap;
92 
93  PluginAdaptor* const m_plugin_adaptor;
94  Plugin* const m_plugin;
95  const unsigned int m_debug_level;
96  std::auto_ptr<ola::usb::HotplugAgent> m_agent;
97  Preferences* const m_preferences;
98 
99  SyncronizedWidgetObserver m_widget_observer;
100  ola::usb::AsyncronousLibUsbAdaptor *m_usb_adaptor; // not owned
101  WidgetFactories m_widget_factories;
102  USBDeviceMap m_device_map;
103 
104  void DeviceEvent(ola::usb::HotplugAgent::EventType event,
105  struct libusb_device *device);
106  void SetupUSBDevice(libusb_device *device);
107 
108  template <typename Widget>
109  bool StartAndRegisterDevice(Widget *widget, Device *device);
110 
111  void ShutdownDevice(Device *device, ola::thread::Future<void> *f);
112 
113  DISALLOW_COPY_AND_ASSIGN(AsyncPluginImpl);
114 };
115 } // namespace usbdmx
116 } // namespace plugin
117 } // namespace ola
118 #endif // PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
bool Stop()
Stop the implementation.
Definition: AsyncPluginImpl.cpp:140
The interface for the Nodle Widgets.
Definition: DMXCProjectsNodleU1.h:43
The EurolitePro Widget.
Definition: EurolitePro.h:42
The asynchronous libusb implementation.
Definition: AsyncPluginImpl.h:60
AsyncPluginImpl(PluginAdaptor *plugin_adaptor, Plugin *plugin, unsigned int debug_level, Preferences *preferences)
Create a new AsyncPluginImpl.
Definition: AsyncPluginImpl.cpp:90
Definition: Device.h:89
A Ja Rule hardware device (widget).
Definition: JaRuleWidget.h:57
bool NewWidget(class AnymauDMX *widget)
Called when a new AnymauDMX is added.
Definition: AsyncPluginImpl.cpp:165
bool Start()
Start the implementation.
Definition: AsyncPluginImpl.cpp:106
The interface for the Fadecandy Widgets.
Definition: ScanlimeFadecandy.h:49
EventType
Definition: HotplugAgent.h:47
Definition: Plugin.h:118
Definition: PluginAdaptor.h:41
The interface for the Sunlite Widgets.
Definition: Sunlite.h:40
Transfers widget add/remove events to another thread.
Definition: SyncronizedWidgetObserver.h:40
A LibUsbAdaptor for use with Asyncronous widgets.
Definition: LibUsbAdaptor.h:563
The interface for an implementation of the USB DMX plugin.
Definition: PluginImplInterface.h:40
The interface for the Velleman Widgets.
Definition: VellemanK8062.h:41
Definition: Preferences.h:145
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Receives notifications when Widgets are added or removed.
Definition: WidgetFactory.h:49
Definition: Future.h:74
The base class for Anyma Widgets.
Definition: AnymauDMX.h:41