20#include <private/qglobal_p.h>
21#include <private/qtcore-config_p.h>
23#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
27# include <private/qcore_unix_p.h>
32class QNativeIpcKeyPrivate
37 static QString legacyKey(
const QNativeIpcKey &key)
40 return key.d->legacyKey_;
43 static void setLegacyKey(QNativeIpcKey &key,
const QString &legacyKey)
45 QNativeIpcKeyPrivate::makeExtended(key)->legacyKey_ = legacyKey;
47 static void setNativeAndLegacyKeys(QNativeIpcKey &key,
const QString &nativeKey,
48 const QString &legacyKey)
50 key.setNativeKey(nativeKey);
51 setLegacyKey(key, legacyKey);
55 static QNativeIpcKeyPrivate *makeExtended(QNativeIpcKey &key)
57 if (!key.isSlowPath())
58 key.d =
new QNativeIpcKeyPrivate;
63namespace QtIpcCommon {
69constexpr bool isIpcSupported(IpcType ipcType, QNativeIpcKey::Type type)
72 case QNativeIpcKey::Type::SystemV:
79 case QNativeIpcKey::Type::PosixRealtime:
80 if (ipcType == IpcType::SharedMemory)
81 return QT_CONFIG(posix_shm);
82 return QT_CONFIG(posix_sem);
84 case QNativeIpcKey::Type::Windows:
92 if (ipcType == IpcType::SharedMemory)
93 return QT_CONFIG(sysv_shm);
94 return QT_CONFIG(sysv_sem);
97template <
auto Member1,
auto... Members>
class IpcStorageVariant
99 template <
typename T,
typename C>
static C extractClass(T C::*);
100 template <
typename T,
typename C>
static T extractObject(T C::*);
103 static constexpr bool IsEnabled =
decltype(extractObject(M))::Enabled;
105 static_assert(std::is_member_object_pointer_v<
decltype(Member1)>);
106 using StorageType =
decltype(extractClass(Member1));
110 template <
typename Lambda>
static auto
111 visit_internal(StorageType &storage, QNativeIpcKey::Type keyType,
const Lambda &lambda)
113 if constexpr ((IsEnabled<Member1> || ... || IsEnabled<Members>)) {
114 if constexpr (IsEnabled<Member1>) {
115 using MemberType1 =
decltype(extractObject(Member1));
116 if (MemberType1::supports(keyType))
117 return lambda(&(storage.*Member1));
119 if constexpr ((... || IsEnabled<Members>))
120 return IpcStorageVariant<Members...>::visit_internal(storage, keyType, lambda);
128 template <
typename Lambda>
auto visit(QNativeIpcKey::Type keyType,
const Lambda &lambda)
130 return visit_internal(d, keyType, lambda);
133 template <
typename Lambda>
static auto
134 staticVisit(QNativeIpcKey::Type keyType,
const Lambda &lambda)
136 if constexpr ((IsEnabled<Member1> || ... || IsEnabled<Members>)) {
137 if constexpr (IsEnabled<Member1>) {
138 using MemberType1 =
decltype(extractObject(Member1));
139 if (MemberType1::supports(keyType))
140 return lambda(
static_cast<MemberType1 *>(
nullptr));
142 if constexpr ((... || IsEnabled<Members>))
143 return IpcStorageVariant<Members...>::staticVisit(keyType, lambda);
152QNativeIpcKey legacyPlatformSafeKey(
const QString &key, IpcType ipcType, QNativeIpcKey::Type type);
153QNativeIpcKey platformSafeKey(
const QString &key, IpcType ipcType, QNativeIpcKey::Type type);
157inline int createUnixKeyFile(
const QByteArray &fileName)
159 int fd = qt_safe_open(fileName.constData(), O_EXCL | O_CREAT | O_RDWR, 0640);
Combined button and popup list for selecting options.