src/qvcore/qvworker.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #ifndef QVWORKER_H
00026 #define QVWORKER_H
00027 
00028 #include <QApplication>
00029 #include <QStringList>
00030 #include <QMap>
00031 #include <QSet>
00032 #include <QThread> // PEDROE
00033 #include <QTimer>// PEDROE
00034 
00035 #include <qvcore/qvimage.h>
00036 #include <qvcore/qvcamera.h>
00037 #include <qvutils/cpustat.h>
00038 #include <qvcore/qvpropertyholder.h>
00039 
00041 class QVWorker: public QThread, public QVPropertyHolder
00042         {
00043         Q_OBJECT
00044 
00045         public:
00046                 typedef enum
00047                         {
00048                         Running,
00049                         RunningOneStep,
00050                         Paused,
00051                         Finished
00052                         } TWorkerStatus;
00053 
00054                 CpuStat cpuStat;
00055 
00056                 QVWorker(QString name = QString());
00057 
00058                 ~QVWorker();
00059 
00063                 virtual void worker() = 0;
00064 
00065                 bool isFinished() const                         { return status == Finished; }
00066                 int getIteration() const                        { return numIterations; }
00067                 TWorkerStatus getStatus() const                 { return status; }
00068                 const QString getErrorStatusString() const      { return errorStatus; }
00069 
00070         // These slots able the worker controller to modify it's state.
00071         // Both objects, QVWorker and QVController should be launched in the
00072         // same thread, for the QVControler object can emit those slots.
00073         public slots:
00074                 void iterate();
00075                 void pause()    { qDebug() << "QVWorker::pause()"; status = Paused;             emit statusUpdate(status);      }
00076                 void unPause()  { qDebug() << "QVWorker::unPause()"; status = Running;          emit statusUpdate(status);      }
00077                 void step()     { qDebug() << "QVWorker::step()"; status = RunningOneStep;      emit statusUpdate(status);      }
00078                 void finish()   { qDebug() << "QVWorker::finish()"; status = Finished;          emit statusUpdate(status);      }
00079 
00080         // Signals (specially newFrame) are for notifying view objects state changes,
00081         // and new data generated by the worker.
00082         signals:
00083                 //void iterateSignal();
00084                 //void newFrame(const QString &, const QVImage<uChar,1> &);
00085                 //void newFrame(const QString &, const QVImage<uChar,3> &);
00086                 void startIteration();
00087                 void endIteration();
00088                 //void outputText(QString);
00089                 void statusUpdate(QVWorker::TWorkerStatus);
00090                 
00091         /*private:
00092                 QTimer *timer;*/
00093         
00094 
00095 
00096         protected:
00097                 int numIterations;
00098                 TWorkerStatus status;
00099                 bool inited;
00100                 QMap<QString, bool> initedParam;
00101                 QString errorStatus;
00102                 QSet<QVCamera *> cameras;
00103 
00104                 void run();
00105 
00106                 void setErrorStatusString(const QString string) { errorStatus = string; }
00107 
00108                 void timeFlag(const QString flag)
00109                         {
00110                         qDebug() << "QVWorker::timeFlag("<< flag <<")";
00111                         cpuStat.setFlag(flag);
00112                         }
00113 
00114                 /*void parseArguments()
00115                         {
00116                         inited = true;
00117                         QStringList arguments = qApp->arguments();
00118                         QVPropertyHolder::parseArguments(arguments);
00119                         }*/
00120         };
00122 #endif

Generated on Thu Dec 13 13:06:25 2007 for QVision by  doxygen 1.5.3