PARP Research Group | Universidad de Murcia |
src/qvblockprogramming/qvprocessingblock.hGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012. 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 QVPROCESSINGBLOCK_H 00026 #define QVPROCESSINGBLOCK_H 00027 00028 #include <QStringList> 00029 #include <QThread> 00030 #include <QTime> 00031 00032 #include <qvblockprogramming/qvcpustatcontroler.h> 00033 #include <QVPropertyContainer> 00034 00045 class QVProcessingBlock: public QThread, public QVPropertyContainer 00046 { 00047 Q_OBJECT 00048 00049 public: 00051 typedef enum 00052 { 00056 Running, 00059 RunningOneStep, 00063 Paused, 00067 Stopped, 00069 Finished 00070 } TBlockStatus; 00071 00076 QVProcessingBlock(const QString name = QString()); 00077 00082 QVProcessingBlock(const QVProcessingBlock &other); 00083 00085 ~QVProcessingBlock(); 00086 00091 virtual void iterate() { }; 00092 00104 void setMinimumDelay(int ms) { minms = ms; }; 00105 00108 bool isFinished() const { return status == Finished; } 00109 00112 bool isPaused() const { return status == Paused; } 00113 00116 bool isStopped() const { return status == Stopped; } 00117 00120 bool isRunning() const { return status == Running; } 00121 00124 TBlockStatus getStatus() const { return status; } 00125 00128 int getIteration() const { return numIterations; } 00129 00132 bool isStatsEnabled() const { return statsEnabled; } 00133 00144 QVStat getCpuStat() const { 00145 if (statsEnabled) return cpuStatControler->value(); 00146 else return QVStat(); 00147 } 00148 00156 void setPrintStatsFrequency(int freq) 00157 { 00158 if (statsEnabled) 00159 { 00160 cpuStatControler->setFreq(freq); 00161 cpuStatControler->setBlockName(getName()); 00162 } 00163 } 00164 00171 void printStats() 00172 { 00173 if (statsEnabled) 00174 cpuStatControler->printStats(); 00175 } 00176 00195 void addTrigger(QString name) { triggerList.push_back(name); } 00196 00198 const QStringList getTriggerList() const { return triggerList; } 00199 00212 void timeFlag(const QString flag) 00213 { 00214 qDebug() << "QVProcessingBlock::timeFlag("<< flag <<")"; 00215 if (statsEnabled) cpuStatControler->setFlag(flag); 00216 } 00217 00218 public slots: 00221 void pause() { qDebug() << "QVProcessingBlock::pause()"; status = Paused; emit statusUpdate(status); } 00222 00225 void unPause() { qDebug() << "QVProcessingBlock::unPause()"; status = Running; emit statusUpdate(status); } 00226 00229 void step() { qDebug() << "QVProcessingBlock::step()"; status = RunningOneStep; emit statusUpdate(status); } 00230 00233 void stop() { qDebug() << "QVProcessingBlock::stop()"; status = Stopped; emit statusUpdate(status); } 00234 00237 void finish() { qDebug() << "QVProcessingBlock::finish()"; status = Finished; emit statusUpdate(status); } 00238 00253 virtual void processTrigger(const QString name) { Q_UNUSED(name); } 00254 00255 signals: 00258 void startIteration(); 00259 00262 void endIteration(uint id, int iteration); 00263 00266 void statusUpdate(QVProcessingBlock::TBlockStatus); 00267 00268 private: 00269 bool statsEnabled; 00270 QVStatControler *cpuStatControler; 00271 int numIterations, maxIterations; 00272 TBlockStatus status; 00273 QStringList triggerList; 00274 QTime iterationTime; 00275 int curms,minms; 00276 00277 protected: 00278 void run(); 00279 void blockIterate(); 00280 }; 00281 00282 Q_DECLARE_METATYPE(QVStat); 00283 #endif |