RTXI  2.4
The Real-Time eXperiment Interface Documentation
event.h
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef EVENT_H
21 #define EVENT_H
22 
23 #include <fifo.h>
24 #include <list>
25 #include <map>
26 #include <pthread.h>
27 #include <rt.h>
28 #include <string>
29 
31 /*
32  * Objects contained within this namespace are responsible
33  * for dispatching signals.
34  */
35 namespace Event
36 {
37 
44 extern const char *RT_PERIOD_EVENT;
51 extern const char *RT_PREPERIOD_EVENT;
58 extern const char *RT_POSTPERIOD_EVENT;
59 
65 extern const char *RT_THREAD_INSERT_EVENT;
71 extern const char *RT_THREAD_REMOVE_EVENT;
77 extern const char *RT_DEVICE_INSERT_EVENT;
83 extern const char *RT_DEVICE_REMOVE_EVENT;
84 
85 extern const char *IO_BLOCK_INSERT_EVENT;
86 extern const char *IO_BLOCK_REMOVE_EVENT;
87 
88 extern const char *IO_LINK_INSERT_EVENT;
89 extern const char *IO_LINK_REMOVE_EVENT;
90 
91 extern const char *WORKSPACE_PARAMETER_CHANGE_EVENT;
92 
98 extern const char *PLUGIN_INSERT_EVENT;
105 extern const char *PLUGIN_REMOVE_EVENT;
106 
110 extern const char *SETTINGS_OBJECT_INSERT_EVENT;
114 extern const char *SETTINGS_OBJECT_REMOVE_EVENT;
115 
116 extern const char *OPEN_FILE_EVENT;
117 extern const char *START_RECORDING_EVENT;
118 extern const char *STOP_RECORDING_EVENT;
119 extern const char *ASYNC_DATA_EVENT;
120 
121 extern const char *THRESHOLD_CROSSING_EVENT;
122 
123 extern const char *START_GENICAM_RECORDING_EVENT;
124 extern const char *PAUSE_GENICAM_RECORDING_EVENT;
125 extern const char *STOP_GENICAM_RECORDING_EVENT;
126 extern const char *GENICAM_SNAPSHOT_EVENT;
127 
128 class Object
129 {
130 
131 public:
132 
133  Object(const char *);
134  ~Object(void);
135 
141  const char *getName(void) const
142  {
143  return name;
144  };
145 
152  void *getParam(const char *) const;
153 
160  void setParam(const char *,void *);
161 
165  const static size_t MAX_PARAMS = 8;
166 
167 private:
168 
169  const char *name;
170  size_t nparams;
171  struct
172  {
173  const char *name;
174  void *value;
175  } params[MAX_PARAMS];
176 
177 }; // class Object
178 
179 class Handler;
180 class RTHandler;
181 
182 /*
183  * Managaes the collection of all objects waiting to
184  * receive signals from events.
185  */
186 class Manager
187 {
188 
189  friend class Handler;
190  friend class RTHandler;
191 
192 public:
193 
201  static Manager *getInstance(void);
202 
213  void postEvent(const Object *event);
214 
225  void postEventRT(const Object *event);
226 
227 private:
228 
229  Manager(void);
230  ~Manager(void);
231  Manager(const Manager &) {};
232  Manager &operator=(const Manager &)
233  {
234  return *getInstance();
235  };
236 
237  static Manager *instance;
238 
239  void registerHandler(Handler *);
240  void unregisterHandler(Handler *);
241 
242  void registerRTHandler(RTHandler *);
243  void unregisterRTHandler(RTHandler *);
244 
245  Mutex mutex;
246  std::list<Handler *> handlerList;
247  RT::List<RTHandler> rthandlerList;
248 
249 }; // class Manager
250 
256 class Handler
257 {
258 
259 public:
260 
261  Handler(void);
262  virtual ~Handler(void);
263 
273  virtual void receiveEvent(const Object *event);
274 
275 }; // class Handler
276 
282 class RTHandler : public RT::List<RTHandler>::Node
283 {
284 
285 public:
286 
287  RTHandler(void);
288  virtual ~RTHandler(void);
289 
299  virtual void receiveEventRT(const Object *event);
300 
301 }; // class RTHandler
302 
303 }; // namespace Event
304 
305 #endif // EVENT_H
Event::Manager::postEvent
void postEvent(const Object *event)
Definition: event.cpp:110
Event::WORKSPACE_PARAMETER_CHANGE_EVENT
const char * WORKSPACE_PARAMETER_CHANGE_EVENT
Definition: event.cpp:35
Event::RT_DEVICE_INSERT_EVENT
const char * RT_DEVICE_INSERT_EVENT
Definition: event.cpp:29
Event::ASYNC_DATA_EVENT
const char * ASYNC_DATA_EVENT
Definition: event.cpp:43
Event::RT_THREAD_REMOVE_EVENT
const char * RT_THREAD_REMOVE_EVENT
Definition: event.cpp:28
Event::SETTINGS_OBJECT_REMOVE_EVENT
const char * SETTINGS_OBJECT_REMOVE_EVENT
Definition: event.cpp:39
Event::RT_POSTPERIOD_EVENT
const char * RT_POSTPERIOD_EVENT
Definition: event.cpp:26
Event::Object::getParam
void * getParam(const char *) const
Definition: event.cpp:81
Event::Handler::receiveEvent
virtual void receiveEvent(const Object *event)
Definition: event.cpp:60
Event::RTHandler
Definition: event.h:282
Event::Manager::getInstance
static Manager * getInstance(void)
Definition: event.cpp:149
Event::IO_BLOCK_INSERT_EVENT
const char * IO_BLOCK_INSERT_EVENT
Definition: event.cpp:31
Event::Handler::Handler
Handler(void)
Definition: event.cpp:50
Event::Object::getName
const char * getName(void) const
Definition: event.h:141
Event::RT_DEVICE_REMOVE_EVENT
const char * RT_DEVICE_REMOVE_EVENT
Definition: event.cpp:30
fifo.h
Event::RTHandler::RTHandler
RTHandler(void)
Definition: event.cpp:62
Event::Object::~Object
~Object(void)
Definition: event.cpp:79
Event::Manager
Definition: event.h:186
Event::Object::value
void * value
Definition: event.h:174
Event
Event Oriented Classes.
Definition: event.h:35
Event::Manager::postEventRT
void postEventRT(const Object *event)
Definition: event.cpp:118
Event::RT_THREAD_INSERT_EVENT
const char * RT_THREAD_INSERT_EVENT
Definition: event.cpp:27
Event::PAUSE_GENICAM_RECORDING_EVENT
const char * PAUSE_GENICAM_RECORDING_EVENT
Definition: event.cpp:46
Event::RTHandler::receiveEventRT
virtual void receiveEventRT(const Object *event)
Definition: event.cpp:72
Mutex
Definition: mutex.h:28
Event::RTHandler::~RTHandler
virtual ~RTHandler(void)
Definition: event.cpp:67
Event::OPEN_FILE_EVENT
const char * OPEN_FILE_EVENT
Definition: event.cpp:40
Event::Manager::Handler
friend class Handler
Definition: event.h:189
Event::Handler::~Handler
virtual ~Handler(void)
Definition: event.cpp:55
Event::Manager::RTHandler
friend class RTHandler
Definition: event.h:190
Event::RT_PERIOD_EVENT
const char * RT_PERIOD_EVENT
Definition: event.cpp:24
Event::SETTINGS_OBJECT_INSERT_EVENT
const char * SETTINGS_OBJECT_INSERT_EVENT
Definition: event.cpp:38
Event::Handler
Definition: event.h:256
Event::Object::MAX_PARAMS
const static size_t MAX_PARAMS
Definition: event.h:165
Event::START_GENICAM_RECORDING_EVENT
const char * START_GENICAM_RECORDING_EVENT
Definition: event.cpp:45
Event::IO_LINK_REMOVE_EVENT
const char * IO_LINK_REMOVE_EVENT
Definition: event.cpp:34
rt.h
Event::STOP_GENICAM_RECORDING_EVENT
const char * STOP_GENICAM_RECORDING_EVENT
Definition: event.cpp:47
Event::IO_BLOCK_REMOVE_EVENT
const char * IO_BLOCK_REMOVE_EVENT
Definition: event.cpp:32
Event::THRESHOLD_CROSSING_EVENT
const char * THRESHOLD_CROSSING_EVENT
Definition: event.cpp:44
Event::GENICAM_SNAPSHOT_EVENT
const char * GENICAM_SNAPSHOT_EVENT
Definition: event.cpp:48
Event::RT_PREPERIOD_EVENT
const char * RT_PREPERIOD_EVENT
Definition: event.cpp:25
RT::List
Definition: rt.h:110
Event::START_RECORDING_EVENT
const char * START_RECORDING_EVENT
Definition: event.cpp:41
Event::Object
Definition: event.h:128
Event::IO_LINK_INSERT_EVENT
const char * IO_LINK_INSERT_EVENT
Definition: event.cpp:33
Event::STOP_RECORDING_EVENT
const char * STOP_RECORDING_EVENT
Definition: event.cpp:42
Event::PLUGIN_INSERT_EVENT
const char * PLUGIN_INSERT_EVENT
Definition: event.cpp:36
Event::PLUGIN_REMOVE_EVENT
const char * PLUGIN_REMOVE_EVENT
Definition: event.cpp:37
Event::Object::setParam
void setParam(const char *, void *)
Definition: event.cpp:89
Event::Object::Object
Object(const char *)
Definition: event.cpp:74