00001 /** 00002 * @file GTXabsl2EngineExecutor.h 00003 * 00004 * Implementation of class GTXabsl2EngineExecutor. 00005 * 00006 * @author Martin Lötzsch 00007 */ 00008 00009 #ifndef __GTXabsl2EngineExecutor_h_ 00010 #define __GTXabsl2EngineExecutor_h_ 00011 00012 #include "Tools/Xabsl2/Xabsl2Engine/Xabsl2Engine.h" 00013 #include "Tools/Module/SolutionRequest.h" 00014 #include "Tools/Streams/InStreams.h" 00015 #include "Tools/MessageQueue/InMessage.h" 00016 #include "Tools/Xabsl2/GT/GTXabsl2Profiler.h" 00017 00018 /** Implements Xabsl2ErrorHandler using the OUTPUT macro */ 00019 class GTXabsl2ErrorHandler : public Xabsl2ErrorHandler 00020 { 00021 public: 00022 /** 00023 * Constructor 00024 * @param id The id of the Xabsl2Engine. 00025 */ 00026 GTXabsl2ErrorHandler(SolutionRequest::xabsl2EngineID id); 00027 00028 /** 00029 * Prints out an error 00030 * @param text The text to display 00031 */ 00032 virtual void printError(const char* text); 00033 00034 /** 00035 * Prints out a message 00036 * @param text The text to display 00037 */ 00038 virtual void printMessage(const char* text); 00039 00040 private: 00041 /** The id of the Xabsl2Engine. */ 00042 SolutionRequest::xabsl2EngineID id; 00043 }; 00044 00045 /** Implements Xabsl2InputSource using the InConfigFile class */ 00046 class Xabsl2FileInputSource : public Xabsl2InputSource, public Xabsl2NamedItem 00047 { 00048 public: 00049 /** 00050 * Constructor. Does not open the file 00051 * @param fileName The file name to open 00052 */ 00053 Xabsl2FileInputSource(const char* fileName); 00054 00055 /** Destructor */ 00056 ~Xabsl2FileInputSource(); 00057 00058 /** opens the source that contains the intermediate code */ 00059 virtual bool open(); 00060 00061 /** closes the source */ 00062 virtual void close(); 00063 00064 /** reads a numeric value from the input source */ 00065 virtual double readValue(); 00066 00067 /** 00068 * reads a string from the input source 00069 * @param destination The position where to write the string 00070 * @param maxLength the maximum length of the string 00071 * @return if the read succeded 00072 */ 00073 virtual bool readString(char* destination, int maxLength); 00074 00075 private: 00076 /** The file to read the data from */ 00077 InConfigFile* file; 00078 }; 00079 00080 /** Implements Xabsl2InputSource using the InConfigMessage class */ 00081 class Xabsl2MessageInputSource : public Xabsl2InputSource 00082 { 00083 public: 00084 /** 00085 * Constructor. Does not open the file 00086 * @param message A reference to the message that contains the intermediate code 00087 */ 00088 Xabsl2MessageInputSource(InConfigMessage& message); 00089 00090 /** Destructor */ 00091 ~Xabsl2MessageInputSource() {}; 00092 00093 /** opens the source that contains the intermediate code */ 00094 virtual bool open() {return true;}; 00095 00096 /** closes the source */ 00097 virtual void close() {}; 00098 00099 /** reads a numeric value from the input source */ 00100 virtual double readValue(); 00101 00102 /** 00103 * reads a string from the input source 00104 * @param destination The position where to write the string 00105 * @param maxLength the maximum length of the string 00106 * @return if the read succeded 00107 */ 00108 virtual bool readString(char* destination, int maxLength); 00109 00110 private: 00111 /** The file to read the data from */ 00112 InConfigMessage& message; 00113 }; 00114 00115 /** 00116 * @class GTXabsl2EngineExecutor 00117 * 00118 * Executes an Xabsl2Engine in the GT - architecture 00119 * 00120 * @author Martin Lötzsch 00121 */ 00122 class GTXabsl2EngineExecutor 00123 { 00124 public: 00125 /** 00126 * Constructor. 00127 * @param id The id of the Xabsl2Engine derivate. 00128 * @param module The id of the module (not the solution) that embeds the engine 00129 * @param frameNumber A reference to a variable containing the current frame number 00130 */ 00131 00132 GTXabsl2EngineExecutor(SolutionRequest::xabsl2EngineID id, 00133 SolutionRequest::ModuleID module, 00134 const unsigned long& frameNumber); 00135 00136 /** destructor */ 00137 ~GTXabsl2EngineExecutor(); 00138 00139 /** 00140 * Creates a new engine 00141 * @param input An input source to read to intermediate code from 00142 */ 00143 void init(Xabsl2InputSource& input); 00144 00145 /** Executes the engine */ 00146 void executeEngine(); 00147 00148 /** Registers symbols and basic behaviors at the engine */ 00149 virtual void registerSymbolsAndBasicBehaviors() = 0; 00150 00151 /** Sets the selected Agent. If the last selected agent was different from 00152 * the new one, the root option is changed depending on the new agent. 00153 * @param name The name of the agent 00154 */ 00155 void setSelectedAgent(const char* name); 00156 00157 /** 00158 * Is called for every incoming debug message. 00159 * @param message An interface to read the message from the queue 00160 * @return if the messag was read 00161 */ 00162 virtual bool handleMessage(InMessage& message); 00163 00164 protected: 00165 00166 /** An engine that executes the XML formalized behaviors */ 00167 Xabsl2Engine* pEngine; 00168 00169 /** Is invoked when errors occur */ 00170 GTXabsl2ErrorHandler errorHandler; 00171 00172 /** Is called if the engine could not be created */ 00173 virtual void executeIfEngineCouldNotBeCreated() = 0; 00174 00175 /** 00176 * Prints the main action that was generated by the execution of the engine to a string 00177 * @param buf the string where to print the action 00178 */ 00179 virtual void printGeneratedMainActionToString(char* buf) = 0; 00180 00181 /** The profiler */ 00182 GTXabsl2Profiler profiler; 00183 00184 private: 00185 00186 /** The id of the Xabsl2Engine derivate. */ 00187 SolutionRequest::xabsl2EngineID id; 00188 00189 /** The id of the module (not the solution) that embeds the engine */ 00190 SolutionRequest::ModuleID module; 00191 00192 //!@name Debug interface to the Xabsl2 Dialog 00193 //!@{ 00194 00195 /** The requested debug mode */ 00196 enum Xabsl2DebugMode { executeRootOption, executeOption, executeBasicBehavior } debugMode; 00197 00198 /** Sends a debug message to the Xabsl2 dialog depending on the last request */ 00199 void sendDebugMessage(); 00200 00201 /** The decimal input symbols that are watched by the Xabsl2 Dialog */ 00202 Xabsl2Array<Xabsl2DecimalInputSymbol*> watchedDecimalInputSymbols; 00203 00204 /** The boolean input symbols that are watched by the Xabsl2 Dialog */ 00205 Xabsl2Array<Xabsl2BooleanInputSymbol*> watchedBooleanInputSymbols; 00206 00207 /** The enumerated input symbols that are watched by the Xabsl2 Dialog */ 00208 Xabsl2Array<Xabsl2EnumeratedInputSymbol*> watchedEnumeratedInputSymbols; 00209 00210 /** The enumerated output symbols that are watched by the Xabsl2 Dialog */ 00211 Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> watchedEnumeratedOutputSymbols; 00212 00213 /** The output symbols that are set from the Xabsl2 Dialog */ 00214 Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> setEnumeratedOutputSymbols; 00215 00216 /** The values for the set output symbols */ 00217 Xabsl2Array<int> setEnumeratedOutputSymbolValues; 00218 00219 //!@} 00220 }; 00221 00222 00223 #endif// __GTXabsl2EngineExecutor_h_ 00224 00225 /* 00226 * Change log : 00227 * 00228 * $Log: GTXabsl2EngineExecutor.h,v $ 00229 * Revision 1.5 2004/09/09 11:37:39 wachter 00230 * - Fixed some more doxygen-errors 00231 * 00232 * Revision 1.4 2004/09/09 10:15:57 spranger 00233 * fixed doxygen-errors 00234 * 00235 * Revision 1.3 2004/05/27 15:44:42 juengel 00236 * profiler is protected now 00237 * 00238 * Revision 1.2 2004/05/23 18:59:06 spranger 00239 * added framenumber to GTXabsl2EngineExecutor for profiler, 00240 * added profiler 00241 * 00242 * Revision 1.1.1.1 2004/05/22 17:37:41 cvsadm 00243 * created new repository GT2004_WM 00244 * 00245 * Revision 1.2 2004/05/17 18:35:23 loetzsch 00246 * continued support for multiple Xabsl engines in different modules 00247 * 00248 * Revision 1.1 2004/05/14 11:37:08 loetzsch 00249 * support for multiple xabsl2engines in different modules 00250 * preliminary GT2004HeadControl (does not work at all) 00251 * 00252 */