Open Lighting Architecture  0.10.4
 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 DMXCProjectsNodleU1 *widget) = 0;
70 
78  virtual bool NewWidget(class EurolitePro *widget) = 0;
79 
87  virtual bool NewWidget(ola::usb::JaRuleWidget *widget) = 0;
88 
96  virtual bool NewWidget(class ScanlimeFadecandy *widget) = 0;
97 
105  virtual bool NewWidget(class Sunlite *widget) = 0;
106 
114  virtual bool NewWidget(class VellemanK8062 *widget) = 0;
115 };
116 
126  public:
127  virtual ~WidgetFactory() {}
128 
138  virtual bool DeviceAdded(
139  WidgetObserver *observer,
140  libusb_device *usb_device,
141  const struct libusb_device_descriptor &descriptor) = 0;
142 
147  virtual std::string Name() const = 0;
148 };
149 
156 template <typename WidgetType>
158  public:
159  explicit BaseWidgetFactory(const std::string &name) : m_name(name) {}
160 
161  std::string Name() const { return m_name; }
162 
163  protected:
170  bool AddWidget(WidgetObserver *observer, WidgetType *widget);
171 
172  private:
173  const std::string m_name;
174 
175  DISALLOW_COPY_AND_ASSIGN(BaseWidgetFactory<WidgetType>);
176 };
177 
178 template <typename WidgetType>
180  WidgetType *widget) {
181  if (!widget->Init()) {
182  delete widget;
183  return false;
184  }
185 
186  if (!observer->NewWidget(widget)) {
187  delete widget;
188  return false;
189  }
190 
191  return true;
192 }
193 } // namespace usbdmx
194 } // namespace plugin
195 } // namespace ola
196 #endif // PLUGINS_USBDMX_WIDGETFACTORY_H_
std::string Name() const
The name of this factory.
Definition: WidgetFactory.h:161
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:125
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.
A partial implementation of WidgetFactory.
Definition: WidgetFactory.h:157
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.
bool AddWidget(WidgetObserver *observer, WidgetType *widget)
Initialize a widget and notify the observer.
Definition: WidgetFactory.h:179
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Receives notifications when Widgets are added or removed.
Definition: WidgetFactory.h:49
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.