19#include <private/qglobal_p.h>
20#include <private/qtcore-config_p.h>
22#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
26# include <private/qcore_unix_p.h>
31class QNativeIpcKeyPrivate
36 static QString legacyKey(
const QNativeIpcKey &key)
39 return key.d->legacyKey_;
42 static void setLegacyKey(QNativeIpcKey &key,
const QString &legacyKey)
44 QNativeIpcKeyPrivate::makeExtended(key)->legacyKey_ = legacyKey;
46 static void setNativeAndLegacyKeys(QNativeIpcKey &key,
const QString &nativeKey,
47 const QString &legacyKey)
49 key.setNativeKey(nativeKey);
50 setLegacyKey(key, legacyKey);
54 static QNativeIpcKeyPrivate *makeExtended(QNativeIpcKey &key)
56 if (!key.isSlowPath())
57 key.d =
new QNativeIpcKeyPrivate;
62namespace QtIpcCommon {
68constexpr bool isIpcSupported(IpcType ipcType, QNativeIpcKey::Type type)
71 case QNativeIpcKey::Type::SystemV:
74 case QNativeIpcKey::Type::PosixRealtime:
75 if (ipcType == IpcType::SharedMemory)
76 return QT_CONFIG(posix_shm);
77 return QT_CONFIG(posix_sem);
79 case QNativeIpcKey::Type::Windows:
87 if (ipcType == IpcType::SharedMemory)
88 return QT_CONFIG(sysv_shm);
89 return QT_CONFIG(sysv_sem);
92template <
auto Member1,
auto... Members>
class IpcStorageVariant
94 template <
typename T,
typename C>
static C extractClass(T C::*);
95 template <
typename T,
typename C>
static T extractObject(T C::*);
98 static constexpr bool IsEnabled =
decltype(extractObject(M))::Enabled;
100 static_assert(std::is_member_object_pointer_v<
decltype(Member1)>);
101 using StorageType =
decltype(extractClass(Member1));
105 template <
typename Lambda>
static auto
106 visit_internal(StorageType &storage, QNativeIpcKey::Type keyType,
const Lambda &lambda)
108 if constexpr ((IsEnabled<Member1> || ... || IsEnabled<Members>)) {
109 if constexpr (IsEnabled<Member1>) {
110 using MemberType1 =
decltype(extractObject(Member1));
111 if (MemberType1::supports(keyType))
112 return lambda(&(storage.*Member1));
114 if constexpr ((... || IsEnabled<Members>))
115 return IpcStorageVariant<Members...>::visit_internal(storage, keyType, lambda);
123 template <
typename Lambda>
auto visit(QNativeIpcKey::Type keyType,
const Lambda &lambda)
125 return visit_internal(d, keyType, lambda);
128 template <
typename Lambda>
static auto
129 staticVisit(QNativeIpcKey::Type keyType,
const Lambda &lambda)
131 if constexpr ((IsEnabled<Member1> || ... || IsEnabled<Members>)) {
132 if constexpr (IsEnabled<Member1>) {
133 using MemberType1 =
decltype(extractObject(Member1));
134 if (MemberType1::supports(keyType))
135 return lambda(
static_cast<MemberType1 *>(
nullptr));
137 if constexpr ((... || IsEnabled<Members>))
138 return IpcStorageVariant<Members...>::staticVisit(keyType, lambda);
147QNativeIpcKey legacyPlatformSafeKey(
const QString &key, IpcType ipcType, QNativeIpcKey::Type type);
148QNativeIpcKey platformSafeKey(
const QString &key, IpcType ipcType, QNativeIpcKey::Type type);
152inline int createUnixKeyFile(
const QByteArray &fileName)
154 int fd = qt_safe_open(fileName.constData(), O_EXCL | O_CREAT | O_RDWR, 0640);
Combined button and popup list for selecting options.