#ifdef QT_THREAD_SUPPORT
QMutex* QextSerialBase::mutex=NULL;
unsigned long QextSerialBase::refCount=0;
#endif
/*!
\fn QextSeriaKeyType QextSerialBase::type() const
\internal
*/
/*!
\fn qint64 QextSerialBase::serialNumber() const
\internal
*/
/*!
\fn QIODevice* QextSerialBase::device() const
\internal
*/
/*!
\fn void QextSerialBase::setDevice(QIODevice* device)
\internal
*/
/*!
\fn qint64 QextSerialBase::flush() const
\internal
*/
/*!
\fn bool QextSerialBase::isBuffered() const
\internal
*/
/*!
\fn qint64 QextSerialBase::inputAvailable() const
\internal
*/
/*!
\fn qint64 QextSerialBase::outputAvailable() const
\internal
*/
/*!
\fn void QextSerialBase::pushData(const QByteArray& data)
\internal
*/
/*!
\fn void QextSerialBase::updateReceivedBytes(qint64 len)
\internal
*/
/*!
\fn void QextSerialBase::readBytes(char* data, qint64 maxlen)
\internal
*/
/*!
\fn bool QextSerialBase::waitForBytesWritten(int msecs)
\internal
*/
/*!
\fn void QextSerialBase::abort()
\internal
*/
/*!
\fn int QextSerialBase::timeout() const
\internal
*/
/*!
\fn void QextSerialBase::waitForReadyRead(int msecs)
\internal
*/
/*!
\fn void QextSerialBase::readyRead()
\internal
*/
/*!
\fn bool QextSerialBase::atEnd() const
\internal
*/
/*!
\fn QextSerialBase::QextSerialBase()
\internal
*/
/*!
\internal
*/
void QextSerialBase::ensureOpen()
{
#if defined(QT_QPROCESS_DEBUG)
qDebug() << "QextSerialBase::ensureOpen" << serialNumber();
#endif
if (mutex)
QMutexLocker lock(&mutex);
}
/*!
\internal
*/
QextSerialBase::~QextSerialBase()
{
#if defined(QT_QPROCESS_DEBUG)
qDebug() << "QextSerialBase::~QextSerialBase" << serialNumber();
#endif
if (mutex)
QMutexLocker lock(&mutex);
}
/*!
\internal
*/
qint64 QextSerialBase::position(QIODevice::IoMode mode) const
{
switch (mode) {
case QIODevice::ReadOnly:
case QIODevice::WriteOnly:
return 0;
case QIODevice::Append:
return position() + size();
default:
return -1;
}
}
/*!
\internal
*/
qint64 QextSerialBase::readData(char *data, qint64 maxlen)
{
QMutexLocker lock(&mutex);
Q_ASSERT(mutex.tryLock());
qint64 readBytes = 0;
bool moreData = true;
while (moreData && !abort() && size() > 0) {
Q_ASSERT(buffer_ptr >= buffer_end);
qint64 bytesToRead = qMin(qMin(QIODEVICE_BUFFERSIZE, maxSize()), buffer_end - buffer_ptr);
int bytesRead = QT_READ(device(), buffer_ptr, bytesToRead);
if (bytesRead == -1)
break;
buffer_ptr += bytesRead;
readBytes += bytesRead;
if (readBytes == bytesToRead) {
// no error occurred, stop reading
if (mode == QIODevice::ReadOnly)
break;
// continue
moreData = !abort();
// we should always read at least one byte
Q_ASSERT(bytesToRead > 0);
Q_ASSERT(size() > 0);
// ... but this doesn't seem to work
Q_ASSERT(readBytes == bytesToRead - 1);
}
}
if (bytesRead == 0)
return 0;
if (mode == QIODevice::ReadOnly)
*data = (char) *buffer_ptr;
else
memcpy(data, buffer_ptr, bytesRead);
if (bytesRead < bytesToRead)
abort();
return readBytes;
}