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 <QStringList>
00029 #include <QThread>
00030 #include <QTime>
00031 
00032 #include <qvutils/qvcpustatcontroler.h>
00033 #include <qvcore/qvpropertycontainer.h>
00034 
00045 class QVWorker: public QThread, public QVPropertyContainer
00046         {
00047         Q_OBJECT
00048 
00049         public:
00051                 typedef enum
00052                         {
00056                         Running,
00059                         RunningOneStep,
00063                         Paused,
00065                         Finished
00066                         } TWorkerStatus;
00067 
00072                 QVWorker(const QString name = QString());
00073 
00078                 virtual void iterate() { std::cerr << "WARNING: redefinition of worker() is deprecated. Redefine iterate() instead." << std::endl; worker(); };
00079 
00083                 virtual void worker() {};
00084 
00096                 void setMinimumDelay(int ms) { minms = ms; };
00097 
00100                 bool isFinished() const { return status == Finished; }
00101 
00104                 bool isPaused() const { return status == Paused; }
00105 
00108                 bool isRunning() const { return status == Running; }
00109 
00112                 TWorkerStatus getStatus() const { return status; }
00113 
00117                 void unlink();
00118 
00121                 int getIteration() const { return numIterations; }
00122 
00131                 QVStat getCpuStat() const { return cpuStatControler.value(); }
00132 
00138                 void printStat(int freq) { cpuStatControler.setFreq(freq); cpuStatControler.setWorkerName(getName()); }
00139 
00158                 void addTrigger(QString name)                   { triggerList.push_back(name); }
00159 
00161                 const QStringList getTriggerList() const        { return triggerList; }
00162 
00163         public slots:
00166                 void pause() { qDebug() << "QVWorker::pause()"; status = Paused; emit statusUpdate(status); }
00167 
00170                 void unPause() { qDebug() << "QVWorker::unPause()"; status = Running; emit statusUpdate(status); }
00171 
00174                 void step() { qDebug() << "QVWorker::step()"; status = RunningOneStep; emit statusUpdate(status); }
00175 
00178                 void finish() { qDebug() << "QVWorker::finish()"; status = Finished; emit statusUpdate(status); }
00179 
00194                 virtual void processTrigger(QString name) { Q_UNUSED(name); }
00195 
00196         signals:
00199                 void startIteration();
00200 
00203                 void endIteration();
00204 
00207                 void endIteration(uint id, int iteration);
00208 
00211                 void statusUpdate(QVWorker::TWorkerStatus);
00212 
00213         private:
00214                 QVStatControler cpuStatControler;
00215                 int numIterations, maxIterations;
00216                 TWorkerStatus status;
00217                 QStringList triggerList;
00218                 QTime iterationTime;
00219                 int curms,minms;
00220 
00221         protected:
00222                 void run();
00223 
00234                 void timeFlag(const QString flag)
00235                         {
00236                         qDebug() << "QVWorker::timeFlag("<< flag <<")";
00237                         cpuStatControler.setFlag(flag);
00238                         }
00239         };
00240 
00241 Q_DECLARE_METATYPE(QVStat);
00242 #endif

Generated on Thu Jul 17 17:23:27 2008 for QVision by  doxygen 1.5.3