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/cpustat.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 00116 int getIteration() const { return numIterations; } 00117 00126 CpuStat &getCpuStat() { return cpuStat; } //FIXME ¿const? 00127 00146 void addTrigger(QString name) { triggerList.push_back(name); } 00147 00149 const QStringList getTriggerList() { return triggerList; } 00150 00151 public slots: 00154 void pause() { qDebug() << "QVWorker::pause()"; status = Paused; emit statusUpdate(status); } 00155 00158 void unPause() { qDebug() << "QVWorker::unPause()"; status = Running; emit statusUpdate(status); } 00159 00162 void step() { qDebug() << "QVWorker::step()"; status = RunningOneStep; emit statusUpdate(status); } 00163 00166 void finish() { qDebug() << "QVWorker::finish()"; status = Finished; emit statusUpdate(status); } 00167 00182 virtual void processTrigger(QString name) { Q_UNUSED(name); } 00183 00184 signals: 00187 void startIteration(); 00188 00191 void endIteration(); 00192 00195 void statusUpdate(QVWorker::TWorkerStatus); 00196 00197 private: 00198 CpuStat cpuStat; 00199 int numIterations; 00200 TWorkerStatus status; 00201 QStringList triggerList; 00202 QTime iterationTime; 00203 int curms,minms; 00204 // float acumms; 00205 00206 protected: 00207 void run(); 00208 00217 void timeFlag(const QString flag) 00218 { 00219 qDebug() << "QVWorker::timeFlag("<< flag <<")"; 00220 cpuStat.setFlag(flag); 00221 } 00222 }; 00223 00224 #endif