Commit d9e7a390 authored by hjk's avatar hjk
Browse files

debugger: simplify trk device logic a bit

parent e58ff77b
......@@ -999,7 +999,6 @@ void Adapter::handleTrkError(const QString &msg)
void Adapter::handleTrkResult(const TrkResult &result)
{
logMessage("HANDLING RESULT: " + result.data);
if (result.isDebugOutput) {
sendTrkAck(result.token);
logMessage(QLatin1String("APPLICATION OUTPUT: ") +
......
......@@ -257,8 +257,18 @@ void TrkWriteQueue::queueTrkInitialPing()
trkWriteQueue.append(TrkMessage(0, 0));
}
struct TrkDevicePrivate {
///////////////////////////////////////////////////////////////////////
//
// TrkDevicePrivate
//
///////////////////////////////////////////////////////////////////////
struct TrkDevicePrivate
{
TrkDevicePrivate();
TrkWriteQueue queue;
#ifdef Q_OS_WIN
HANDLE hdevice;
#else
......@@ -298,11 +308,13 @@ TrkDevicePrivate::TrkDevicePrivate() :
TrkDevice::TrkDevice(QObject *parent) :
QObject(parent),
d(new TrkDevicePrivate),
qd(new TrkWriteQueue)
d(new TrkDevicePrivate)
{}
TrkDevice::~TrkDevice()
{
connect(this, SIGNAL(messageReceived(trk::TrkResult)),
this, SLOT(slotHandleResult(trk::TrkResult)));
close();
delete d;
}
bool TrkDevice::open(const QString &port, QString *errorMessage)
......@@ -355,14 +367,6 @@ bool TrkDevice::open(const QString &port, QString *errorMessage)
#endif
}
TrkDevice::~TrkDevice()
{
close();
delete d;
delete qd;
}
void TrkDevice::close()
{
if (!isOpen())
......@@ -493,6 +497,7 @@ void TrkDevice::tryTrkRead()
//if (verbose())
// logMessage("Read TrkResult " + r.data.toHex());
qDebug() << "RECEIVE DATA: " << r.data.toHex();
d->queue.slotHandleResult(r);
emit messageReceived(r);
if (!rawData.isEmpty())
emit rawDataReceived(rawData);
......@@ -515,12 +520,12 @@ void TrkDevice::emitError(const QString &s)
void TrkDevice::sendTrkMessage(byte code, Callback callback,
const QByteArray &data, const QVariant &cookie, bool invokeOnNAK)
{
qd->queueTrkMessage(code, callback, data, cookie, invokeOnNAK);
d->queue.queueTrkMessage(code, callback, data, cookie, invokeOnNAK);
}
void TrkDevice::sendTrkInitialPing()
{
qd->queueTrkInitialPing();
d->queue.queueTrkInitialPing();
}
bool TrkDevice::sendTrkAck(byte token)
......@@ -536,10 +541,10 @@ bool TrkDevice::sendTrkAck(byte token)
void TrkDevice::tryTrkWrite()
{
TrkMessage message;
if (!qd->pendingMessage(&message))
if (!d->queue.pendingMessage(&message))
return;
const bool success = trkWriteRawMessage(message);
qd->notifyWriteResult(success);
d->queue.notifyWriteResult(success);
}
bool TrkDevice::trkWriteRawMessage(const TrkMessage &msg)
......@@ -554,10 +559,5 @@ bool TrkDevice::trkWriteRawMessage(const TrkMessage &msg)
return rc;
}
void TrkDevice::slotHandleResult(const TrkResult &result)
{
qd->slotHandleResult(result);
}
} // namespace trk
......@@ -46,8 +46,6 @@ namespace trk {
struct TrkResult;
struct TrkMessage;
struct TrkDevicePrivate;
class TrkWriteQueue;
struct TrkWriteQueueIODevicePrivate;
/* TrkDevice: Implements a Windows COM or Linux device for
* Trk communications. Provides synchronous write and asynchronous
......@@ -116,15 +114,11 @@ public:
// Send an Ack synchronously, bypassing the queue
bool sendTrkAck(unsigned char token);
private slots:
void slotHandleResult(const trk::TrkResult &);
private:
void tryTrkWrite();
bool trkWriteRawMessage(const TrkMessage &msg);
TrkDevicePrivate *d;
TrkWriteQueue *qd;
};
} // namespace trk
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment