00001 /** 00002 * @file Process.h 00003 * 00004 * Contains the definition of class Process and macros for receivers and senders 00005 */ 00006 00007 #ifndef __Process_h_ 00008 #define __Process_h_ 00009 00010 #include "Tools/MessageQueue/MessageQueue.h" 00011 #include "Tools/Debugging/DebugKeyTable.h" 00012 #include "Tools/Module/ModuleHandler.h" 00013 #include "Platform/ProcessFramework.h" 00014 00015 /** 00016 * @class Process 00017 * 00018 * System independent base class for Processes. 00019 * 00020 * Process is the common base for processes in the GT2002 Project. 00021 * The embedding into the system environment is done by system dependent frameworks that use 00022 * derivates of the Process class. 00023 */ 00024 class Process : public PlatformProcess, public MessageHandler 00025 { 00026 public: 00027 00028 /** 00029 * Constructor. 00030 * @param debugIn A reference to an incoming debug queue 00031 * @param debugOut A reference to an outgoing debug queue 00032 */ 00033 Process(MessageQueue& debugIn, MessageQueue& debugOut); 00034 00035 /** 00036 * The main function is called from the process framework once in each frame. 00037 * It does the debug handling and calls the main function in the derivates. 00038 * @return If 0 is returned, the function main will not be called on a timed basis 00039 * again. A positive number specifies the minimum number of microseconds to 00040 * wait before the next frame starts. A negative number specifies a cycle 00041 * time, i.e. the time between two activations of the main() function. 00042 */ 00043 int processMain(); 00044 00045 /** 00046 * The main funtion is called once in each frame. 00047 * It must be implemented. 00048 * @return If 0 is returned, the function main will not be called on a timed basis 00049 * again. A positive number specifies the minimum number of microseconds to 00050 * wait before the next frame starts. A negative number specifies a cycle 00051 * time, i.e. the time between two activations of the main() function. 00052 */ 00053 virtual int main() = 0; 00054 00055 /** 00056 * That function is called once before the first main(). It can be used 00057 * for things that can't be done in the constructor. 00058 */ 00059 virtual void init() {} 00060 00061 /** 00062 * Is called for every incoming debug message. 00063 * @param message An interface to read the message from the queue 00064 * @return true if message was handled 00065 */ 00066 virtual bool handleMessage(InMessage& message); 00067 00068 private: 00069 /** 00070 * Determines if the process is already initialized. Becomes true short 00071 * before the first call of main() 00072 */ 00073 bool initialized; 00074 00075 protected: 00076 00077 /** A module handler for managing runtime exchangeable modules */ 00078 ModuleHandler moduleHandler; 00079 00080 /** A table of debug keys for runtime debug requests.*/ 00081 DebugKeyTable debugKeyTable; 00082 00083 /** A queue for incoming debug messages */ 00084 MessageQueue& debugIn; 00085 00086 /** A queue for outgoing debug messages */ 00087 MessageQueue& debugOut; 00088 }; 00089 00090 /** 00091 * This template class implements a sender for debug packages. 00092 * It ensures that only a package is sent if it is not empty. 00093 */ 00094 template<class T> class MultiDebugSender : public Sender<T> 00095 { 00096 public: 00097 /** 00098 * The constructor. 00099 * @param process The process this sender is associated with. 00100 * @param name The Aperios connection name of the sender without the process name. 00101 * @param blocking Decides whether this sender blocks the execution of the next frame 00102 * until all connected receivers have requested a new package. 00103 */ 00104 MultiDebugSender(PlatformProcess* process,const char* name,bool blocking) 00105 : Sender<T>(process,name,blocking) {} 00106 00107 /** 00108 * Marks the package for sending and transmits it to all receivers that already requested for it. 00109 * All other receiver may get it later if they request for it before the package is changed. 00110 * In function will only send a package if it is not empty. 00111 */ 00112 virtual void send() 00113 { 00114 if(requestedNew() && !isEmpty()) 00115 { 00116 Sender<T>::send(); 00117 clear(); 00118 } 00119 } 00120 }; 00121 00122 /** 00123 * This class implements a sender for MessageQueues. 00124 * It ensures that only a package is sent if it is not empty. 00125 */ 00126 class DebugSender : public MultiDebugSender<MessageQueue> 00127 { 00128 public: 00129 /** 00130 * The constructor. 00131 * @param process The process this sender is associated with. 00132 * @param name The Aperios connection name of the sender without the process name. 00133 * @param blocking Decides whether this sender blocks the execution of the next frame 00134 * until all connected receivers have requested a new package. 00135 */ 00136 DebugSender(PlatformProcess* process,const char* name,bool blocking) 00137 : MultiDebugSender<MessageQueue>(process,name,blocking) {} 00138 }; 00139 00140 /** 00141 * The macro declares two debugging queues. 00142 * The macro shall be the first entry in the declaration of a process. 00143 */ 00144 #define DEBUGGING \ 00145 Receiver<MessageQueue> theDebugReceiver; \ 00146 DebugSender theDebugSender 00147 00148 /** 00149 * The macro initializes the two debugging queues and the base class. 00150 * The macro shall be the first entry after the colon in constructor 00151 * of the process. 00152 */ 00153 #define INIT_DEBUGGING \ 00154 Process(theDebugReceiver,theDebugSender), \ 00155 theDebugReceiver(this,"Receiver.MessageQueue.O",false), \ 00156 theDebugSender(this,"Sender.MessageQueue.S",false) 00157 00158 /** 00159 * The macro declares a receiver. 00160 * It must be used inside a declaration of a process, after the macro DEBUGGING. 00161 * @param type The type of the package. The variable actually declared has 00162 * a type compatible to "type" and is called "thetypeReceiver". 00163 */ 00164 #define RECEIVER(type) \ 00165 Receiver<type> the##type##Receiver 00166 00167 /** 00168 * The macro initializes a receiver for a certain type. It must be part of the 00169 * initializer list of the constructor of the process. 00170 * @param type The type of the package. The variable actually declared has 00171 * a type compatible to "type" and is called "thetypeReceiver". 00172 * @param blocking Decides whether this receiver blocks the execution of the next frame 00173 * until it has received a package. 00174 */ 00175 #define INIT_RECEIVER(type,blocking) \ 00176 the##type##Receiver(this,"Receiver." #type ".O",blocking) 00177 00178 /** 00179 * The macro declares a sender. 00180 * It must be used inside a declaration of a process, after the macro DEBUGGING. 00181 * @param type The type of the package. The variable actually declared has 00182 * a type compatible to "type" and is called "thetypeSender". 00183 */ 00184 #define SENDER(type) \ 00185 Sender<type> the##type##Sender 00186 00187 /** 00188 * The macro initializes a sender for a certain type. It must be part of the 00189 * initializer list of the constructor of the process. 00190 * @param type The type of the package. The variable actually declared has 00191 * a type compatible to "type" and is called "thetypeSender". 00192 * @param blocking Decides whether this sender blocks the execution of the next frame 00193 * until all connected receivers have requested a new package. 00194 */ 00195 #define INIT_SENDER(type,blocking) \ 00196 the##type##Sender(this,"Sender." #type ".S",blocking) 00197 00198 /** 00199 * The macro declares a receiver for a MessageQueue. 00200 * It must be used inside a declaration of a process, after the macro DEBUGGING. 00201 * It shall only be used in the Debug process. 00202 * @param source The source process of the package. The variable actually declared is 00203 * of type MessageQueue and is called "thesourceReceiver". 00204 */ 00205 #define DEBUG_RECEIVER(source) \ 00206 class Receive##source##MessageQueue : public MessageQueue {}; \ 00207 Receiver<Receive##source##MessageQueue> the##source##Receiver 00208 00209 /** 00210 * The macro initializes a receiver for a MessageQueue. It must be part of the 00211 * initializer list of the constructor of the process. 00212 * @param source The source process of the package. The variable actually declared is 00213 * of type MessageQueue and is called "thesourceReceiver". 00214 */ 00215 #define INIT_DEBUG_RECEIVER(source) \ 00216 the##source##Receiver(this,#source "Receiver.MessageQueue.O",false) \ 00217 00218 /** 00219 * The macro declares a sender for a MessageQueue. 00220 * It must be used inside a declaration of a process, after the macro DEBUGGING. 00221 * It shall only be used in the Debug process. 00222 * @param target The target process of the package. The variable actually declared is 00223 * of type MessageQueue and is called "thetargetReceiver". 00224 */ 00225 #define DEBUG_SENDER(target) \ 00226 class Send##target##MessageQueue : public MessageQueue {}; \ 00227 MultiDebugSender<Send##target##MessageQueue> the##target##Sender 00228 00229 /** 00230 * The macro initializes a sender for a MessageQueue. It must be part of the 00231 * initializer list of the constructor of the process. 00232 * @param target The target process of the package. The variable actually declared is 00233 * of type MessageQueue and is called "thetargetSender". 00234 */ 00235 #define INIT_DEBUG_SENDER(target) \ 00236 the##target##Sender(this,#target "Sender.MessageQueue.S",false) 00237 00238 #endif //__Process_h_ 00239 00240 /* 00241 * Change log : 00242 * 00243 * $Log: Process.h,v $ 00244 * Revision 1.1.1.1 2004/05/22 17:35:54 cvsadm 00245 * created new repository GT2004_WM 00246 * 00247 * Revision 1.1 2003/10/07 10:13:21 cvsadm 00248 * Created GT2004 (M.J.) 00249 * 00250 * Revision 1.1.1.1 2003/07/02 09:40:28 cvsadm 00251 * created new repository for the competitions in Padova from the 00252 * tamara CVS (Tuesday 2:00 pm) 00253 * 00254 * removed unused solutions 00255 * 00256 * Revision 1.5 2003/03/06 11:52:54 dueffert 00257 * re-order warning removed 00258 * 00259 * Revision 1.4 2002/12/07 16:40:45 roefer 00260 * Blocking for theDebugReceiver changed 00261 * 00262 * Revision 1.3 2002/10/14 13:14:24 dueffert 00263 * doxygen comments corrected 00264 * 00265 * Revision 1.2 2002/09/10 21:07:30 loetzsch 00266 * continued change of module/solution mechanisms 00267 * 00268 * Revision 1.1 2002/09/10 15:53:58 cvsadm 00269 * Created new project GT2003 (M.L.) 00270 * - Cleaned up the /Src/DataTypes directory 00271 * - Removed challenge related source code 00272 * - Removed processing of incoming audio data 00273 * - Renamed AcousticMessage to SoundRequest 00274 * 00275 * Revision 1.5 2002/07/23 16:40:12 roefer 00276 * Router and SimGT2002 adapted to new message queue and streams 00277 * 00278 * Revision 1.4 2002/07/23 13:48:40 loetzsch 00279 * - new streaming classes 00280 * - removed many #include statements 00281 * - exchanged StaticQueue by MessageQueue 00282 * - new debug message handling 00283 * - general clean up 00284 * 00285 * Revision 1.3 2002/07/13 10:54:58 roefer 00286 * New command and sound sender 00287 * 00288 * Revision 1.2 2002/05/14 20:59:21 hebbel 00289 * added macro for SoundDataReceiver 00290 * 00291 * Revision 1.1.1.1 2002/05/10 12:40:32 cvsadm 00292 * Moved GT2002 Project from ute to tamara. 00293 * 00294 * Revision 1.21 2002/05/06 16:05:32 hebbel 00295 * Added Macro for buffered sender 00296 * 00297 * Revision 1.20 2002/05/05 14:06:43 roefer 00298 * SimGT2002 processes block as the ones on Aperios 00299 * 00300 * Revision 1.19 2002/04/21 21:03:07 roefer 00301 * Again, events block with &-logic 00302 * 00303 * Revision 1.18 2002/04/21 16:09:02 roefer 00304 * Anchor removed 00305 * 00306 * Revision 1.17 2002/04/20 15:52:22 roefer 00307 * Project simpified, WATCH and WATCH_PART added 00308 * 00309 * Revision 1.16 2002/04/06 09:55:53 roefer 00310 * Image and SensorData path through DebugQueues changed 00311 * 00312 * Revision 1.15 2002/02/21 14:22:22 loetzsch 00313 * added inclusion of Player.h and Stopwatch.h 00314 * 00315 * Revision 1.14 2002/02/05 20:02:15 risler 00316 * handleDebugMessage now returns bool, added debug message handling to ImageProcessor 00317 * 00318 * Revision 1.13 2002/01/30 17:29:13 loetzsch 00319 * handleDebugMessage um Parameter timestamp erweitert 00320 * 00321 * Revision 1.12 2002/01/22 22:42:25 loetzsch 00322 * Added init() again. 00323 * 00324 * Revision 1.11 2002/01/19 12:43:16 risler 00325 * enabled SolutionRequest, changed HandleDebugMessage calls 00326 * 00327 * Revision 1.10 2002/01/18 23:27:51 loetzsch 00328 * solutionRequest and setSolutionRequest added 00329 * 00330 * Revision 1.9 2002/01/15 16:25:09 roefer 00331 * init() removed 00332 * 00333 * Revision 1.8 2001/12/20 17:12:25 loetzsch 00334 * Virtual function init(), that is called before the first main(), 00335 * added. 00336 * 00337 * Revision 1.7 2001/12/19 15:20:53 loetzsch 00338 * Debug Sender nicht mehr blockierend 00339 * 00340 * Revision 1.6 2001/12/15 20:32:08 roefer 00341 * Senders and receivers are now part of the processes 00342 * 00343 * Revision 1.5 2001/12/12 18:08:56 loetzsch 00344 * Streaming- Operatoren für Bilder eingebaut, DebugKeyTable nicht- statisch gemacht, Debuggin Mechanismen weitergemacht, Bilder aus Logfiles in RobotControl anzeigen, Logfiles in HU1/Debug auf den Stick schreiben 00345 * 00346 * Revision 1.4 2001/12/10 17:47:10 risler 00347 * change log added 00348 * 00349 */