WinRT: Shared memory support
WinRT supports in-memory file mapping via CreateFileMappingFromApp. This is unimplemented on Windows Phone. Change-Id: Ic5692e501cd2fe9e1337829bdeb933fccc804abe Done-with: Andrew Knight Reviewed-by: Maurice Kalinowski <maurice.kalinowski@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>bb10
parent
95e0da216f
commit
89f299201d
|
|
@ -105,12 +105,17 @@ HANDLE QSharedMemoryPrivate::handle()
|
|||
errorString = QSharedMemory::tr("%1: unable to make key").arg(function);
|
||||
return 0;
|
||||
}
|
||||
#ifndef Q_OS_WINCE
|
||||
hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16());
|
||||
#else
|
||||
#if defined(Q_OS_WINPHONE)
|
||||
Q_UNIMPLEMENTED();
|
||||
hand = 0;
|
||||
#elif defined(Q_OS_WINRT)
|
||||
hand = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, (PCWSTR)nativeKey.utf16());
|
||||
#elif defined(Q_OS_WINCE)
|
||||
// This works for opening a mapping too, but always opens it with read/write access in
|
||||
// attach as it seems.
|
||||
hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)nativeKey.utf16());
|
||||
#else
|
||||
hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16());
|
||||
#endif
|
||||
if (!hand) {
|
||||
setErrorString(function);
|
||||
|
|
@ -141,7 +146,14 @@ bool QSharedMemoryPrivate::create(int size)
|
|||
}
|
||||
|
||||
// Create the file mapping.
|
||||
#if defined(Q_OS_WINPHONE)
|
||||
Q_UNIMPLEMENTED();
|
||||
hand = 0;
|
||||
#elif defined(Q_OS_WINRT)
|
||||
hand = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, size, (PCWSTR)nativeKey.utf16());
|
||||
#else
|
||||
hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16());
|
||||
#endif
|
||||
setErrorString(function);
|
||||
|
||||
// hand is valid when it already exists unlike unix so explicitly check
|
||||
|
|
@ -155,7 +167,14 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
|
|||
{
|
||||
// Grab a pointer to the memory block
|
||||
int permissions = (mode == QSharedMemory::ReadOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS);
|
||||
#if defined(Q_OS_WINPHONE)
|
||||
Q_UNIMPLEMENTED();
|
||||
memory = 0;
|
||||
#elif defined(Q_OS_WINRT)
|
||||
memory = (void *)MapViewOfFileFromApp(handle(), permissions, 0, 0);
|
||||
#else
|
||||
memory = (void *)MapViewOfFile(handle(), permissions, 0, 0, 0);
|
||||
#endif
|
||||
if (0 == memory) {
|
||||
setErrorString(QLatin1String("QSharedMemory::attach"));
|
||||
cleanHandle();
|
||||
|
|
@ -179,10 +198,15 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
|
|||
bool QSharedMemoryPrivate::detach()
|
||||
{
|
||||
// umap memory
|
||||
#if defined(Q_OS_WINPHONE)
|
||||
Q_UNIMPLEMENTED();
|
||||
return false;
|
||||
#else
|
||||
if (!UnmapViewOfFile(memory)) {
|
||||
setErrorString(QLatin1String("QSharedMemory::detach"));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
memory = 0;
|
||||
size = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue