diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2013-01-19 14:17:38 +0400 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2013-01-19 17:32:24 +0100 |
commit | 67aefdc87a746423c5566701592565025a243160 (patch) | |
tree | b6b84d6cdd0787ec9aab93c42f0cbf7cd0be3516 | |
parent | 531bb65d0f4ddfe489ea0d402bbb947ef6eb683e (diff) | |
download | qtserialport-67aefdc87a746423c5566701592565025a243160.tar.gz |
Fix bytesAvailable() method
This method should have a different implementation for
different platforms. For example, for Win32, it should
return the value of actualReadBufferSize, although for
other platforms - value of readBuffer.size().
To solve the problem was introduced additional private
platform-specific method bytesAvailable() which has a
different implementation for platforms.
Change-Id: I23f6648ca1fd4aebf5d650b2c01737cf67db1fe8
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r-- | src/serialport/serialport.cpp | 2 | ||||
-rw-r--r-- | src/serialport/serialport_symbian.cpp | 5 | ||||
-rw-r--r-- | src/serialport/serialport_symbian_p.h | 2 | ||||
-rw-r--r-- | src/serialport/serialport_unix.cpp | 5 | ||||
-rw-r--r-- | src/serialport/serialport_unix_p.h | 2 | ||||
-rw-r--r-- | src/serialport/serialport_win.cpp | 5 | ||||
-rw-r--r-- | src/serialport/serialport_win_p.h | 2 | ||||
-rw-r--r-- | src/serialport/serialport_wince.cpp | 5 |
8 files changed, 27 insertions, 1 deletions
diff --git a/src/serialport/serialport.cpp b/src/serialport/serialport.cpp index 577bc58..25b043d 100644 --- a/src/serialport/serialport.cpp +++ b/src/serialport/serialport.cpp @@ -1037,7 +1037,7 @@ bool SerialPort::isSequential() const qint64 SerialPort::bytesAvailable() const { Q_D(const SerialPort); - return d->readBuffer.size() + QIODevice::bytesAvailable(); + return d->bytesAvailable() + QIODevice::bytesAvailable(); } /*! \reimp diff --git a/src/serialport/serialport_symbian.cpp b/src/serialport/serialport_symbian.cpp index dfbeeff..365fa6a 100644 --- a/src/serialport/serialport_symbian.cpp +++ b/src/serialport/serialport_symbian.cpp @@ -244,6 +244,11 @@ qint64 SerialPortPrivate::systemOutputQueueSize () const return 0; } +qint64 SerialPortPrivate::bytesAvailable() const +{ + return readBuffer.size(); +} + qint64 SerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) { // TODO: Implement me diff --git a/src/serialport/serialport_symbian_p.h b/src/serialport/serialport_symbian_p.h index 62a1574..5b43e46 100644 --- a/src/serialport/serialport_symbian_p.h +++ b/src/serialport/serialport_symbian_p.h @@ -70,6 +70,8 @@ public: qint64 systemInputQueueSize () const; qint64 systemOutputQueueSize () const; + qint64 bytesAvailable() const; + qint64 readFromBuffer(char *data, qint64 maxSize); qint64 writeToBuffer(const char *data, qint64 maxSize); diff --git a/src/serialport/serialport_unix.cpp b/src/serialport/serialport_unix.cpp index bb1a71c..deab68d 100644 --- a/src/serialport/serialport_unix.cpp +++ b/src/serialport/serialport_unix.cpp @@ -359,6 +359,11 @@ qint64 SerialPortPrivate::systemOutputQueueSize () const return nbytes; } +qint64 SerialPortPrivate::bytesAvailable() const +{ + return readBuffer.size(); +} + qint64 SerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) { if (readBuffer.isEmpty()) diff --git a/src/serialport/serialport_unix_p.h b/src/serialport/serialport_unix_p.h index 1a63cb0..b76c718 100644 --- a/src/serialport/serialport_unix_p.h +++ b/src/serialport/serialport_unix_p.h @@ -76,6 +76,8 @@ public: qint64 systemInputQueueSize () const; qint64 systemOutputQueueSize () const; + qint64 bytesAvailable() const; + qint64 readFromBuffer(char *data, qint64 maxSize); qint64 writeToBuffer(const char *data, qint64 maxSize); diff --git a/src/serialport/serialport_win.cpp b/src/serialport/serialport_win.cpp index c8c37e8..1f8d45f 100644 --- a/src/serialport/serialport_win.cpp +++ b/src/serialport/serialport_win.cpp @@ -388,6 +388,11 @@ qint64 SerialPortPrivate::systemOutputQueueSize () const #ifndef Q_OS_WINCE +qint64 SerialPortPrivate::bytesAvailable() const +{ + return actualReadBufferSize; +} + qint64 SerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) { if (actualReadBufferSize == 0) diff --git a/src/serialport/serialport_win_p.h b/src/serialport/serialport_win_p.h index d246f1d..a889560 100644 --- a/src/serialport/serialport_win_p.h +++ b/src/serialport/serialport_win_p.h @@ -83,6 +83,8 @@ public: qint64 systemInputQueueSize () const; qint64 systemOutputQueueSize () const; + qint64 bytesAvailable() const; + qint64 readFromBuffer(char *data, qint64 maxSize); qint64 writeToBuffer(const char *data, qint64 maxSize); diff --git a/src/serialport/serialport_wince.cpp b/src/serialport/serialport_wince.cpp index 7489747..e713ce9 100644 --- a/src/serialport/serialport_wince.cpp +++ b/src/serialport/serialport_wince.cpp @@ -228,6 +228,11 @@ bool SerialPortPrivate::flush() return notifyWrite() && ::FlushFileBuffers(descriptor); } +qint64 SerialPortPrivate::bytesAvailable() const +{ + return readBuffer.size(); +} + qint64 SerialPortPrivate::readFromBuffer(char *data, qint64 maxSize) { if (readBuffer.isEmpty()) |