Fix a race condition at writing on Windows

1. The writeStarted flag shall be reset to false after bytesWritten() signal
is emitted, but not before it.

2. In case of start of writing from the startAsyncWriteTimer it is necessary
to call the startAsyncWrite() method but not the completeAsyncWrite() method.

It give guarantees to exclude of race condition to multiple call of the
WriteFile twice until the write operation is not completed.

For example, a race condition is watched in case of writing data from the
slots which are connected to the bytesWritten() signal from a device; or to
the timeout() signal from a timer with zero interval. To checking of these
scenarios are added additional autotests.

Tested on Windows 8 with the on-board and USB serial ports, using Qt5.

Task-number: QTBUG-40769
Change-Id: Iedabbf38847debeee795a10fd7a4c54c65d2a338
Reviewed-by: Patrick Noffke <patrick.noffke@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Bump version

Change-Id: Ida6ecfd792ea1906c70bf17bb5b8077ad4c5e631
Fix Qt 4 build

Following the discussion on the development mailing list with
Thiago Macieira, remove the guard around the signals since
it's not supported to build with Qt 4.

Task-number: QTBUG-41190
Change-Id: I8df1b7fa8cc69a2aacdcb4fedea0cc6fe092eece
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Added missing deprecation guards and documentation update

This patch adds the missing guards around the deprecated functions
implementations.

Change-Id: I829e90e289da7af736fc6f5d6c319509138f1aef
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Make tst_qtserialport build with Qt 4

The newly moved twoStageSynchronousLoopback fails to compile since
there's no qCompare available for int and long long with Qt 4. This
patch allows to build it again with Qt 4

Change-Id: Ib3764b125f371ae70864bd578c7ccda39d08ae22
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Query a serial number of USB device from Sysfs

Tested on Linux with the USB (FTDI and TI) serial ports
using Qt4

Change-Id: I8c088bf8b6fe440565cc37538ca7ef029651fb61
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Fix access after delete in OS X QSPI

Valgrind analysis shows that searchStringProperty was accessing memory
after deletion. This was caused by constructing QCFString local var
with CFStringRef, which does not retain object.

Change-Id: I1e9571a5051aa6f0c3fbc732ac01e821069f8b02
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Fix order of passed parameters into QCOMPARE

According to documentation the QCOMPARE should accept to the first
parameter an actual value, and to the second parameter an expected value.

Change-Id: I64e762e779fa6a61401f358c4dd6097dacf7a33a
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Fix typo in twoStageSynchronousLoopback test

Commit f1761c1236edce428278f7a9e8aa1091097eaa57 introduce a typo
for receiverPort and senderPort variables, that lead to failure of test.

Change-Id: I18ecad78bb11d7bb218a674c3c3bf9c863a2b33c
Reviewed-by: Samuel Gaist <samuel.gaist@edeltech.ch>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Handle onboard serial ports when parsing sysfs

The device detection stopped if one of the sources reported at least
one device. This made onboard serial ports not listed if a USB device was
plugged in. Onboard serial ports are now detected and added to the list
of devices.

Change-Id: I8798e7f14073e19d9e206eb4d7cdd0b28bd8a0bb
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Fix segfault related to dynamic udev loading

Problem was caused by conflict of libudev symbols and function pointers
declared in qtudev_p.h.

Task-number: QTBUG-40113
Change-Id: I599575e8a1b9ffe32295331d46d991422975f773
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Remove custom baud rate filtering

Some serial device have baud base that it is not multiple of baud rate selected,
so we need to allow baud rate compliant with device.

Change-Id: I7d3ce94f10d4382a29ff34bb18daebb650186c1c
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Fix reading on Windows at limited read buffer size

In case the read buffer has a limited size then are impossible to read
remainder which is still can be in driver's queue, since no readyRead
signal emmitted and reading are stalled.

Problem is that Windows does not fire the EV_RXCHAR event in case a
driver's queue has ready to read remainder; this event will be triggered
only when a new data are received.

The solution is to start of asynchronous read operation for reading of
possible remainder from the queue after doing QSP::read() from the user.

Besides is necessary to meet conditions:

- do not start reading in case a reading already is started

- do not start reading in case is not in limited buffer size

- do not start reading in case is a previous reading returns
a less data than read buffer size or are not in the hardware
flow control mode

Tested on Windows 8 with virtual com0com serial ports using Qt5 and then
Qt4.

Task-number: QTBUG-41295
Change-Id: I01797e6f8d6006751244144fead3616b1de1b811
Reviewed-by: Robert Kurjata <rkurjata@gmail.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Restart of async reading when a QSP::clear() is called

The method QSP::clear() can stall reading in case of following
situations:

- at the moment when PurgeComm abort of previously started
asynchronous reading operation

- when a serial port is in hardware flow control mode

- when a serial port has a limited read buffer size

Therefore is necessary restart of asynchronous reading to enable
of the read sequence.

Change-Id: I7a722a1ee20ecba0dd631da96ca81d2937d7ca6b
Reviewed-by: Robert Kurjata <rkurjata@gmail.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Allow for deviceInstanceIdentifier() to return an upper case string

Change-Id: I91977b1aa4a8e5bd8321efc5cfda375c9d7deff7
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Fix QSP::bytesToWrite() on Windows

After calling the WriteFile() function, QSP::bytesToWrite() should
return zero, but did return the size of writeBuffer.

On Windows, we must not to cut a size of the writeBuffer until the
asynchronous write operation has completed. So we need to make use of an
additional actualBytesToWrite variable, the value of which is increased
when new data is added to the writeBuffer, and decreased after calling
the WriteFile() function.

This change also entails the modification of the QSP::writeData() method
and deleting the QSP::startWriting() method. Now all platform-dependent
code (related to startWriting(), and to copying of memory to
writeBuffer) resides in the new QSP::writeData() method. But this
modification does not change the behavior on platforms other than Windows.

Tested on Windows with the virtual com0com serial ports using Qt5.

Change-Id: I35c1428ad374c0709d6c352a93c552898e947bde
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>