diff options
author | Tom Sutcliffe <ext-thomas.1.sutcliffe@nokia.com> | 2011-05-11 10:09:23 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2011-05-11 10:11:52 (GMT) |
commit | 7acaea8557c1c6a758d9a26eff3fb1b3ec19084f (patch) | |
tree | 9d3946a31537e190b524317953c95af5ad71316e /src | |
parent | baecfbc7f7e0ec7edddb74a2e760c685977e9084 (diff) | |
download | Qt-7acaea8557c1c6a758d9a26eff3fb1b3ec19084f.zip Qt-7acaea8557c1c6a758d9a26eff3fb1b3ec19084f.tar.gz Qt-7acaea8557c1c6a758d9a26eff3fb1b3ec19084f.tar.bz2 |
QmlDebug: Fix QmlOstPlugin compilation failure
Implement waitForMessage()/waitForReadyRead functionality required
by bde58ad1e7d2b38d.
Reviewed-by: kkoehne
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp | 6 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h | 1 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp | 42 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_ost/qostdevice.h | 4 |
4 files changed, 51 insertions, 2 deletions
diff --git a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp index 1c91c34..3fb7ccf 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp +++ b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp @@ -109,6 +109,12 @@ void QmlOstPlugin::disconnect() d->protocol = 0; } +void QmlOstPlugin::waitForMessage() +{ + Q_D(QmlOstPlugin); + d->protocol->waitForReadyRead(-1); +} + void QmlOstPlugin::setPort(int port, bool block) { Q_UNUSED(port); diff --git a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h index eee6ee1..b4ff377 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h +++ b/src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h @@ -68,6 +68,7 @@ public: bool isConnected() const; void send(const QByteArray &message); void disconnect(); + bool waitForMessage(); private Q_SLOTS: void readyRead(); diff --git a/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp b/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp index 21b0169..d3b2661 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp +++ b/src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp @@ -57,6 +57,8 @@ public: Cancel(); } + TInt& AoFlags() { return ((TInt*)&iStatus)[1]; } + private: void RunL(); void DoCancel(); @@ -65,6 +67,7 @@ private: RUsbOstComm ost; TBuf8<4096> readBuf; QByteArray dataBuf; + TBool inReadyRead; }; QOstDevice::QOstDevice(QObject *parent) : @@ -116,7 +119,11 @@ void QOstDevicePrivate::RunL() ost.ReadMessage(iStatus, readBuf); SetActive(); - emit q->readyRead(); + if (!inReadyRead) { + inReadyRead = true; + emit q->readyRead(); + inReadyRead = false; + } } else { q->setErrorString(QString("Error %1 from RUsbOstComm::ReadMessage()").arg(iStatus.Int())); } @@ -178,3 +185,36 @@ qint64 QOstDevice::bytesAvailable() const Q_D(const QOstDevice); return d->dataBuf.length(); } + +bool QOstDevice::waitForReadyRead(int msecs) +{ + Q_D(QOstDevice); + if (msecs >= 0) { + RTimer timer; + TInt err = timer.CreateLocal(); + if (err) return false; + TRequestStatus timeoutStat; + timer.After(timeoutStat, msecs*1000); + User::WaitForRequest(timeoutStat, d->iStatus); + if (timeoutStat != KRequestPending) { + // Timed out + timer.Close(); + return false; + } else { + // We got data, so cancel timer + timer.Cancel(); + User::WaitForRequest(timeoutStat); + timer.Close(); + // And drop through + } + } else { + // Just wait forever for data + User::WaitForRequest(d->iStatus); + } + + // If we get here we have data + TInt err = d->iStatus.Int(); + d->AoFlags() &= ~3; // This is necessary to clean up the scheduler as you're not supposed to bypass it like this + TRAP_IGNORE(d->RunL()); + return err == KErrNone; +} diff --git a/src/plugins/qmltooling/qmldbg_ost/qostdevice.h b/src/plugins/qmltooling/qmldbg_ost/qostdevice.h index 2c26ff7..200e607 100644 --- a/src/plugins/qmltooling/qmldbg_ost/qostdevice.h +++ b/src/plugins/qmltooling/qmldbg_ost/qostdevice.h @@ -61,10 +61,12 @@ public: bool open(int ostProtocolId); void close(); + bool waitForReadyRead(int msecs); + qint64 bytesAvailable() const; + protected: qint64 readData(char *data, qint64 maxSize); qint64 writeData(const char *data, qint64 maxSize); - qint64 bytesAvailable() const; private: QOstDevicePrivate* d_ptr; |