5 #include "workerthread.h"
7 WorkerThread::WorkerThread(QObject
*parent
)
10 qDebug("WorkerThread::WorkerThread()");
12 // Initialize random generator here
15 // Make thread work forever by default
18 // At this point the class hasn't been fully initialized.
19 // The user must call setFileName(), before run()'ing.
22 WorkerThread::~WorkerThread()
24 qDebug("WorkerThread::~WorkerThread()");
36 void WorkerThread::run(void)
39 qDebug("WorkerThread::run()");
44 if (m_data
.size() >= 2007) {
46 condition
.wait(&m_mutex
);
50 qDebug("Reading from file");
52 if (in
.status() == QDataStream::ReadPastEnd
) {
53 qDebug("Datastream has read past end");
64 void WorkerThread::setFileName(QString fileName
)
66 qDebug("WorkerThread::setFileName()");
71 // Caution: discard all old data in QQueue
72 // Worst case scenario if you don't: frame read corruption
76 // XXX: toLatin1() segfaults
77 m_file
.setFileName(fileName
);
78 if (!m_file
.open(QIODevice::ReadOnly
)) {
79 qDebug("Cannot open file name: %s", fileName
.toLatin1());
83 in
.setDevice(&m_file
);
87 quint32
WorkerThread::getMagicVersion(void) const
89 qDebug("WorkerThread::getMagicVersion()");
91 return m_magicVersion
;
94 quint32
WorkerThread::getProtocolVersion(void) const
96 qDebug("WorkerThread::getProtocolVersion()");
98 return m_protocolVersion
;
101 float WorkerThread::getDurationInSec(void) const
103 qDebug("WorkerThread::getDurationInSec()");
105 return m_durationInSec
;
108 quint32
WorkerThread::getNumOfRecords(void) const
110 qDebug("WorkerThread::getNumOfRecords()");
112 return m_numOfRecords
;
115 void WorkerThread::extractFileHeader(void)
117 qDebug("WorkerThread::extractFileHeader()");
119 in
>> m_magicVersion
;
120 //Q_ASSERT(m_magicVersion == 0xA0B0C0D0);
122 in
>> m_protocolVersion
;
123 //Q_ASSERT(m_protocolVersion == 0x1);
125 in
>> m_durationInSec
;
126 in
>> m_numOfRecords
;
128 // qDebug() adds an extra space between items,
129 // plus a new line in the last one.
130 qDebug() << "Magic version =" << hex
<< m_magicVersion
;
131 qDebug() << "Protocol version =" << m_protocolVersion
;
132 qDebug() << "Duration in sec = " << m_durationInSec
;
133 qDebug() << "Number of records =" << m_numOfRecords
;