Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:39

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSYSTEMSEMAPHORE_H
0005 #define QSYSTEMSEMAPHORE_H
0006 
0007 #include <QtCore/qcoreapplication.h>
0008 #include <QtCore/qtipccommon.h>
0009 #include <QtCore/qstring.h>
0010 #include <QtCore/qscopedpointer.h>
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 #if QT_CONFIG(systemsemaphore)
0015 
0016 class QSystemSemaphorePrivate;
0017 
0018 class Q_CORE_EXPORT QSystemSemaphore
0019 {
0020     Q_GADGET
0021     Q_DECLARE_TR_FUNCTIONS(QSystemSemaphore)
0022 public:
0023     enum AccessMode
0024     {
0025         Open,
0026         Create
0027     };
0028     Q_ENUM(AccessMode)
0029 
0030     enum SystemSemaphoreError
0031     {
0032         NoError,
0033         PermissionDenied,
0034         KeyError,
0035         AlreadyExists,
0036         NotFound,
0037         OutOfResources,
0038         UnknownError
0039     };
0040 
0041     QSystemSemaphore(const QNativeIpcKey &key, int initialValue = 0, AccessMode = Open);
0042     ~QSystemSemaphore();
0043 
0044     void setNativeKey(const QNativeIpcKey &key, int initialValue = 0, AccessMode = Open);
0045     void setNativeKey(const QString &key, int initialValue = 0, AccessMode mode = Open,
0046                       QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs())
0047     { setNativeKey({ key, type }, initialValue, mode); }
0048     QNativeIpcKey nativeIpcKey() const;
0049 
0050     QSystemSemaphore(const QString &key, int initialValue = 0, AccessMode mode = Open);
0051     void setKey(const QString &key, int initialValue = 0, AccessMode mode = Open);
0052     QString key() const;
0053 
0054     bool acquire();
0055     bool release(int n = 1);
0056 
0057     SystemSemaphoreError error() const;
0058     QString errorString() const;
0059 
0060     static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION;
0061     static QNativeIpcKey platformSafeKey(const QString &key,
0062             QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs);
0063     static QNativeIpcKey legacyNativeKey(const QString &key,
0064             QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs());
0065 
0066 private:
0067     Q_DISABLE_COPY(QSystemSemaphore)
0068     QScopedPointer<QSystemSemaphorePrivate> d;
0069 };
0070 
0071 #endif // QT_CONFIG(systemsemaphore)
0072 
0073 QT_END_NAMESPACE
0074 
0075 #endif // QSYSTEMSEMAPHORE_H