Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WidgetFactory.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  * WidgetFactory.h
17  * Creates USB Widgets.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_WIDGETFACTORY_H_
22 #define PLUGINS_USBDMX_WIDGETFACTORY_H_
23 
24 #include <libusb.h>
25 #include <map>
26 #include <string>
27 #include "ola/Logging.h"
28 #include "ola/base/Macro.h"
29 #include "ola/stl/STLUtils.h"
30 
31 namespace ola {
32 
33 namespace usb {
34 class JaRuleWidget;
35 } // namespace usb
36 
37 namespace plugin {
38 namespace usbdmx {
39 
50  public:
51  virtual ~WidgetObserver() {}
52 
60  virtual bool NewWidget(class AnymauDMX *widget) = 0;
61 
69  virtual bool NewWidget(class AVLdiyD512 *widget) = 0;
70 
78  virtual bool NewWidget(class DMXCProjectsNodleU1 *widget) = 0;
79 
87  virtual bool NewWidget(class DMXCreator512Basic *widget) = 0;
88 
96  virtual bool NewWidget(class EurolitePro *widget) = 0;
97 
105  virtual bool NewWidget(class ShowJockeyDMXU1 *widget) = 0;
106 
114  virtual bool NewWidget(ola::usb::JaRuleWidget *widget) = 0;
115 
123  virtual bool NewWidget(class ScanlimeFadecandy *widget) = 0;
124 
132  virtual bool NewWidget(class Sunlite *widget) = 0;
133 
141  virtual bool NewWidget(class VellemanK8062 *widget) = 0;
142 };
143 
153  public:
154  virtual ~WidgetFactory() {}
155 
165  virtual bool DeviceAdded(
166  WidgetObserver *observer,
167  libusb_device *usb_device,
168  const struct libusb_device_descriptor &descriptor) = 0;
169 
174  virtual std::string Name() const = 0;
175 };
176 
183 template <typename WidgetType>
185  public:
186  explicit BaseWidgetFactory(const std::string &name) : m_name(name) {}
187 
188  std::string Name() const { return m_name; }
189 
190  protected:
197  bool AddWidget(WidgetObserver *observer, WidgetType *widget);
198 
199  private:
200  const std::string m_name;
201 
202  DISALLOW_COPY_AND_ASSIGN(BaseWidgetFactory<WidgetType>);
203 };
204 
205 template <typename WidgetType>
207  WidgetType *widget) {
208  if (!widget->Init()) {
209  delete widget;
210  return false;
211  }
212 
213  if (!observer->NewWidget(widget)) {
214  delete widget;
215  return false;
216  }
217 
218  return true;
219 }
220 } // namespace usbdmx
221 } // namespace plugin
222 } // namespace ola
223 #endif // PLUGINS_USBDMX_WIDGETFACTORY_H_
std::string Name() const
The name of this factory.
Definition: WidgetFactory.h:188
The interface for the Nodle Widgets.
Definition: DMXCProjectsNodleU1.h:43
The EurolitePro Widget.
Definition: EurolitePro.h:42
Creates new Widget objects to represent DMX USB hardware.
Definition: WidgetFactory.h:152
A Ja Rule hardware device (widget).
Definition: JaRuleWidget.h:57
The interface for the Fadecandy Widgets.
Definition: ScanlimeFadecandy.h:49
The interface for the Sunlite Widgets.
Definition: Sunlite.h:40
virtual bool DeviceAdded(WidgetObserver *observer, libusb_device *usb_device, const struct libusb_device_descriptor &descriptor)=0
Called when a new USB device is added.
Helper functions for STL classes.
The base class for AVLdiy Widgets.
Definition: AVLdiyD512.h:41
A partial implementation of WidgetFactory.
Definition: WidgetFactory.h:184
The interface for the Velleman Widgets.
Definition: VellemanK8062.h:41
virtual bool NewWidget(class AnymauDMX *widget)=0
Called when a new AnymauDMX is added.
Helper macros.
The ShowJockey-DMX-U1 Widget.
Definition: ShowJockeyDMXU1.h:54
bool AddWidget(WidgetObserver *observer, WidgetType *widget)
Initialize a widget and notify the observer.
Definition: WidgetFactory.h:206
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
Header file for OLA Logging.
The base class for Anyma Widgets.
Definition: AnymauDMX.h:41
virtual std::string Name() const =0
The name of this factory.