7#if QT_CONFIG(systemsemaphore)
8#include <QtCore/q20memory.h>
12using namespace QtIpcCommon;
15inline void QSystemSemaphorePrivate::constructBackend()
20inline void QSystemSemaphorePrivate::destructBackend()
22 visit([](
auto p) { std::destroy_at(
p); });
71#if QT_DEPRECATED_SINCE(6, 10)
84QSystemSemaphore::QSystemSemaphore(
const QString &
key,
int initialValue, AccessMode
mode)
85 : QSystemSemaphore(legacyNativeKey(
key), initialValue,
mode)
127QSystemSemaphore::QSystemSemaphore(
const QNativeIpcKey &
key,
int initialValue, AccessMode
mode)
128 :
d(new QSystemSemaphorePrivate(
key.
type()))
130 setNativeKey(
key, initialValue,
mode);
148QSystemSemaphore::~QSystemSemaphore()
190void QSystemSemaphore::setNativeKey(
const QNativeIpcKey &
key,
int initialValue, AccessMode
mode)
192 if (
key ==
d->nativeKey &&
mode == Open)
194 if (!isKeyTypeSupported(
key.type())) {
195 d->setError(KeyError,
tr(
"%1: unsupported key type")
196 .
arg(
"QSystemSemaphore::setNativeKey"_L1));
202 if (
key.type() ==
d->nativeKey.type()) {
207 d->destructBackend();
209 d->constructBackend();
211 d->initialValue = initialValue;
214 d->legacyKey.clear();
227QNativeIpcKey QSystemSemaphore::nativeIpcKey()
const
232#if QT_DEPRECATED_SINCE(6, 10)
244void QSystemSemaphore::setKey(
const QString &
key,
int initialValue, AccessMode
mode)
246 setNativeKey(legacyNativeKey(
key), initialValue,
mode);
257QString QSystemSemaphore::key()
const
276bool QSystemSemaphore::acquire()
278 return d->modifySemaphore(-1);
302bool QSystemSemaphore::release(
int n)
307 qWarning(
"QSystemSemaphore::release: n is negative.");
310 return d->modifySemaphore(
n);
319QSystemSemaphore::SystemSemaphoreError QSystemSemaphore::error()
const
354QString QSystemSemaphore::errorString()
const
356 return d->errorString;
365 errorString = QSystemSemaphore::tr(
"%1: permission denied").
arg(function);
366 error = QSystemSemaphore::PermissionDenied;
369 errorString = QSystemSemaphore::tr(
"%1: already exists").
arg(function);
370 error = QSystemSemaphore::AlreadyExists;
373 errorString = QSystemSemaphore::tr(
"%1: does not exist").
arg(function);
374 error = QSystemSemaphore::NotFound;
379 errorString = QSystemSemaphore::tr(
"%1: out of resources").
arg(function);
380 error = QSystemSemaphore::OutOfResources;
383 errorString = QSystemSemaphore::tr(
"%1: key too long").
arg(function);
384 error = QSystemSemaphore::KeyError;
387 errorString = QSystemSemaphore::tr(
"%1: unknown error: %2")
389 error = QSystemSemaphore::UnknownError;
390#if defined QSYSTEMSEMAPHORE_DEBUG
396bool QSystemSemaphore::isKeyTypeSupported(QNativeIpcKey::Type
type)
398 if (!isIpcSupported(IpcType::SystemSemaphore,
type))
400 using Variant =
decltype(QSystemSemaphorePrivate::backend);
401 return Variant::staticVisit(
type, [](
auto ptr) {
402 using Impl = std::decay_t<
decltype(*ptr)>;
403 return Impl::runtimeSupportCheck();
407QNativeIpcKey QSystemSemaphore::platformSafeKey(
const QString &
key, QNativeIpcKey::Type
type)
409 return { QtIpcCommon::platformSafeKey(
key, IpcType::SystemSemaphore,
type),
type };
412QNativeIpcKey QSystemSemaphore::legacyNativeKey(
const QString &
key, QNativeIpcKey::Type
type)
414 return { legacyPlatformSafeKey(
key, IpcType::SystemSemaphore,
type),
type };
419#include "moc_qsystemsemaphore.cpp"
\macro QT_RESTRICTED_CAST_FROM_ASCII
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 * error
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
static ControlElement< T > * ptr(QWidget *widget)