Hormiga 1.0

/var/www/hormigaproject.com.ar/files/src/step/step.h

Go to the documentation of this file.
00001 
00002 /*
00003 # Hormiga - Software de cálculo programable.
00004 #
00005 # Copyright (C) 2008, 2009 Leonardo Román, Hugo J. Curti, Norma  Ercoli,
00006 # Universidad Nacional del Centro de la Provincia de Buenos Aires
00007 # (UNCPBA)
00008 #
00009 # Este programa es parte de Hormiga.
00010 #
00011 # Hormiga es software libre. Puede redistribuirlo y/o modificarlo
00012 # bajo los términos de la Licencia Pública General de GNU según es
00013 # publicada por la Free Software Foundation, versión 2. Vea el archivo
00014 # COPIA (español, no oficial) o COPYING (inglés, oficial) en directorio
00015 # raíz.
00016 #
00017 # Hormiga se distribuye con la esperanza de que sea útil, pero SIN
00018 # NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL implícita o sin
00019 # garantizar la CONVENIENCIA PARA UN PROPÓSITO PARTICULAR. Véase la
00020 # Licencia Pública General de GNU para más detalles.
00021 #
00022 # Debería haber recibido una copia de la Licencia Pública General junto
00023 # con Hormiga. Si no ha sido así, escriba a la Free Software
00024 # Foundation, Inc., en 675 Mass Ave, Cambridge, MA 02139, EEUU.
00025 # Añada también información sobre cómo contactar con usted mediante
00026 # correo electrónico y postal.
00027 #
00028 # This file is part of Hormiga.
00029 #
00030 # Hormiga is free software; you can redistribute it and/or modify
00031 # it under the terms of the GNU General Public License version 2
00032 # as published by the Free Software Foundation; see the file COPYING
00033 # in the top directory for details.
00034 #
00035 # Hormiga is distributed in the hope that it will be useful,
00036 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00037 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00038 # GNU General Public License for more details.
00039 #
00040 # You should have received a copy of the GNU General Public License
00041 # along with Hormiga; if not, write to the Free Software
00042 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00043 # USA
00044 */
00045 
00046 #ifndef STEP_HEADER
00047 #define STEP_HEADER
00048 
00049 #include "defines.h"
00050 #include "statement/statement_interface.h"
00051 #include "step/capture.h"
00052 #include "step/report.h"
00053 
00054 #include <QObject>
00055 #include <QThread>
00056 #include <QMutex>
00057 
00058 class StepCondition
00059 {
00060 public:
00061     virtual bool eval() = 0 ;
00062     virtual T_STRING getText() = 0 ;
00063     virtual ~StepCondition() {}
00064 };
00065 
00066 class StepConditionSingle : public StepCondition
00067 {
00068 public:
00069     StepConditionSingle ( Operand *condition , T_STRING text ) ;
00070     virtual ~StepConditionSingle() ;
00071     virtual bool eval() ;
00072     virtual T_STRING getText() ;
00073 protected:
00074     Operand *condition ;
00075     T_STRING text ;
00076 };
00077 
00078 class StepConditionComposite : public StepCondition
00079 {
00080 public:
00081     StepConditionComposite ( T_STEP_CONDITIONS_LIST* list ) ;
00082     virtual ~StepConditionComposite() ;
00083     virtual bool eval() ;
00084     virtual T_STRING getText() ;
00085 protected:
00086     T_STEP_CONDITIONS_LIST* list ;
00087     StepCondition* last ;
00088 };
00089 
00090 class Step : public QThread
00091 {
00092     Q_OBJECT
00093 public:
00094     enum state { NotSatisfied, Satisfied, Executing, Accepted } ;
00095     virtual T_STRING toString () const ;
00096     T_STRING getName () ;
00097     //virtual bool getState () ;
00098     virtual void setStepNeeds ( T_STEP_LIST *stepsNeeded ) ;
00099     virtual void setExecutionBlock ( Statement *execBlock ) ;
00100     virtual void setCaptures ( T_CAPTURE_LIST *captures ) ;
00101     virtual void setReports ( T_REPORT_LIST *reports ) ;
00102     virtual void setStepCondition ( StepCondition *condition ) ;
00103     Step ( T_STRING name ) ;
00104     ~Step () ;
00105     virtual void changeState ( Step::state newState ) ;
00106 
00107 public slots:
00108     void notifyStepState( Step* peer , Step::state newState , Step::state oldState ) ;
00109     void run () ;
00110     void sleep ()  {execSleep.lock(); }
00111     void wakeUp () {execSleep.unlock(); }
00112 
00114     void showMessage ( int severity , T_STRING msg ) { emit message(severity,msg) ;}
00115 
00116 signals:
00117     void stateChanged ( Step* emisor , Step::state newState , Step::state oldState ) ;
00118     void needInput( Step* emisor , T_CAPTURE_LIST* captures ) ;
00119     void reportOutput ( Step* emisor , T_REPORT_LIST* reports ) ;
00120     void message ( int severity , T_STRING msg ) ;
00121 
00122 protected:
00129     virtual bool exec ( bool interactive ) ;
00130 
00131     unsigned int unsatisfiedDependencesCount ;
00132     Step::state currentState ;
00133     bool alreadyExecuted ;
00134     T_STEP_LIST *stepsNeeded ;
00135     Statement *execBlock ;
00136     T_CAPTURE_LIST *captures ;
00137     T_REPORT_LIST *reports ;
00138     StepCondition *condition ;
00139     T_STRING name ;
00140     QMutex execSleep ;
00141 };
00142 
00143 #endif // STEP_H