Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SyncronizedWidgetObserver.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  * SyncronizedWidgetObserver.h
17  * Transfers widget add/remove events to another thread.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_SYNCRONIZEDWIDGETOBSERVER_H_
22 #define PLUGINS_USBDMX_SYNCRONIZEDWIDGETOBSERVER_H_
23 
24 #include "plugins/usbdmx/WidgetFactory.h"
25 
26 #include "ola/io/SelectServerInterface.h"
27 #include "ola/thread/Future.h"
28 #include "ola/thread/Thread.h"
29 
30 namespace ola {
31 namespace plugin {
32 namespace usbdmx {
33 
41  public:
49 
50  bool NewWidget(class AnymauDMX *widget) {
51  return DispatchNewWidget(widget);
52  }
53 
54  bool NewWidget(class EurolitePro *widget) {
55  return DispatchNewWidget(widget);
56  }
57 
58  bool NewWidget(class JaRuleWidget *widget) {
59  return DispatchNewWidget(widget);
60  }
61 
62  bool NewWidget(class ScanlimeFadecandy *widget) {
63  return DispatchNewWidget(widget);
64  }
65 
66  bool NewWidget(class Sunlite *widget) {
67  return DispatchNewWidget(widget);
68  }
69 
70  bool NewWidget(class VellemanK8062 *widget) {
71  return DispatchNewWidget(widget);
72  }
73 
74  void WidgetRemoved(class AnymauDMX *widget) {
75  DispatchWidgetRemoved(widget);
76  }
77 
78  void WidgetRemoved(class EurolitePro *widget) {
79  DispatchWidgetRemoved(widget);
80  }
81 
82  void WidgetRemoved(class JaRuleWidget *widget) {
83  DispatchWidgetRemoved(widget);
84  }
85 
86  void WidgetRemoved(class ScanlimeFadecandy *widget) {
87  DispatchWidgetRemoved(widget);
88  }
89 
90  void WidgetRemoved(class Sunlite *widget) {
91  DispatchWidgetRemoved(widget);
92  }
93 
94  void WidgetRemoved(class VellemanK8062 *widget) {
95  DispatchWidgetRemoved(widget);
96  }
97 
98  private:
99  typedef ola::thread::Future<bool> AddFuture;
100  typedef ola::thread::Future<void> RemoveFuture;
101 
102  WidgetObserver* const m_observer;
103  ola::io::SelectServerInterface* const m_ss;
104  const ola::thread::ThreadId m_main_thread_id;
105 
106  template<typename WidgetClass>
107  bool DispatchNewWidget(WidgetClass *widget);
108 
109  template<typename WidgetClass>
110  void DispatchWidgetRemoved(WidgetClass *widget);
111 
112  template<typename WidgetClass>
113  void HandleNewWidget(WidgetClass *widget, AddFuture *f);
114 
115  template<typename WidgetClass>
116  void HandleWidgetRemoved(WidgetClass *widget, RemoveFuture *f);
117 
118  DISALLOW_COPY_AND_ASSIGN(SyncronizedWidgetObserver);
119 };
120 } // namespace usbdmx
121 } // namespace plugin
122 } // namespace ola
123 #endif // PLUGINS_USBDMX_SYNCRONIZEDWIDGETOBSERVER_H_