Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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:
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
52 Qt::HANDLE fileHandle = INVALID_HANDLE_VALUE;
53#else
54 int fileHandle = -1;
55#endif
56
57 std::chrono::milliseconds staleLockTime = std::chrono::seconds{30};
59 bool isLocked = false;
60
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
76
77#endif /* QLOCKFILE_P_H */
\inmodule QtCore
Definition qbytearray.h:57
QLockFilePrivate(const QString &fn)
Definition qlockfile_p.h:34
QLockFile::LockError tryLock_sys()
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
static Q_CORE_EXPORT QString processNameByPid(qint64 pid)
QLockFile::LockError lockError
Definition qlockfile_p.h:58
QByteArray lockFileContents() const
\inmodule QtCore
Definition qlockfile.h:17
LockError
This enum describes the result of the last call to lock() or tryLock().
Definition qlockfile.h:40
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
void * HANDLE
INT_PTR intptr_t
GLfloat GLfloat f
GLuint64 GLenum GLint fd
long long qint64
Definition qtypes.h:60