Open Lighting Architecture  0.9.4
 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 ScanlimeFadecandy *widget) {
59  return DispatchNewWidget(widget);
60  }
61 
62  bool NewWidget(class Sunlite *widget) {
63  return DispatchNewWidget(widget);
64  }
65 
66  bool NewWidget(class VellemanK8062 *widget) {
67  return DispatchNewWidget(widget);
68  }
69 
70  void WidgetRemoved(class AnymauDMX *widget) {
71  DispatchWidgetRemoved(widget);
72  }
73 
74  void WidgetRemoved(class EurolitePro *widget) {
75  DispatchWidgetRemoved(widget);
76  }
77 
78  void WidgetRemoved(class ScanlimeFadecandy *widget) {
79  DispatchWidgetRemoved(widget);
80  }
81 
82  void WidgetRemoved(class Sunlite *widget) {
83  DispatchWidgetRemoved(widget);
84  }
85 
86  void WidgetRemoved(class VellemanK8062 *widget) {
87  DispatchWidgetRemoved(widget);
88  }
89 
90  private:
91  typedef ola::thread::Future<bool> AddFuture;
92  typedef ola::thread::Future<void> RemoveFuture;
93 
94  WidgetObserver* const m_observer;
96  const ola::thread::ThreadId m_main_thread_id;
97 
98  template<typename WidgetClass>
99  bool DispatchNewWidget(WidgetClass *widget);
100 
101  template<typename WidgetClass>
102  void DispatchWidgetRemoved(WidgetClass *widget);
103 
104  template<typename WidgetClass>
105  void HandleNewWidget(WidgetClass *widget, AddFuture *f);
106 
107  template<typename WidgetClass>
108  void HandleWidgetRemoved(WidgetClass *widget, RemoveFuture *f);
109 
110  DISALLOW_COPY_AND_ASSIGN(SyncronizedWidgetObserver);
111 };
112 } // namespace usbdmx
113 } // namespace plugin
114 } // namespace ola
115 #endif // PLUGINS_USBDMX_SYNCRONIZEDWIDGETOBSERVER_H_