Cancel();
}
+ TInt& AoFlags() { return ((TInt*)&iStatus)[1]; }
+
private:
void RunL();
void DoCancel();
RUsbOstComm ost;
TBuf8<4096> readBuf;
QByteArray dataBuf;
+ TBool inReadyRead;
};
QOstDevice::QOstDevice(QObject *parent) :
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()));
}
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;
+}
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;