PCMApplication.h

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00027 
00028 #ifndef __PCM_APPLICATION_H__
00029 #  define __PCM_APPLICATION_H__
00030 
00031 //
00032 // Inner includes
00033 //
00034 
00035 #  include "PCMPremeditations.h"
00036 
00037 #  include "PCMSingleton.h"
00038 
00039 #  include "PCMException.h"
00040 
00041 #  include "PCMLogger.h"
00042 
00043 #  include "PCMPointer.h"
00044 
00045 #  include "PCMNetServer.h"
00046 
00047 #  include "PCMNetClient.h"
00048 
00049 #  include "PCMStringConverter.h"
00050 
00051 #  include "PCMCluster.h"
00052 
00053 #  include "PCMHost.h"
00054 
00055 #  include "PCMHostInfo.h"
00056 
00057 #  include "PCMConfigOptions.h"
00058 
00059 #  include "PCMPluginManager.h"
00060 
00061 //
00062 // Outer includes
00063 //
00064 
00065 #  include <readline/readline.h>
00066 
00067 #  include <readline/history.h>
00068 
00069 //
00070 // Scripting bind includes (for Squirrel)
00071 //
00072 
00073 #  include <squirrel/squirrel.h>
00074 #  include <squirrel/sqstdio.h>
00075 #  include <squirrel/sqstdaux.h>
00076 #  include <squirrel/sqplus.h>
00077 
00078 namespace ParCompMark
00079 {
00080 
00087   class Application:public Singleton < Application >
00088   {
00089 
00090         //
00091         // Unit test class
00092         //
00093 #  ifdef PARCOMPMARK_TEST
00094         friend class ParCompMarkTest::TestApplication;
00095 #  endif
00096 
00097         //
00098         // Scripting binding (for Squirrel)
00099         //
00100 
00102 
00103 
00111    public:static void squirrelGlue()
00112         {
00113          ::SqPlus::SQClassDef < Application > (_T("Application")).staticFunc(&Application::getInstance,
00114                                                                                 _T("getInstance")).
00115                 func(&Application::loadLowLevelScript, _T("loadLowLevelScript")).func(&Application::loadDynamicScript,
00116                                                                                   _T("loadDynamicScript")).
00117                 func(&Application::loadScenarioScript, _T("loadScenarioScript")).func(&Application::pushSquirrelCommand,
00118                                                                                   _T("pushSquirrelCommand")).
00119                 func(&Application::quit, _T("quit")).func(&Application::compileDynamic,
00120                                                         _T("compileDynamic")).func(&Application::start,
00121                                                                                   _T("start")).
00122                 func(&Application::stop, _T("stop")).func(&Application::autoDetection,
00123                                                         _T("autoDetection")).func(&Application::cleanup,
00124                                                                                  _T("cleanup")).
00125                 func(&Application::getHostListForSquirrel,
00126                   _T("getHostListForSquirrel")).func(&Application::getLowLevelScriptForSquirrel,
00127                                                         _T("getLowLevelScriptForSquirrel")).
00128                 func(&Application::getDynamicScriptForSquirrel,
00129                   _T("getDynamicScriptForSquirrel")).func(&Application::hasScenarioScript,
00130                                                           _T("hasScenarioScript")).
00131                 func(&Application::getDynamicScriptParametersForSquirrel,
00132                   _T("getDynamicScriptParametersForSquirrel")).func(&Application::getProgramInfo,
00133                                                                    _T("getProgramInfo")).
00134                 staticFunc(&Application::getExpectedHostCount,
00135                          _T("getExpectedHostCount")).func(&Application::getDynamicScriptCompiled,
00136                                                          _T("getDynamicScriptCompiled")).
00137                 func(&Application::setDynamicScriptCompiled,
00138                   _T("setDynamicScriptCompiled")).func(&Application::getCompRun, _T("getCompRun"));
00139         }
00140 
00142 
00143         //
00144         // Enumerations
00145         //
00146 
00147    protected:
00148 
00150         enum PostCommand
00151         {
00152 
00154          NOTHING,
00155 
00157          LOADSCENARIO,
00158 
00160          LOADDYNAMIC,
00161 
00163          COMPILE,
00164 
00166          START,
00167 
00169          COMPILE_START,
00170 
00172          STOP,
00173 
00175          QUIT,
00176 
00178          STOP_QUIT
00179         };
00180 
00182         enum DynamicScriptParameterType
00183         {
00184 
00186          STRING = 0,
00187 
00189          INTEGER = 1,
00190 
00192          REAL = 2,
00193 
00195          BOOL = 3
00196         };
00197 
00199         enum UserInterface
00200         {
00201 
00203          NONE,
00204 
00206          CONSOLE
00207         };
00208 
00209         //
00210         // Typedefs
00211         //
00212 
00213    protected:
00214 
00216         typedef struct
00217 
00218         {               
00220          s8 shortName;                                    
00222           std::string longName;                                                                            
00224           std::string description;                                                                                                                                        
00226          bool hasArgument;                                                                                                                                                                                                                      
00227          void (*handler) (const std::string &);
00228         } CommandLineOption;
00229 
00231         typedef struct
00232 
00233         {               
00235          std::string name;                                                       
00237          DynamicScriptParameterType type;                                                                                                         
00239           std::string description;                                                                                                                                                                                        
00241           std::set < std::string > possibleValues;                                                                                                                                                                                                                                                                                                                               
00242           std::string defaultValue;
00243         } DynamicScriptParameter;
00244 
00245         //
00246         // Class constants
00247         //
00248 
00250 
00251 
00252    public:
00253 
00259         static const std::string PCAPINUT;
00260 
00266         static const std::string PARCOMPMARKNUT;
00267 
00273         static const std::string UTILSNUT;
00274 
00280         static const std::string ABBREVIATIONSNUT;
00281 
00287         static const std::string DYNAMICINITNUT;
00288 
00294         static const std::string UIINITNUT;
00295 
00301         static const std::string COMMANDDIRECTORY;
00302 
00308         static const std::string HELPNUT;
00309 
00315         static const std::string PCIMPLEMENTATIONS[];
00316 
00317    protected:
00318 
00324         static const Application::CommandLineOption mCommandLineOptions[];
00325 
00331         static const u32 mCommandLineOptionCount;
00332 
00338         static const std::string mUsageString;
00339 
00341 
00342         //
00343         // Class variables
00344         //
00345 
00347 
00348 
00349    protected:
00350 
00356         static std::string mLibrarySearchPath;
00357 
00363         static bool mCommanderMode;
00364 
00370         static bool mGUIMode;
00371 
00377         static bool mManualClusterDescription;
00378 
00384         static std::string mClusterDescription;
00385 
00391         static bool mLowLevelMode;
00392 
00398         static bool mInteractiveParameters;
00399 
00405         static std::string mParameters;
00406 
00412         static std::string mInput;
00413 
00419         static std::string mOutput;
00420 
00426         static int mExpectedHostCount;
00427 
00433         static UserInterface mUserInterface;
00434 
00436 
00437         //
00438         // Variables
00439         //
00440 
00442 
00443 
00444    protected:
00445 
00451         HostInfo * mHostInfo;
00452 
00458         bool mInitialized;
00459 
00465         PostCommand mPostCommand;
00466 
00472         bool mQuiting;
00473 
00479         bool mOutputIsDone;
00480 
00486         OutputNode::Pointer mOutputDocument;
00487 
00493         OutputNode::Pointer mCurrentExecutionOutputDocument;
00494 
00500         u32 mExecutionIndex;
00501 
00507         OutputNode::Pointer mCollectClusterDescription;
00508 
00514         ConfigOptions::Pointer mConfigOptions;
00515 
00521         std::string mLowLevelScript;
00522 
00528         std::string mDynamicScript;
00529 
00535         std::string mScenarioScript;
00536 
00544         std::list < std::string > mSquirrelCommandList;
00545 
00551         bool mDynamicScriptCompiled;
00552 
00558         NetServer *mServer;
00559 
00565         NetClient *mClient;
00566 
00572         bool mCompRun;
00573 
00579         SqVM::Pointer mDynamicScriptSqVM;
00580 
00586         SqVM::Pointer mUserInterfaceSqVM;
00587 
00593         std::list < DynamicScriptParameter * >mDynamicScriptParameters;
00594 
00596 
00597         //
00598         // Constructors & destructor
00599         //
00600 
00602 
00603 
00604    public:
00605 
00609         Application();
00610 
00614         virtual ~ Application();
00615 
00617 
00618         //
00619         // Getters & setters
00620         //
00621 
00623 
00624 
00625    public:
00626 
00632         static const std::string & getLibrarySearchPath();
00633 
00639         static void setLibrarySearchPath(const std::string & librarysearchpath);
00640 
00646         HostInfo *getHostInfo() const;
00647 
00653         const bool & getInitialized() const;
00654 
00660         const Application::PostCommand & getPostCommand() const;
00661 
00667         const bool & getQuiting() const;
00668 
00674         const bool & getOutputIsDone() const;
00675 
00681         OutputNode::Pointer & getOutputDocument();
00682 
00688         OutputNode::Pointer & getCurrentExecutionOutputDocument();
00689 
00695         u32 & getExecutionIndex();
00696 
00702         OutputNode::Pointer & getCollectClusterDescription();
00703 
00709         ConfigOptions::Pointer & getConfigOptions();
00710 
00716         const std::string & getLowLevelScript() const;
00717 
00723         const std::string & getDynamicScript() const;
00724 
00730         const std::string & getScenarioScript() const;
00731 
00737         const std::list < std::string > &getSquirrelCommandList() const;
00738 
00744         bool & getDynamicScriptCompiled();
00745 
00751         void setDynamicScriptCompiled(const bool dynamicscriptcompiled);
00752 
00758         NetServer *getServer() const;
00759 
00765         NetClient *getClient() const;
00766 
00772         static const std::string & getUsageString();
00773 
00779         static const bool & getCommanderMode();
00780 
00786         static const bool & getGUIMode();
00787 
00793         static const bool & getManualClusterDescription();
00794 
00800         static const std::string & getClusterDescription();
00801 
00807         static const bool & getLowLevelMode();
00808 
00814         static const bool & getInteractiveParameters();
00815 
00821         static const std::string & getParameters();
00822 
00828         static const std::string & getInput();
00829 
00835         static const std::string & getOutput();
00836 
00842         static int &getExpectedHostCount();
00843 
00849         static const Application::UserInterface & getUserInterface();
00850 
00856         bool & getCompRun();
00857 
00859 
00860         //
00861         // Class methods
00862         //
00863 
00865 
00866 
00867    public:
00868 
00875         static int complement(int first, int second);
00876 
00882         static void parseCommandLine(const u32 & argc, const char **&argv);
00883 
00888         static void showHelp(const std::string & strarg);
00889 
00894         static void showVersion(const std::string & strarg);
00895 
00900         static void setCommanderOn(const std::string & strarg);
00901 
00906         static void setGUIOn(const std::string & strarg);
00907 
00912         static void setLowLevelOn(const std::string & strarg);
00913 
00918         static void setLowLevelScriptFile(const std::string & strarg);
00919 
00924         static void setDynamicScriptFile(const std::string & strarg);
00925 
00930         static void setScenarioScriptFile(const std::string & strarg);
00931 
00936         static void setCluster(const std::string & strarg);
00937 
00942         static void setParameters(const std::string & strarg);
00943 
00948         static void setInput(const std::string & strarg);
00949 
00954         static void setOutput(const std::string & strarg);
00955 
00960         static void setExpectedHostCount(const std::string & hostCount);
00961 
00966         static void setUserInterface(const std::string & strUI);
00967 
00973         static bool hasEnvironmentVariable(const std::string & name);
00974 
00980         static std::string getEnvironmentVariable(const std::string & name);
00981 
00985         static void terminateHandler();
00986 
00990         static void terminateHandlerNOP();
00991 
00995         static void unexpectedHandler();
00996 
01001         static void segfaultHandler(int value);
01002 
01007         static void interruptHandler(int value);
01008 
01013         static Application *getInstance();
01014 
01016 
01017         //
01018         // Methods
01019         //
01020 
01022 
01023 
01024    public:
01025 
01029         virtual void setupHandlers() const;
01030 
01034         virtual void initialize();
01035 
01039         virtual void finalize();
01040 
01044         virtual void finalizeCommander();
01045 
01049         virtual void finalizeSoldier();
01050 
01054         virtual void setFromConfigOptions();
01055 
01059         virtual void createVirtualMachines();
01060 
01066         virtual bool startOperation();
01067 
01071         virtual void writeOutput();
01072 
01076         virtual void waitForOutput();
01077 
01081         virtual void quit();
01082 
01086         virtual void compileDynamic();
01087 
01091         virtual void start();
01092 
01096         virtual void stop();
01097 
01101         virtual void autoDetection();
01102 
01106         virtual void cleanup();
01107 
01112         virtual char *getHostListForSquirrel();
01113 
01118         virtual char *getLowLevelScriptForSquirrel();
01119 
01124         virtual char *getDynamicScriptForSquirrel();
01125 
01130         virtual bool hasScenarioScript();
01131 
01136         virtual char *getDynamicScriptParametersForSquirrel();
01137 
01142         virtual char *getProgramInfo();
01143 
01147         virtual void calculateMessageSendTime();
01148 
01152         virtual void _pseudoStop();
01153 
01154    protected:
01155 
01160         virtual bool commanderOperation();
01161 
01166         virtual bool soldierOperation();
01167 
01172         virtual bool textUserInterface();
01173 
01178         virtual bool noUserInterface();
01179 
01185         virtual bool executeUserCommand(const std::string & command);
01186 
01191         virtual bool processSquirrelCommandList();
01192 
01196         virtual void doPostCommand();
01197 
01202         virtual void loadLowLevelScript(const char *filename);
01203 
01208         virtual void loadDynamicScript(const char *filename);
01209 
01214         virtual void loadScenarioScript(const char *filename);
01215 
01220         virtual void pushSquirrelCommand(const char *command);
01221 
01226         virtual void createLowLevelScript(const std::string & clusterDescription);
01227 
01231         virtual void processScenarioScript();
01232 
01236         virtual void setEnvironmentVariablesToSquirrel();
01237 
01242         virtual void initializeDynamicScriptParameters(const bool & reset);
01243 
01247         virtual void retrieveDynamicScriptParameters();
01248 
01252         virtual void _loadScenario();
01253 
01257         virtual void _loadDynamic();
01258 
01262         virtual void _compileDynamic();
01263 
01267         virtual void _start();
01268 
01272         virtual void _stop();
01273 
01277         virtual void _quit();
01278 
01280 
01281   };
01282 
01283   //
01284   // Include header implementation
01285   //
01286 
01287 #  include "PCMApplication_impl.h"
01288 
01289 }
01290 
01291 // Declare Application class (and its enums) for SqPlus binding
01293 DECLARE_INSTANCE_TYPE_NAME(ParCompMark::Application, Application);
01294 
01295 #endif