1 | // Copyright (C) 2016 The Qt Company Ltd. |
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 QSYSTEMSEMAPHORE_H |
5 | #define QSYSTEMSEMAPHORE_H |
6 | |
7 | #include <QtCore/qcoreapplication.h> |
8 | #include <QtCore/qtipccommon.h> |
9 | #include <QtCore/qstring.h> |
10 | #include <QtCore/qscopedpointer.h> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | #if QT_CONFIG(systemsemaphore) |
15 | |
16 | class QSystemSemaphorePrivate; |
17 | |
18 | class Q_CORE_EXPORT QSystemSemaphore |
19 | { |
20 | Q_GADGET |
21 | Q_DECLARE_TR_FUNCTIONS(QSystemSemaphore) |
22 | public: |
23 | enum AccessMode |
24 | { |
25 | Open, |
26 | Create |
27 | }; |
28 | Q_ENUM(AccessMode) |
29 | |
30 | enum SystemSemaphoreError |
31 | { |
32 | NoError, |
33 | PermissionDenied, |
34 | KeyError, |
35 | AlreadyExists, |
36 | NotFound, |
37 | OutOfResources, |
38 | UnknownError |
39 | }; |
40 | |
41 | QSystemSemaphore(const QNativeIpcKey &key, int initialValue = 0, AccessMode = Open); |
42 | ~QSystemSemaphore(); |
43 | |
44 | void setNativeKey(const QNativeIpcKey &key, int initialValue = 0, AccessMode = Open); |
45 | void setNativeKey(const QString &key, int initialValue = 0, AccessMode mode = Open, |
46 | QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs()) |
47 | { setNativeKey(key: { key, type }, initialValue, mode); } |
48 | QNativeIpcKey nativeIpcKey() const; |
49 | |
50 | #if QT_DEPRECATED_SINCE(6, 10) |
51 | QT_DEPRECATED_VERSION_X_6_10("Please refer to 'Native IPC Key' documentation" ) |
52 | QSystemSemaphore(const QString &key, int initialValue = 0, AccessMode mode = Open); |
53 | QT_DEPRECATED_VERSION_X_6_10("Please refer to 'Native IPC Key' documentation" ) |
54 | void setKey(const QString &key, int initialValue = 0, AccessMode mode = Open); |
55 | QT_DEPRECATED_VERSION_X_6_10("Please refer to 'Native IPC Key' documentation" ) |
56 | QString key() const; |
57 | #endif |
58 | |
59 | bool acquire(); |
60 | bool release(int n = 1); |
61 | |
62 | SystemSemaphoreError error() const; |
63 | QString errorString() const; |
64 | |
65 | static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION; |
66 | static QNativeIpcKey platformSafeKey(const QString &key, |
67 | QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs); |
68 | static QNativeIpcKey legacyNativeKey(const QString &key, |
69 | QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs()); |
70 | |
71 | private: |
72 | Q_DISABLE_COPY(QSystemSemaphore) |
73 | QScopedPointer<QSystemSemaphorePrivate> d; |
74 | }; |
75 | |
76 | #endif // QT_CONFIG(systemsemaphore) |
77 | |
78 | QT_END_NAMESPACE |
79 | |
80 | #endif // QSYSTEMSEMAPHORE_H |
81 | |