Open Lighting Architecture  Latest Git
 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/SynchronizedWidgetObserver.h"
44 #include "plugins/usbdmx/WidgetFactory.h"
45 
46 namespace ola {
47 namespace usb {
48 class LibUsbThread;
49 class AsynchronousLibUsbAdaptor;
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 AVLdiyD512 *widget);
83  bool NewWidget(class DMXCProjectsNodleU1 *widget);
84  bool NewWidget(class DMXCreator512Basic *widget);
85  bool NewWidget(class EurolitePro *widget);
86  bool NewWidget(ola::usb::JaRuleWidget *widget);
87  bool NewWidget(class ScanlimeFadecandy *widget);
88  bool NewWidget(class ShowJockeyDMXU1 *widget);
89  bool NewWidget(class Sunlite *widget);
90  bool NewWidget(class VellemanK8062 *widget);
91 
92  private:
93  typedef std::vector<class WidgetFactory*> WidgetFactories;
94  typedef std::map<ola::usb::USBDeviceID, class DeviceState*> USBDeviceMap;
95 
96  PluginAdaptor* const m_plugin_adaptor;
97  Plugin* const m_plugin;
98  const unsigned int m_debug_level;
99  std::auto_ptr<ola::usb::HotplugAgent> m_agent;
100  Preferences* const m_preferences;
101 
102  SynchronizedWidgetObserver m_widget_observer;
103  ola::usb::AsynchronousLibUsbAdaptor *m_usb_adaptor; // not owned
104  WidgetFactories m_widget_factories;
105  USBDeviceMap m_device_map;
106 
107  void DeviceEvent(ola::usb::HotplugAgent::EventType event,
108  struct libusb_device *device);
109  void SetupUSBDevice(libusb_device *device);
110 
111  template <typename Widget>
112  bool StartAndRegisterDevice(Widget *widget, Device *device);
113 
114  void ShutdownDevice(Device *device, ola::thread::Future<void> *f);
115 
116  DISALLOW_COPY_AND_ASSIGN(AsyncPluginImpl);
117 };
118 } // namespace usbdmx
119 } // namespace plugin
120 } // namespace ola
121 #endif // PLUGINS_USBDMX_ASYNCPLUGINIMPL_H_
bool Stop()
Stop the implementation.
Definition: AsyncPluginImpl.cpp:148
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:95
Definition: Device.h:95
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:173
bool Start()
Start the implementation.
Definition: AsyncPluginImpl.cpp:111
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
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
Definition: Future.h:74
The base class for Anyma Widgets.
Definition: AnymauDMX.h:41