![]() |
University of Murcia, Spain ![]() |
src/qvcore/qvworker.hGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008, 2009. 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 00166 void setPrintStatsFrequency(int freq) 00167 { 00168 //std::cout << "ERERERWERWERWEFWEFWE " << freq << std::endl; 00169 if (statsEnabled) 00170 { 00171 //std::cout << "\txxxxx " << freq << std::endl; 00172 cpuStatControler->setFreq(freq); 00173 cpuStatControler->setWorkerName(getName()); 00174 } 00175 } 00176 00183 void printStats() 00184 { 00185 if (statsEnabled) 00186 cpuStatControler->printStats(); 00187 } 00188 00207 void addTrigger(QString name) { triggerList.push_back(name); } 00208 00210 const QStringList getTriggerList() const { return triggerList; } 00211 00212 public slots: 00215 void pause() { qDebug() << "QVWorker::pause()"; status = Paused; emit statusUpdate(status); } 00216 00219 void unPause() { qDebug() << "QVWorker::unPause()"; status = Running; emit statusUpdate(status); } 00220 00223 void step() { qDebug() << "QVWorker::step()"; status = RunningOneStep; emit statusUpdate(status); } 00224 00227 void stop() { qDebug() << "QVWorker::stop()"; status = Stoped; emit statusUpdate(status); } 00228 00231 void finish() { qDebug() << "QVWorker::finish()"; status = Finished; emit statusUpdate(status); } 00232 00247 virtual void processTrigger(const QString name) { Q_UNUSED(name); } 00248 00249 //virtual void processTrigger(QString name) 00250 // { std::cout << "QVWorker::processTrigger(QString) is deprecated, use QVWorker::processTrigger(const QString); instead." << std::endl; } 00251 00252 signals: 00255 void startIteration(); 00256 00259 void endIteration(uint id, int iteration); 00260 00263 void statusUpdate(QVWorker::TWorkerStatus); 00264 00265 private: 00266 bool statsEnabled; 00267 QVStatControler *cpuStatControler; 00268 int numIterations, maxIterations; 00269 TWorkerStatus status; 00270 QStringList triggerList; 00271 QTime iterationTime; 00272 int curms,minms; 00273 00274 protected: 00275 void run(); 00276 00289 void timeFlag(const QString flag) 00290 { 00291 qDebug() << "QVWorker::timeFlag("<< flag <<")"; 00292 if (statsEnabled) cpuStatControler->setFlag(flag); 00293 } 00294 00295 void workerIterate(); 00296 }; 00297 00298 Q_DECLARE_METATYPE(QVStat); 00299 #endif |