4#ifndef QSHAREDMEMORY_P_H
5#define QSHAREDMEMORY_P_H
20#include <QtCore/qstring.h>
22#if QT_CONFIG(sharedmemory)
25#include "private/qobject_p.h"
27#if QT_CONFIG(posix_shm)
30#if QT_CONFIG(sysv_shm)
36class QSharedMemoryPrivate;
38#if QT_CONFIG(systemsemaphore)
42class QSharedMemoryLocker
46 Q_NODISCARD_CTOR QSharedMemoryLocker(QSharedMemory *sharedMemory) : q_sm(sharedMemory)
51 inline ~QSharedMemoryLocker()
59 if (q_sm && q_sm->lock())
70class QSharedMemoryPosix
74 static bool supports(QNativeIpcKey::Type
type)
75 {
return type == QNativeIpcKey::Type::PosixRealtime; }
76 static bool runtimeSupportCheck();
78 bool handle(QSharedMemoryPrivate *self);
79 bool cleanHandle(QSharedMemoryPrivate *self);
81 bool attach(QSharedMemoryPrivate *self, QSharedMemory::AccessMode
mode);
82 bool detach(QSharedMemoryPrivate *self);
87class QSharedMemorySystemV
91 static bool supports(QNativeIpcKey::Type
type)
93 static bool runtimeSupportCheck();
95#if QT_CONFIG(sysv_sem)
96 key_t
handle(QSharedMemoryPrivate *self);
97 bool cleanHandle(QSharedMemoryPrivate *self);
99 bool attach(QSharedMemoryPrivate *self, QSharedMemory::AccessMode
mode);
100 bool detach(QSharedMemoryPrivate *self);
103 void updateNativeKeyFile(
const QNativeIpcKey &nativeKey);
110class QSharedMemoryWin32
114 static constexpr bool Enabled =
true;
116 static constexpr bool Enabled =
false;
118 static bool runtimeSupportCheck() {
return Enabled; }
119 static bool supports(QNativeIpcKey::Type
type)
120 {
return type == QNativeIpcKey::Type::Windows; }
123 bool cleanHandle(QSharedMemoryPrivate *self);
125 bool attach(QSharedMemoryPrivate *self, QSharedMemory::AccessMode
mode);
126 bool detach(QSharedMemoryPrivate *self);
133 Q_DECLARE_PUBLIC(QSharedMemory)
136 QSharedMemoryPrivate(QNativeIpcKey::Type
type) : nativeKey(
type)
137 { constructBackend(); }
138 ~QSharedMemoryPrivate();
142 QNativeIpcKey nativeKey;
144#if QT_CONFIG(systemsemaphore)
145 using SemaphoreAccessMode = QSystemSemaphore::AccessMode;
146 QSystemSemaphore systemSemaphore{ QNativeIpcKey() };
147 bool lockedByMe =
false;
149 enum SemaphoreAccessMode {};
151 QSharedMemory::SharedMemoryError
error = QSharedMemory::NoError;
156 QSharedMemoryPosix posix;
157 QSharedMemorySystemV sysv;
158 QSharedMemoryWin32 win32;
160 QtIpcCommon::IpcStorageVariant<&Backend::posix, &Backend::sysv, &Backend::win32> backend;
162 void constructBackend();
163 void destructBackend();
164 bool initKey(SemaphoreAccessMode
mode);
166 template <
typename Lambda>
auto visit(
const Lambda &lambda)
168 return backend.visit(nativeKey.type(), lambda);
173 return visit([&](
auto p) {
return !!
p->handle(
this); });
177 return visit([&](
auto p) {
return p->cleanHandle(
this); });
181 return visit([&](
auto p) {
return p->create(
this,
size); });
183 bool attach(QSharedMemory::AccessMode
mode)
185 return visit([&](
auto p) {
return p->attach(
this,
mode); });
189 return visit([&](
auto p) {
return p->detach(
this); });
197#if QT_CONFIG(systemsemaphore)
198 bool tryLocker(QSharedMemoryLocker *locker,
const QString &function) {
199 if (!locker->lock()) {
200 errorString = QSharedMemory::tr(
"%1: unable to lock").arg(function);
201 error = QSharedMemory::LockError;
206 QNativeIpcKey semaphoreNativeKey()
const;
\macro QT_RESTRICTED_CAST_FROM_ASCII
auto visit(Fn &&fn, QIODevice *socket, Args &&...args)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLsizei const GLchar * message
GLsizei GLenum GLsizei GLsizei GLuint memory
static void setError(QJsonObject *response, const QString &msg)
#define Q_AUTOTEST_EXPORT
#define QT_CONFIG(feature)