![]() |
University of Murcia, Spain ![]() |
src/qvcore/qvworker.hGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008. 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 <QVPropertyContainer> 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, 00067 Stoped, 00069 Finished 00070 } TWorkerStatus; 00071 00076 QVWorker(const QString name = QString()); 00077 00082 QVWorker(const QVWorker &other); 00083 00085 ~QVWorker(); 00086 00091 virtual void iterate() { std::cerr << "WARNING: redefinition of worker() is deprecated. Redefine iterate() instead." << std::endl; worker(); }; 00092 00096 virtual void worker() {}; 00097 00109 void setMinimumDelay(int ms) { minms = ms; }; 00110 00113 bool isFinished() const { return status == Finished; } 00114 00117 bool isPaused() const { return status == Paused; } 00118 00121 bool isStoped() const { return status == Stoped; } 00122 00125 bool isRunning() const { return status == Running; } 00126 00129 TWorkerStatus getStatus() const { return status; } 00130 /* 00134 void unlink(); 00135 */ 00138 int getIteration() const { return numIterations; } 00139 00142 bool isStatsEnabled() const { return statsEnabled; } 00143 00154 QVStat getCpuStat() const { 00155 if (statsEnabled) return cpuStatControler->value(); 00156 else return QVStat(); 00157 } 00158 00167 void printStat(int freq) { 00168 if (statsEnabled) { 00169 cpuStatControler->setFreq(freq); 00170 cpuStatControler->setWorkerName(getName()); 00171 } 00172 } 00173 00192 void addTrigger(QString name) { triggerList.push_back(name); } 00193 00195 const QStringList getTriggerList() const { return triggerList; } 00196 00197 public slots: 00200 void pause() { qDebug() << "QVWorker::pause()"; status = Paused; emit statusUpdate(status); } 00201 00204 void unPause() { qDebug() << "QVWorker::unPause()"; status = Running; emit statusUpdate(status); } 00205 00208 void step() { qDebug() << "QVWorker::step()"; status = RunningOneStep; emit statusUpdate(status); } 00209 00212 void stop() { qDebug() << "QVWorker::stop()"; status = Stoped; emit statusUpdate(status); } 00213 00216 void finish() { qDebug() << "QVWorker::finish()"; status = Finished; emit statusUpdate(status); } 00217 00232 virtual void processTrigger(QString name) { Q_UNUSED(name); } 00233 00234 signals: 00237 void startIteration(); 00238 00241 void endIteration(uint id, int iteration); 00242 00245 void statusUpdate(QVWorker::TWorkerStatus); 00246 00247 private: 00248 bool statsEnabled; 00249 QVStatControler *cpuStatControler; 00250 int numIterations, maxIterations; 00251 TWorkerStatus status; 00252 QStringList triggerList; 00253 QTime iterationTime; 00254 int curms,minms; 00255 00256 protected: 00257 void run(); 00258 00271 void timeFlag(const QString flag) 00272 { 00273 qDebug() << "QVWorker::timeFlag("<< flag <<")"; 00274 if (statsEnabled) cpuStatControler->setFlag(flag); 00275 } 00276 }; 00277 00278 Q_DECLARE_METATYPE(QVStat); 00279 #endif |