Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Xabsl2/GT/GTXabsl2EngineExecutor.h

Go to the documentation of this file.

    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/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   GTXabsl2EngineExecutor(SolutionRequest::xabsl2EngineID id,
    00132     SolutionRequest::ModuleID module,
    00133     const unsigned long& frameNumber);
    00134
    00135   /** destructor */
    00136   ~GTXabsl2EngineExecutor();
    00137
    00138   /**
    00139   * Creates a new engine
    00140   * @param input An input source to read to intermediate code from
    00141   */
    00142   void init(Xabsl2InputSource& input);
    00143
    00144   /** Executes the engine */
    00145   void executeEngine();
    00146
    00147   /** Registers symbols and basic behaviors at the engine */
    00148   virtual void registerSymbolsAndBasicBehaviors() = 0;
    00149
    00150   /** Sets the selected Agent. If the last selected agent was different from
    00151   * the new one, the root option is changed depending on the new agent.
    00152   * @param name The name of the agent
    00153   */
    00154   void setSelectedAgent(const char* name);
    00155
    00156   /**
    00157   * Is called for every incoming debug message.
    00158   * @param message An interface to read the message from the queue
    00159   * @return if the messag was read
    00160   */
    00161   virtual bool handleMessage(InMessage& message);
    00162
    00163 protected:
    00164
    00165   /** An engine that executes the XML formalized behaviors */
    00166   Xabsl2Engine* pEngine;
    00167
    00168   /** Is invoked when errors occur */
    00169   GTXabsl2ErrorHandler errorHandler;
    00170
    00171   /** Is called if the engine could not be created */
    00172   virtual void executeIfEngineCouldNotBeCreated() = 0;
    00173
    00174   /**
    00175   * Prints the main action that was generated by the execution of the engine to a string
    00176   * @param buf the string where to print the action
    00177   */
    00178   virtual void printGeneratedMainActionToString(char* buf) = 0;
    00179
    00180   /** The profiler */
    00181   GTXabsl2Profiler profiler;
    00182
    00183 private:
    00184
    00185   /** The id of the Xabsl2Engine derivate. */
    00186   SolutionRequest::xabsl2EngineID id;
    00187
    00188   /** The id of the module (not the solution) that embeds the engine */
    00189   SolutionRequest::ModuleID module;
    00190
    00191   //!@name Debug interface to the Xabsl2 Dialog
    00192   //!@{
    00193
    00194   /** The requested debug mode */
    00195   enum Xabsl2DebugMode { executeRootOption, executeOption, executeBasicBehavior } debugMode;
    00196
    00197   /** Sends a debug message to the Xabsl2 dialog depending on the last request */
    00198   void sendDebugMessage();
    00199
    00200   /** The decimal input symbols that are watched by the Xabsl2 Dialog */
    00201   Xabsl2Array<Xabsl2DecimalInputSymbol*> watchedDecimalInputSymbols;
    00202
    00203   /** The boolean input symbols that are watched by the Xabsl2 Dialog */
    00204   Xabsl2Array<Xabsl2BooleanInputSymbol*> watchedBooleanInputSymbols;
    00205
    00206   /** The enumerated input symbols that are watched by the Xabsl2 Dialog */
    00207   Xabsl2Array<Xabsl2EnumeratedInputSymbol*> watchedEnumeratedInputSymbols;
    00208
    00209   /** The enumerated output symbols that are watched by the Xabsl2 Dialog */
    00210   Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> watchedEnumeratedOutputSymbols;
    00211
    00212   /** The output symbols that are set from the Xabsl2 Dialog */
    00213   Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> setEnumeratedOutputSymbols;
    00214
    00215   /** The values for the set output symbols */
    00216   Xabsl2Array<int> setEnumeratedOutputSymbolValues;
    00217
    00218   //!@}
    00219 };
    00220
    00221
    00222 #endif// __GTXabsl2EngineExecutor_h_