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); });
74QSystemSemaphore::QSystemSemaphore(
const QString &
key,
int initialValue, AccessMode
mode)
75 : QSystemSemaphore(legacyNativeKey(
key), initialValue,
mode)
115QSystemSemaphore::QSystemSemaphore(
const QNativeIpcKey &
key,
int initialValue, AccessMode
mode)
116 :
d(new QSystemSemaphorePrivate(
key.
type()))
118 setNativeKey(
key, initialValue,
mode);
136QSystemSemaphore::~QSystemSemaphore()
178void QSystemSemaphore::setNativeKey(
const QNativeIpcKey &
key,
int initialValue, AccessMode
mode)
180 if (
key ==
d->nativeKey &&
mode == Open)
182 if (!isKeyTypeSupported(
key.type())) {
183 d->setError(KeyError,
tr(
"%1: unsupported key type")
184 .
arg(
"QSystemSemaphore::setNativeKey"_L1));
190 if (
key.type() ==
d->nativeKey.type()) {
195 d->destructBackend();
197 d->constructBackend();
199 d->initialValue = initialValue;
213QNativeIpcKey QSystemSemaphore::nativeIpcKey()
const
228void QSystemSemaphore::setKey(
const QString &
key,
int initialValue, AccessMode
mode)
230 setNativeKey(legacyNativeKey(
key), initialValue,
mode);
239QString QSystemSemaphore::key()
const
241 return QNativeIpcKeyPrivate::legacyKey(
d->nativeKey);
257bool QSystemSemaphore::acquire()
259 return d->modifySemaphore(-1);
283bool QSystemSemaphore::release(
int n)
288 qWarning(
"QSystemSemaphore::release: n is negative.");
291 return d->modifySemaphore(
n);
300QSystemSemaphore::SystemSemaphoreError QSystemSemaphore::error()
const
335QString QSystemSemaphore::errorString()
const
337 return d->errorString;
346 errorString = QSystemSemaphore::tr(
"%1: permission denied").arg(function);
347 error = QSystemSemaphore::PermissionDenied;
350 errorString = QSystemSemaphore::tr(
"%1: already exists").arg(function);
351 error = QSystemSemaphore::AlreadyExists;
354 errorString = QSystemSemaphore::tr(
"%1: does not exist").arg(function);
355 error = QSystemSemaphore::NotFound;
360 errorString = QSystemSemaphore::tr(
"%1: out of resources").arg(function);
361 error = QSystemSemaphore::OutOfResources;
364 errorString = QSystemSemaphore::tr(
"%1: key too long").arg(function);
365 error = QSystemSemaphore::KeyError;
368 errorString = QSystemSemaphore::tr(
"%1: unknown error: %2")
370 error = QSystemSemaphore::UnknownError;
371#if defined QSYSTEMSEMAPHORE_DEBUG
377bool QSystemSemaphore::isKeyTypeSupported(QNativeIpcKey::Type
type)
379 if (!isIpcSupported(IpcType::SystemSemaphore,
type))
381 using Variant =
decltype(QSystemSemaphorePrivate::backend);
382 return Variant::staticVisit(
type, [](
auto ptr) {
383 using Impl = std::decay_t<
decltype(*ptr)>;
384 return Impl::runtimeSupportCheck();
388QNativeIpcKey QSystemSemaphore::platformSafeKey(
const QString &
key, QNativeIpcKey::Type
type)
390 return QtIpcCommon::platformSafeKey(
key, IpcType::SystemSemaphore,
type);
393QNativeIpcKey QSystemSemaphore::legacyNativeKey(
const QString &
key, QNativeIpcKey::Type
type)
395 return QtIpcCommon::legacyPlatformSafeKey(
key, IpcType::SystemSemaphore,
type);
400#include "moc_qsystemsemaphore.cpp"
\macro QT_RESTRICTED_CAST_FROM_ASCII
auto visit(Fn &&fn, QIODevice *socket, Args &&...args)
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)