summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2013-07-07 21:29:26 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-08 18:11:14 +0200
commit238309f65ba8faaa0b88a4f3d06a224fe3652467 (patch)
tree15960906f2764d99c18408b3ebb5a33e1c9f37e4
parent5d2f051855fab4499532c9abcc0babf065cdc5d6 (diff)
downloadqtserialport-238309f65ba8faaa0b88a4f3d06a224fe3652467.tar.gz
Revert "Add property to set exclusivity"
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>
-rw-r--r--src/serialport/qserialport.cpp44
-rw-r--r--src/serialport/qserialport.h15
-rw-r--r--src/serialport/qserialport_p.h1
-rw-r--r--src/serialport/qserialport_symbian.cpp6
-rw-r--r--src/serialport/qserialport_symbian_p.h1
-rw-r--r--src/serialport/qserialport_unix.cpp76
-rw-r--r--src/serialport/qserialport_unix_p.h3
-rw-r--r--src/serialport/qserialport_win.cpp6
-rw-r--r--src/serialport/qserialport_win_p.h1
9 files changed, 24 insertions, 129 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index d90b48d..96f06d4 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -73,7 +73,6 @@ QSerialPortPrivateData::QSerialPortPrivateData(QSerialPort *q)
, stopBits(QSerialPort::UnknownStopBits)
, flow(QSerialPort::UnknownFlowControl)
, policy(QSerialPort::IgnorePolicy)
- , exclusiveMode(QSerialPort::FullyExclusive)
, settingsRestoredOnClose(true)
, q_ptr(q)
{
@@ -321,27 +320,6 @@ int QSerialPortPrivateData::timeoutValue(int msecs, int elapsed)
\sa QSerialPort::error
*/
-/*!
- \enum QSerialPort::ExclusiveModeFlag
-
- This enum describes the level of exclusivity to set on the serial port.
-
- \value NotExclusive The serial port may be opened elsewhere even if it
- is open here. This flag only has effect on Unix.
- \value LockFileExclusive A lock file prevents the serial port from being
- opened elsewhere while it is open here. This flag
- only has effect on Unix.
- \value DriverExclusive The serial port driver prevents the serial port
- from being opened elsewhere while it is open here.
- This flag only has effect on Unix if the ioctl
- request TIOCEXCL is available.
- \value FullyExclusive Both the serial port driver and, if on Unix, a
- lock file prevent the serial port from being opened
- elsewhere while it is open here.
-
- \sa QSerialPort::exclusiveMode
-*/
-
/*!
@@ -511,28 +489,6 @@ void QSerialPort::close()
}
/*!
- \property QSerialPort::exclusiveMode
- \brief the exclusivity of this object's claim on the serial port
-
- If the setting is successful, returns true; otherwise returns false. Serial
- ports are set to QSerialPort::FullyExclusive by default.
-
- This flag is always QSerialPort::FullyExclusive on Windows and Symbian and
- cannot be changed.
-*/
-bool QSerialPort::setExclusiveMode(ExclusiveMode exclusiveMode)
-{
- Q_D(QSerialPort);
- return d->setExclusiveMode(exclusiveMode);
-}
-
-QSerialPort::ExclusiveMode QSerialPort::exclusiveMode() const
-{
- Q_D(const QSerialPort);
- return d->exclusiveMode;
-}
-
-/*!
\property QSerialPort::settingsRestoredOnClose
\brief the flag which allows to restore the previous settings while closing
the serial port.
diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h
index 6ec8e25..c193bcd 100644
--- a/src/serialport/qserialport.h
+++ b/src/serialport/qserialport.h
@@ -65,11 +65,10 @@ class Q_SERIALPORT_EXPORT QSerialPort : public QIODevice
Q_PROPERTY(bool dataTerminalReady READ isDataTerminalReady WRITE setDataTerminalReady NOTIFY dataTerminalReadyChanged)
Q_PROPERTY(bool requestToSend READ isRequestToSend WRITE setRequestToSend NOTIFY requestToSendChanged)
Q_PROPERTY(SerialPortError error READ error RESET clearError NOTIFY error)
- Q_PROPERTY(ExclusiveMode exclusiveMode READ exclusiveMode WRITE setExclusiveMode)
Q_PROPERTY(bool settingsRestoredOnClose READ settingsRestoredOnClose WRITE setSettingsRestoredOnClose NOTIFY settingsRestoredOnCloseChanged)
Q_ENUMS(BaudRate DataBits Parity StopBits FlowControl DataErrorPolicy SerialPortError)
- Q_FLAGS(Directions PinoutSignals ExclusiveMode)
+ Q_FLAGS(Directions PinoutSignals)
public:
@@ -161,14 +160,6 @@ public:
UnknownError
};
- enum ExclusiveModeFlag {
- NotExclusive = 0,
- LockFileExclusive = 1,
- DriverExclusive = 2,
- FullyExclusive = LockFileExclusive | DriverExclusive
- };
- Q_DECLARE_FLAGS(ExclusiveMode, ExclusiveModeFlag)
-
explicit QSerialPort(QObject *parent = 0);
explicit QSerialPort(const QString &name, QObject *parent = 0);
explicit QSerialPort(const QSerialPortInfo &info, QObject *parent = 0);
@@ -182,9 +173,6 @@ public:
bool open(OpenMode mode) Q_DECL_OVERRIDE;
void close() Q_DECL_OVERRIDE;
- bool setExclusiveMode(ExclusiveMode exclusiveMode);
- ExclusiveMode exclusiveMode() const;
-
void setSettingsRestoredOnClose(bool restore);
bool settingsRestoredOnClose() const;
@@ -264,7 +252,6 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::Directions)
Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::PinoutSignals)
-Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::ExclusiveMode)
QT_END_NAMESPACE
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index b74cda6..abd9cb6 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -80,7 +80,6 @@ public:
QSerialPort::DataErrorPolicy policy;
bool dataTerminalReady;
bool requestToSend;
- QSerialPort::ExclusiveMode exclusiveMode;
bool settingsRestoredOnClose;
QSerialPort * const q_ptr;
};
diff --git a/src/serialport/qserialport_symbian.cpp b/src/serialport/qserialport_symbian.cpp
index 3e904ab..2bba5a4 100644
--- a/src/serialport/qserialport_symbian.cpp
+++ b/src/serialport/qserialport_symbian.cpp
@@ -158,12 +158,6 @@ void QSerialPortPrivate::close()
descriptor.Close();
}
-bool QSerialPortPrivate::setExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode)
-{
- Q_UNUSED(exclusiveMode);
- return false;
-}
-
QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals() const
{
QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
diff --git a/src/serialport/qserialport_symbian_p.h b/src/serialport/qserialport_symbian_p.h
index 1b235f5..7f9eadd 100644
--- a/src/serialport/qserialport_symbian_p.h
+++ b/src/serialport/qserialport_symbian_p.h
@@ -84,7 +84,6 @@ public:
bool setStopBits(QSerialPort::StopBits stopBits);
bool setFlowControl(QSerialPort::FlowControl flowControl);
bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy);
- bool setExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode);
bool notifyRead();
bool notifyWrite();
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 0e19d05..2f6c8cc 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -139,7 +139,11 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
{
- if (isLockedByFile()) {
+ QByteArray portName = portNameFromSystemLocation(systemLocation).toLocal8Bit();
+ const char *ptr = portName.constData();
+
+ bool byCurrPid = false;
+ if (QTtyLocker::isLocked(ptr, &byCurrPid)) {
q_ptr->setError(QSerialPort::PermissionError);
return false;
}
@@ -165,13 +169,17 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
return false;
}
- if (!changeExclusiveMode(exclusiveMode)) {
- ::close(descriptor);
+ ::fcntl(descriptor, F_SETFL, FNDELAY);
+
+ QTtyLocker::lock(ptr);
+ if (!QTtyLocker::isLocked(ptr, &byCurrPid)) {
q_ptr->setError(QSerialPort::PermissionError);
return false;
}
- ::fcntl(descriptor, F_SETFL, FNDELAY);
+#ifdef TIOCEXCL
+ ::ioctl(descriptor, TIOCEXCL);
+#endif
if (::tcgetattr(descriptor, &restoredTermios) == -1) {
q_ptr->setError(decodeSystemError());
@@ -209,6 +217,10 @@ void QSerialPortPrivate::close()
#endif
}
+#ifdef TIOCNXCL
+ ::ioctl(descriptor, TIOCNXCL);
+#endif
+
if (readNotifier) {
readNotifier->setEnabled(false);
readNotifier->deleteLater();
@@ -227,24 +239,19 @@ void QSerialPortPrivate::close()
exceptionNotifier = 0;
}
- changeExclusiveMode(QSerialPort::NotExclusive);
-
::close(descriptor);
+ QByteArray portName = portNameFromSystemLocation(systemLocation).toLocal8Bit();
+ const char *ptr = portName.constData();
+
+ bool byCurrPid = false;
+ if (QTtyLocker::isLocked(ptr, &byCurrPid) && byCurrPid)
+ QTtyLocker::unlock(ptr);
+
descriptor = -1;
isCustomBaudRateSupported = false;
}
-bool QSerialPortPrivate::setExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode)
-{
- if (descriptor != -1 && !changeExclusiveMode(exclusiveMode)) {
- q_ptr->setError(QSerialPort::PermissionError);
- return false;
- }
- this->exclusiveMode = exclusiveMode;
- return true;
-}
-
QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals() const
{
int arg = 0;
@@ -1333,41 +1340,4 @@ QList<qint32> QSerialPortPrivate::standardBaudRates()
return standardBaudRateMap().keys();
}
-bool QSerialPortPrivate::isLockedByFile()
-{
- QByteArray portName = portNameFromSystemLocation(systemLocation).toLocal8Bit();
- const char *ptr = portName.constData();
- bool byCurrPid;
-
- return QTtyLocker::isLocked(ptr, &byCurrPid);
-}
-
-bool QSerialPortPrivate::changeExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode)
-{
- QByteArray portName = portNameFromSystemLocation(systemLocation).toLocal8Bit();
- const char *ptr = portName.constData();
- bool byCurrPid;
-
- if (exclusiveMode & QSerialPort::LockFileExclusive) {
- QTtyLocker::lock(ptr);
- if (!QTtyLocker::isLocked(ptr, &byCurrPid))
- return false;
- } else {
- if (QTtyLocker::isLocked(ptr, &byCurrPid) && byCurrPid)
- QTtyLocker::unlock(ptr);
- }
-
-#ifdef TIOCEXCL
- if (exclusiveMode & QSerialPort::DriverExclusive) {
- if (::ioctl(descriptor, TIOCEXCL) < 0) {
- QTtyLocker::unlock(ptr);
- return false;
- }
- } else
- ::ioctl(descriptor, TIOCNXCL);
-#endif
-
- return true;
-}
-
QT_END_NAMESPACE
diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h
index 3d96ecb..ce70c24 100644
--- a/src/serialport/qserialport_unix_p.h
+++ b/src/serialport/qserialport_unix_p.h
@@ -91,7 +91,6 @@ public:
bool setStopBits(QSerialPort::StopBits stopBits);
bool setFlowControl(QSerialPort::FlowControl flow);
bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy);
- bool setExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode);
bool readNotification();
bool writeNotification(int maxSize = INT_MAX);
@@ -150,8 +149,6 @@ private:
#endif
qint64 readPerChar(char *data, qint64 maxSize);
- bool isLockedByFile();
- bool changeExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode);
};
QT_END_NAMESPACE
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index dacd57d..c3261a2 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -310,12 +310,6 @@ void QSerialPortPrivate::close()
#endif // #ifndef Q_OS_WINCE
-bool QSerialPortPrivate::setExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode)
-{
- Q_UNUSED(exclusiveMode);
- return false;
-}
-
QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals() const
{
DWORD modemStat = 0;
diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h
index 02810c0..a59ea9a 100644
--- a/src/serialport/qserialport_win_p.h
+++ b/src/serialport/qserialport_win_p.h
@@ -97,7 +97,6 @@ public:
bool setStopBits(QSerialPort::StopBits stopBits);
bool setFlowControl(QSerialPort::FlowControl flowControl);
bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy);
- bool setExclusiveMode(QSerialPort::ExclusiveMode exclusiveMode);
bool processIoErrors(bool error);
#ifndef Q_OS_WINCE