-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeviceCommunicationWorker.cpp
44 lines (38 loc) · 1.15 KB
/
deviceCommunicationWorker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "deviceCommunicationWorker.h"
#include <QDebug>
#include "unistd.h"
DeviceCommunicationWorker::DeviceCommunicationWorker(QObject* parent): QObject(parent), device(0)
{
}
void DeviceCommunicationWorker::connectToDevice()
{
// TODO fixme
qDebug() << "starting up";
device = new TMCDevice("/dev/usbtmc1");
}
void DeviceCommunicationWorker::doWork()
{
while ( ! device ) {
qDebug() << "device is not set, waiting for startup...";
sleep(1);
}
while ( true ) {
QMutexLocker lock(&requestsLock);
if ( requests.isEmpty() ) {
return;
}
CommunicationRequest* request = requests.dequeue();
lock.unlock();
CommunicationReply* reply = request->execute(device);
QMetaObject::invokeMethod(request->notifyReady, request->notifyMethod.toAscii(),
Qt::QueuedConnection, Q_ARG(CommunicationReply*, reply));
delete request;
}
}
void DeviceCommunicationWorker::enqueue(CommunicationRequest* request)
{
requestsLock.lock();
requests.enqueue(request);
requestsLock.unlock();
QMetaObject::invokeMethod(this, "doWork");
}