Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:28

0001 // Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QLOCKFILE_H
0005 #define QLOCKFILE_H
0006 
0007 #include <QtCore/qstring.h>
0008 #include <QtCore/qscopedpointer.h>
0009 
0010 #include <chrono>
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 class QLockFilePrivate;
0015 
0016 class Q_CORE_EXPORT QLockFile
0017 {
0018 public:
0019     QLockFile(const QString &fileName);
0020     ~QLockFile();
0021 
0022     QString fileName() const;
0023 
0024     bool lock();
0025     bool tryLock(int timeout);
0026     void unlock();
0027 
0028     void setStaleLockTime(int);
0029     int staleLockTime() const;
0030 
0031     bool tryLock(std::chrono::milliseconds timeout = std::chrono::milliseconds::zero());
0032 
0033     void setStaleLockTime(std::chrono::milliseconds value);
0034     std::chrono::milliseconds staleLockTimeAsDuration() const;
0035 
0036     bool isLocked() const;
0037     bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
0038     bool removeStaleLockFile();
0039 
0040     enum LockError {
0041         NoError = 0,
0042         LockFailedError = 1,
0043         PermissionError = 2,
0044         UnknownError = 3
0045     };
0046     LockError error() const;
0047 
0048 protected:
0049     QScopedPointer<QLockFilePrivate> d_ptr;
0050 
0051 private:
0052     Q_DECLARE_PRIVATE(QLockFile)
0053     Q_DISABLE_COPY(QLockFile)
0054 };
0055 
0056 QT_END_NAMESPACE
0057 
0058 #endif // QLOCKFILE_H