| 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 QSHAREDMEMORY_H | 
| 5 | #define QSHAREDMEMORY_H | 
| 6 |  | 
| 7 | #include <QtCore/qtipccommon.h> | 
| 8 | #ifndef QT_NO_QOBJECT | 
| 9 | # include <QtCore/qobject.h> | 
| 10 | #else | 
| 11 | # include <QtCore/qobjectdefs.h> | 
| 12 | # include <QtCore/qscopedpointer.h> | 
| 13 | # include <QtCore/qstring.h> | 
| 14 | #endif | 
| 15 |  | 
| 16 | QT_BEGIN_NAMESPACE | 
| 17 |  | 
| 18 | #if QT_CONFIG(sharedmemory) | 
| 19 |  | 
| 20 | class QSharedMemoryPrivate; | 
| 21 |  | 
| 22 | class Q_CORE_EXPORT QSharedMemory : public QObject | 
| 23 | { | 
| 24 |     Q_OBJECT | 
| 25 |     Q_DECLARE_PRIVATE(QSharedMemory) | 
| 26 |  | 
| 27 | public: | 
| 28 |     enum AccessMode | 
| 29 |     { | 
| 30 |         ReadOnly, | 
| 31 |         ReadWrite | 
| 32 |     }; | 
| 33 |     Q_ENUM(AccessMode) | 
| 34 |  | 
| 35 |     enum SharedMemoryError | 
| 36 |     { | 
| 37 |         NoError, | 
| 38 |         PermissionDenied, | 
| 39 |         InvalidSize, | 
| 40 |         KeyError, | 
| 41 |         AlreadyExists, | 
| 42 |         NotFound, | 
| 43 |         LockError, | 
| 44 |         OutOfResources, | 
| 45 |         UnknownError | 
| 46 |     }; | 
| 47 |     Q_ENUM(SharedMemoryError) | 
| 48 |  | 
| 49 |     QSharedMemory(QObject *parent = nullptr); | 
| 50 |     QSharedMemory(const QNativeIpcKey &key, QObject *parent = nullptr); | 
| 51 |     ~QSharedMemory(); | 
| 52 |  | 
| 53 |     QSharedMemory(const QString &key, QObject *parent = nullptr); | 
| 54 |     void setKey(const QString &key); | 
| 55 |     QString key() const; | 
| 56 |  | 
| 57 |     void setNativeKey(const QNativeIpcKey &key); | 
| 58 |     void setNativeKey(const QString &key, QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs()) | 
| 59 |     { setNativeKey({ key, type }); } | 
| 60 |     QString nativeKey() const; | 
| 61 |     QNativeIpcKey nativeIpcKey() const; | 
| 62 | #if QT_CORE_REMOVED_SINCE(6, 5) | 
| 63 |     void setNativeKey(const QString &key); | 
| 64 | #endif | 
| 65 |  | 
| 66 |     bool create(qsizetype size, AccessMode mode = ReadWrite); | 
| 67 |     qsizetype size() const; | 
| 68 |  | 
| 69 |     bool attach(AccessMode mode = ReadWrite); | 
| 70 |     bool isAttached() const; | 
| 71 |     bool detach(); | 
| 72 |  | 
| 73 |     void *data(); | 
| 74 |     const void* constData() const; | 
| 75 |     const void *data() const; | 
| 76 |  | 
| 77 | #if QT_CONFIG(systemsemaphore) | 
| 78 |     bool lock(); | 
| 79 |     bool unlock(); | 
| 80 | #endif | 
| 81 |  | 
| 82 |     SharedMemoryError error() const; | 
| 83 |     QString errorString() const; | 
| 84 |  | 
| 85 |     static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION; | 
| 86 |     static QNativeIpcKey platformSafeKey(const QString &key, | 
| 87 |             QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs); | 
| 88 |     static QNativeIpcKey legacyNativeKey(const QString &key, | 
| 89 |             QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs()); | 
| 90 |  | 
| 91 | private: | 
| 92 |     Q_DISABLE_COPY(QSharedMemory) | 
| 93 | }; | 
| 94 |  | 
| 95 | #endif // QT_CONFIG(sharedmemory) | 
| 96 |  | 
| 97 | QT_END_NAMESPACE | 
| 98 |  | 
| 99 | #endif // QSHAREDMEMORY_H | 
| 100 |  |