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:
75 case QNativeIpcKey::Type::PosixRealtime:
76 if (ipcType == IpcType::SharedMemory)
77 return QT_CONFIG(posix_shm);
78 return QT_CONFIG(posix_sem);
80 case QNativeIpcKey::Type::Windows:
88 if (ipcType == IpcType::SharedMemory)
89 return QT_CONFIG(sysv_shm);
90 return QT_CONFIG(sysv_sem);
93template <
auto Member1,
auto... Members>
class IpcStorageVariant
95 template <
typename T,
typename C>
static C extractClass(T C::*);
96 template <
typename T,
typename C>
static T extractObject(T C::*);
99 static constexpr bool IsEnabled =
decltype(extractObject(M))::Enabled;
101 static_assert(std::is_member_object_pointer_v<
decltype(Member1)>);
102 using StorageType =
decltype(extractClass(Member1));
106 template <
typename Lambda>
static auto
107 visit_internal(StorageType &storage, QNativeIpcKey::Type keyType,
const Lambda &lambda)
109 if constexpr ((IsEnabled<Member1> || ... || IsEnabled<Members>)) {
110 if constexpr (IsEnabled<Member1>) {
111 using MemberType1 =
decltype(extractObject(Member1));
112 if (MemberType1::supports(keyType))
113 return lambda(&(storage.*Member1));
115 if constexpr ((... || IsEnabled<Members>))
116 return IpcStorageVariant<Members...>::visit_internal(storage, keyType, lambda);
124 template <
typename Lambda>
auto visit(QNativeIpcKey::Type keyType,
const Lambda &lambda)
126 return visit_internal(d, keyType, lambda);
129 template <
typename Lambda>
static auto
130 staticVisit(QNativeIpcKey::Type keyType,
const Lambda &lambda)
132 if constexpr ((IsEnabled<Member1> || ... || IsEnabled<Members>)) {
133 if constexpr (IsEnabled<Member1>) {
134 using MemberType1 =
decltype(extractObject(Member1));
135 if (MemberType1::supports(keyType))
136 return lambda(
static_cast<MemberType1 *>(
nullptr));
138 if constexpr ((... || IsEnabled<Members>))
139 return IpcStorageVariant<Members...>::staticVisit(keyType, lambda);
148QNativeIpcKey legacyPlatformSafeKey(
const QString &key, IpcType ipcType, QNativeIpcKey::Type type);
149QNativeIpcKey platformSafeKey(
const QString &key, IpcType ipcType, QNativeIpcKey::Type type);
153inline int createUnixKeyFile(
const QByteArray &fileName)
155 int fd = qt_safe_open(fileName.constData(), O_EXCL | O_CREAT | O_RDWR, 0640);