summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialport_unix_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Move all platform-specific declarations into one QSPPrivateDenis Shienkov2014-11-141-194/+0
| | | | | | | | | | This is near to the internal Qt PIMPL style. Also it will allow to use QIODevicePrivate is more smoothly in next patches. Tested on Windows 8, Linux, OSX 10.9 with on-board serial port. Change-Id: Ieef4b05d0bf11cf2da6420e58629bea1818108f9 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Merge remote-tracking branch 'origin/5.3' into 5.4Frederik Gladhorn2014-10-141-1/+4
|\ | | | | | | Change-Id: Id7e66059233e8d07ba44cad19048d9cddc68e250
| * Fix QSP::bytesToWrite() on WindowsDenis Shienkov2014-10-061-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * Fix reading on Windows at limited read buffer sizeDenis Shienkov2014-10-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Update license headers and add new license filesAntti Kokko2014-09-091-18/+10
|/ | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 & LICENSE.GPLv2 - Removed LICENSE.GPL Change-Id: I08685205169cdd4b49a651ed98f36ba1e6c1bb29 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Add missing private headers warningsSamuel Gaist2014-08-181-0/+11
| | | | | Change-Id: Ia60bf0d020d98a6fda8f689d631bb8681950d15f Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Fix leak of a descriptor after unsuccessful openingDenis Shienkov2014-07-311-0/+1
| | | | | | | | | In case of unsuccessful initialization of a device at the opening, a valid descriptor has to be closed before return from the open() method. Task-number: QTBUG-40414 Change-Id: I45568f176e003d9be1fe8c3017da29f39908efb0 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Remove the exception notifier handling for *nixDenis Shienkov2014-06-121-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The exception notifier does not do any useful operation while processing I/O but only complicates error handling. It has been thoughtlessly introduced at beginning in hope that in the future it can it is useful, but the practice showed that it not so. Problem is that in case of ejection of an open USB device from a host there is the infinite triggering of the exception notifier that leads to program hangup. We could stop an exception notifier in this case, but it not rationally because after the exception notifier is triggered the read notifier which also enters the infinite loop. Thus the read notifier anyway duplicates the exception notifier, as for functionality and as for an error code. Therefore more rationally to completely remove the exception notifier. So in case of the ResourceError we need just to stop of the read notifier, because it is a critical error. Then an user will be notified on the ResourceError appearance and must to close the device himself. Though work was checked only on Linux, but we can do not worry, and to refuse from this notifier in MacOSX also. Because anyway in MacOSX this type of notifier is not supported, at least from the Qt 5.1 and above: https://qt.gitorious.org/qt/qtbase/source/982fdd4ef556f63ba77384a0dbe97928e610091b:src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp#L210 Besides in documentation on QSocketNotifier is recommended do not use the Exception mode: http://qt-project.org/doc/qt-5/qsocketnotifier.html#Type-enum Tested on ArchLinux 64 bit with the USB PL2303 device, ZTE modem, Android serial port using Qt4 and then Qt5. Task-number: QTBUG-36727 Task-number: QTBUG-35829 Change-Id: I4ea6db2a1c7f10c096d57817c00edefc4f0595ff Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Peter Kümmel <syntheticpp@gmx.net> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Refactor unix setBaudRate() error handlingRafael Roquetto2014-05-271-3/+5
| | | | | | | | Return QSerialPort::SerialPortError instead of bool Change-Id: I79d731c1a0178ef0238495d7e9bb3e1b866e82c0 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Refactor QSerialPortPrivate::setBaudRate()Rafael Roquetto2014-05-141-5/+4
| | | | | | | | | | | Split platform specific functions into their own setCustomBaudRate() methods to improve readability. As a side-effect, remove isCustomBaudRateSupported flag. Change-Id: Ia26d5472219756fbf186c78aa049bba72966d7b5 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Make it possible to set the port values before openingLaszlo Papp2014-03-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch also changes the behavior of the open method. We do not use port detection anymore for good. It has been a broken concept, and it is very unlikely that anyone has ever relied on it. If anyone had done that, they would be in trouble anyway, getting noisy warnings needlessly and all that. The other option was also considered to keep this behavior optionally as the default, but that would complicate the API too much without not much gain. The default port settings are now also the sane 9600,8,N,1, and no flow control. Also please note that the serial port is closed automatically in the open method if any of the settings fails. Several subsequent changes can follow this one, namely: * Changing the examples to show this usage. * Add a QSerialPortSettings data structure as it seems to be common currently in client codes. * Add the QML plugin with only thin wrapper declarative classes and all that. * Deprecate the restore settings on close API. * Remove the internal current and restored data representations. * Add further error values to the API for the fine tuning of the error reporting when there are setting errors on open. * Add proper test coverage. In short, this change opens the gate up for many interesting subsequent changes that would be useful for the module overall. In general, this change makes it possible to reach the feature parity with QextSerialPort so that we are not much worse anymore. We could do the same that QextSerialPort could do many years ago, already. Task-number: QTBUG-33774 Change-Id: I8527672f8b0bb2581fa7054ccffda66ab7fa4a85 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Rename the flow to flowControl for consistencyLaszlo Papp2014-03-011-1/+1
| | | | | Change-Id: Ida3c4ff049f21bd96fd64b41c66787b3961ada5e Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Do not emit bytesWritten() while data aren't transferredDenis Shienkov2014-02-121-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The serial port very slow device therefore the system call write() doesn't guarantee that data were transferred completely to the device. It guarantee only that data were sent to the driver from the user space. Thus it is wrong to emit the bytesWritten() signal at once after successful writing. The correct solution is to store the number of transferred data in some variable (e.g. pendingBytesWritten in this case) and to wait for the next notification from the WriteNotifier that the write FIFO of device is empty (i.e. when all data were really transferred) and ready to transmission of the next portion of data. Also good decision is to divide a data transfer operation into two methods: startAsyncWrite() and completeAsyncWrite(), similar with the Windows implementation. Where the startAsyncWrite() invokes the write() system call, and the completeAsyncWrite() is invoked by a writeNotifier to complete writing operation or start a new startAsyncWrite() operation. Tested on Arch Linux 64 bit with the on-board and the USB (PL2303) serial ports with use Qt4 and then Qt5. Change-Id: I1c274b2052a9bd54811586c6f1cfdf080b400263 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Remove the unused SystemIn/OutputQueue size methodsLaszlo Papp2014-02-091-3/+0
| | | | | | Change-Id: Iafab6ccc376da7a856b409017bbc42c36c016253 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Add error handling to some missing functionsLaszlo Papp2014-02-081-2/+2
| | | | | | Change-Id: If8dee1819d493fa4b27eba99de611c61bfdfe7a3 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Optimize access to the write bufferDenis Shienkov2014-01-151-1/+1
| | | | | | | | | | | | | | | Earlier for writing in writeBuffer was used the QSerialPortPrivate::writeToBuffer() method which contained a similar code for each platform. Therefore it is reasonable to delete this method, and to move its common functionality to the QSerialPort::writeData(). Also all platform-dependent code of start of data transfer move to the QSerialPortPrivate::startWriting() method. Change-Id: I1423723fd69c05df974f8ba597e3dd71d5a797dd Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Reimplement low level data sendingDenis Shienkov2013-12-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | A feature of writing of the buffer by chunks of 512 bytes (by default) was introduced earlier as the developers option in order that it was possible to regulate load of the CPU and quantity of emitted signals of bytesWritten() just change WriteChunkSize value in source code. As shows of the practice, the most optimal mode is writing of whole content of the buffer without division into chunks. It reduces load of CPU (because reduces a quantity of the events triggers) and also simplifies the source code. But potentially there can be negative consequences of writing of whole buffer directly in case of broken driver: * A kernel panic (or BSOD) in case of writing a data large than driver's internal queue. * Can be transferred not all data from the buffer, but only their part. Change-Id: I0fcac1ccf3c752579978b4745771accbf8274267 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Use direct access to the read bufferDenis Shienkov2013-11-281-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Replace the home-grown QTtyLocker with QLockFileLaszlo Papp2013-11-061-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This can be more widely adopted later, and not just for the Linux backend. It would be more than a few-liner change for stable, so this change change is kept minimal (of course apart from the big file integration). The only big problem with QLockFile currently is that we cannot change the file name on the fly as it seems, just for construction. Even the copy constructor and assignment operators are private. It means the class currently seems to be non-eligible for QtSerialPort needs where it is necessary to change for open anytime, and be accessible by open/serial for the before and after read/write session for the same file name. Also, I had to get rid of the QTemporary file internals because we cannot have access to the internal engine with Qt 4. I also had to make a small thread class for the protected msleep in QThread for Qt 4. There was a small improvement for the hidden dependency problem with gethostname. That was also sent to QtCore proper. Also, the windows backend for the QLockFile class is not copied for simplicity. It would not be used as of now. There is also a short convenience around QLockFile established to handle system-wide lock file paths. There is also some error handling added if the lock directory paths are not readable or writable. This will end users identify the problems like on Android. Tested on Archlinux with Qt 4 and then 5. Task-number: QTBUG-34474 Change-Id: I7adf29527c01ad331d3eeff5ae4c5a4113bde083 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Make the return value void for methods that would always return trueLaszlo Papp2013-10-301-1/+1
| | | | | | Change-Id: Iaa869b8b618db630d46726d7ebeac83e8a826af3 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Use the term 'directions' for representing the directionsLaszlo Papp2013-09-041-2/+2
| | | | | | | | | | | | 1) The previous 'dir' is incorrect because it should be plural for consistency based upon the other variable names. 2) 'dir' can be misleading in the context where such a term is also used for representing a directory, like in our case. Change-Id: I650cc64c2669286a4d7ef071a2ab3b7b63228977 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Fix the compilation for Android with Qt 5.Laszlo Papp2013-09-031-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1) The termios struct is basically copied and pasted from the documentation: http://linux.die.net/man/3/termios Since, it is just an interface without complicated methods, it is not copyrightable, so it is safe enough. 2) This is also the same situation with the two defines we need for the kernel interface. They are just interface numbers, and not something that copyrightable. This has also been double checked and discussed with Lars in email. 3) The ::tcdrain convenience method cannot be used on Android, so the fallback "raw" ioctl syscall is used with the relevant parameters, e.g. TCSBREAK. http://linux.die.net/man/3/tcdrain 5) cfsetspeed seems to be a BSD 4.4 extension based on the termios(3) man page: http://linux.die.net/man/3/termios "cfsetspeed() is a 4.4BSD extension. It takes the same arguments as cfsetispeed(), and sets both input and output speed." ... hence this is replaced with separate calls for input and output without a specific Android "ifdef" in the code. It is actually also more consistent with the setcfispeed and setcfospeed just right above that snippet. Task-number: QTBUG-33139 Change-Id: If0abb8cec9e900fa2b6fc24df938cb778a344d55 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Eliminate the "q_ptr->" call by using Q_Q(QSerialPort)Laszlo Papp2013-07-281-0/+2
| | | | | | | | | | | Unfortunately, the q_ptr data member cannot yet be deleted from the internal data class because QIODevicePrivate would need to be inherited then. That is not a simple change considering the Qt4 support. Hence, that part of the logic is put on hold, but can be expected in an upcoming change at some point, soon. Change-Id: Ic8ba9621dd647f4afa1b91d01c858c836d1cc0c8 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Remove the const modifier from the pinoutSignals internal methodsLaszlo Papp2013-07-271-1/+1
| | | | | | | | | Logically, these methods set the error on their member, the public QSerialPort class, hence these are not const methods similarly to the public variant. Change-Id: I1580cf371556c820ce8e7df43121bc2800b08b40 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Revert "Add property to set exclusivity"Laszlo Papp2013-07-081-3/+0
| | | | | | | | | | | | | | | | | | | This reverts commit 4c67500e5d14e561e37b4bdc056f059d3eefdfa4. "dev: unfrozen branch, containing alpha-quality code that is ready to go into beta testing at any time" ... from: http://qt-project.org/wiki/Branch-Guidelines Please respect the basic principles. In doubts, do not approve changes yourself, but ask for help. Besides the illegit nature of this change, it has fundamental documentation issues as well. It is summer, and this can wait until 5.2, so please do /not/ rush with approvals. Change-Id: Ic2763394035c776088cb28f9c04086920cedb3a2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add property to set exclusivityAlex Henrie2013-07-031-0/+3
| | | | | | | | | Disabling the serial port driver's exclusive mode is necessary for pseudo serial ports and some USB/serial adapters to work correctly. Change-Id: I74d45feed619817b61e265b00aec8b0ebfae7a33 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Update the documentation and internal setBreakEnabled APILaszlo Papp2013-05-061-1/+1
| | | | | | | | | | | | | The change 0add3b934b8405fc5b65efeba9f05cc1dc353e64 changed the API, and we had a compromise in there to get the API changes in as soon as possible. This change tries to address the suggested documentation and internal API changes. Only tested on Linux with Qt 4.8.4 and Qt 5.1, so it might break on other platforms. Change-Id: I153e5a35d76beb26e04dbabf184bc9b90ef4b70b Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Drop the Lines/Line terms in favor of PinoutSignals/SignalLaszlo Papp2013-02-221-1/+1
| | | | | | | Change-Id: Icc8c52dd32f918f13e9221e32ab7eeb11217f054 Reviewed-by: Ray Donnelly <mingw.android@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Remove the QtSerialPort namespace define and hence namespace usageLaszlo Papp2013-02-071-4/+0
| | | | | | | | | | * This is for following the convention in the Qt Project with the rest. * This fixes examples and tests to build now as all of them are broken due to the regression. Change-Id: I3f4d64d97466520aea621da582a64a0d97e32136 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Fix the potential build breaks introduced by a previous commit (regression)Laszlo Papp2013-02-071-0/+4
| | | | | | | | | | | | | This is due to the fact the Qt namespace is not considered which is normally not a problem as it is empty by default. However, using something like "-qtnamespace MyNamespace" when configuring Qt will break the QtSerialPort build completely. This is intended to be a fix for the library, and the examples/tests will be fixed in a separate commit if necessary. Change-Id: Iecd24dc5135c3a9645910754589dfd8bf4942337 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Change the Dtr/Rts API to something less cryptic and more Qt'ishLaszlo Papp2013-02-021-2/+2
| | | | | | Change-Id: Ic7992e62d50a787d8ad657504e1768ab0061ed31 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Rename the PortError to SerialPortError to be more consistent and talkativeLaszlo Papp2013-02-021-1/+1
| | | | | | | | | It is necessary not to get a potential Error enumeration overridden in QIODevice in order to be specific. It is also how other QIODevice subclasses handle the API more or less. Change-Id: I9f5b5601118be4b7a285b965ea5ea5e995848e8e Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
* Make all the file renames and relevant changesLaszlo Papp2013-01-271-0/+156
"git log --follow /path/to/the/file/in/question" can be used, for instance, for the renamed files to get the whole history. Change-Id: I20da087ca88e2c179a6c3232772fa21575e0aa6a Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>