persistentstorage/sql/SRC/Server/SqlSrvMain.cpp
branchRCL_3
changeset 8 fa9941cf3867
parent 0 08ec8eefde2f
child 9 667e88a979d7
equal deleted inserted replaced
6:5ffdb8f2067f 8:fa9941cf3867
   231 		}
   231 		}
   232    	}
   232    	}
   233 
   233 
   234 /**
   234 /**
   235 Creates new CSqlSrvSession instance.
   235 Creates new CSqlSrvSession instance.
       
   236 If SQLSRV_STARTUP_TEST macro is defined, then the function returns NULL.
       
   237 The "real" implementation of the function is not used in this case because the used unit test will require 
       
   238 a lot of cpp files to be included into the test build (t_sqlstartup).
   236 
   239 
   237 @return A pointer to the created CSqlSrvSession instance.
   240 @return A pointer to the created CSqlSrvSession instance.
   238 
   241 
   239 @leave KErrNoMemory, an out of memory condition has occured;
   242 @leave KErrNoMemory, an out of memory condition has occured;
   240        KErrNotSupported, the client side library version differs from the server version.
   243        KErrNotSupported, the client side library version differs from the server version.
   241        
   244        
   242 @see CSqlSrvSession
   245 @see CSqlSrvSession
   243 */
   246 */
   244 CSession2* CSqlServer::NewSessionL(const TVersion &aVersion, const RMessage2&) const
   247 CSession2* CSqlServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
   245 	{
   248     {
   246 	if(!User::QueryVersionSupported(::SqlSrvVersion(), aVersion))
   249 #ifdef SQLSRV_STARTUP_TEST
   247 		{
   250     aVersion.Name();//to prevent the compiler warning ("unused parameter").
   248 		User::Leave(KErrNotSupported);
   251     return NULL;
   249 		}
   252 #else
   250 	CSqlSrvSession* sess = CSqlSrvSession::NewL();
   253     if(!User::QueryVersionSupported(::SqlSrvVersion(), aVersion))
   251 	return sess;
   254         {
   252 	}
   255         User::Leave(KErrNotSupported);
       
   256         }
       
   257     CSqlSrvSession* sess = CSqlSrvSession::NewL();
       
   258     return sess;
       
   259 #endif //SQLSRV_STARTUP_TEST
       
   260     }
   253 
   261 
   254 /**
   262 /**
   255 CSqlServer's active object priority.
   263 CSqlServer's active object priority.
   256 
   264 
   257 @internalComponent
   265 @internalComponent
   281 		             Note that the function may also leave with some other database specific 
   289 		             Note that the function may also leave with some other database specific 
   282 			         errors categorised as ESqlDbError.
   290 			         errors categorised as ESqlDbError.
   283 */
   291 */
   284 void CSqlServer::ConstructL()
   292 void CSqlServer::ConstructL()
   285 	{
   293 	{
       
   294 #ifndef SQLSRV_STARTUP_TEST
       
   295 	//Start the server only in "normal" builds, not in the case where t_sqlstartup unit test tests directly
       
   296 	//the SQL server startup code.
   286 	StartL(KSqlSrvName);
   297 	StartL(KSqlSrvName);
       
   298 #endif	
   287 #ifdef _SQLPROFILER 
   299 #ifdef _SQLPROFILER 
   288     TheSqlSrvStartTime.UniversalTime();
   300     TheSqlSrvStartTime.UniversalTime();
   289     SQLPROFILER_SERVER_START();
   301     SQLPROFILER_SERVER_START();
   290 #endif  
   302 #endif  
   291 	//Configure the SQLite library
   303 	//Configure the SQLite library
   327 	// Create the BUR instance
   339 	// Create the BUR instance
   328 	iBackupClient=CSqlBackupClient::NewL(this);
   340 	iBackupClient=CSqlBackupClient::NewL(this);
   329 	//Compactor
   341 	//Compactor
   330 	iCompactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KSqlCompactStepIntervalMs);
   342 	iCompactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KSqlCompactStepIntervalMs);
   331 #ifdef _DEBUG
   343 #ifdef _DEBUG
   332 	/*
   344     //The following statements exist to prevent the failure of the OOM testing in debug mode.
   333 	 The following statements exist to prevent the failure of the resource allocation 
   345 	//The standard C library allocates some memory at the startup and stores a pointer to the allocated memory
   334 	 checking for debug mode. 
   346 	//in the TLS. During normal API OOM testing the SQL server is not restarted, it never goes down.
   335 	 They allocate some memory when the server object is constructed so avoid these memory 
   347 	//Then the TLS and the allocated memory are not released. In which case the OOM testing will fail
   336 	 allocations during debug mode. 
   348 	//(because the standard C library performs a lazy initialization and the allocation and TLS usage will be made
   337 	 */
   349 	//at the point of first use of some C function. This is out of the control of the test code).
   338 const TInt KAnyNumber	= 0xAA55; 
   350 	//In order to avoid that, during the SQL server startup here, before the OOM test goes and checks what 
   339 const TInt KGreatSize = 1024; 
   351 	//is the allocated memory at the beginning, a fake sprintf() call is made in order to force the mentioned above  
       
   352 	//allocation in the standard C library.
       
   353 	//All explanations above are true, except one case when the SQl server startup code is tested directly.
       
   354     #ifndef SQLSRV_STARTUP_TEST
       
   355 	const TInt KAnyNumber	= 0xAA55; 
   340  	char tmp[32]; 
   356  	char tmp[32]; 
   341  	sprintf(tmp, "%04X", KAnyNumber);
   357  	sprintf(tmp, "%04X", KAnyNumber);
       
   358     const TInt KGreatSize = 1024; 
   342  	__SQLLEAVE_IF_ERROR(ReAllocBuf(KGreatSize));
   359  	__SQLLEAVE_IF_ERROR(ReAllocBuf(KGreatSize));
   343 #endif 	
   360     #endif //SQLSRV_STARTUP_TEST 	
       
   361 #endif //_DEBUG 	
   344 	}
   362 	}
   345 
   363 
   346 /**
   364 /**
   347 Retrieves in iCollationDllName current(default) collation dll name.
   365 Retrieves in iCollationDllName current(default) collation dll name.
   348 see TExtendedLocale
   366 see TExtendedLocale
   434 					 Note that the function may leave also with some other database specific or OS specific
   452 					 Note that the function may leave also with some other database specific or OS specific
   435 					 error codes.
   453 					 error codes.
   436 */
   454 */
   437 void CSqlServer::GetBackUpListL(TSecureId aUid, RArray<TParse>& aFileList)
   455 void CSqlServer::GetBackUpListL(TSecureId aUid, RArray<TParse>& aFileList)
   438 	{
   456 	{
       
   457 	aFileList.Reset();
   439 	TFindFile findFile(iFileData.Fs());
   458 	TFindFile findFile(iFileData.Fs());
   440 	CDir* fileNameCol = NULL;
   459 	CDir* fileNameCol = NULL;
   441 	TUidName uidName = (static_cast <TUid> (aUid)).Name();
   460 	TUidName uidName = (static_cast <TUid> (aUid)).Name();
   442 	TBuf<KMaxUidName + sizeof(KMatchAllDbFiles)> fileNameMask(uidName);
   461 	TBuf<KMaxUidName + sizeof(KMatchAllDbFiles)> fileNameMask(uidName);
   443 	fileNameMask.Append(KMatchAllDbFiles);
   462 	fileNameMask.Append(KMatchAllDbFiles);
   477 				}
   496 				}
   478 			CleanupStack::PopAndDestroy(fileNameCol);
   497 			CleanupStack::PopAndDestroy(fileNameCol);
   479 			fileNameCol = NULL;
   498 			fileNameCol = NULL;
   480 			} while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files
   499 			} while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files
   481 		}//end of "if(err == KErrNone)"
   500 		}//end of "if(err == KErrNone)"
       
   501 	//TODO: once DEF144134 gets fixed, the next 2 lines shall be removed
       
   502 	delete fileNameCol;
       
   503 	fileNameCol = NULL;
   482 	__SQLASSERT(!fileNameCol, ESqlPanicInternalError);
   504 	__SQLASSERT(!fileNameCol, ESqlPanicInternalError);
   483 	if(err != KErrNotFound && err != KErrNone)
   505 	if(err != KErrNotFound && err != KErrNone)
   484 		{
   506 		{
   485 		__SQLLEAVE(err);
   507 		__SQLLEAVE(err);
   486 		}
   508 		}
   487 	}
   509 	}
   488 
   510 
   489 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   511 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   490 ////////////////////////////////////////   SQL server startup   //////////////////////////////////////////////
   512 ////////////////////////////////////////   SQL server startup   //////////////////////////////////////////////
   491 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   513 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   514 
       
   515 #ifndef SQLSRV_STARTUP_TEST
   492 
   516 
   493 //Run the SQL server
   517 //Run the SQL server
   494 static void RunServerL()
   518 static void RunServerL()
   495 	{
   519 	{
   496 	// naming the server thread after the server helps to debug panics
   520 	// naming the server thread after the server helps to debug panics
   524 	__UHEAP_MARKEND;
   548 	__UHEAP_MARKEND;
   525 
   549 
   526 	return err;
   550 	return err;
   527 	}
   551 	}
   528 
   552 
       
   553 #endif //SQLSRV_STARTUP_TEST