summaryrefslogtreecommitdiffstats
path: root/src/serialport/qt4support
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-10-23 16:20:03 +0400
committerDenis Shienkov <denis.shienkov@gmail.com>2014-10-23 19:50:22 +0200
commit0c2819dafa67d5989ffb82283c36e1916db732b7 (patch)
tree05529ec198803a104ff0655a51c1f6dfaf285ce2 /src/serialport/qt4support
parentb7707238c85db36041a5fb6c4eda4c689835690a (diff)
Drop the Qt4 support
Now QtSerialPort can be built for Qt5 only. QtSerialPort for Qt4 is developed in a separate branch. Change-Id: Iaaa95fb7cb0aedbfc1b17ed11717fff8f9c126a0 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'src/serialport/qt4support')
-rw-r--r--src/serialport/qt4support/include/QtCore/qlockfile.h79
-rw-r--r--src/serialport/qt4support/include/QtCore/qwineventnotifier.h79
-rw-r--r--src/serialport/qt4support/include/private/qcore_mac_p.h140
-rw-r--r--src/serialport/qt4support/include/private/qcore_unix_p.h116
-rw-r--r--src/serialport/qt4support/include/private/qlockfile_p.h96
-rw-r--r--src/serialport/qt4support/include/private/qringbuffer_p.h311
-rw-r--r--src/serialport/qt4support/install-helper.pri52
-rw-r--r--src/serialport/qt4support/serialport.prf27
-rw-r--r--src/serialport/qt4support/src/qlockfile.cpp344
-rw-r--r--src/serialport/qt4support/src/qlockfile_unix.cpp191
10 files changed, 0 insertions, 1435 deletions
diff --git a/src/serialport/qt4support/include/QtCore/qlockfile.h b/src/serialport/qt4support/include/QtCore/qlockfile.h
deleted file mode 100644
index a35eee52..00000000
--- a/src/serialport/qt4support/include/QtCore/qlockfile.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLOCKFILE_H
-#define QLOCKFILE_H
-
-#include <QtCore/qstring.h>
-#include <QtCore/qscopedpointer.h>
-
-QT_BEGIN_NAMESPACE
-
-class QLockFilePrivate;
-
-class Q_CORE_EXPORT QLockFile
-{
-public:
- QLockFile(const QString &fileName);
- ~QLockFile();
-
- bool lock();
- bool tryLock(int timeout = 0);
- void unlock();
-
- void setStaleLockTime(int);
- int staleLockTime() const;
-
- bool isLocked() const;
- bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
- bool removeStaleLockFile();
-
- enum LockError {
- NoError = 0,
- LockFailedError = 1,
- PermissionError = 2,
- UnknownError = 3
- };
- LockError error() const;
-
-protected:
- QScopedPointer<QLockFilePrivate> d_ptr;
-
-private:
- Q_DECLARE_PRIVATE(QLockFile)
- Q_DISABLE_COPY(QLockFile)
-};
-
-QT_END_NAMESPACE
-
-#endif // QLOCKFILE_H
diff --git a/src/serialport/qt4support/include/QtCore/qwineventnotifier.h b/src/serialport/qt4support/include/QtCore/qwineventnotifier.h
deleted file mode 100644
index 6d835925..00000000
--- a/src/serialport/qt4support/include/QtCore/qwineventnotifier.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QWINEVENTNOTIFIER_H
-#define QWINEVENTNOTIFIER_H
-
-#include "QtCore/qobject.h"
-
-#ifdef Q_OS_WIN
-#include "QtCore/qt_windows.h"
-
-QT_BEGIN_NAMESPACE
-
-class Q_CORE_EXPORT QWinEventNotifier : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QObject)
-
-public:
- explicit QWinEventNotifier(QObject *parent = 0);
- explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0);
- ~QWinEventNotifier();
-
- void setHandle(HANDLE hEvent);
- HANDLE handle() const;
-
- bool isEnabled() const;
-
-public Q_SLOTS:
- void setEnabled(bool enable);
-
-Q_SIGNALS:
- void activated(HANDLE hEvent);
-
-protected:
- bool event(QEvent * e);
-
-private:
- Q_DISABLE_COPY(QWinEventNotifier)
-
- HANDLE handleToEvent;
- bool enabled;
-};
-
-QT_END_NAMESPACE
-
-#endif // Q_OS_WIN
-
-#endif // QWINEVENTNOTIFIER_H
diff --git a/src/serialport/qt4support/include/private/qcore_mac_p.h b/src/serialport/qt4support/include/private/qcore_mac_p.h
deleted file mode 100644
index a5c79fa8..00000000
--- a/src/serialport/qt4support/include/private/qcore_mac_p.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCORE_MAC_P_H
-#define QCORE_MAC_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef __IMAGECAPTURE__
-# define __IMAGECAPTURE__
-#endif
-
-#if defined(QT_BOOTSTRAPPED)
-#include <ApplicationServices/ApplicationServices.h>
-#else
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
-#include "qglobal.h"
-
-#ifdef Q_OS_MACX
-#include <CoreServices/CoreServices.h>
-#endif
-
-#ifdef __OBJC__
-#include <Foundation/Foundation.h>
-#endif
-
-#include "qstring.h"
-
-#if defined( __OBJC__) && defined(QT_NAMESPACE)
-#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__) @compatibility_alias __KLASS__ QT_MANGLE_NAMESPACE(__KLASS__)
-#else
-#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__)
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*
- Helper class that automates refernce counting for CFtypes.
- After constructing the QCFType object, it can be copied like a
- value-based type.
-
- Note that you must own the object you are wrapping.
- This is typically the case if you get the object from a Core
- Foundation function with the word "Create" or "Copy" in it. If
- you got the object from a "Get" function, either retain it or use
- constructFromGet(). One exception to this rule is the
- HIThemeGet*Shape functions, which in reality are "Copy" functions.
-*/
-template <typename T>
-class Q_CORE_EXPORT QCFType
-{
-public:
- inline QCFType(const T &t = 0) : type(t) {}
- inline QCFType(const QCFType &helper) : type(helper.type) { if (type) CFRetain(type); }
- inline ~QCFType() { if (type) CFRelease(type); }
- inline operator T() { return type; }
- inline QCFType operator =(const QCFType &helper)
- {
- if (helper.type)
- CFRetain(helper.type);
- CFTypeRef type2 = type;
- type = helper.type;
- if (type2)
- CFRelease(type2);
- return *this;
- }
- inline T *operator&() { return &type; }
- template <typename X> X as() const { return reinterpret_cast<X>(type); }
- static QCFType constructFromGet(const T &t)
- {
- CFRetain(t);
- return QCFType<T>(t);
- }
-protected:
- T type;
-};
-
-class Q_CORE_EXPORT QCFString : public QCFType<CFStringRef>
-{
-public:
- inline QCFString(const QString &str) : QCFType<CFStringRef>(0), string(str) {}
- inline QCFString(const CFStringRef cfstr = 0) : QCFType<CFStringRef>(cfstr) {}
- inline QCFString(const QCFType<CFStringRef> &other) : QCFType<CFStringRef>(other) {}
- operator QString() const;
- operator CFStringRef() const;
- static QString toQString(CFStringRef cfstr);
- static CFStringRef toCFStringRef(const QString &str);
-#ifdef __OBJC__
- static QString toQString(const NSString *nsstr);
- static NSString *toNSString(const QString &string);
-#endif
-
-private:
- QString string;
-};
-
-QT_END_NAMESPACE
-
-#endif // QCORE_MAC_P_H
diff --git a/src/serialport/qt4support/include/private/qcore_unix_p.h b/src/serialport/qt4support/include/private/qcore_unix_p.h
deleted file mode 100644
index 6a7fb725..00000000
--- a/src/serialport/qt4support/include/private/qcore_unix_p.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCORE_UNIX_P_H
-#define QCORE_UNIX_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of Qt code on Unix. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qplatformdefs.h"
-
-#ifndef Q_OS_UNIX
-# error "qcore_unix_p.h included on a non-Unix system"
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <errno.h>
-#include <fcntl.h>
-
-#define EINTR_LOOP(var, cmd) \
- do { \
- var = cmd; \
- } while (var == -1 && errno == EINTR)
-
-QT_BEGIN_NAMESPACE
-
-// don't call QT_OPEN or ::open
-// call qt_safe_open
-static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777)
-{
-#ifdef O_CLOEXEC
- flags |= O_CLOEXEC;
-#endif
- register int fd;
- EINTR_LOOP(fd, QT_OPEN(pathname, flags, mode));
-
- // unknown flags are ignored, so we have no way of verifying if
- // O_CLOEXEC was accepted
- if (fd != -1)
- ::fcntl(fd, F_SETFD, FD_CLOEXEC);
- return fd;
-}
-#undef QT_OPEN
-#define QT_OPEN qt_safe_open
-
-static inline qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
-{
- qint64 ret = 0;
- EINTR_LOOP(ret, QT_READ(fd, data, maxlen));
- return ret;
-}
-#undef QT_READ
-#define QT_READ qt_safe_read
-
-static inline qint64 qt_safe_write(int fd, const void *data, qint64 len)
-{
- qint64 ret = 0;
- EINTR_LOOP(ret, QT_WRITE(fd, data, len));
- return ret;
-}
-#undef QT_WRITE
-#define QT_WRITE qt_safe_write
-
-static inline int qt_safe_close(int fd)
-{
- register int ret;
- EINTR_LOOP(ret, QT_CLOSE(fd));
- return ret;
-}
-#undef QT_CLOSE
-#define QT_CLOSE qt_safe_close
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/serialport/qt4support/include/private/qlockfile_p.h b/src/serialport/qt4support/include/private/qlockfile_p.h
deleted file mode 100644
index ec36733e..00000000
--- a/src/serialport/qt4support/include/private/qlockfile_p.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLOCKFILE_P_H
-#define QLOCKFILE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qlockfile.h>
-#include <QtCore/qfile.h>
-
-#ifdef Q_OS_WIN
-#include <qt_windows.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QLockFilePrivate
-{
-public:
- QLockFilePrivate(const QString &fn)
- : fileName(fn),
-#ifdef Q_OS_WIN
- fileHandle(INVALID_HANDLE_VALUE),
-#else
- fileHandle(-1),
-#endif
- staleLockTime(30 * 1000), // 30 seconds
- lockError(QLockFile::NoError),
- isLocked(false)
- {
- }
- QLockFile::LockError tryLock_sys();
- bool removeStaleLock();
- bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
- // Returns \c true if the lock belongs to dead PID, or is old.
- // The attempt to delete it will tell us if it was really stale or not, though.
- bool isApparentlyStale() const;
-
-#ifdef Q_OS_UNIX
- static int checkFcntlWorksAfterFlock();
-#endif
-
- QString fileName;
-#ifdef Q_OS_WIN
- Qt::HANDLE fileHandle;
-#else
- int fileHandle;
-#endif
- int staleLockTime; // "int milliseconds" is big enough for 24 days
- QLockFile::LockError lockError;
- bool isLocked;
-};
-
-QT_END_NAMESPACE
-
-#endif /* QLOCKFILE_P_H */
diff --git a/src/serialport/qt4support/include/private/qringbuffer_p.h b/src/serialport/qt4support/include/private/qringbuffer_p.h
deleted file mode 100644
index 2279f1bc..00000000
--- a/src/serialport/qt4support/include/private/qringbuffer_p.h
+++ /dev/null
@@ -1,311 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QRINGBUFFER_P_H
-#define QRINGBUFFER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of a number of Qt sources files. This header file may change from
-// version to version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qlist.h>
-
-QT_BEGIN_NAMESPACE
-
-class QRingBuffer
-{
-public:
- explicit inline QRingBuffer(int growth = 4096) :
- head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) {
- buffers.append(QByteArray());
- }
-
- inline int nextDataBlockSize() const {
- return (tailBuffer == 0 ? tail : buffers.first().size()) - head;
- }
-
- inline const char *readPointer() const {
- return buffers.isEmpty() ? 0 : (buffers.first().constData() + head);
- }
-
- // access the bytes at a specified position
- // the out-variable length will contain the amount of bytes readable
- // from there, e.g. the amount still the same QByteArray
- inline const char *readPointerAtPosition(qint64 pos, qint64 &length) const {
- if (pos >= 0) {
- pos += head;
- for (int i = 0; i < buffers.size(); ++i) {
- length = (i == tailBuffer ? tail : buffers[i].size());
- if (length > pos) {
- length -= pos;
- return buffers[i].constData() + pos;
- }
- pos -= length;
- }
- }
-
- length = 0;
- return 0;
- }
-
- inline void free(int bytes) {
- while (bytes > 0) {
- int blockSize = buffers.first().size() - head;
-
- if (tailBuffer == 0 || blockSize > bytes) {
- bufferSize -= bytes;
- if (bufferSize <= 0)
- clear(); // try to minify/squeeze us
- else
- head += bytes;
- return;
- }
-
- bufferSize -= blockSize;
- bytes -= blockSize;
- buffers.removeFirst();
- --tailBuffer;
- head = 0;
- }
- }
-
- inline char *reserve(int bytes) {
- if (bytes <= 0)
- return 0;
-
- // if need buffer reallocation
- if (tail + bytes > buffers.last().size()) {
- if (tail >= basicBlockSize) {
- // shrink this buffer to its current size
- buffers.last().resize(tail);
-
- // create a new QByteArray
- buffers.append(QByteArray());
- ++tailBuffer;
- tail = 0;
- }
- buffers.last().resize(qMax(basicBlockSize, tail + bytes));
- }
-
- char *writePtr = buffers.last().data() + tail;
- bufferSize += bytes;
- tail += bytes;
- return writePtr;
- }
-
- inline void truncate(int pos) {
- if (pos < size())
- chop(size() - pos);
- }
-
- inline void chop(int bytes) {
- while (bytes > 0) {
- if (tailBuffer == 0 || tail > bytes) {
- bufferSize -= bytes;
- if (bufferSize <= 0)
- clear(); // try to minify/squeeze us
- else
- tail -= bytes;
- return;
- }
-
- bufferSize -= tail;
- bytes -= tail;
- buffers.removeLast();
- --tailBuffer;
- tail = buffers.last().size();
- }
- }
-
- inline bool isEmpty() const {
- return tailBuffer == 0 && tail == 0;
- }
-
- inline int getChar() {
- if (isEmpty())
- return -1;
- char c = *readPointer();
- free(1);
- return int(uchar(c));
- }
-
- inline void putChar(char c) {
- char *ptr = reserve(1);
- *ptr = c;
- }
-
- inline void ungetChar(char c) {
- --head;
- if (head < 0) {
- buffers.prepend(QByteArray());
- buffers.first().resize(basicBlockSize);
- head = basicBlockSize - 1;
- ++tailBuffer;
- }
- buffers.first()[head] = c;
- ++bufferSize;
- }
-
- inline int size() const {
- return bufferSize;
- }
-
- inline void clear() {
- buffers.erase(buffers.begin() + 1, buffers.end());
- buffers.first().clear();
-
- head = tail = 0;
- tailBuffer = 0;
- bufferSize = 0;
- }
-
- inline int indexOf(char c) const {
- int index = 0;
- int j = head;
- for (int i = 0; i < buffers.size(); ++i) {
- const char *ptr = buffers[i].constData() + j;
- j = index + (i == tailBuffer ? tail : buffers[i].size()) - j;
-
- while (index < j) {
- if (*ptr++ == c)
- return index;
- ++index;
- }
- j = 0;
- }
- return -1;
- }
-
- inline int indexOf(char c, int maxLength) const {
- int index = 0;
- int j = head;
- for (int i = 0; index < maxLength && i < buffers.size(); ++i) {
- const char *ptr = buffers[i].constData() + j;
- j = qMin(index + (i == tailBuffer ? tail : buffers[i].size()) - j, maxLength);
-
- while (index < j) {
- if (*ptr++ == c)
- return index;
- ++index;
- }
- j = 0;
- }
- return -1;
- }
-
- inline int read(char *data, int maxLength) {
- int bytesToRead = qMin(size(), maxLength);
- int readSoFar = 0;
- while (readSoFar < bytesToRead) {
- int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, nextDataBlockSize());
- if (data)
- memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock);
- readSoFar += bytesToReadFromThisBlock;
- free(bytesToReadFromThisBlock);
- }
- return readSoFar;
- }
-
- // read an unspecified amount (will read the first buffer)
- inline QByteArray read() {
- if (bufferSize == 0)
- return QByteArray();
-
- QByteArray qba(buffers.takeFirst());
-
- qba.reserve(0); // avoid that resizing needlessly reallocates
- if (tailBuffer == 0) {
- qba.resize(tail);
- tail = 0;
- buffers.append(QByteArray());
- } else {
- --tailBuffer;
- }
- qba.remove(0, head); // does nothing if head is 0
- head = 0;
- bufferSize -= qba.size();
- return qba;
- }
-
- // append a new buffer to the end
- inline void append(const QByteArray &qba) {
- if (tail == 0) {
- buffers.last() = qba;
- } else {
- buffers.last().resize(tail);
- buffers.append(qba);
- ++tailBuffer;
- }
- tail = qba.size();
- bufferSize += tail;
- }
-
- inline int skip(int length) {
- return read(0, length);
- }
-
- inline int readLine(char *data, int maxLength) {
- if (!data || --maxLength <= 0)
- return -1;
-
- int i = indexOf('\n', maxLength);
- i = read(data, i >= 0 ? (i + 1) : maxLength);
-
- // Terminate it.
- data[i] = '\0';
- return i;
- }
-
- inline bool canReadLine() const {
- return indexOf('\n') >= 0;
- }
-
-private:
- QList<QByteArray> buffers;
- int head, tail;
- int tailBuffer; // always buffers.size() - 1
- const int basicBlockSize;
- int bufferSize;
-};
-
-QT_END_NAMESPACE
-
-#endif // QRINGBUFFER_P_H
diff --git a/src/serialport/qt4support/install-helper.pri b/src/serialport/qt4support/install-helper.pri
deleted file mode 100644
index a8607587..00000000
--- a/src/serialport/qt4support/install-helper.pri
+++ /dev/null
@@ -1,52 +0,0 @@
-QTSERIALPORT_PROJECT_INCLUDEDIR = $$QTSERIALPORT_BUILD_ROOT/include/QtSerialPort
-QTSERIALPORT_PROJECT_INCLUDEDIR ~=s,/,$$QMAKE_DIR_SEP,
-
-system("$$QMAKE_MKDIR $$QTSERIALPORT_PROJECT_INCLUDEDIR")
-
-for(header_file, PUBLIC_HEADERS) {
- header_file ~=s,/,$$QMAKE_DIR_SEP,
- system("$$QMAKE_COPY \"$${header_file}\" \"$$QTSERIALPORT_PROJECT_INCLUDEDIR\"")
-}
-
-unix:!symbian {
- SOURCES += \
- $$PWD/src/qlockfile.cpp \
- $$PWD/src/qlockfile_unix.cpp
-}
-
-# This is a quick workaround for generating forward header with Qt4.
-
-!equals(QMAKE_HOST.os, Windows): maybe_quote = "\'"
-system("echo $${maybe_quote}$${LITERAL_HASH}include \"qserialport.h\"$${maybe_quote} > \"$$QTSERIALPORT_PROJECT_INCLUDEDIR/QSerialPort\"")
-system("echo $${maybe_quote}$${LITERAL_HASH}include \"qserialportinfo.h\"$${maybe_quote} > \"$$QTSERIALPORT_PROJECT_INCLUDEDIR/QSerialPortInfo\"")
-
-PUBLIC_HEADERS += \
- $$PUBLIC_HEADERS \
- \"$$QTSERIALPORT_PROJECT_INCLUDEDIR/QSerialPort\" \
- \"$$QTSERIALPORT_PROJECT_INCLUDEDIR/QSerialPortInfo\"
-
-target_headers.files = $$PUBLIC_HEADERS
-target_headers.path = $$[QT_INSTALL_HEADERS]/QtSerialPort
-INSTALLS += target_headers
-
-mkspecs_features.files = $$QTSERIALPORT_PROJECT_ROOT/src/serialport/qt4support/serialport.prf
-mkspecs_features.path = $$[QT_INSTALL_DATA]/mkspecs/features
-INSTALLS += mkspecs_features
-
-win32 {
- dlltarget.path = $$[QT_INSTALL_BINS]
- INSTALLS += dlltarget
-}
-
-target.path = $$[QT_INSTALL_LIBS]
-INSTALLS += target
-
-INCLUDEPATH += $$QTSERIALPORT_BUILD_ROOT/include $$QTSERIALPORT_BUILD_ROOT/include/QtSerialPort
-lessThan(QT_MAJOR_VERSION, 5) {
- QTSERIALPORT_PROJECT_QT4SUPPORT_INCLUDEDIR = $$QTSERIALPORT_PROJECT_ROOT/src/serialport/qt4support/include
- INCLUDEPATH += \
- $$QTSERIALPORT_PROJECT_QT4SUPPORT_INCLUDEDIR \
- $$QTSERIALPORT_PROJECT_QT4SUPPORT_INCLUDEDIR/QtCore \
- $$QTSERIALPORT_PROJECT_QT4SUPPORT_INCLUDEDIR/private
-}
-DEFINES += QT_BUILD_SERIALPORT_LIB
diff --git a/src/serialport/qt4support/serialport.prf b/src/serialport/qt4support/serialport.prf
deleted file mode 100644
index b1d65e11..00000000
--- a/src/serialport/qt4support/serialport.prf
+++ /dev/null
@@ -1,27 +0,0 @@
-!mac:qtAddLibrary(QtSerialPort)
-
-!isEmpty(QTSERIALPORT_BUILD_ROOT) {
- INCLUDEPATH -= $$QMAKE_INCDIR_QT/QtSerialPort
- QMAKE_INCDIR += $$QTSERIALPORT_BUILD_ROOT/include $$QTSERIALPORT_BUILD_ROOT/include/QtSerialPort
-
- QTSERIALPORT_BUILD_SUBDIR = src/serialport
- debug_and_release_target {
- CONFIG(debug, debug|release) {
- QTSERIALPORT_BUILD_SUBDIR = $$QTSERIALPORT_BUILD_SUBDIR/debug
- } else {
- QTSERIALPORT_BUILD_SUBDIR = $$QTSERIALPORT_BUILD_SUBDIR/release
- }
- }
-
- QMAKE_LIBDIR += $$QTSERIALPORT_BUILD_ROOT/$$QTSERIALPORT_BUILD_SUBDIR
-}
-
-mac {
- INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtSerialPort
-
- if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
- LIBS += -lQtSerialPort$${QT_LIBINFIX}_debug
- } else {
- LIBS += -lQtSerialPort$${QT_LIBINFIX}
- }
-}
diff --git a/src/serialport/qt4support/src/qlockfile.cpp b/src/serialport/qt4support/src/qlockfile.cpp
deleted file mode 100644
index 1f406cf1..00000000
--- a/src/serialport/qt4support/src/qlockfile.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qlockfile.h"
-#include "qlockfile_p.h"
-
-#include <QtCore/qthread.h>
-#include <QtCore/qelapsedtimer.h>
-#include <QtCore/qdatetime.h>
-
-QT_BEGIN_NAMESPACE
-
-class QLockFileThread : public QThread
-{
-public:
- static void msleep(unsigned long msecs) { QThread::msleep(msecs); }
-};
-
-/*!
- \class QLockFile
- \inmodule QtCore
- \brief The QLockFile class provides locking between processes using a file.
- \since 5.1
-
- A lock file can be used to prevent multiple processes from accessing concurrently
- the same resource. For instance, a configuration file on disk, or a socket, a port,
- a region of shared memory...
-
- Serialization is only guaranteed if all processes that access the shared resource
- use QLockFile, with the same file path.
-
- QLockFile supports two use cases:
- to protect a resource for a short-term operation (e.g. verifying if a configuration
- file has changed before saving new settings), and for long-lived protection of a
- resource (e.g. a document opened by a user in an editor) for an indefinite amount of time.
-
- When protecting for a short-term operation, it is acceptable to call lock() and wait
- until any running operation finishes.
- When protecting a resource over a long time, however, the application should always
- call setStaleLockTime(0) and then tryLock() with a short timeout, in order to
- warn the user that the resource is locked.
-
- If the process holding the lock crashes, the lock file stays on disk and can prevent
- any other process from accessing the shared resource, ever. For this reason, QLockFile
- tries to detect such a "stale" lock file, based on the process ID written into the file,
- and (in case that process ID got reused meanwhile), on the last modification time of
- the lock file (30s by default, for the use case of a short-lived operation).
- If the lock file is found to be stale, it will be deleted.
-
- For the use case of protecting a resource over a long time, you should therefore call
- setStaleLockTime(0), and when tryLock() returns LockFailedError, inform the user
- that the document is locked, possibly using getLockInfo() for more details.
-*/
-
-/*!
- \enum QLockFile::LockError
-
- This enum describes the result of the last call to lock() or tryLock().
-
- \value NoError The lock was acquired successfully.
- \value LockFailedError The lock could not be acquired because another process holds it.
- \value PermissionError The lock file could not be created, for lack of permissions
- in the parent directory.
- \value UnknownError Another error happened, for instance a full partition
- prevented writing out the lock file.
-*/
-
-/*!
- Constructs a new lock file object.
- The object is created in an unlocked state.
- When calling lock() or tryLock(), a lock file named \a fileName will be created,
- if it doesn't already exist.
-
- \sa lock(), unlock()
-*/
-QLockFile::QLockFile(const QString &fileName)
- : d_ptr(new QLockFilePrivate(fileName))
-{
-}
-
-/*!
- Destroys the lock file object.
- If the lock was acquired, this will release the lock, by deleting the lock file.
-*/
-QLockFile::~QLockFile()
-{
- unlock();
-}
-
-/*!
- Sets \a staleLockTime to be the time in milliseconds after which
- a lock file is considered stale.
- The default value is 30000, i.e. 30 seconds.
- If your application typically keeps the file locked for more than 30 seconds
- (for instance while saving megabytes of data for 2 minutes), you should set
- a bigger value using setStaleLockTime().
-
- The value of \a staleLockTime is used by lock() and tryLock() in order
- to determine when an existing lock file is considered stale, i.e. left over
- by a crashed process. This is useful for the case where the PID got reused
- meanwhile, so the only way to detect a stale lock file is by the fact that
- it has been around for a long time.
-
- \sa staleLockTime()
-*/
-void QLockFile::setStaleLockTime(int staleLockTime)
-{
- Q_D(QLockFile);
- d->staleLockTime = staleLockTime;
-}
-
-/*!
- Returns the time in milliseconds after which
- a lock file is considered stale.
-
- \sa setStaleLockTime()
-*/
-int QLockFile::staleLockTime() const
-{
- Q_D(const QLockFile);
- return d->staleLockTime;
-}
-
-/*!
- Returns \c true if the lock was acquired by this QLockFile instance,
- otherwise returns \c false.
-
- \sa lock(), unlock(), tryLock()
-*/
-bool QLockFile::isLocked() const
-{
- Q_D(const QLockFile);
- return d->isLocked;
-}
-
-/*!
- Creates the lock file.
-
- If another process (or another thread) has created the lock file already,
- this function will block until that process (or thread) releases it.
-
- Calling this function multiple times on the same lock from the same
- thread without unlocking first is not allowed. This function will
- \e dead-lock when the file is locked recursively.
-
- Returns \c true if the lock was acquired, false if it could not be acquired
- due to an unrecoverable error, such as no permissions in the parent directory.
-
- \sa unlock(), tryLock()
-*/
-bool QLockFile::lock()
-{
- return tryLock(-1);
-}
-
-/*!
- Attempts to create the lock file. This function returns \c true if the
- lock was obtained; otherwise it returns \c false. If another process (or
- another thread) has created the lock file already, this function will
- wait for at most \a timeout milliseconds for the lock file to become
- available.
-
- Note: Passing a negative number as the \a timeout is equivalent to
- calling lock(), i.e. this function will wait forever until the lock
- file can be locked if \a timeout is negative.
-
- If the lock was obtained, it must be released with unlock()
- before another process (or thread) can successfully lock it.
-
- Calling this function multiple times on the same lock from the same
- thread without unlocking first is not allowed, this function will
- \e always return false when attempting to lock the file recursively.
-
- \sa lock(), unlock()
-*/
-bool QLockFile::tryLock(int timeout)
-{
- Q_D(QLockFile);
- QElapsedTimer timer;
- if (timeout > 0)
- timer.start();
- int sleepTime = 100;
- forever {
- d->lockError = d->tryLock_sys();
- switch (d->lockError) {
- case NoError:
- d->isLocked = true;
- return true;
- case PermissionError:
- case UnknownError:
- return false;
- case LockFailedError:
- if (!d->isLocked && d->isApparentlyStale()) {
- // Stale lock from another thread/process
- // Ensure two processes don't remove it at the same time
- QLockFile rmlock(d->fileName + QLatin1String(".rmlock"));
- if (rmlock.tryLock()) {
- if (d->isApparentlyStale() && d->removeStaleLock())
- continue;
- }
- }
- break;
- }
- if (timeout == 0 || (timeout > 0 && timer.hasExpired(timeout)))
- return false;
- QLockFileThread::msleep(sleepTime);
- if (sleepTime < 5 * 1000)
- sleepTime *= 2;
- }
- // not reached
- return false;
-}
-
-/*!
- \fn void QLockFile::unlock()
- Releases the lock, by deleting the lock file.
-
- Calling unlock() without locking the file first, does nothing.
-
- \sa lock(), tryLock()
-*/
-
-/*!
- Retrieves information about the current owner of the lock file.
-
- If tryLock() returns \c false, and error() returns LockFailedError,
- this function can be called to find out more information about the existing
- lock file:
- \list
- \li the PID of the application (returned in \a pid)
- \li the \a hostname it's running on (useful in case of networked filesystems),
- \li the name of the application which created it (returned in \a appname),
- \endlist
-
- Note that tryLock() automatically deleted the file if there is no
- running application with this PID, so LockFailedError can only happen if there is
- an application with this PID (it could be unrelated though).
-
- This can be used to inform users about the existing lock file and give them
- the choice to delete it. After removing the file using removeStaleLockFile(),
- the application can call tryLock() again.
-
- This function returns \c true if the information could be successfully retrieved, false
- if the lock file doesn't exist or doesn't contain the expected data.
- This can happen if the lock file was deleted between the time where tryLock() failed
- and the call to this function. Simply call tryLock() again if this happens.
-*/
-bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
-{
- Q_D(const QLockFile);
- return d->getLockInfo(pid, hostname, appname);
-}
-
-bool QLockFilePrivate::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
-{
- QFile reader(fileName);
- if (!reader.open(QIODevice::ReadOnly))
- return false;
-
- QByteArray pidLine = reader.readLine();
- pidLine.chop(1);
- QByteArray appNameLine = reader.readLine();
- appNameLine.chop(1);
- QByteArray hostNameLine = reader.readLine();
- hostNameLine.chop(1);
- if (pidLine.isEmpty() || appNameLine.isEmpty())
- return false;
-
- qint64 thePid = pidLine.toLongLong();
- if (pid)
- *pid = thePid;
- if (appname)
- *appname = QString::fromUtf8(appNameLine);
- if (hostname)
- *hostname = QString::fromUtf8(hostNameLine);
- return thePid > 0;
-}
-
-/*!
- Attempts to forcefully remove an existing lock file.
-
- Calling this is not recommended when protecting a short-lived operation: QLockFile
- already takes care of removing lock files after they are older than staleLockTime().
-
- This method should only be called when protecting a resource for a long time, i.e.
- with staleLockTime(0), and after tryLock() returned LockFailedError, and the user
- agreed on removing the lock file.
-
- Returns \c true on success, false if the lock file couldn't be removed. This happens
- on Windows, when the application owning the lock is still running.
-*/
-bool QLockFile::removeStaleLockFile()
-{
- Q_D(QLockFile);
- if (d->isLocked) {
- qWarning("removeStaleLockFile can only be called when not holding the lock");
- return false;
- }
- return d->removeStaleLock();
-}
-
-/*!
- Returns the lock file error status.
-
- If tryLock() returns \c false, this function can be called to find out
- the reason why the locking failed.
-*/
-QLockFile::LockError QLockFile::error() const
-{
- Q_D(const QLockFile);
- return d->lockError;
-}
-
-QT_END_NAMESPACE
diff --git a/src/serialport/qt4support/src/qlockfile_unix.cpp b/src/serialport/qt4support/src/qlockfile_unix.cpp
deleted file mode 100644
index fbcb57ee..00000000
--- a/src/serialport/qt4support/src/qlockfile_unix.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "private/qlockfile_p.h"
-
-#include "QtCore/qtemporaryfile.h"
-#include "QtCore/qcoreapplication.h"
-#include "QtCore/qfileinfo.h"
-#include "QtCore/qdebug.h"
-#include "QtCore/qdatetime.h"
-
-#include <sys/file.h> // flock
-#include <sys/types.h> // kill
-#include <signal.h> // kill
-#include <unistd.h>
-
-#include <errno.h>
-
-QT_BEGIN_NAMESPACE
-
-#define EINTR_LOOP(var, cmd) \
- do { \
- var = cmd; \
- } while (var == -1 && errno == EINTR)
-
-// don't call QT_OPEN or ::open
-// call qt_safe_open
-static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777)
-{
-#ifdef O_CLOEXEC
- flags |= O_CLOEXEC;
-#endif
- int fd;
- EINTR_LOOP(fd, ::open(pathname, flags, mode));
-
- // unknown flags are ignored, so we have no way of verifying if
- // O_CLOEXEC was accepted
- if (fd != -1)
- ::fcntl(fd, F_SETFD, FD_CLOEXEC);
- return fd;
-}
-
-static inline qint64 qt_safe_write(int fd, const void *data, qint64 len)
-{
- qint64 ret = 0;
- EINTR_LOOP(ret, ::write(fd, data, len));
- return ret;
-}
-
-static QString localHostName() // from QHostInfo::localHostName()
-{
- char hostName[512];
- if (gethostname(hostName, sizeof(hostName)) == -1)
- return QString();
- hostName[sizeof(hostName) - 1] = '\0';
- return QString::fromLocal8Bit(hostName);
-}
-
-// ### merge into qt_safe_write?
-static qint64 qt_write_loop(int fd, const char *data, qint64 len)
-{
- qint64 pos = 0;
- while (pos < len) {
- const qint64 ret = qt_safe_write(fd, data + pos, len - pos);
- if (ret == -1) // e.g. partition full
- return pos;
- pos += ret;
- }
- return pos;
-}
-
-static bool setNativeLocks(int fd)
-{
-#if defined(LOCK_EX) && defined(LOCK_NB)
- if (flock(fd, LOCK_EX | LOCK_NB) == -1) // other threads, and other processes on a local fs
- return false;
-#endif
- struct flock flockData;
- flockData.l_type = F_WRLCK;
- flockData.l_whence = SEEK_SET;
- flockData.l_start = 0;
- flockData.l_len = 0; // 0 = entire file
- flockData.l_pid = getpid();
- if (fcntl(fd, F_SETLK, &flockData) == -1) // for networked filesystems
- return false;
- return true;
-}
-
-QLockFile::LockError QLockFilePrivate::tryLock_sys()
-{
- // Assemble data, to write in a single call to write
- // (otherwise we'd have to check every write call)
- // Use operator% from the fast builder to avoid multiple memory allocations.
- QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) + '\n'
- + qAppName().toUtf8() + '\n'
- + localHostName().toUtf8() + '\n';
-
- const QByteArray lockFileName = QFile::encodeName(fileName);
- const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644);
- if (fd < 0) {
- switch (errno) {
- case EEXIST:
- return QLockFile::LockFailedError;
- case EACCES:
- case EROFS:
- return QLockFile::PermissionError;
- default:
- return QLockFile::UnknownError;
- }
- }
- // Ensure nobody else can delete the file while we have it
- if (!setNativeLocks(fd))
- qWarning() << "setNativeLocks failed:" << strerror(errno);
-
- // We hold the lock, continue.
- fileHandle = fd;
-
- QLockFile::LockError error = QLockFile::NoError;
- if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size())
- error = QLockFile::UnknownError; // partition full
- return error;
-}
-
-bool QLockFilePrivate::removeStaleLock()
-{
- const QByteArray lockFileName = QFile::encodeName(fileName);
- const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY, 0644);
- if (fd < 0) // gone already?
- return false;
- bool success = setNativeLocks(fd) && (::unlink(lockFileName) == 0);
- close(fd);
- return success;
-}
-
-bool QLockFilePrivate::isApparentlyStale() const
-{
- qint64 pid;
- QString hostname, appname;
- if (!getLockInfo(&pid, &hostname, &appname))
- return false;
- if (hostname == localHostName()) {
- if (::kill(pid, 0) == -1 && errno == ESRCH)
- return true; // PID doesn't exist anymore
- }
- const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());
- return staleLockTime > 0 && age > staleLockTime;
-}
-
-void QLockFile::unlock()
-{
- Q_D(QLockFile);
- if (!d->isLocked)
- return;
- close(d->fileHandle);
- d->fileHandle = -1;
- QFile::remove(d->fileName);
- d->lockError = QLockFile::NoError;
- d->isLocked = false;
-}
-
-QT_END_NAMESPACE