Use qDebug() instead of std::cout
[agianapa.git] / qt / sphere-orbit-camera-gui / workerthread.cpp
bloba185440e04c16692828ff79b3154af6558b6df98
1 #include <cstdlib>
2 #include <iostream>
4 #include "workerthread.h"
6 WorkerThread::WorkerThread(QObject *parent, QQueue<float> *pData)
7 : QThread(parent)
9 qDebug("WorkerThread::WorkerThread()");
11 // Initialize random generator here
12 srand(time(NULL));
14 m_file.setFileName("foo.dat");
15 m_file.open(QIODevice::ReadOnly);
16 in.setDevice(&m_file);
18 abort = false;
19 prev = 0;
20 this->pData = pData;
23 WorkerThread::~WorkerThread()
25 qDebug("WorkerThread::~WorkerThread()");
27 mutex.lock();
28 abort = true;
29 condition.wakeOne();
30 mutex.unlock();
32 m_file.close();
34 wait();
37 void WorkerThread::run(void)
39 float r;
41 qDebug("WorkerThread::run()");
43 // Loop
44 while (!abort) {
45 mutex.lock();
46 if (pData->size() >= 667) {
47 qDebug("BLOCKED");
48 condition.wait(&mutex);
49 mutex.unlock();
51 else {
52 in >> r;
53 pData->enqueue(r);
54 mutex.unlock();
59 void WorkerThread::setData(QQueue<float> *pData)
61 qDebug("WorkerThread::setData()");
63 this->pData = pData;
66 void WorkerThread::setFileName(QString fileName)
68 qDebug("WorkerThread::setFileName()");
70 // Close old file
71 m_file.close();
73 // Caution: discard all old data in QQueue
74 // Worst case scenario if you don't: frame read corruption
75 pData->clear();
77 // Open new one
78 m_file.setFileName(fileName);
79 m_file.open(QIODevice::ReadOnly);
80 in.setDevice(&m_file);