1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/OsLayer/os_symbian.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,313 @@
1.4 +/**
1.5 +* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Declarations for the multi-threaded Symbian OS porting layer.
1.19 +*
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +
1.25 +/**
1.26 + @file
1.27 +*/
1.28 +#ifndef OS_SYMBIAN_H
1.29 +#define OS_SYMBIAN_H
1.30 +
1.31 +#include <sqlite3.h>
1.32 +#include "FileBuf64.h"
1.33 +
1.34 +#ifdef SQLITE_OS_SYMBIAN
1.35 +
1.36 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.37 +////////////////////////// TStaticFs /////////////////////////////////////////////////////////////////////////////////////////
1.38 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.39 +
1.40 +/**
1.41 +This class encapsulates a RFs object.
1.42 +Only one RFs object is created per process.
1.43 +The class has a build dependent implementation:
1.44 + - a single global static TStaticFs variable is defined for the hardware builds;
1.45 + - the process local storage (TPls) is used for storing TStaticFs object for the emulator builds;
1.46 +
1.47 +@see TPls
1.48 +
1.49 +@internalComponent
1.50 +*/
1.51 +NONSHARABLE_CLASS(TStaticFs)
1.52 + {
1.53 +public:
1.54 + TStaticFs(); //Build dependent implementation
1.55 + TInt Connect();
1.56 + static RFs& Fs(); //Build dependent implementation
1.57 +private:
1.58 + RFs iFs;
1.59 + };
1.60 +
1.61 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.62 +////////////////////////// sqlite3_mutex /////////////////////////////////////////////////////////////////////////////////////
1.63 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.64 +
1.65 +const TInt KStaticMutexCount = SQLITE_MUTEX_STATIC_LRU2 - 1;//"-1": excluding fast and recoursive mutex types
1.66 +
1.67 +/**
1.68 +This class describes a mutex object.
1.69 +SQLite uses three mutex types: static, fast and recursive.
1.70 +
1.71 +The static mutexes are expected to be created prior first SQLite function call.
1.72 +The OS porting layer provides build dependent implementation for the static mutextes:
1.73 + - The static mutexes are defined as global variables for the hardware builds.
1.74 + The mutex creation is performed in the global variable's constructor.
1.75 + If the mutex creation fails, the program will be terminated;
1.76 + - The static mutexes are stored in the process local storage for the emulator builds.
1.77 + If the mutex creation fails, the program will be terminated;
1.78 +
1.79 +The difference between fast and recursive mutextes is that the recursive mutexes can be entered mutiple times
1.80 +by the same thread. The OS porting layer makes no difference between fast and recursive mutexes at the moment.
1.81 +Whether the SQLite requests fast or ecursive mutex, a recursive mutex will be created.
1.82 +The recursive mutex creation can fail, in which case the error will be reported back to the caller.
1.83 +
1.84 +Note that even though sqlite3_mutex has virtual methods, it is not declared as a standard Symbian OS "C" class
1.85 +because sqlite3_mutex is an abstract type, externally declared and used by SQLite (SQLite is a C library).
1.86 +SQLite deals only with pointers to sqlite3_mutex objects. See the declaration in sqlite3.h file.
1.87 +
1.88 +@see TPls
1.89 +@see CRecursiveMutex
1.90 +@see TStaticMutex
1.91 +
1.92 +@internalComponent
1.93 +*/
1.94 +NONSHARABLE_CLASS(sqlite3_mutex)
1.95 + {
1.96 +public:
1.97 + sqlite3_mutex();
1.98 + TInt Create();
1.99 + virtual ~sqlite3_mutex();
1.100 + void Enter();
1.101 + void Leave();
1.102 + TBool IsHeld() const;
1.103 +private:
1.104 + TInt iRefCount;
1.105 + TThreadId iOwnerThreadId;
1.106 + RMutex iMutex;
1.107 + };
1.108 +
1.109 +/**
1.110 +sqlite3_mutex derived class. Describes a recursive mutex.
1.111 +The mutex creation can fail, the error will be reported back to the caller.
1.112 +
1.113 +This is not a standard Symbian OS "C" class, not derived from CBase.
1.114 +CRecursiveMutex is a specialization of the sqlite3_mutex class, used for recursive mutexes.
1.115 +
1.116 +@see sqlite3_mutex
1.117 +
1.118 +@internalComponent
1.119 +*/
1.120 +NONSHARABLE_CLASS(CRecursiveMutex) : public sqlite3_mutex
1.121 + {
1.122 +public:
1.123 + static CRecursiveMutex* New();
1.124 + virtual ~CRecursiveMutex();
1.125 +
1.126 +private:
1.127 + CRecursiveMutex()
1.128 + {
1.129 + }
1.130 + };
1.131 +
1.132 +/**
1.133 +sqlite3_mutex derived class. Describes a static mutex.
1.134 +If the mutex creation fails, the program will be terminated.
1.135 +
1.136 +@see sqlite3_mutex
1.137 +
1.138 +@internalComponent
1.139 +*/
1.140 +NONSHARABLE_CLASS(TStaticMutex) : public sqlite3_mutex
1.141 + {
1.142 +public:
1.143 + TStaticMutex(); //Build dependent implementation
1.144 + };
1.145 +
1.146 +/**
1.147 +Returns a pointer to already created static mutex.
1.148 +The function has build dependet implementation:
1.149 + - The static mutexes are defined as global objects for the hardware builds;
1.150 + - The static mutexes are stored in th eprocess local storage for the emulator builds;
1.151 +
1.152 +@see TPls
1.153 +@see sqlite3_mutex
1.154 +
1.155 +@param aType The static mutex type
1.156 +@return sqlite3_mutex pointer
1.157 +
1.158 +@panic SqliteMt 6 Process local storage initialization failure (the emulator builds only)
1.159 +@panic SqliteMt 22 The mutex type is bigger than SQLITE_MUTEX_STATIC_LRU2
1.160 +
1.161 +@internalComponent
1.162 +*/
1.163 +sqlite3_mutex* StaticMutex(TInt aType); //Build dependent implementation
1.164 +
1.165 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.166 +////////////////////////// TMutexApi ////////////////////////////////////////////////////////////////////////////////////////
1.167 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.168 +
1.169 +/**
1.170 +Defines mutex API, that is needed by SQLite.
1.171 +
1.172 +SQLite creates a mutex using the TMutexApi::Alloc() method.
1.173 +Depending on aType parameter value, either existing static mutex will be used or a new recursive mutex will be created.
1.174 +
1.175 +@see TheMutexMethods
1.176 +@see sqlite3_mutex
1.177 +@see CRecursiveMutex
1.178 +@see TStaticMutex
1.179 +
1.180 +@internalComponent
1.181 +*/
1.182 +NONSHARABLE_CLASS(TMutexApi)
1.183 + {
1.184 +public:
1.185 + static int Init();
1.186 + static int End();
1.187 + static sqlite3_mutex* Alloc(int aType);
1.188 + static void Free(sqlite3_mutex* aMutex);
1.189 + static void Enter(sqlite3_mutex* aMutex);
1.190 + static int Try(sqlite3_mutex* aMutex);
1.191 + static void Leave(sqlite3_mutex* aMutex);
1.192 + static int Held(sqlite3_mutex* aMutex);
1.193 + static int Notheld(sqlite3_mutex* aMutex);
1.194 + };
1.195 +
1.196 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.197 +////////////////////////// TDbFile //////////////////////////////////////////////////////////////////////////////////////////
1.198 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.199 +
1.200 +/**
1.201 +TDbFile derives from the sqlite3_file structure, adding data members needed for processing the SQLite requests to the OS layer.
1.202 +When SQLite needs an access to a file, SQLite allocates memory for a new TDbFile instance and passes a pointer to that
1.203 +instance to TVfs::Open(). TVfs::Open() creates/opens the file and initializes the TDbFile instance.
1.204 +SQLite uses the initialized TDbFile instance (actually SQLite knows and uses the sqlite3_file, the base structure)
1.205 +every time when needs to read or write from/to the file, using for that an appropriate TFileIo method.
1.206 +
1.207 +No virtual methods here! sqlite3_file contains data members. If a virtual method is added, that will shift the offset of the
1.208 +data members from the beginning of the sqlite3_file object by 4 bytes. This is not what SQLite (C code) expects.
1.209 +
1.210 +@internalComponent
1.211 +
1.212 +@see TVfs
1.213 +@see TFileIo
1.214 +@see TVfs::Open()
1.215 +*/
1.216 +NONSHARABLE_STRUCT(TDbFile) : public sqlite3_file
1.217 + {
1.218 + inline TDbFile();
1.219 + RFileBuf64 iFileBuf;
1.220 + HBufC* iFullName; //Used for the "delete file" operation
1.221 + TInt iSharedLockByte;
1.222 + TInt iLockType;
1.223 + TBool iReadOnly;
1.224 + TInt iSectorSize;
1.225 + TInt iDeviceCharacteristics;
1.226 + };
1.227 +
1.228 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.229 +////////////////////////// TFileIo //////////////////////////////////////////////////////////////////////////////////////////
1.230 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.231 +
1.232 +/**
1.233 +TFileIo class offers static methods for performing operations on a file.
1.234 +Every TFileIo method has a pointer to a sqlite3_file instance (so, a TDbFile instance) as its first argument.
1.235 +
1.236 +SQLite never accesses the file system directly, only through function pointers, data members of the sqlite3_io_methods structure.
1.237 +The OS porting layer defines a single instance of sqlite3_io_methods structure, TheFileIoApi, and uses the TFileIo to initialize the
1.238 +sqlite3_io_methods data members (function pointers).
1.239 +Every time when SQLite creates/opens a file using TVfs::Open(), TVfs::Open() will pass back to SQLite a pointer to the single
1.240 +initialized sqlite3_io_methods instance (TheFileIoApi) that will be used later by SQLite for accessing the file.
1.241 +
1.242 +@internalComponent
1.243 +
1.244 +@see TVfs
1.245 +@see TVfs::Open()
1.246 +@see TDbFile
1.247 +*/
1.248 +NONSHARABLE_CLASS(TFileIo)
1.249 + {
1.250 +public:
1.251 + static int Close(sqlite3_file* aDbFile);
1.252 + static int Read(sqlite3_file* aDbFile, void* aBuf, int aAmt, sqlite3_int64 aOffset);
1.253 + static int Write(sqlite3_file* aDbFile, const void* aData, int aAmt, sqlite3_int64 aOffset);
1.254 + static int Truncate(sqlite3_file* aDbFile, sqlite3_int64 aLength);
1.255 + static int Sync(sqlite3_file* aDbFile, int aFlags);
1.256 + static int FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize);
1.257 + static int Lock(sqlite3_file* aDbFile, int aLockType);
1.258 + static int Unlock(sqlite3_file* aDbFile, int aLockType);
1.259 + static int CheckReservedLock(sqlite3_file* aDbFile, int *aResOut);
1.260 + static int FileControl(sqlite3_file* aDbFile, int aOp, void* aArg);
1.261 + static int SectorSize(sqlite3_file* aDbFile);
1.262 + static int DeviceCharacteristics(sqlite3_file* aDbFile);
1.263 +private:
1.264 + static TInt GetReadLock(TDbFile& aDbFile);
1.265 + static TInt UnlockReadLock(TDbFile& aDbFile);
1.266 + };
1.267 +
1.268 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.269 +////////////////////////// TVfs //////////////////////////////////////////////////////////////////////////////////////////
1.270 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.271 +
1.272 +/**
1.273 +@return Pointer to the sqlite3_vfs interface
1.274 +
1.275 +@see TVfs
1.276 +
1.277 +@panic SqliteMt 7 Process local storage initialization failure (the emulator builds only)
1.278 +
1.279 +@internalComponent
1.280 +*/
1.281 +sqlite3_vfs* VfsApi();//Platform dependend implementation
1.282 +
1.283 +/**
1.284 +TVfs ("VFS" - virtual file system) class offers methods for creating/openning a file, deleting a file,
1.285 +a "sleep" method, a "time" method, a "rand" method, etc.
1.286 +SQLite never accesses the OS API directly, only through the API offered by TVfs and TFileIo classes.
1.287 +
1.288 +@internalComponent
1.289 +
1.290 +@see TFileIo
1.291 +*/
1.292 +NONSHARABLE_CLASS(TVfs)
1.293 + {
1.294 +public:
1.295 + static int Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags);
1.296 + static int Delete(sqlite3_vfs* aVfs, const char* aFileName, int aSyncDir);
1.297 + static int Access(sqlite3_vfs* aVfs, const char* aFileName, int aFlags, int* aResOut);
1.298 + static int FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf);
1.299 + static int Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf);
1.300 + static int Sleep(sqlite3_vfs* aVfs, int aMicrosec);
1.301 + static int CurrentTime(sqlite3_vfs* aVfs, double* aNow);
1.302 + static int GetLastError(sqlite3_vfs *sVfs, int aBufLen, char* aBuf);
1.303 +private:
1.304 + static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo);
1.305 + static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo);
1.306 + static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo);
1.307 + static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize);
1.308 + static TInt DoFileSizeCorruptionCheck(TDbFile& aDbFile, const TDesC& aFname, TInt aFmode);
1.309 + };
1.310 +
1.311 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.312 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.313 +
1.314 +#endif//SQLITE_OS_SYMBIAN
1.315 +
1.316 +#endif//OS_SYMBIAN_H