QmlDebug: Fix QmlOstPlugin compilation failure
authorTom Sutcliffe <ext-thomas.1.sutcliffe@nokia.com>
Wed, 11 May 2011 10:09:23 +0000 (12:09 +0200)
committerKai Koehne <kai.koehne@nokia.com>
Thu, 12 May 2011 11:57:58 +0000 (13:57 +0200)
Implement waitForMessage()/waitForReadyRead functionality required
by bde58ad1e7d2b38d.

Reviewed-by: kkoehne
(cherry picked from commit 7acaea8557c1c6a758d9a26eff3fb1b3ec19084f)

src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp
src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h
src/plugins/qmltooling/qmldbg_ost/qostdevice.cpp
src/plugins/qmltooling/qmldbg_ost/qostdevice.h

index 1c91c34..3fb7ccf 100644 (file)
@@ -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);
index eee6ee1..b4ff377 100644 (file)
@@ -68,6 +68,7 @@ public:
     bool isConnected() const;
     void send(const QByteArray &message);
     void disconnect();
+    bool waitForMessage();
 
 private Q_SLOTS:
     void readyRead();
index 21b0169..d3b2661 100644 (file)
@@ -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;
+}
index 2c26ff7..200e607 100644 (file)
@@ -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;