17# define MAX_PATH PATH_MAX
22#if QT_CONFIG(sharedmemory)
24using namespace QtIpcCommon;
27QSharedMemoryPrivate::~QSharedMemoryPrivate()
32inline void QSharedMemoryPrivate::constructBackend()
38inline void QSharedMemoryPrivate::destructBackend()
40 visit([](
auto p) { std::destroy_at(
p); });
43#if QT_CONFIG(systemsemaphore)
44inline QNativeIpcKey QSharedMemoryPrivate::semaphoreNativeKey()
const
46 if (isIpcSupported(IpcType::SharedMemory, QNativeIpcKey::Type::Windows)
47 && nativeKey.type() == QNativeIpcKey::Type::Windows) {
49 auto suffix =
"_sem"_L1;
50 QString semkey = nativeKey.nativeKey();
53 return { semkey, QNativeIpcKey::Type::Windows };
109 : QSharedMemory(QNativeIpcKey(),
parent)
128#if QT_DEPRECATED_SINCE(6, 10)
141 : QSharedMemory(legacyNativeKey(
key),
parent)
143 d_func()->legacyKey =
key;
156QSharedMemory::~QSharedMemory()
164#if QT_DEPRECATED_SINCE(6, 10)
189 setNativeKey(legacyNativeKey(
key));
234void QSharedMemory::setNativeKey(
const QNativeIpcKey &
key)
237 if (
key ==
d->nativeKey &&
key.isEmpty())
239 if (!isKeyTypeSupported(
key.type())) {
240 d->setError(KeyError,
tr(
"%1: unsupported key type")
241 .
arg(
"QSharedMemory::setNativeKey"_L1));
249 if (
key.type() ==
d->nativeKey.type()) {
254 d->destructBackend();
256 d->constructBackend();
260bool QSharedMemoryPrivate::initKey(SemaphoreAccessMode
mode)
264#if QT_CONFIG(systemsemaphore)
265 systemSemaphore.setNativeKey(semaphoreNativeKey(), 1,
mode);
266 if (systemSemaphore.error() != QSystemSemaphore::NoError) {
268 errorString = QSharedMemory::tr(
"%1: unable to set key on lock (%2)")
269 .
arg(function, systemSemaphore.errorString());
270 switch(systemSemaphore.error()) {
271 case QSystemSemaphore::PermissionDenied:
272 error = QSharedMemory::PermissionDenied;
274 case QSystemSemaphore::KeyError:
275 error = QSharedMemory::KeyError;
277 case QSystemSemaphore::AlreadyExists:
278 error = QSharedMemory::AlreadyExists;
280 case QSystemSemaphore::NotFound:
281 error = QSharedMemory::NotFound;
283 case QSystemSemaphore::OutOfResources:
284 error = QSharedMemory::OutOfResources;
286 case QSystemSemaphore::UnknownError:
288 error = QSharedMemory::UnknownError;
297 error = QSharedMemory::NoError;
301#if QT_DEPRECATED_SINCE(6, 10)
314QString QSharedMemory::key()
const
316 Q_D(
const QSharedMemory);
334QString QSharedMemory::nativeKey()
const
336 Q_D(
const QSharedMemory);
337 return d->nativeKey.nativeKey();
353QNativeIpcKey QSharedMemory::nativeIpcKey()
const
355 Q_D(
const QSharedMemory);
374#if QT_CONFIG(systemsemaphore)
375 if (!
d->initKey(QSystemSemaphore::Create))
377 QSharedMemoryLocker
lock(
this);
378 if (!
d->nativeKey.isEmpty() && !
d->tryLocker(&
lock, function))
386 d->error = QSharedMemory::InvalidSize;
388 QSharedMemory::tr(
"%1: create size is less then 0").arg(function);
392 if (!
d->create(
size))
395 return d->attach(
mode);
409 Q_D(
const QSharedMemory);
437bool QSharedMemory::attach(AccessMode
mode)
441 if (isAttached() || !
d->initKey({}))
443#if QT_CONFIG(systemsemaphore)
444 QSharedMemoryLocker
lock(
this);
445 if (!
d->nativeKey.isEmpty() && !
d->tryLocker(&
lock,
"QSharedMemory::attach"_L1))
449 if (isAttached() || !
d->handle())
452 return d->attach(
mode);
461bool QSharedMemory::isAttached()
const
463 Q_D(
const QSharedMemory);
464 return (
nullptr !=
d->memory);
477bool QSharedMemory::detach()
483#if QT_CONFIG(systemsemaphore)
484 QSharedMemoryLocker
lock(
this);
485 if (!
d->nativeKey.isEmpty() && !
d->tryLocker(&
lock,
"QSharedMemory::detach"_L1))
504void *QSharedMemory::data()
522const void *QSharedMemory::constData()
const
524 Q_D(
const QSharedMemory);
531const void *QSharedMemory::data()
const
533 Q_D(
const QSharedMemory);
537#if QT_CONFIG(systemsemaphore)
549bool QSharedMemory::lock()
553 qWarning(
"QSharedMemory::lock: already locked");
556 if (
d->systemSemaphore.acquire()) {
557 d->lockedByMe =
true;
560 const auto function =
"QSharedMemory::lock"_L1;
561 d->errorString = QSharedMemory::tr(
"%1: unable to lock").arg(function);
562 d->error = QSharedMemory::LockError;
574bool QSharedMemory::unlock()
579 d->lockedByMe =
false;
580 if (
d->systemSemaphore.release())
582 const auto function =
"QSharedMemory::unlock"_L1;
583 d->errorString = QSharedMemory::tr(
"%1: unable to unlock").arg(function);
584 d->error = QSharedMemory::LockError;
624QSharedMemory::SharedMemoryError QSharedMemory::error()
const
626 Q_D(
const QSharedMemory);
638QString QSharedMemory::errorString()
const
640 Q_D(
const QSharedMemory);
641 return d->errorString;
649 errorString = QSharedMemory::tr(
"%1: permission denied").
arg(function);
650 error = QSharedMemory::PermissionDenied;
653 errorString = QSharedMemory::tr(
"%1: already exists").
arg(function);
654 error = QSharedMemory::AlreadyExists;
657 errorString = QSharedMemory::tr(
"%1: doesn't exist").
arg(function);
658 error = QSharedMemory::NotFound;
663 errorString = QSharedMemory::tr(
"%1: out of resources").
arg(function);
664 error = QSharedMemory::OutOfResources;
667 errorString = QSharedMemory::tr(
"%1: unknown error: %2")
669 error = QSharedMemory::UnknownError;
670#if defined QSHAREDMEMORY_DEBUG
676bool QSharedMemory::isKeyTypeSupported(QNativeIpcKey::Type
type)
678 if (!isIpcSupported(IpcType::SharedMemory,
type))
680 using Variant =
decltype(QSharedMemoryPrivate::backend);
681 return Variant::staticVisit(
type, [](
auto ptr) {
682 using Impl = std::decay_t<
decltype(*ptr)>;
683 return Impl::runtimeSupportCheck();
687QNativeIpcKey QSharedMemory::platformSafeKey(
const QString &
key, QNativeIpcKey::Type
type)
689 return { QtIpcCommon::platformSafeKey(
key, IpcType::SharedMemory,
type),
type };
692QNativeIpcKey QSharedMemory::legacyNativeKey(
const QString &
key, QNativeIpcKey::Type
type)
694 return { legacyPlatformSafeKey(
key, IpcType::SharedMemory,
type),
type };
701#include "moc_qsharedmemory.cpp"
\macro QT_RESTRICTED_CAST_FROM_ASCII
void truncate(qsizetype pos)
Truncates the string at the given position index.
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Combined button and popup list for selecting options.
T * construct_at(T *ptr, Args &&... args)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
DBusConnection const char DBusError * error
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
static ControlElement< T > * ptr(QWidget *widget)
GLenum GLuint GLintptr GLsizeiptr size
[1]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent