Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlockfile.h
Go to the documentation of this file.
1// Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QLOCKFILE_H
6#define QLOCKFILE_H
7
8#include <QtCore/qstring.h>
9#include <QtCore/qscopedpointer.h>
10
11#include <chrono>
12#include <memory>
13
14QT_BEGIN_NAMESPACE
15
16class QLockFilePrivate;
17
18class Q_CORE_EXPORT QLockFile
19{
20public:
21 explicit QLockFile(const QString &fileName);
22 ~QLockFile();
23
24 QString fileName() const;
25
26 bool lock();
27 QT_CORE_INLINE_SINCE(6, 10)
28 bool tryLock(int timeout);
29 void unlock();
30
31 QT_CORE_INLINE_SINCE(6, 10)
32 void setStaleLockTime(int);
33 QT_CORE_INLINE_SINCE(6, 10)
34 int staleLockTime() const;
35
36 bool tryLock(std::chrono::milliseconds timeout = std::chrono::milliseconds::zero());
37
38 void setStaleLockTime(std::chrono::milliseconds value);
39 std::chrono::milliseconds staleLockTimeAsDuration() const;
40
41 bool isLocked() const;
42 bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
43 bool removeStaleLockFile();
44
45 enum LockError {
46 NoError = 0,
47 LockFailedError = 1,
48 PermissionError = 2,
49 UnknownError = 3
50 };
51 LockError error() const;
52
53private:
54 std::unique_ptr<QLockFilePrivate> d_ptr;
55
56 Q_DECLARE_PRIVATE(QLockFile)
57 Q_DISABLE_COPY(QLockFile)
58};
59
60#if QT_CORE_INLINE_IMPL_SINCE(6, 10)
61bool QLockFile::tryLock(int timeout)
62{
63 return tryLock(std::chrono::milliseconds{timeout});
64}
65
66void QLockFile::setStaleLockTime(int staleLockTime)
67{
68 setStaleLockTime(std::chrono::milliseconds{staleLockTime});
69}
70
71int QLockFile::staleLockTime() const
72{
73 return int(staleLockTimeAsDuration().count());
74}
75#endif // QT_CORE_INLINE_IMPL_SINCE(6, 10)
76
77QT_END_NAMESPACE
78
79#endif // QLOCKFILE_H
QLockFilePrivate(const QString &fn)
bool isApparentlyStale() const
QByteArray lockFileContents() const
\inmodule QtCore
Definition qlockfile.h:19
static QString machineName()
Definition qlockfile.cpp:40
static bool getLockInfo_helper(const QString &fileName, LockFileInfo *info)