persistentstorage/sqlite3api/OsLayer/os_symbian_emul.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20  @file
    20  @file
    21 */
    21 */
    22 #include "os_symbian.h"
    22 #include "os_symbian.h"
    23 #include <pls.h>
    23 #include <pls.h>
    24 #include <e32std.h>
    24 #include <e32std.h>
    25 #include "SqliteUtil.h"
       
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "os_symbian_emulTraces.h"
       
    29 #endif
       
    30 #include "SqliteTraceDef.h"
       
    31 
    25 
    32 #ifdef SQLITE_OS_SYMBIAN
    26 #ifdef SQLITE_OS_SYMBIAN
    33 
    27 
    34 const TUid KSqliteUid = {0x10285A79};//See UID3 in SQLite3.mmp file - it should be the same
    28 const TUid KSqliteUid = {0x10285A79};//See UID3 in SQLite3.mmp file - it should be the same
    35 
    29 
    82 		TInt cnt = 0;
    76 		TInt cnt = 0;
    83 		while(iTable[idx].iKey != aKey && iTable[idx].iKey != NULL && ++cnt < KMaxEntries)
    77 		while(iTable[idx].iKey != aKey && iTable[idx].iKey != NULL && ++cnt < KMaxEntries)
    84 			{
    78 			{
    85 			idx = ++idx % KMaxEntries;
    79 			idx = ++idx % KMaxEntries;
    86 			}
    80 			}
    87 		__ASSERT_ALWAYS(cnt < KMaxEntries, __SQLITEPANIC2(ESqliteOsPanicMaxKeysExceeded));
    81 		__ASSERT_ALWAYS(cnt < KMaxEntries, User::Panic(KPanicCategory, EPanicMaxKeysExceeded));
    88 		if(!iTable[idx].iKey)
    82 		if(!iTable[idx].iKey)
    89 			{
    83 			{
    90 			Add(idx, aKey, aLength);
    84 			Add(idx, aKey, aLength);
    91 			}
    85 			}
    92 		return iTable[idx].iData;
    86 		return iTable[idx].iData;
   109 	@param aLength Global variable data length in bytes
   103 	@param aLength Global variable data length in bytes
   110 	@panic SqliteMt 10 There is no space in the WSD buffer for the new variable
   104 	@panic SqliteMt 10 There is no space in the WSD buffer for the new variable
   111 	*/
   105 	*/
   112 	void Add(TInt aIdx, const TUint8* aKey, TInt aLength)
   106 	void Add(TInt aIdx, const TUint8* aKey, TInt aLength)
   113 		{
   107 		{
   114 		__ASSERT_ALWAYS((iSize + aLength) <= KBufferSize, __SQLITEPANIC2(ESqliteOsPanicBufferSizeExceeded));
   108 		__ASSERT_ALWAYS((iSize + aLength) <= KBufferSize, User::Panic(KPanicCategory, EPanicBufferSizeExceeded));
   115 		//Add new entry to the hash table and the intial value to the WSD buffer
   109 		//Add new entry to the hash table and the intial value to the WSD buffer
   116 		iTable[aIdx].iKey = aKey;
   110 		iTable[aIdx].iKey = aKey;
   117 		iTable[aIdx].iData = iNext;
   111 		iTable[aIdx].iData = iNext;
   118 		iNext = Mem::Copy(iNext, aKey, aLength);
   112 		iNext = Mem::Copy(iNext, aKey, aLength);
   119 		iSize += aLength;
   113 		iSize += aLength;
   163 
   157 
   164 @internalComponent
   158 @internalComponent
   165 */
   159 */
   166 static TInt PlsInitialize(TPls* aPls)
   160 static TInt PlsInitialize(TPls* aPls)
   167 	{
   161 	{
   168 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, PLSINITIALIZE_ENTRY, "OS-Entry;0;PlsInitialize"));
   162 	__ASSERT_ALWAYS(aPls != NULL, User::Panic(KPanicCategory, EPanicNullPls1));
   169 	__ASSERT_ALWAYS(aPls != NULL, __SQLITEPANIC2(ESqliteOsPanicNullPls1));
       
   170 	//Global RFs object
   163 	//Global RFs object
   171 	TInt err = aPls->iStaticFs.Connect();
   164 	TInt err = aPls->iStaticFs.Connect();
   172 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, PLSINITIALIZE1, "OS;0;PlsInitialize;iStaticFs.Connect() err=%d", err));
   165 	__ASSERT_ALWAYS(err == KErrNone , User::Panic(KPanicCategory, EPanicFsCreationError));
   173 	__ASSERT_ALWAYS(err == KErrNone, __SQLITEPANIC2(ESqliteOsPanicFsCreationError));
       
   174 	//Static mutexes
   166 	//Static mutexes
   175 	TInt idx = 0;
   167 	for(TInt i=0;i<(sizeof(aPls->iStaticMutex)/sizeof(aPls->iStaticMutex[0])) && err==KErrNone;++i)
   176 	for(;idx<(sizeof(aPls->iStaticMutex)/sizeof(aPls->iStaticMutex[0])) && err==KErrNone;++idx)
   168 		{
   177 		{
   169 		err = aPls->iStaticMutex[i].Create();
   178 		err = aPls->iStaticMutex[idx].Create();
   170 		}
   179 		}
   171 	__ASSERT_ALWAYS(err == KErrNone , User::Panic(KPanicCategory, EPanicMutexCreationError));
   180 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, PLSINITIALIZE2, "OS;0;PlsInitialize;iStaticMutex[%d].Create() err=%d", idx, err));
       
   181 	__ASSERT_ALWAYS(err == KErrNone , __SQLITEPANIC2(ESqliteOsPanicMutexCreationError));
       
   182 	//WSD map
   172 	//WSD map
   183 	//...already initialized by its constructor
   173 	//...already initialized by its constructor
   184 	//sqlite3_vfs object	
   174 	//sqlite3_vfs object	
   185 	aPls->iVfsApi.iVersion 		= 1;
   175 	aPls->iVfsApi.iVersion 		= 1;
   186 	aPls->iVfsApi.szOsFile 		= sizeof(TDbFile);
   176 	aPls->iVfsApi.szOsFile 		= sizeof(TDbFile);
   199 	aPls->iVfsApi.xRandomness 	= &TVfs::Randomness;
   189 	aPls->iVfsApi.xRandomness 	= &TVfs::Randomness;
   200 	aPls->iVfsApi.xSleep 		= &TVfs::Sleep;
   190 	aPls->iVfsApi.xSleep 		= &TVfs::Sleep;
   201 	aPls->iVfsApi.xCurrentTime 	= &TVfs::CurrentTime;
   191 	aPls->iVfsApi.xCurrentTime 	= &TVfs::CurrentTime;
   202 	aPls->iVfsApi.xGetLastError	= &TVfs::GetLastError;
   192 	aPls->iVfsApi.xGetLastError	= &TVfs::GetLastError;
   203 	
   193 	
   204 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, PLSINITIALIZE_EXIT, "OS-Exit;0;PlsInitialize"));
       
   205 	return KErrNone;
   194 	return KErrNone;
   206 	}
   195 	}
   207 
   196 
   208 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   197 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   209 //////////////////////////  TStaticFs  /////////////////////////////////////////////////////////////////////////////////////////
   198 //////////////////////////  TStaticFs  /////////////////////////////////////////////////////////////////////////////////////////
   222 @panic SqliteMt 5 Process local storage initialization failure
   211 @panic SqliteMt 5 Process local storage initialization failure
   223 */
   212 */
   224 RFs& TStaticFs::Fs()
   213 RFs& TStaticFs::Fs()
   225 	{
   214 	{
   226 	TPls* pls = ::Pls(KSqliteUid, &PlsInitialize);
   215 	TPls* pls = ::Pls(KSqliteUid, &PlsInitialize);
   227 	__ASSERT_ALWAYS(pls != 0, __SQLITEPANIC2(ESqliteOsPanicNullPls2));
   216 	__ASSERT_ALWAYS(pls != 0, User::Panic(KPanicCategory, EPanicNullPls2));
   228 	__ASSERT_DEBUG(pls->iStaticFs.iFs.Handle() != KNullHandle, __SQLITEPANIC2(ESqliteOsPanicInvalidFs));
   217 	__ASSERT_DEBUG(pls->iStaticFs.iFs.Handle() != KNullHandle, User::Panic(KPanicCategory, EPanicInvalidFs));
   229 	return pls->iStaticFs.iFs;
   218 	return pls->iStaticFs.iFs;
   230 	}
   219 	}
   231 
   220 
   232 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   221 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   233 //////////////////////////  TStaticMutex  //////////////////////////////////////////////////////////////////////////////////////
   222 //////////////////////////  TStaticMutex  //////////////////////////////////////////////////////////////////////////////////////
   238 	}
   227 	}
   239 
   228 
   240 sqlite3_mutex* StaticMutex(TInt aType)
   229 sqlite3_mutex* StaticMutex(TInt aType)
   241 	{
   230 	{
   242 	TPls* pls = ::Pls(KSqliteUid, &PlsInitialize);
   231 	TPls* pls = ::Pls(KSqliteUid, &PlsInitialize);
   243 	__ASSERT_ALWAYS(pls != 0, __SQLITEPANIC2(ESqliteOsPanicNullPls3));
   232 	__ASSERT_ALWAYS(pls != 0, User::Panic(KPanicCategory, EPanicNullPls3));
   244 	__ASSERT_ALWAYS((TUint)aType < (sizeof(pls->iStaticMutex)/sizeof(pls->iStaticMutex[0])), __SQLITEPANIC2(ESqliteOsPanicInvalidMutexType));
   233 	__ASSERT_ALWAYS((TUint)aType < (sizeof(pls->iStaticMutex)/sizeof(pls->iStaticMutex[0])), User::Panic(KPanicCategory, EPanicInvalidMutexType));
   245 	return &pls->iStaticMutex[aType];
   234 	return &pls->iStaticMutex[aType];
   246 	}
   235 	}
   247 
   236 
   248 
   237 
   249 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   238 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   262 
   251 
   263 @see TWsdMap
   252 @see TWsdMap
   264 */
   253 */
   265 int sqlite3_wsd_init(int aWsdBufSize, int aWsdEntryCount)
   254 int sqlite3_wsd_init(int aWsdBufSize, int aWsdEntryCount)
   266 	{
   255 	{
   267 	__ASSERT_ALWAYS(aWsdBufSize <= TWsdMap::KBufferSize, __SQLITEPANIC2(ESqliteOsPanicWsdBufSize));
   256 	__ASSERT_ALWAYS(aWsdBufSize <= TWsdMap::KBufferSize, User::Panic(KPanicCategory, EPanicWsdBufSize));
   268 	__ASSERT_ALWAYS(aWsdEntryCount <= TWsdMap::KMaxEntries, __SQLITEPANIC2(ESqliteOsPanicWsdEntryCount));
   257 	__ASSERT_ALWAYS(aWsdEntryCount <= TWsdMap::KMaxEntries, User::Panic(KPanicCategory, EPanicWsdEntryCount));
   269 	return SQLITE_OK;	
   258 	return SQLITE_OK;	
   270 	}
   259 	}
   271 
   260 
   272 /**
   261 /**
   273 Performs a search in the WSD map (in the process local storage) for a global variable identified by the aKey parameter.
   262 Performs a search in the WSD map (in the process local storage) for a global variable identified by the aKey parameter.
   281 @see TWsdMap
   270 @see TWsdMap
   282 @see TPls
   271 @see TPls
   283 */
   272 */
   284 void* sqlite3_wsd_find(void* aKey, int aLength)
   273 void* sqlite3_wsd_find(void* aKey, int aLength)
   285 	{
   274 	{
   286 	__ASSERT_ALWAYS(aKey != NULL, __SQLITEPANIC2(ESqliteOsPanicNullKey));
   275 	__ASSERT_ALWAYS(aKey != NULL, User::Panic(KPanicCategory, EPanicNullKey));
   287 	return ::Pls(KSqliteUid, &PlsInitialize)->iWsdMap.Find(static_cast <const TUint8*> (aKey), aLength);
   276 	return ::Pls(KSqliteUid, &PlsInitialize)->iWsdMap.Find(static_cast <const TUint8*> (aKey), aLength);
   288 	}
   277 	}
   289 
   278 
   290 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   279 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   291 //////////////////////////  sqlite3_vfs     ///////////////////////////////////////////////////////////////////////////////////
   280 //////////////////////////  sqlite3_vfs     ///////////////////////////////////////////////////////////////////////////////////
   292 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   281 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   293 
   282 
   294 sqlite3_vfs* VfsApi()
   283 sqlite3_vfs* VfsApi()
   295 	{
   284 	{
   296 	TPls* pls = ::Pls(KSqliteUid, &PlsInitialize);
   285 	TPls* pls = ::Pls(KSqliteUid, &PlsInitialize);
   297 	__ASSERT_ALWAYS(pls != 0, __SQLITEPANIC2(ESqliteOsPanicNullPls4));
   286 	__ASSERT_ALWAYS(pls != 0, User::Panic(KPanicCategory, EPanicNullPls4));
   298 	return &pls->iVfsApi;
   287 	return &pls->iVfsApi;
   299 	}
   288 	}
   300 
   289 
   301 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   290 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   302 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   291 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////