| 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 |     QSystemSemaphore(const QString &key, int initialValue = 0, AccessMode mode = Open); | 
| 51 |     void setKey(const QString &key, int initialValue = 0, AccessMode mode = Open); | 
| 52 |     QString key() const; | 
| 53 |  | 
| 54 |     bool acquire(); | 
| 55 |     bool release(int n = 1); | 
| 56 |  | 
| 57 |     SystemSemaphoreError error() const; | 
| 58 |     QString errorString() const; | 
| 59 |  | 
| 60 |     static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION; | 
| 61 |     static QNativeIpcKey platformSafeKey(const QString &key, | 
| 62 |             QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs); | 
| 63 |     static QNativeIpcKey legacyNativeKey(const QString &key, | 
| 64 |             QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs()); | 
| 65 |  | 
| 66 | private: | 
| 67 |     Q_DISABLE_COPY(QSystemSemaphore) | 
| 68 |     QScopedPointer<QSystemSemaphorePrivate> d; | 
| 69 | }; | 
| 70 |  | 
| 71 | #endif // QT_CONFIG(systemsemaphore) | 
| 72 |  | 
| 73 | QT_END_NAMESPACE | 
| 74 |  | 
| 75 | #endif // QSYSTEMSEMAPHORE_H | 
| 76 |  |