tzservices/tzserver/Server/Source/DataProvider.cpp
changeset 0 2e3d3ce01487
child 81 676b6116ca93
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2004-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 //
       
    15 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    16 #include <tzuserdefineddata.h>
       
    17 #endif
       
    18 #include "dataprovider.h"
       
    19 #include "ReadOnlyTzDb.h"
       
    20 #include "vtzrules.h"
       
    21 #include "timezoneserver.h"
       
    22 
       
    23 CTzDataProvider* CTzDataProvider::NewL(RFs& aFs, CTzSwiObserver& aSwiObserver, 
       
    24 		CTzUserDataDb& aTzUserDataDb, MTzDataObserver& aTzDataObserver)
       
    25 	{
       
    26 	CTzDataProvider* self = new(ELeave) CTzDataProvider(aFs, aTzUserDataDb, aTzDataObserver);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL(aSwiObserver);
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CTzDataProvider::CTzDataProvider(RFs& aFs, CTzUserDataDb& aTzUerDataDb, MTzDataObserver& aTzDataObserver)
       
    34 :	iFs(aFs),
       
    35 	iTzDataObserver(aTzDataObserver),
       
    36 	iUserDataTzDb(aTzUerDataDb)
       
    37 	{
       
    38 	}
       
    39 
       
    40 void CTzDataProvider::ConstructL(CTzSwiObserver& aSwiObserver)
       
    41 	{
       
    42 	iReadOnlyTzDb = CReadOnlyTzDb::NewL(iFs, aSwiObserver, iTzDataObserver);
       
    43 	}
       
    44 
       
    45 CTzDataProvider::~CTzDataProvider()
       
    46 	{
       
    47 	delete iReadOnlyTzDb;
       
    48 	}
       
    49 
       
    50 void CTzDataProvider::ReleaseTzRules()
       
    51 	{
       
    52 	iReadOnlyTzDb->ReleaseData();
       
    53 	}
       
    54 
       
    55 TBool CTzDataProvider::IsIdInDbL(TUint aTzId)
       
    56 	{
       
    57 	if(CTzId::IsUserTzId(aTzId))
       
    58 		{
       
    59 		return iUserDataTzDb.IsIdInDbL(aTzId);
       
    60 		}
       
    61 	else
       
    62 		{
       
    63 		return iReadOnlyTzDb->IsIdInDbL(aTzId);	
       
    64 		}
       
    65 	}
       
    66 
       
    67 void CTzDataProvider::GetTzRulesL(CTzRules& aTzRules, CTzId& aTzId) const
       
    68 	{
       
    69 	if(aTzId.IsUserTzId())
       
    70 		{
       
    71 		iUserDataTzDb.ReadTzRulesL(aTzRules, aTzId.TimeZoneNumericID());
       
    72 		}
       
    73 	else
       
    74 		{
       
    75 		iReadOnlyTzDb->GetTzRulesL(aTzRules, aTzId);	
       
    76 		}
       
    77 	}
       
    78 
       
    79 CTzId* CTzDataProvider::GetDefaultTimeZoneIdL() const
       
    80 	{
       
    81 	return iReadOnlyTzDb->GetDefaultTimeZoneIdL();
       
    82 	}
       
    83 
       
    84 /**
       
    85 Retrieves the UTC offset for an array of numeric time zone identifiers.  The
       
    86 offset is written back into aTimeZoneIdArray at the position that the numeric
       
    87 identifier was read from, overwriting the original identifier.
       
    88 
       
    89 @param aTimeZoneIdArray Flat buffer consisting of a TInt for the number of
       
    90 identifiers followed by the numeric time zone identifiers (TInt's) for which the
       
    91 current UTC offset is required.
       
    92 */
       
    93 void CTzDataProvider::GetOffsetsForTimeZoneIdsL(CBufFlat& aTimeZoneIdArray) const
       
    94 	{
       
    95 	const TInt KElementSize = sizeof(TInt);
       
    96 	
       
    97 	// Get number of time zone identifiers in array.
       
    98 	TInt arrayOffset = 0;
       
    99 	TInt numIds = 0;
       
   100 	aTimeZoneIdArray.Read(arrayOffset, &numIds, KElementSize);
       
   101 
       
   102 	// Advance array offset to first time zone identifier.
       
   103 	arrayOffset += KElementSize;
       
   104 
       
   105 	// To obtain the current UTC offset we need to know the current UTC time.
       
   106 	TTime now;
       
   107 	now.UniversalTime();
       
   108 
       
   109 	while(arrayOffset <= numIds*KElementSize)
       
   110 		{
       
   111 		TInt id = 0;
       
   112 		
       
   113 		// Get the time zone identifier at the current array position.
       
   114 		aTimeZoneIdArray.Read(arrayOffset, &id, KElementSize);
       
   115 		
       
   116 		TInt utcOffset = 0;
       
   117 		
       
   118 		if(CTzId::IsUserTzId(id))
       
   119 			{
       
   120 			CTzRules* rules = CTzRules::NewL(0, KMaxYear);
       
   121 			CleanupStack::PushL(rules);
       
   122 			TRAPD(err, iUserDataTzDb.ReadTzRulesL(*rules, id));
       
   123 
       
   124 			// Assume the rules are not found and therefore that the UTC offset
       
   125 			// shall be 0 (this follows the behaviour of CReadOnlyTzDb::-
       
   126 			// GetOffsetForTimeZoneIdL()).
       
   127 			utcOffset = 0;
       
   128 
       
   129 			if(err != KErrNotFound)
       
   130 				{
       
   131 				User::LeaveIfError(err);
       
   132 				utcOffset = rules->GetOffsetL(now, ETzUtcTimeReference);
       
   133 				}
       
   134 
       
   135 			CleanupStack::PopAndDestroy(rules);
       
   136 			}
       
   137 		else
       
   138 			{
       
   139 			utcOffset = iReadOnlyTzDb->GetOffsetForTimeZoneIdL(now, id);	
       
   140 			}
       
   141 
       
   142 		// Replace the time zone identifier with the UTC offset.
       
   143 		aTimeZoneIdArray.Write(arrayOffset, &utcOffset, KElementSize);
       
   144 
       
   145 		// Advance array offset to next time zone identifier.
       
   146 		arrayOffset += KElementSize;
       
   147 		}
       
   148 	}
       
   149 
       
   150 void CTzDataProvider::BackupBeginningL()
       
   151 	{
       
   152 	iReadOnlyTzDb->BackupBeginningL();
       
   153 	iUserDataTzDb.BackupBeginningL();
       
   154 	}
       
   155 
       
   156 void CTzDataProvider::BackupCompletedL()
       
   157 	{
       
   158 	iReadOnlyTzDb->BackupCompletedL();
       
   159 	iUserDataTzDb.BackupCompletedL();
       
   160 	}
       
   161 void CTzDataProvider::RestoreBeginningL()
       
   162 	{
       
   163 	iReadOnlyTzDb->RestoreBeginningL();
       
   164 	iUserDataTzDb.RestoreBeginningL();
       
   165 	}
       
   166 
       
   167 void CTzDataProvider::RestoreCompletedL()
       
   168 	{
       
   169 	iReadOnlyTzDb->RestoreCompletedL();
       
   170 	iUserDataTzDb.RestoreCompletedL();
       
   171 	}