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_p.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
4#ifndef QLOCKFILE_P_H
5#define QLOCKFILE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/qlockfile.h>
20#include <QtCore/qfile.h>
21
22#include <qplatformdefs.h>
23
24#ifdef Q_OS_WIN
25#include <io.h>
26#include <qt_windows.h>
27#endif
28
30
32{
33public:
34 QLockFilePrivate(const QString &fn)
35 : fileName(fn)
36 {
37 }
39 bool removeStaleLock();
41 // Returns \c true if the lock belongs to dead PID, or is old.
42 // The attempt to delete it will tell us if it was really stale or not, though.
43 bool isApparentlyStale() const;
44
45 // used in dbusmenu
46 Q_CORE_EXPORT static QString processNameByPid(qint64 pid);
47 static bool isProcessRunning(qint64 pid, const QString &appname);
48
50
51#ifdef Q_OS_WIN
53#else
54 int fileHandle = -1;
55#endif
56
57 std::chrono::milliseconds staleLockTime = std::chrono::seconds{30};
59 bool isLocked = false;
60
61 static int getLockFileHandle(QLockFile *f)
62 {
63 int fd;
64#ifdef Q_OS_WIN
65 // Use of this function on Windows WILL leak a file descriptor.
66 fd = _open_osfhandle(intptr_t(f->d_func()->fileHandle), 0);
67#else
68 fd = f->d_func()->fileHandle;
69#endif
70 QT_LSEEK(fd, 0, SEEK_SET);
71 return fd;
72 }
73};
74
75QT_END_NAMESPACE
76
77#endif /* QLOCKFILE_P_H */
QLockFilePrivate(const QString &fn)
Definition qlockfile_p.h:34
bool isApparentlyStale() const
static bool isProcessRunning(qint64 pid, const QString &appname)
std::chrono::milliseconds staleLockTime
Definition qlockfile_p.h:57
static int getLockFileHandle(QLockFile *f)
Definition qlockfile_p.h:61
QByteArray lockFileContents() const
\inmodule QtCore
Definition qlockfile.h:17
Combined button and popup list for selecting options.
static QString machineName()
Definition qlockfile.cpp:32
static bool getLockInfo_helper(const QString &fileName, LockFileInfo *info)