File indexing completed on 2025-01-18 10:07:36
0001
0002
0003
0004 #ifndef QSHAREDMEMORY_H
0005 #define QSHAREDMEMORY_H
0006
0007 #include <QtCore/qtipccommon.h>
0008 #ifndef QT_NO_QOBJECT
0009 # include <QtCore/qobject.h>
0010 #else
0011 # include <QtCore/qobjectdefs.h>
0012 # include <QtCore/qscopedpointer.h>
0013 # include <QtCore/qstring.h>
0014 #endif
0015
0016 QT_BEGIN_NAMESPACE
0017
0018 #if QT_CONFIG(sharedmemory)
0019
0020 class QSharedMemoryPrivate;
0021
0022 class Q_CORE_EXPORT QSharedMemory : public QObject
0023 {
0024 Q_OBJECT
0025 Q_DECLARE_PRIVATE(QSharedMemory)
0026
0027 public:
0028 enum AccessMode
0029 {
0030 ReadOnly,
0031 ReadWrite
0032 };
0033 Q_ENUM(AccessMode)
0034
0035 enum SharedMemoryError
0036 {
0037 NoError,
0038 PermissionDenied,
0039 InvalidSize,
0040 KeyError,
0041 AlreadyExists,
0042 NotFound,
0043 LockError,
0044 OutOfResources,
0045 UnknownError
0046 };
0047 Q_ENUM(SharedMemoryError)
0048
0049 QSharedMemory(QObject *parent = nullptr);
0050 QSharedMemory(const QNativeIpcKey &key, QObject *parent = nullptr);
0051 ~QSharedMemory();
0052
0053 QSharedMemory(const QString &key, QObject *parent = nullptr);
0054 void setKey(const QString &key);
0055 QString key() const;
0056
0057 void setNativeKey(const QNativeIpcKey &key);
0058 void setNativeKey(const QString &key, QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs())
0059 { setNativeKey({ key, type }); }
0060 QString nativeKey() const;
0061 QNativeIpcKey nativeIpcKey() const;
0062 #if QT_CORE_REMOVED_SINCE(6, 5)
0063 void setNativeKey(const QString &key);
0064 #endif
0065
0066 bool create(qsizetype size, AccessMode mode = ReadWrite);
0067 qsizetype size() const;
0068
0069 bool attach(AccessMode mode = ReadWrite);
0070 bool isAttached() const;
0071 bool detach();
0072
0073 void *data();
0074 const void* constData() const;
0075 const void *data() const;
0076
0077 #if QT_CONFIG(systemsemaphore)
0078 bool lock();
0079 bool unlock();
0080 #endif
0081
0082 SharedMemoryError error() const;
0083 QString errorString() const;
0084
0085 static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION;
0086 static QNativeIpcKey platformSafeKey(const QString &key,
0087 QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs);
0088 static QNativeIpcKey legacyNativeKey(const QString &key,
0089 QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs());
0090
0091 private:
0092 Q_DISABLE_COPY(QSharedMemory)
0093 };
0094
0095 #endif
0096
0097 QT_END_NAMESPACE
0098
0099 #endif