RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
136  const char *getName(void) const
137  {
138  return name;
139  };
140 
141  void *getParam(const char *) const;
142  void setParam(const char *,void *);
143 
144  const static size_t MAX_PARAMS = 8;
145 
146 private:
147 
148  const char *name;
149  size_t nparams;
150  struct
151  {
152  const char *name;
153  void *value;
154  } params[MAX_PARAMS];
155 
156 }; // class Object
157 
158 class Handler;
159 class RTHandler;
160 
161 /*
162  * Managaes the collection of all objects waiting to
163  * receive signals from events.
164  */
165 class Manager
166 {
167 
168  friend class Handler;
169  friend class RTHandler;
170 
171 public:
172 
180  static Manager *getInstance(void);
181 
192  void postEvent(const Object *event);
193 
204  void postEventRT(const Object *event);
205 
206 private:
207 
208  Manager(void);
209  ~Manager(void);
210  Manager(const Manager &) {};
212  {
213  return *getInstance();
214  };
215 
216  static Manager *instance;
217 
218  void registerHandler(Handler *);
219  void unregisterHandler(Handler *);
220 
223 
225  std::list<Handler *> handlerList;
227 
228 }; // class Manager
229 
235 class Handler
236 {
237 
238 public:
239 
240  Handler(void);
241  virtual ~Handler(void);
242 
252  virtual void receiveEvent(const Object *event);
253 
254 }; // class Handler
255 
261 class RTHandler : public RT::List<RTHandler>::Node
262 {
263 
264 public:
265 
266  RTHandler(void);
267  virtual ~RTHandler(void);
268 
278  virtual void receiveEventRT(const Object *event);
279 
280 }; // class RTHandler
281 
282 }; // namespace Event
283 
284 #endif // EVENT_H
size_t nparams
Definition: event.h:149
Mutex mutex
Definition: event.h:224
void registerHandler(Handler *)
Definition: event.cpp:124
const char * RT_PERIOD_EVENT
Definition: event.cpp:24
Manager(void)
Definition: event.cpp:106
const char * OPEN_FILE_EVENT
Definition: event.cpp:40
const char * name
Definition: event.h:148
void setParam(const char *, void *)
Definition: event.cpp:89
Definition: rt.h:98
const char * IO_LINK_REMOVE_EVENT
Definition: event.cpp:34
void * value
Definition: event.h:153
void * getParam(const char *) const
Definition: event.cpp:81
~Manager(void)
Definition: event.cpp:108
const char * STOP_GENICAM_RECORDING_EVENT
Definition: event.cpp:47
const char * SETTINGS_OBJECT_INSERT_EVENT
Definition: event.cpp:38
void postEvent(const Object *event)
Definition: event.cpp:110
const char * START_GENICAM_RECORDING_EVENT
Definition: event.cpp:45
virtual void receiveEventRT(const Object *event)
Definition: event.cpp:72
~Object(void)
Definition: event.cpp:79
const char * GENICAM_SNAPSHOT_EVENT
Definition: event.cpp:48
static const size_t MAX_PARAMS
Definition: event.h:144
const char * RT_PREPERIOD_EVENT
Definition: event.cpp:25
Definition: mutex.h:28
virtual void receiveEvent(const Object *event)
Definition: event.cpp:60
Manager(const Manager &)
Definition: event.h:210
const char * IO_BLOCK_REMOVE_EVENT
Definition: event.cpp:32
const char * START_RECORDING_EVENT
Definition: event.cpp:41
const char * THRESHOLD_CROSSING_EVENT
Definition: event.cpp:44
void unregisterRTHandler(RTHandler *)
Definition: event.cpp:141
std::list< Handler * > handlerList
Definition: event.h:225
static Manager * getInstance(void)
Definition: event.cpp:149
virtual ~Handler(void)
Definition: event.cpp:55
const char * STOP_RECORDING_EVENT
Definition: event.cpp:42
const char * PLUGIN_INSERT_EVENT
Definition: event.cpp:36
const char * IO_LINK_INSERT_EVENT
Definition: event.cpp:33
const char * PLUGIN_REMOVE_EVENT
Definition: event.cpp:37
const char * RT_THREAD_REMOVE_EVENT
Definition: event.cpp:28
static Manager * instance
Definition: event.h:214
RT::List< RTHandler > rthandlerList
Definition: event.h:226
const char * WORKSPACE_PARAMETER_CHANGE_EVENT
Definition: event.cpp:35
const char * RT_DEVICE_INSERT_EVENT
Definition: event.cpp:29
RTHandler(void)
Definition: event.cpp:62
const char * ASYNC_DATA_EVENT
Definition: event.cpp:43
const char * SETTINGS_OBJECT_REMOVE_EVENT
Definition: event.cpp:39
struct Event::Object::@3 params[MAX_PARAMS]
const char * RT_POSTPERIOD_EVENT
Definition: event.cpp:26
const char * IO_BLOCK_INSERT_EVENT
Definition: event.cpp:31
virtual ~RTHandler(void)
Definition: event.cpp:67
const char * RT_DEVICE_REMOVE_EVENT
Definition: event.cpp:30
void registerRTHandler(RTHandler *)
Definition: event.cpp:136
void unregisterHandler(Handler *)
Definition: event.cpp:130
Manager & operator=(const Manager &)
Definition: event.h:211
Event Oriented Classes.
Definition: event.h:35
void postEventRT(const Object *event)
Definition: event.cpp:118
Handler(void)
Definition: event.cpp:50
const char * PAUSE_GENICAM_RECORDING_EVENT
Definition: event.cpp:46
const char * RT_THREAD_INSERT_EVENT
Definition: event.cpp:27
Object(const char *)
Definition: event.cpp:74
const char * getName(void) const
Definition: event.h:136