persistentstorage/sql/OsLayer/os_symbian.cpp
branchRCL_3
changeset 8 fa9941cf3867
parent 6 5ffdb8f2067f
child 10 31a8f755b7fe
equal deleted inserted replaced
6:5ffdb8f2067f 8:fa9941cf3867
   698 public:
   698 public:
   699 	RFs			iFs;		//File session instance.
   699 	RFs			iFs;		//File session instance.
   700 	TFileName	iSysPrivDir;//"<system drive>:\" + process's private data path. Initialized in sqlite3SymbianFsOpen().
   700 	TFileName	iSysPrivDir;//"<system drive>:\" + process's private data path. Initialized in sqlite3SymbianFsOpen().
   701 							//Used for storing sqlite temporary files.
   701 							//Used for storing sqlite temporary files.
   702 	TInt64		iSeed;
   702 	TInt64		iSeed;
   703 	RAllocator*	iAllocator;
   703 
   704 
       
   705 	enum {KZeroBufSize = SQLITE_DEFAULT_SECTOR_SIZE};
       
   706     TBuf8<KZeroBufSize> iZeroBuf;
       
   707 	
       
   708 private:	
   704 private:	
   709 	static COsLayerData* 	iOsLayerData;
   705 	static COsLayerData* 	iOsLayerData;
   710 	TInt					iStoredOsErrorCode;	//Contains the last OS error code.
   706 	TInt					iStoredOsErrorCode;	//Contains the last OS error code.
   711 	const RMessage2* 		iMessage;			//Fh data
   707 	const RMessage2* 		iMessage;			//Fh data
   712 	TBool					iReadOnly;			//Fh data
   708 	TBool					iReadOnly;			//Fh data
   713 	};
   709 	};
       
   710 
       
   711 /**
       
   712 This functon returns a reference to the current thread allocator object.
       
   713 The static RAllocator& variable will be initialized once at the moment when the function is called for 
       
   714 first time. 
       
   715 */
       
   716 static RAllocator& Allocator()
       
   717     {
       
   718     static RAllocator& allocator = User::Allocator();
       
   719     return allocator;
       
   720     }
   714 
   721 
   715 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   722 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   716 ///////////////////////////////////       TDbFile struct declaration      /////////////////////////////////////////////////////
   723 ///////////////////////////////////       TDbFile struct declaration      /////////////////////////////////////////////////////
   717 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   724 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   718 
   725 
  1040 
  1047 
  1041 /**
  1048 /**
  1042 Initializes the COsLayerData data members with their default values.
  1049 Initializes the COsLayerData data members with their default values.
  1043 */
  1050 */
  1044 inline COsLayerData::COsLayerData() :
  1051 inline COsLayerData::COsLayerData() :
  1045 	iAllocator(0),
       
  1046 	iStoredOsErrorCode(KErrNone),
  1052 	iStoredOsErrorCode(KErrNone),
  1047 	iMessage(0),
  1053 	iMessage(0),
  1048 	iReadOnly(EFalse)
  1054 	iReadOnly(EFalse)
  1049 	{
  1055 	{
  1050 	TTime now;
  1056 	TTime now;
  1051 	now.UniversalTime();
  1057 	now.UniversalTime();
  1052 	iSeed = now.Int64();
  1058 	iSeed = now.Int64();
  1053    	iZeroBuf.FillZ(COsLayerData::KZeroBufSize);
       
  1054 	}
  1059 	}
  1055 
  1060 
  1056 /**
  1061 /**
  1057 Destroys the COsLayerData instance.
  1062 Destroys the COsLayerData instance.
  1058 
  1063 
  1082 @see TVfs
  1087 @see TVfs
  1083 @see TheVfsApi
  1088 @see TheVfsApi
  1084 */
  1089 */
  1085 TInt COsLayerData::DoCreate()
  1090 TInt COsLayerData::DoCreate()
  1086 	{
  1091 	{
  1087 	iAllocator = &User::Allocator();
       
  1088 	__FS_CALL(EFsOpFsConnect, 0);
  1092 	__FS_CALL(EFsOpFsConnect, 0);
  1089 	TInt err = iFs.Connect();
  1093 	TInt err = iFs.Connect();
  1090 	if(err != KErrNone)
  1094 	if(err != KErrNone)
  1091 		{
  1095 		{
  1092 		return err;	
  1096 		return err;	
  1445 
  1449 
  1446 /**
  1450 /**
  1447 SQLite OS porting layer API.
  1451 SQLite OS porting layer API.
  1448 
  1452 
  1449 Closes the file referred by aDbFile parameter.
  1453 Closes the file referred by aDbFile parameter.
  1450 If aDbFile, which is actually a pointer to a TDbFile instance, the iFullName data member is not NULL, 
  1454 If aDbFile.iFullName data member is not NULL, then the file will be deleted.
  1451 then the file will be deleted.
       
  1452 
  1455 
  1453 @param aDbFile A pointer to a TDbFile instance, than contains the file handle to be closed.
  1456 @param aDbFile A pointer to a TDbFile instance, than contains the file handle to be closed.
  1454 
  1457 
  1455 @return SQLITE_OK
  1458 @return SQLITE_OK
  1456 
  1459 
  1463 	__OS_CALL(EOsFileClose, 0, 0);
  1466 	__OS_CALL(EOsFileClose, 0, 0);
  1464 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0);
  1467 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0);
  1465 	__FS_CALL(EFsOpFileClose, 0);
  1468 	__FS_CALL(EFsOpFileClose, 0);
  1466 	dbFile.iFileBuf.Close();
  1469 	dbFile.iFileBuf.Close();
  1467 	if(dbFile.iFullName)
  1470 	if(dbFile.iFullName)
  1468 		{
  1471 		{//"iFullName" will not be NULL only when TVfs::Open() is called with SQLITE_OPEN_DELETEONCLOSE flag.
       
  1472 		 //That means - SQlite expects the file to be deleted after the file close operation. 
  1469 		__FS_CALL(EFsOpFileDelete, 0);
  1473 		__FS_CALL(EFsOpFileDelete, 0);
  1470 		(void)COsLayerData::Instance().iFs.Delete(*dbFile.iFullName);
  1474 		(void)COsLayerData::Instance().iFs.Delete(*dbFile.iFullName);
  1471 		delete dbFile.iFullName;
  1475 		delete dbFile.iFullName;
  1472 		}
  1476 		}
  1473 	return SQLITE_OK;
  1477 	return SQLITE_OK;
  2299 		{
  2303 		{
  2300 		__FS_CALL(EFsOpFileClose, 0);
  2304 		__FS_CALL(EFsOpFileClose, 0);
  2301 		dbFile.iFileBuf.Close();	
  2305 		dbFile.iFileBuf.Close();	
  2302 		delete dbFile.iFullName;
  2306 		delete dbFile.iFullName;
  2303 		dbFile.iFullName = NULL;
  2307 		dbFile.iFullName = NULL;
       
  2308         if(!aFileName && fname.Length() > 0)
       
  2309             {//temporary file, the error is not KErrNone. Then delete the file (after a successfull 
       
  2310              //temporary file creation there could be a failed memory allocation)
       
  2311             (void)osLayerData.iFs.Delete(fname);
       
  2312             }
  2304 		}
  2313 		}
  2305 	else
  2314 	else
  2306 		{
  2315 		{
  2307 		dbFile.pMethods = &TheFileIoApi;
  2316 		dbFile.pMethods = &TheFileIoApi;
  2308 		if(fhStrType != EFhMainDbStr)
  2317 		if(fhStrType != EFhMainDbStr)
  2612 @internalComponent
  2621 @internalComponent
  2613 */
  2622 */
  2614 extern "C" void* sqlite3SymbianMalloc(size_t aSize)
  2623 extern "C" void* sqlite3SymbianMalloc(size_t aSize)
  2615 	{
  2624 	{
  2616 	__MEM_CALL(EMemOpAlloc, aSize, 0);
  2625 	__MEM_CALL(EMemOpAlloc, aSize, 0);
  2617 	return COsLayerData::Instance().iAllocator->Alloc(aSize);
  2626 	return Allocator().Alloc(aSize);
  2618 	}
  2627 	}
  2619 
  2628 
  2620 /**
  2629 /**
  2621 SQLite OS porting layer API.
  2630 SQLite OS porting layer API.
  2622 
  2631 
  2625 @internalComponent
  2634 @internalComponent
  2626 */
  2635 */
  2627 extern "C" void* sqlite3SymbianRealloc(void* aPtr, size_t aSize)
  2636 extern "C" void* sqlite3SymbianRealloc(void* aPtr, size_t aSize)
  2628 	{
  2637 	{
  2629 #ifdef _SQLPROFILER
  2638 #ifdef _SQLPROFILER
  2630 	TInt size = COsLayerData::Instance().iAllocator->AllocLen(aPtr);
  2639 	TInt size = Allocator().AllocLen(aPtr);
  2631 	__MEM_CALL(EMemOpRealloc, aSize, size);
  2640 	__MEM_CALL(EMemOpRealloc, aSize, size);
  2632 #endif
  2641 #endif
  2633 	return COsLayerData::Instance().iAllocator->ReAlloc(aPtr, aSize);
  2642 	return Allocator().ReAlloc(aPtr, aSize);
  2634 	}
  2643 	}
  2635 
  2644 
  2636 /**
  2645 /**
  2637 SQLite OS porting layer API.
  2646 SQLite OS porting layer API.
  2638 
  2647 
  2641 @internalComponent
  2650 @internalComponent
  2642 */
  2651 */
  2643 extern "C" void sqlite3SymbianFree(void* aPtr)
  2652 extern "C" void sqlite3SymbianFree(void* aPtr)
  2644 	{
  2653 	{
  2645 #ifdef _SQLPROFILER
  2654 #ifdef _SQLPROFILER
  2646 	TInt size = COsLayerData::Instance().iAllocator->AllocLen(aPtr);
  2655 	TInt size = Allocator().AllocLen(aPtr);
  2647 	__MEM_CALL(EMemOpFree, size, 0);
  2656 	__MEM_CALL(EMemOpFree, size, 0);
  2648 #endif
  2657 #endif
  2649 	COsLayerData::Instance().iAllocator->Free(aPtr);
  2658 	Allocator().Free(aPtr);
  2650 	}
  2659 	}
  2651 
  2660 
  2652 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2661 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2653 ///////////////////////////////////       SQLite init/release functions     ///////////////////////////////////////////////////
  2662 ///////////////////////////////////       SQLite init/release functions     ///////////////////////////////////////////////////
  2654 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2663 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////