Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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
31namespace ola {
32
33namespace usb {
34class JaRuleWidget;
35} // namespace usb
36
37namespace plugin {
38namespace 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
156template <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 BaseWidgetFactory(const BaseWidgetFactory &) = delete;
176 const BaseWidgetFactory &operator=(const BaseWidgetFactory &) = delete;
177};
178
179template <typename WidgetType>
181 WidgetType *widget) {
182 if (!widget->Init()) {
183 delete widget;
184 return false;
185 }
186
187 if (!observer->NewWidget(widget)) {
188 delete widget;
189 return false;
190 }
191
192 return true;
193}
194} // namespace usbdmx
195} // namespace plugin
196} // namespace ola
197#endif // PLUGINS_USBDMX_WIDGETFACTORY_H_
Header file for OLA Logging.
Helper macros.
Helper functions for STL classes.
The base class for Anyma Widgets.
Definition AnymauDMX.h:41
A partial implementation of WidgetFactory.
Definition WidgetFactory.h:157
bool AddWidget(WidgetObserver *observer, WidgetType *widget)
Initialize a widget and notify the observer.
Definition WidgetFactory.h:180
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
The interface for the Fadecandy Widgets.
Definition ScanlimeFadecandy.h:49
The interface for the Sunlite Widgets.
Definition Sunlite.h:40
The interface for the Velleman Widgets.
Definition VellemanK8062.h:41
Creates new Widget objects to represent DMX USB hardware.
Definition WidgetFactory.h:125
virtual std::string Name() const =0
The name of this factory.
virtual bool DeviceAdded(WidgetObserver *observer, libusb_device *usb_device, const struct libusb_device_descriptor &descriptor)=0
Called when a new USB device is added.
Receives notifications when Widgets are added or removed.
Definition WidgetFactory.h:49
virtual bool NewWidget(class DMXCProjectsNodleU1 *widget)=0
Called when a new DMXCProjects Nodle U1 widget is added.
virtual bool NewWidget(ola::usb::JaRuleWidget *widget)=0
Called when a new Ja Rule widget is added.
virtual bool NewWidget(class Sunlite *widget)=0
Called when a new Sunlite is added.
virtual bool NewWidget(class AnymauDMX *widget)=0
Called when a new AnymauDMX is added.
virtual bool NewWidget(class ScanlimeFadecandy *widget)=0
Called when a new ScanlimeFadecandy is added.
virtual bool NewWidget(class EurolitePro *widget)=0
Called when a new EurolitePro is added.
virtual bool NewWidget(class VellemanK8062 *widget)=0
Called when a new VellemanK8062 is added.
A Ja Rule hardware device (widget).
Definition JaRuleWidget.h:57
The namespace containing all OLA symbols.
Definition Credentials.cpp:44