tzservices/tzserver/Server/Source/readonlytzdb.cpp
changeset 81 676b6116ca93
parent 0 2e3d3ce01487
equal deleted inserted replaced
78:175a0d824084 81:676b6116ca93
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-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".
    16 #include <tz.h>
    16 #include <tz.h>
    17 #include "ReadOnlyTzDb.h"
    17 #include "ReadOnlyTzDb.h"
    18 #include <f32file.h>
    18 #include <f32file.h>
    19 #include "dataprovider.h"
    19 #include "dataprovider.h"
    20 #include <vtzrules.h>
    20 #include <vtzrules.h>
       
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "readonlytzdbTraces.h"
       
    24 #endif
       
    25 
       
    26 
    21 
    27 
    22 const TUint KDefaultTzNumericId = 0;
    28 const TUint KDefaultTzNumericId = 0;
    23 
    29 
    24 // TZ Database is stored in the timezone server's own private area
    30 // TZ Database is stored in the timezone server's own private area
    25 _LIT(KTzDbFileNameRom,"Z:\\private\\1020383E\\TZDB.DBZ");
    31 _LIT(KTzDbFileNameRom,"Z:\\private\\1020383E\\TZDB.DBZ");
    59 //
    65 //
    60 // Loads the TZ Database from given file into RAM.
    66 // Loads the TZ Database from given file into RAM.
    61 //
    67 //
    62 TInt CReadOnlyTzDb::CopyDatabaseToRam(const TDesC& aTzDbFileName)
    68 TInt CReadOnlyTzDb::CopyDatabaseToRam(const TDesC& aTzDbFileName)
    63   {
    69   {
       
    70     OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_COPYDATABASETORAM_ENTRY, "CReadOnlyTzDb::CopyDatabaseToRam Entry;aTzDbFileName=%S", aTzDbFileName );
       
    71     
    64 	TInt error = KErrNone;
    72 	TInt error = KErrNone;
    65 	RFile file;
    73 	RFile file;
    66 
    74 
    67 	TUint fileMode = EFileShareReadersOnly | EFileRead | EFileStream;
    75 	TUint fileMode = EFileShareReadersOnly | EFileRead | EFileStream;
    68 
    76 
    98 					}
   106 					}
    99 				}
   107 				}
   100 			}
   108 			}
   101 		}
   109 		}
   102 	file.Close();
   110 	file.Close();
       
   111 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_COPYDATABASETORAM_EXIT, "CReadOnlyTzDb::CopyDatabaseToRam Exit;error=%d", error );
       
   112 	
   103 	return error;
   113 	return error;
   104 	}
   114 	}
   105   
   115   
   106 TInt CReadOnlyTzDb::InvalidateFlashDatabaseL()
   116 TInt CReadOnlyTzDb::InvalidateFlashDatabaseL()
   107 	{
   117 	{
   118 	return error;
   128 	return error;
   119 	}
   129 	}
   120 
   130 
   121 void CReadOnlyTzDb::InitialiseL()
   131 void CReadOnlyTzDb::InitialiseL()
   122 	{
   132 	{
       
   133     OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, DUP1_CREADONLYTZDB_INITIALISEL_ENTRY, "CReadOnlyTzDb::InitialiseL Entry" );
       
   134     
   123 	// deny access to Flash-based database 
   135 	// deny access to Flash-based database 
   124 	// if it is being restored in this precise moment
   136 	// if it is being restored in this precise moment
   125 	// We must not allow access to the ROM-based DB either, 
   137 	// We must not allow access to the ROM-based DB either, 
   126 	// because this might contain outdated data.
   138 	// because this might contain outdated data.
   127 	if (iRestoreInProcess)
   139 	if (iRestoreInProcess)
   128 		{
   140 		{
       
   141 	    OstTraceDef0( OST_TRACE_CATEGORY_DEBUG,TRACE_ERROR, CREADONLYTZDB_INITIALISEL, "CReadOnlyTzDb::InitialiseL:Error:Restoring in process" );
       
   142 	    
   129 		User::Leave(KErrNotReady);
   143 		User::Leave(KErrNotReady);
   130 		}
   144 		}
   131 		
   145 		
   132 	//
   146 	//
   133 	// try to copy TZ Database from file in Flash drive
   147 	// try to copy TZ Database from file in Flash drive
   189 	iLinksTable	= CTzDbLinksTable::NewL(*this, *(reinterpret_cast<TTzLinksTable*>(KLinksBaseAddress)));
   203 	iLinksTable	= CTzDbLinksTable::NewL(*this, *(reinterpret_cast<TTzLinksTable*>(KLinksBaseAddress)));
   190 	iStdTimeAlignmentsTable	= CTzDbStdTimeAlignmentsTable::NewL(*(reinterpret_cast<TTzStdTimeAlignmentsTable*>(KStdTimeAlignmentsBaseAddress)));
   204 	iStdTimeAlignmentsTable	= CTzDbStdTimeAlignmentsTable::NewL(*(reinterpret_cast<TTzStdTimeAlignmentsTable*>(KStdTimeAlignmentsBaseAddress)));
   191 	iRuleSetsTable = CTzDbRuleSetsTable::NewL(*this, *(reinterpret_cast<TTzRuleSetsTable*>(KRuleSetsBaseAddress)));
   205 	iRuleSetsTable = CTzDbRuleSetsTable::NewL(*this, *(reinterpret_cast<TTzRuleSetsTable*>(KRuleSetsBaseAddress)));
   192 	iRuleUsesTable = CTzDbRuleUsesTable::NewL(*(reinterpret_cast<TTzRuleUsesTable*>(KRuleUsesBaseAddress)));
   206 	iRuleUsesTable = CTzDbRuleUsesTable::NewL(*(reinterpret_cast<TTzRuleUsesTable*>(KRuleUsesBaseAddress)));
   193 	iRuleDefinitionsTable = CTzDbRuleDefinitionsTable::NewL(*(reinterpret_cast<TTzRuleDefinitionsTable*>(KRuleDefinitionsBaseAddress)));	
   207 	iRuleDefinitionsTable = CTzDbRuleDefinitionsTable::NewL(*(reinterpret_cast<TTzRuleDefinitionsTable*>(KRuleDefinitionsBaseAddress)));	
       
   208 	OstTraceDef0( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, DUP1_CREADONLYTZDB_INITIALISEL_EXIT, "CReadOnlyTzDb::InitialiseL Exit" );
       
   209 	
   194 	}
   210 	}
   195 
   211 
   196 //
   212 //
   197 // Releases all RAM used by the database
   213 // Releases all RAM used by the database
   198 //
   214 //
   222 //
   238 //
   223 // Returns the CTzId object that corresponds to the location set as default in the database
   239 // Returns the CTzId object that corresponds to the location set as default in the database
   224 //
   240 //
   225 CTzId* CReadOnlyTzDb::GetDefaultTimeZoneIdL()
   241 CTzId* CReadOnlyTzDb::GetDefaultTimeZoneIdL()
   226 	{
   242 	{
       
   243     OstTraceDef0( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CREADONLYTZDB_GETDEFAULTTIMEZONEIDL_ENTRY, "CReadOnlyTzDb::GetDefaultTimeZoneIdL Entry" );
       
   244     
   227 	if (iZonesTable == NULL)
   245 	if (iZonesTable == NULL)
   228 		{
   246 		{
   229 		InitialiseL();
   247 		InitialiseL();
   230 		}
   248 		}
   231 
   249 
   232 	CTzId* defTZID = NULL;
   250 	CTzId* defTZID = NULL;
   233 	CTzDbZone* defZone = GetZoneL((reinterpret_cast<TTzHeader*>(iStartAddress))->iOffsetToDefaultZone);
   251 	CTzDbZone* defZone = GetZoneL((reinterpret_cast<TTzHeader*>(iStartAddress))->iOffsetToDefaultZone);
   234 
   252 
   235 	if (defZone)
   253 	if (defZone)
   236 		{
   254 		{
       
   255 	    
   237 		CleanupStack::PushL(defZone); // push #1
   256 		CleanupStack::PushL(defZone); // push #1
   238 
   257 
   239 		HBufC8* fullZoneName = defZone->GetFullZoneNameLC(); // push #2
   258 		HBufC8* fullZoneName = defZone->GetFullZoneNameLC(); // push #2
   240 		defTZID = CTzId::NewL(defZone->LocationId());
   259 		defTZID = CTzId::NewL(defZone->LocationId());
   241 		CleanupStack::PushL(defTZID); // push #3
   260 		CleanupStack::PushL(defTZID); // push #3
   242 		defTZID->SetIdL(*fullZoneName);
   261 		defTZID->SetIdL(*fullZoneName);
   243 
   262 
   244 		CleanupStack::Pop(defTZID);
   263 		CleanupStack::Pop(defTZID);
   245 		CleanupStack::PopAndDestroy(2, defZone);
   264 		CleanupStack::PopAndDestroy(2, defZone);
   246 		}
   265 		
   247 
   266 		}
       
   267 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_GETDEFAULTTIMEZONEIDL_EXIT, "CReadOnlyTzDb::GetDefaultTimeZoneIdL Exit" );
       
   268 	
   248 	return defTZID;
   269 	return defTZID;
   249 	}
   270 	}
   250 
   271 
   251 void CReadOnlyTzDb::GetTzRulesL(CTzRules& aTzRules, CTzId& aTzId)
   272 void CReadOnlyTzDb::GetTzRulesL(CTzRules& aTzRules, CTzId& aTzId)
   252 	{
   273 	{
       
   274     
       
   275   OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_GETTZRULESL_ENTRY, "CReadOnlyTzDb::GetTzRulesL Entry;Time zone id =%u", aTzId.TimeZoneNumericID());
       
   276   
   253 	if (iZonesTable == NULL)
   277 	if (iZonesTable == NULL)
   254 		{
   278 		{
   255 		InitialiseL();
   279 		InitialiseL();
   256 		}
   280 		}
   257 		
   281 		
   258 	TRAPD(err, DoGetTzRulesL(aTzRules, aTzId));
   282 	TRAPD(err, DoGetTzRulesL(aTzRules, aTzId));
   259 	if ( (err == KErrCorrupt) && (iTzDbData) )
   283 	if ( (err == KErrCorrupt) && (iTzDbData) )
   260 		{
   284 		{
       
   285 	    
   261 		ReleaseData();
   286 		ReleaseData();
   262 		// if the corruption occurred while accessing the Flash DB, we must flag it 
   287 		// if the corruption occurred while accessing the Flash DB, we must flag it 
   263 		// as corrupt before propagating the leave
   288 		// as corrupt before propagating the leave
   264 		if (iTzDbDataFromFlash)
   289 		if (iTzDbDataFromFlash)
   265 		  {
   290 		  {
   266 			InvalidateFlashDatabaseL();
   291 			InvalidateFlashDatabaseL();
   267 			}
   292 			}
   268 		}
   293 		}
   269 		
   294 		
   270 	User::LeaveIfError(err);
   295 	User::LeaveIfError(err);
       
   296 	OstTraceDef0( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CREADONLYTZDB_GETTZRULESL_EXIT, "CReadOnlyTzDb::GetTzRulesL Exit" );
       
   297 	
   271 	}
   298 	}
   272 	
   299 	
   273 void CReadOnlyTzDb::DoGetTzRulesL(CTzRules& aTzRules, CTzId& aTzId)
   300 void CReadOnlyTzDb::DoGetTzRulesL(CTzRules& aTzRules, CTzId& aTzId)
   274 	{
   301 	{
   275 	CTzDbZone* zone = FindZoneL(aTzId,ETrue);
   302 	CTzDbZone* zone = FindZoneL(aTzId,ETrue);
   301 //
   328 //
   302 // If aFillInLocationIDs is ETrue, it also fills in the unset zone ID in the supplied CTzId
   329 // If aFillInLocationIDs is ETrue, it also fills in the unset zone ID in the supplied CTzId
   303 //
   330 //
   304 CTzDbZone* CReadOnlyTzDb::FindZoneL(CTzId& aLocation, TBool aFillInLocationIDs)
   331 CTzDbZone* CReadOnlyTzDb::FindZoneL(CTzId& aLocation, TBool aFillInLocationIDs)
   305 	{
   332 	{
       
   333     OstTraceDefExt3( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CREADONLYTZDB_FINDZONEL_EnTRY, "CReadOnlyTzDb::FindZoneL;Time zone id=%u;Time zone name=%s;aFillInLocationIDs=%u", aLocation.TimeZoneNumericID(), aLocation.TimeZoneNameID(), aFillInLocationIDs );
       
   334     
   306 	CTzDbZone* zone = NULL;
   335 	CTzDbZone* zone = NULL;
   307 	if (aLocation.TimeZoneNumericID() > KDefaultTzNumericId)
   336 	if (aLocation.TimeZoneNumericID() > KDefaultTzNumericId)
   308 		{
   337 		{
   309 		zone = FindZoneByNumericIdL(aLocation.TimeZoneNumericID());
   338 		zone = FindZoneByNumericIdL(aLocation.TimeZoneNumericID());
   310 		if (zone && aFillInLocationIDs)
   339 		if (zone && aFillInLocationIDs)
   324 			CleanupStack::PushL(zone); // push #1
   353 			CleanupStack::PushL(zone); // push #1
   325 			aLocation.SetId(zone->LocationId());
   354 			aLocation.SetId(zone->LocationId());
   326 			CleanupStack::Pop(zone); // pop #1
   355 			CleanupStack::Pop(zone); // pop #1
   327 			}
   356 			}
   328 		}
   357 		}
       
   358 OstTraceDef0( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CREADONLYTZDB_FINDZONEL_EXIT, "CReadOnlyTzDb::FindZoneL Exit" );
   329 
   359 
   330 	return zone;
   360 	return zone;
   331 	}
   361 	}
   332 
   362 
   333 //
   363 //
   336 // Returns the Zone as a CTzDbZone* (NULL if it can't find
   366 // Returns the Zone as a CTzDbZone* (NULL if it can't find
   337 // a Zone in the database that matches the received location)
   367 // a Zone in the database that matches the received location)
   338 //
   368 //
   339 CTzDbZone* CReadOnlyTzDb::FindZoneByNameL(const TDesC8& aLocation)
   369 CTzDbZone* CReadOnlyTzDb::FindZoneByNameL(const TDesC8& aLocation)
   340 	{
   370 	{
       
   371     OstTraceDefExt1( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CREADONLYTZDB_FINDZONEBYNAMEL_ENTRY, "CReadOnlyTzDb::FindZoneByNameL Entry;aLocation.=%s", aLocation );
       
   372     
       
   373            
   341 	// first of all, look in links table
   374 	// first of all, look in links table
   342 	CTzDbZone* retZone = iLinksTable->FindZoneL(aLocation);
   375 	CTzDbZone* retZone = iLinksTable->FindZoneL(aLocation);
   343 
   376 
   344 	if (retZone == NULL) 
   377 	if (retZone == NULL) 
   345 		{ // received location was the name of an actual zone
   378 		{ // received location was the name of an actual zone
   366 			CleanupStack::PopAndDestroy(region); // pop #3
   399 			CleanupStack::PopAndDestroy(region); // pop #3
   367 			} // if (region)  
   400 			} // if (region)  
   368 		
   401 		
   369 		CleanupStack::PopAndDestroy(2,regionName); // pop #2, #1 - cityName, regionName
   402 		CleanupStack::PopAndDestroy(2,regionName); // pop #2, #1 - cityName, regionName
   370 		}
   403 		}
       
   404 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_FINDZONEBYNAMEL_EXIT, "CReadOnlyTzDb::FindZoneByNameL Exit" );
   371 
   405 
   372 	return retZone;
   406 	return retZone;
   373 	}
   407 	}
   374 
   408 
   375 CTzDbZone* CReadOnlyTzDb::FindZoneByNumericIdL(TUint aLocationId)
   409 CTzDbZone* CReadOnlyTzDb::FindZoneByNumericIdL(TUint aLocationId)
   467 
   501 
   468 @return	TInt offset from UTC (in minutes).
   502 @return	TInt offset from UTC (in minutes).
   469 */
   503 */
   470 TInt CReadOnlyTzDb::GetOffsetForTimeZoneIdL(const TTime& aTime, TInt aTzId)
   504 TInt CReadOnlyTzDb::GetOffsetForTimeZoneIdL(const TTime& aTime, TInt aTzId)
   471 	{
   505 	{
       
   506  
       
   507     OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_GETOFFSETFORTIMEZONEIDL_ENTRY, "CReadOnlyTzDb::GetOffsetForTimeZoneIdL Entry;aTzId=%d;Year=%d;Month=%d;Day=%d", aTzId, aTime.DateTime().Year(), aTime.DateTime().Month(), aTime.DateTime().Day());
       
   508     OstTraceDefExt3(OST_TRACE_CATEGORY_DEBUG, TRACE_FLOW_PARAM, CREADONLYTZDB_GETOFFSETFORTIMEZONEIDL_PARAM, "parameters..;Hour=%d;Minute=%d;seconds=%d",aTime.DateTime().Hour(),aTime.DateTime().Minute() ,aTime.DateTime().Second() );
       
   509     
   472 	if (iZonesTable == NULL)
   510 	if (iZonesTable == NULL)
   473 		{
   511 		{
   474 		InitialiseL();
   512 		InitialiseL();
   475 		}
   513 		}
   476 	
   514 	
   501 			offset = timeAlignment->UtcOffset();
   539 			offset = timeAlignment->UtcOffset();
   502 			delete timeAlignment;
   540 			delete timeAlignment;
   503 			}
   541 			}
   504 		CleanupStack::PopAndDestroy(zone);
   542 		CleanupStack::PopAndDestroy(zone);
   505 		}
   543 		}
       
   544 		OstTraceDef1( OST_TRACE_CATEGORY_DEBUG,TRACE_FLOW_PARAM, CREADONLYTZDB_GETOFFSETFORTIMEZONEIDL_EXIT, "CReadOnlyTzDb::GetOffsetForTimeZoneIdL Exit;offset=%u", offset );
   506 			
   545 			
   507 	return offset;
   546 	return offset;
   508 	}
   547 	}
   509 
   548 
   510 //
   549 //