persistentstorage/sqlite3api/OsLayer/os_symbian_hrdw.cpp
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // The Symbian OS porting layer - multi-threaded implementation. 
       
    15 // Platform dependend implementation of the static mutexes and the file session API.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 #include "os_symbian.h"
       
    23 
       
    24 #ifdef SQLITE_OS_SYMBIAN
       
    25 
       
    26 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    27 //////////////////////////  TStaticFs  /////////////////////////////////////////////////////////////////////////////////////////
       
    28 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    29 
       
    30 /**
       
    31 Single global RFs instance
       
    32 
       
    33 @see TStaticFs
       
    34 
       
    35 @internalComponent
       
    36 */
       
    37 static TStaticFs TheFs;
       
    38 
       
    39 /**
       
    40 Connects the RFs.
       
    41 If the operation fails, the program will be terminated.
       
    42 
       
    43 @see TStaticFs
       
    44 */
       
    45 TStaticFs::TStaticFs()
       
    46 	{
       
    47 	TInt err = Connect();
       
    48 	if(err != KErrNone)
       
    49 		{
       
    50 		RDebug::Print(_L("===SQLITE OS porting layer, file session creation has failed with err=%d.\r\n"), err);
       
    51 		User::Exit(err);	
       
    52 		}
       
    53 	}
       
    54 
       
    55 /**
       
    56 Returns a reference to the already created global RFs object.
       
    57 
       
    58 @return RFs reference
       
    59 
       
    60 @panic SqliteMt 3 Invalid RFs handle
       
    61 
       
    62 @see TStaticFs
       
    63 */
       
    64 RFs& TStaticFs::Fs()
       
    65 	{
       
    66 	__ASSERT_DEBUG(TheFs.iFs.Handle() != KNullHandle, User::Panic(KPanicCategory, EPanicInvalidFs));
       
    67 	return TheFs.iFs;
       
    68 	}
       
    69 
       
    70 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    71 //////////////////////////  TStaticMutex  //////////////////////////////////////////////////////////////////////////////////////
       
    72 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    73 
       
    74 /**
       
    75 Global array of static mutexes.
       
    76 
       
    77 @see TStaticMutex
       
    78 
       
    79 @internalComponent
       
    80 */
       
    81 static TStaticMutex	TheStaticMutex[KStaticMutexCount];
       
    82 
       
    83 /**
       
    84 Creates the static mutexes.
       
    85 If the creation fails, the program will be terminated.
       
    86 
       
    87 @see TStaticMutex
       
    88 */
       
    89 TStaticMutex::TStaticMutex()
       
    90 	{
       
    91 	TInt err = Create();
       
    92 	if(err != KErrNone)
       
    93 		{
       
    94 		RDebug::Print(_L("===SQLITE OS porting layer, static mutex creation has failed with err=%d.\r\n"), err);
       
    95 		User::Exit(err);	
       
    96 		}
       
    97 	}
       
    98 
       
    99 sqlite3_mutex* StaticMutex(TInt aType)
       
   100 	{
       
   101 	__ASSERT_ALWAYS((TUint)aType < (sizeof(TheStaticMutex)/sizeof(TheStaticMutex[0])), User::Panic(KPanicCategory, EPanicInvalidMutexType));
       
   102 	return &TheStaticMutex[aType];
       
   103 	}
       
   104 
       
   105 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   106 //////////////////////////  sqlite3_vfs     ///////////////////////////////////////////////////////////////////////////////////
       
   107 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   108 
       
   109 /**
       
   110 Global sqlite3_vfs object.
       
   111 
       
   112 @see VfsApi
       
   113 @see TVfs
       
   114 
       
   115 @internalComponent
       
   116 */
       
   117 static sqlite3_vfs TheVfsApi = 
       
   118 	{
       
   119 	/*iVersion =*/		1,
       
   120 	/*szOsFile =*/ 		sizeof(TDbFile),
       
   121 	/*mxPathname =*/ 	KMaxFileName,
       
   122 	/*pNext =*/ 		NULL,
       
   123 	/*zName =*/ 		"SymbianSqliteMt",
       
   124 	/*pAppData =*/ 		NULL,
       
   125 	/*xOpen =*/ 		&TVfs::Open,
       
   126 	/*xDelete =*/ 		&TVfs::Delete,
       
   127 	/*xAccess =*/ 		&TVfs::Access,
       
   128 	/*xFullPathname =*/ &TVfs::FullPathName,
       
   129 	/*xDlOpen =*/ 		NULL,
       
   130 	/*xDlError =*/ 		NULL,
       
   131 	/*xDlSym =*/ 		NULL,
       
   132 	/*xDlClose =*/ 		NULL,
       
   133 	/*xRandomness =*/ 	&TVfs::Randomness,
       
   134 	/*xSleep =*/ 		&TVfs::Sleep,
       
   135 	/*xCurrentTime =*/ 	&TVfs::CurrentTime,
       
   136 	/*xGetLastError =*/ &TVfs::GetLastError
       
   137 	};
       
   138 
       
   139 sqlite3_vfs* VfsApi()
       
   140 	{
       
   141 	return &TheVfsApi;		
       
   142 	}
       
   143 
       
   144 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   145 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   146 
       
   147 #endif//SQLITE_OS_SYMBIAN