Open Lighting Architecture: plugins/usbdmx/WidgetFactory.h Source File

| 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
49 class WidgetObserver {
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
125 class WidgetFactory {
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>
157 class BaseWidgetFactory : public WidgetFactory {
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>
180 bool BaseWidgetFactory<WidgetType>::AddWidget(WidgetObserver *observer,
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_
Logging.h
Header file for OLA Logging.
Macro.h
Helper macros.
STLUtils.h
Helper functions for STL classes.
ola::plugin::usbdmx::AnymauDMX
The base class for Anyma Widgets.
Definition AnymauDMX.h:41
ola::plugin::usbdmx::BaseWidgetFactory::AddWidget
bool AddWidget(WidgetObserver *observer, WidgetType *widget)
Initialize a widget and notify the observer.
Definition WidgetFactory.h:180
ola::plugin::usbdmx::BaseWidgetFactory::Name
std::string Name() const
The name of this factory.
Definition WidgetFactory.h:161
ola::plugin::usbdmx::DMXCProjectsNodleU1
The interface for the Nodle Widgets.
Definition DMXCProjectsNodleU1.h:43
ola::plugin::usbdmx::EurolitePro
The EurolitePro Widget.
Definition EurolitePro.h:42
ola::plugin::usbdmx::ScanlimeFadecandy
The interface for the Fadecandy Widgets.
Definition ScanlimeFadecandy.h:49
ola::plugin::usbdmx::Sunlite
The interface for the Sunlite Widgets.
Definition Sunlite.h:40
ola::plugin::usbdmx::VellemanK8062
The interface for the Velleman Widgets.
Definition VellemanK8062.h:41
ola::plugin::usbdmx::WidgetFactory
Creates new Widget objects to represent DMX USB hardware.
Definition WidgetFactory.h:125
ola::plugin::usbdmx::WidgetFactory::Name
virtual std::string Name() const =0
The name of this factory.
ola::plugin::usbdmx::WidgetFactory::DeviceAdded
virtual bool DeviceAdded(WidgetObserver *observer, libusb_device *usb_device, const struct libusb_device_descriptor &descriptor)=0
Called when a new USB device is added.
ola::plugin::usbdmx::WidgetObserver
Receives notifications when Widgets are added or removed.
Definition WidgetFactory.h:49
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(class DMXCProjectsNodleU1 *widget)=0
Called when a new DMXCProjects Nodle U1 widget is added.
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(ola::usb::JaRuleWidget *widget)=0
Called when a new Ja Rule widget is added.
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(class Sunlite *widget)=0
Called when a new Sunlite is added.
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(class AnymauDMX *widget)=0
Called when a new AnymauDMX is added.
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(class ScanlimeFadecandy *widget)=0
Called when a new ScanlimeFadecandy is added.
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(class EurolitePro *widget)=0
Called when a new EurolitePro is added.
ola::plugin::usbdmx::WidgetObserver::NewWidget
virtual bool NewWidget(class VellemanK8062 *widget)=0
Called when a new VellemanK8062 is added.
ola::usb::JaRuleWidget
A Ja Rule hardware device (widget).
Definition JaRuleWidget.h:57
ola::plugin::usbdmx
The plugin for hardware using libusb.
ola::plugin
Code for supported devices and protocols.
ola::usb
USB Device drivers.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44