![]() |
University of Murcia ![]() |
src/qvblockprogramming/qvprocessingblock.hGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008, 2009, 2010. 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 Stoped, 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 isStoped() const { return status == Stoped; } 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 00200 public slots: 00203 void pause() { qDebug() << "QVProcessingBlock::pause()"; status = Paused; emit statusUpdate(status); } 00204 00207 void unPause() { qDebug() << "QVProcessingBlock::unPause()"; status = Running; emit statusUpdate(status); } 00208 00211 void step() { qDebug() << "QVProcessingBlock::step()"; status = RunningOneStep; emit statusUpdate(status); } 00212 00215 void stop() { qDebug() << "QVProcessingBlock::stop()"; status = Stoped; emit statusUpdate(status); } 00216 00219 void finish() { qDebug() << "QVProcessingBlock::finish()"; status = Finished; emit statusUpdate(status); } 00220 00235 virtual void processTrigger(const QString name) { Q_UNUSED(name); } 00236 00237 signals: 00240 void startIteration(); 00241 00244 void endIteration(uint id, int iteration); 00245 00248 void statusUpdate(QVProcessingBlock::TBlockStatus); 00249 00250 private: 00251 bool statsEnabled; 00252 QVStatControler *cpuStatControler; 00253 int numIterations, maxIterations; 00254 TBlockStatus status; 00255 QStringList triggerList; 00256 QTime iterationTime; 00257 int curms,minms; 00258 00259 protected: 00260 void run(); 00261 00274 void timeFlag(const QString flag) 00275 { 00276 qDebug() << "QVProcessingBlock::timeFlag("<< flag <<")"; 00277 if (statsEnabled) cpuStatControler->setFlag(flag); 00278 } 00279 00280 void blockIterate(); 00281 }; 00282 00283 Q_DECLARE_METATYPE(QVStat); 00284 #endif |