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