Use ZeroMemory on Windows instead of zero memset

See the documentation for details:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366920(v=vs.85).aspx

Two immediate advantages:

1) Consistent with the rest of Qt.

2) It is more convenient and explicit than the raw memset.

Unfortunately, Windows CE does not seem to have this supported, so it is not
changed in there:

http://users.atw.hu/lingoland/akademia/zeromem.htm

"Windows CE: Unsupported."

Change-Id: I44154c320f13054e1bfd08e3ff1e957430eeeb49
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Add the missing error handling on Windows for QSerialPort

Change-Id: Ia6bbf1d3958b7b9930650399ce6e99e7cc98ef2a
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Remove the standard input copy/paste issue from the QIODevice documentation

Change-Id: I03d4be1bf7fd5670c563484759eda670c9a0cb75
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Do not handle "no data available" as error in the timeout handler

Change-Id: I132a668f1eca2d7a1ac353b6e088b7b07d4e2e12
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Remove the very bizarre whitespaces from inconsistent macro usages

b8af6f604cd86897c8a04825700892fd9970a616 introduced this for no any valid
reason. There was no review back then, so any silly stuff like this could sneak
in.

Change-Id: I80c21e9f2a7c5eec3b126e8080132ca43a60f12b
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Replace the silly empty output with a reasonable "N/A" placeholder

Change-Id: Iad5076e9a192f5a07e41314d286bc02e46ea92c8
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Eliminate the "canAppendToList" variable usage

There are problems with this variable:

1) It should have been called "isSerialPortValid" or something like that to be
more precise abouts its functionality.

2) It should have had false value by default since we do not assume everything
is correct by default, and exclude certain ones, but the other way around,
logically.

3) Most importantly: It makes the code unnecessarily longer since the loop can
be continued with the next iteration without the need to insert an invalid
serial port and an interim variable.

Tested the cenumerator example on Linux with udev using Qt 4 and then 5. There
are no regressions found.

Change-Id: I4f6bdce402f03eac696c0d2ce9448e59baedf56b
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Merge two mini-functions for the hard coded list

It is done for the following reason:

1) Consistency with the unix backend of the QSerialPort class, where the
serialPortLockFilePath free function is also like this.

2) There is no point in having a separate free function for initializing a
variable when it is only used in one place.

3) It is less abstraction.

4) It is negligibly faster.

5) It is still a small enough free function, and naturally fits the one page
maximum limit for a function which is the general recommendation in projects.

6) Last, but not least: It also makes the code shorter and more concise.

Change-Id: Ie07f06521e11038bdd3cc504a56cadcf00e68269
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Do not use parentheses around a single statement for consistency

Change-Id: I54533863c80933eed8f01de190bb7713f64f6999
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Remove the unnecessary and noisy comments for the serial port info files

Comments are noisy, useless, and can get outdated. The only comments that might
make sense to me the ones where we note future tasks, such as TODO (or FIXME).
The code should document itself.

The serial port files need a separate evaluation since a lot of stuff is
inherited from QtCore in there where the comments should probably be kept for
consistency.

Change-Id: I6c759c7138f64546c2c4e27a039667c556a30db9
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Simplify the standard baudrate getter by dropping the foreach

1f1ca7490fa6e2231f396e564dacbbd8d0e10b29 rewrote this part of the code, but the
needless logic has not be dropped respectively. It was necessary before the
rewrite since the raw qint32* type had to be converted to QList<qint32>, but
since we have a more Qt'ish data storage up front, we do not need to iterate
through the list since it is ready-made for us.

Change-Id: Iab5d4b0d48de3fc27fb41a4694f044bd58e760c4
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Try to load udev at runtime if we do not link against it

There was an explicit option previously added into 5.2.0 due to lack of time to
implement this runtime resolution properly. The libudev load variable can now be
eliminated which also simplifies the packaging.

This change also takes care of avoiding the regression by not loading udev at
runtime at all for Qt 4. That has always been the case, so there are no
regressions there. A TODO comment has been left in the code though about it.

The helper free functions cannot be static because they are declared as friend
outside that source file. Ideally, we could have a better approach, but that
would require more significant refactoring, and such a revamp has to become
stable in the 'dev' branch before going into the 'stable' branch. Thereby, this
is an acceptable compromise.

It does not break binary compatibility either to remove or add friend
declarations to a class.

The change has been tested on Archlinux (x86_64) with Qt 4 and then 5 using the
cenumerator example. The change has been tested both with udev and without that,
i.e with sysfs on my Linux system.

Change-Id: Ia7d7ecb336c1de1913e1dd60177ae7469e90c329
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Drop the empty data check in favor of proper error code handling

Change-Id: Iad0f2c58a4f52daebd02a71fd7b404cb283602dc
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Bump MODULE_VERSION to 5.2.1

Change-Id: Ie52035bd9eec3fffb2c2b2b6b9869dd23f4ace3f
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Matti Paaso <matti.paaso@digia.com>
test: Add 5.1.0 bic data for linux-gcc-ia32

Change-Id: I23025d79468650a62c881d3c8cbedfcb7d039495
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Document the real meaning of the parity enumeration values

Change-Id: I58f689e6bf8480c5a608f91d7f4fb7a83235d631
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Use direct access to the read buffer

1. Use the auxiliary array to store the chunks of data at reading
on Windows.

The additional array is used for temporary storing the data chunks of
the each asynchronous reading operation. This data will be appended to
the class read buffer when asynchronous operation completed. It reduce
quantity of calls for reallocation of the input ring buffer because now
the reallocation with the actual data is carried out once in the
completeAsyncRead() method.

2. Delete the bytesAvailable() and readFromBuffer() methods from
the QSerialPortPrivate.

These methods are not necessary any more, because now the size and content
of the read buffer always has actual value. Now all dependent methods
can access to the read buffer directly without the intermediaries,
like bytesAvailable() and readFromBuffer().

Tested the build with Qt4 and then Qt5 for:

* Windows 7/8, MinGW
* Windows CE Pocket PC, VS2005
* Android platforms ARM and x86
* Archlinux 64-bit

Tested the work with the terminal, the creader(a)sync, the cwriter(a)sync
examples with Qt4 and then Qt5 for:

* Windows 7/8 with the virtual com0com, the physical on-board and the
USB PL2303 devices
* Archlinux 64-bit with the physical on-board and the USB PL2303 devices

Change-Id: I6871f8933588377646ffeccf1d2c21bb6caada24
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Clear unused members of the overlapped structure before each usage

For more detail, see remarks from the MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684342%28v=vs.85%29.aspx

Change-Id: Id6e5adc48e8a4648f1aabba598696b34c658a159
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Optimization of the write notifier algorithm

The algorithm before the commit eca1a6d30a98861cb811cb2faf8d01334e60dd7c
could process the write events from the several notifiers, which could be
created in data transfer operation.

But now the write notifier always is in one instance, so can do following
optimizations:

* The method lookupFreeWriteCompletionNotifier() now is renamed to the
lookupWriteCompletionNotifier() and returns the pointer to the existing
notifier without creating them (by analogy with others lookupXX() methods).

* Now there is no need to control the write notifier state (to do enable
or disable) in data transfer process. The current algorithm doesn't require
it and the write notifier enabled once when port opens.

* Use the open mode flag instead of low-level events mask to create the
write notifiers. Also, this handling was added similarly to the read
notifier.

Tested the work with the terminal, the creader(a)sync, the cwriter(a)sync
examples with Qt4 and then Qt5 on Windows 7/8 with use:

* the virtual serial ports (the com0com project)
* the physical on-board serial ports and the USB serial ports

Change-Id: I8bc6a025a00dde986fde38c052d3ade4215938ec
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Add the additional enumeration through Device Interface Class GUID

The current "Setup Class GUID" approach ignores the devices which has
been created by the drivers with a custom setup GUID's (e.g. Eltima
Virtual Serial Port Driver and so on).

In this case need to add each new custom GUID to the list. But it is
not a good solution and shall be used as a last resort.

The good solution is use of the "Device Interface Class GUID" instead
of the "Setup Class GUID" because it is the recommended way:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff545036%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/hardware/ff545046%28v=vs.85%29.aspx

A new approach uses the standard GUID_DEVINTERFACE_COMPORT and
GUID_DEVINTERFACE_MODEM GUID's which shall be used for the development
of any serial port drivers. Besides requires adding of the additional
DIGCF_DEVICEINTERFACE flag for the SetupDiGetClassDevs() function,
see MSDN:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff551069%28v=vs.85%29.aspx

It should be noted that this approach also can ignore some devices
with drivers which don't use the recommendation. Earlier already
there were attempts to implement this approach but unsuccessful,
see more 3bfe998860e0bfd3ce48784188eaa0d58bf86da1 and
bcdeb589dd9d3b0ff7270d380d043b1882eefdc0 commits.

Thus, it seems effective to use both "Setup Class GUID" and
"Device Interface Class GUID" approaches that will complement each
other. In this case can be keep only the standard GUID's.

1. Now all GUID classes are in the QUuid form and stored in the
constant list of pairs as QPair<uuid, flags>. It allows to avoid the
old heritage related to the pure-C coding style.

2. The second "flags" parameter from the pair is the DWORD input
parameter for the SetupDiGetClassDevs() function which specify the
control options that filter the device information elements. It
allows to pass the appropriate flags for the each used approach
independently.

Tested with the cenumerator example on Windows with Qt4 and then Qt5,
no regressions found.

Task-number: QTBUG-33313
Change-Id: I478905e8ae4b79b7d967e0727d2e1620ad667177
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>