summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-07-21 18:19:39 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-07-21 18:19:39 (GMT)
commitb8327a0d5c5192750f7bf959290f6a50cdcb85b5 (patch)
tree46fe034e7bac86f83fe97c586cfcf2ff51bcfbad /src/corelib
parent45f372edda9d43bc98c7742a5dfdd89e4efbe225 (diff)
parent433872d7e26a6a99297e231ac3bc0f603c9cefe8 (diff)
downloadQt-b8327a0d5c5192750f7bf959290f6a50cdcb85b5.zip
Qt-b8327a0d5c5192750f7bf959290f6a50cdcb85b5.tar.gz
Qt-b8327a0d5c5192750f7bf959290f6a50cdcb85b5.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-earth-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-earth-staging: QNetworkAccessFileBackend: Add warning for file url without scheme. Native memory mapped file support Fix compiler warning Create QScopedResource class
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qfsfileengine.cpp6
-rw-r--r--src/corelib/io/qfsfileengine_p.h10
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp56
-rw-r--r--src/corelib/kernel/qcore_symbian_p.h24
4 files changed, 92 insertions, 4 deletions
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index 0d23a27..548f9cf 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -120,7 +120,7 @@ void QFSFileEnginePrivate::init()
openMode = QIODevice::NotOpen;
fd = -1;
fh = 0;
-#ifdef Q_OS_SYMBIAN
+#if defined (Q_OS_SYMBIAN) && !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP)
fileHandleForMaps = -1;
#endif
lastIOCommand = IOFlushCommand;
@@ -368,8 +368,10 @@ bool QFSFileEnginePrivate::closeFdFh()
if (fd == -1 && !fh
#ifdef Q_OS_SYMBIAN
&& !symbianFile.SubSessionHandle()
+#ifndef QT_SYMBIAN_USE_NATIVE_FILEMAP
&& fileHandleForMaps == -1
#endif
+#endif
)
return false;
@@ -378,7 +380,7 @@ bool QFSFileEnginePrivate::closeFdFh()
bool closed = true;
tried_stat = 0;
-#ifdef Q_OS_SYMBIAN
+#if defined(Q_OS_SYMBIAN) && !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP)
// Map handle is always owned by us so always close it
if (fileHandleForMaps >= 0) {
QT_CLOSE(fileHandleForMaps);
diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h
index 79dda1b..f93250e 100644
--- a/src/corelib/io/qfsfileengine_p.h
+++ b/src/corelib/io/qfsfileengine_p.h
@@ -62,6 +62,12 @@
#ifdef Q_OS_SYMBIAN
#include <f32file.h>
+//This macro will be defined if the OS supports memory mapped files
+#if defined (SYMBIAN_FILE_MAPPING_SUPPORTED) && !defined (WINS)
+//simpler define to check in sources
+#define QT_SYMBIAN_USE_NATIVE_FILEMAP
+#include <f32filemap.h>
+#endif
#endif
#ifndef QT_NO_FSFILEENGINE
@@ -139,9 +145,11 @@ public:
*/
TInt symbianFilePos;
#endif
+#ifndef QT_SYMBIAN_USE_NATIVE_FILEMAP
mutable int fileHandleForMaps;
int getMapHandle();
#endif
+#endif
#ifdef Q_WS_WIN
HANDLE fileHandle;
@@ -153,6 +161,8 @@ public:
#endif
mutable DWORD fileAttrib;
+#elif defined (QT_SYMBIAN_USE_NATIVE_FILEMAP)
+ QHash<uchar *, RFileMap> maps;
#else
QHash<uchar *, QPair<int /*offset % PageSize*/, size_t /*length + offset % PageSize*/> > maps;
#endif
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 681e55d..9de282a 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -602,7 +602,7 @@ int QFSFileEnginePrivate::nativeHandle() const
return fh ? fileno(fh) : fd;
}
-#ifdef Q_OS_SYMBIAN
+#if defined(Q_OS_SYMBIAN) && !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP)
int QFSFileEnginePrivate::getMapHandle()
{
if (symbianFile.SubSessionHandle()) {
@@ -925,6 +925,7 @@ QString QFSFileEngine::owner(FileOwner own) const
return QFileSystemEngine::resolveUserName(ownerId(own));
return QFileSystemEngine::resolveGroupName(ownerId(own));
#else
+ Q_UNUSED(own)
return QString();
#endif
}
@@ -1045,9 +1046,47 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
QT_OFF_T realOffset = QT_OFF_T(offset);
realOffset &= ~(QT_OFF_T(pageSize - 1));
+#ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP
+ TInt nativeMapError = KErrNone;
+ RFileMap mapping;
+ TUint mode(EFileMapRemovableMedia);
+ //If the file was opened for write or read/write, then open the map for read/write
+ if (openMode & QIODevice::WriteOnly)
+ mode |= EFileMapWrite;
+ if (symbianFile.SubSessionHandle()) {
+ nativeMapError = mapping.Open(symbianFile, offset, size, mode);
+ } else {
+ //map file by name if we don't have a native handle
+ QString fn = QFileSystemEngine::absoluteName(fileEntry).nativeFilePath();
+ TUint filemode = EFileShareReadersOrWriters | EFileRead;
+ if (openMode & QIODevice::WriteOnly)
+ filemode |= EFileWrite;
+ nativeMapError = mapping.Open(qt_s60GetRFs(), qt_QString2TPtrC(fn), filemode, offset, size, mode);
+ }
+ if (nativeMapError == KErrNone) {
+ QScopedResource<RFileMap> ptr(mapping); //will call Close if adding to mapping throws an exception
+ uchar *address = mapping.Base();
+ maps[address] = mapping;
+ ptr.take();
+ return address;
+ }
+ QFile::FileError reportedError = QFile::UnspecifiedError;
+ switch (nativeMapError) {
+ case KErrAccessDenied:
+ case KErrPermissionDenied:
+ reportedError = QFile::PermissionsError;
+ break;
+ case KErrNoMemory:
+ reportedError = QFile::ResourceError;
+ break;
+ }
+ q->setError(reportedError, QSystemError(nativeMapError, QSystemError::NativeError).toString());
+ return 0;
+#else
#ifdef Q_OS_SYMBIAN
+ //older phones & emulator don't support native mapping, so need to keep the open C way around for those.
void *mapAddress;
- TRAPD(err, mapAddress = QT_MMAP((void*)0, realSize,
+ TRAPD(err, mapAddress = QT_MMAP((void*)0, realSize,
access, MAP_SHARED, getMapHandle(), realOffset));
if (err != KErrNone) {
qWarning("OpenC bug: leave from mmap %d", err);
@@ -1079,6 +1118,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
break;
}
return 0;
+#endif
}
bool QFSFileEnginePrivate::unmap(uchar *ptr)
@@ -1090,6 +1130,17 @@ bool QFSFileEnginePrivate::unmap(uchar *ptr)
return false;
}
+#ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP
+ RFileMap mapping = maps.value(ptr);
+ TInt err = mapping.Flush();
+ mapping.Close();
+ maps.remove(ptr);
+ if (err) {
+ q->setError(QFile::WriteError, QSystemError(err, QSystemError::NativeError).toString());
+ return false;
+ }
+ return true;
+#else
uchar *start = ptr - maps[ptr].first;
size_t len = maps[ptr].second;
if (-1 == munmap(start, len)) {
@@ -1098,6 +1149,7 @@ bool QFSFileEnginePrivate::unmap(uchar *ptr)
}
maps.remove(ptr);
return true;
+#endif
#else
return false;
#endif
diff --git a/src/corelib/kernel/qcore_symbian_p.h b/src/corelib/kernel/qcore_symbian_p.h
index 3019e05..a8f576d 100644
--- a/src/corelib/kernel/qcore_symbian_p.h
+++ b/src/corelib/kernel/qcore_symbian_p.h
@@ -59,6 +59,7 @@
#include <qstring.h>
#include <qrect.h>
#include <qhash.h>
+#include <qscopedpointer.h>
#include <f32file.h>
#include <es_sock.h>
@@ -262,6 +263,29 @@ private:
RConnection *iDefaultConnection;
};
+template <typename T> class QScopedPointerResourceCloser
+{
+public:
+ static inline void cleanup(T* pointer)
+ {
+ if (pointer)
+ pointer->Close();
+ }
+};
+
+/*typical use:
+ RFile file;
+ file.Open(...);
+ QScopedResource<RFile> ptr(file);
+ container.append(file); //this may throw std::bad_alloc, in which case file.Close() is called by destructor
+ ptr.take(); //if we reach this line, ownership is transferred to the container
+ */
+template <typename T> class QScopedResource : public QScopedPointer<T, QScopedPointerResourceCloser<T> >
+{
+public:
+ inline QScopedResource(T& resource) : QScopedPointer<T, QScopedPointerResourceCloser<T> >(&resource) {}
+};
+
QT_END_NAMESPACE
QT_END_HEADER