tzservices/tzserver/Client/Source/timezone.cpp
changeset 0 2e3d3ce01487
child 81 676b6116ca93
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1997-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 
       
    16 #include "timezoneserver.h"
       
    17 #include <tzdefines.h>
       
    18 #include <tz.h>
       
    19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    20 #include <tzusernames.h> //new file added for CTzUserNames which is publishedPartner
       
    21 #endif
       
    22 #include <tzlocalizedcityrecord.h>
       
    23 #include <tzlocalizedtimezonerecord.h>
       
    24 #include "tzrules.h"
       
    25 #include <s32mem.h>
       
    26 #include <vtzrules.h>
       
    27 #include <tzupdate.h>
       
    28 #include "tzruleholder.h"
       
    29 
       
    30 const TInt KNumConnectRetries = 5;
       
    31 
       
    32 // Define server name
       
    33 _LIT(KServerCode,"TZSERVER");
       
    34 
       
    35 // Return the client side version no.
       
    36 TVersion RTz::Version() const
       
    37 	{
       
    38 	return (TVersion(KTimeZoneServerMajorVersion,
       
    39 			KTimeZoneServerMinorVersion,
       
    40 			KTimeZoneServerBuildVersion));
       
    41 	}
       
    42 
       
    43 // 
       
    44 //Start the server process/thread which lives in an EPOCEXE object
       
    45 //
       
    46 TInt RTz::StartServer()
       
    47 	{
       
    48 	const TInt KIntServerType = 0x10004019;
       
    49 	const TUidType serverUid(KNullUid,TUid::Uid(KIntServerType));
       
    50 	
       
    51 	TRequestStatus started(KRequestPending);
       
    52 	TRendezvous rendezvous;
       
    53 	rendezvous.iId = RThread().Id();		// id of this thread
       
    54 	rendezvous.iStatus = &started;
       
    55 
       
    56 	RProcess server;
       
    57 	TInt err = server.Create(KServerCode,
       
    58 						TPtrC(reinterpret_cast<TText*>(&rendezvous),
       
    59 						sizeof(rendezvous)/sizeof(TText)),serverUid);
       
    60 
       
    61 	if (err != KErrNone)
       
    62 		{
       
    63 		return err;
       
    64 		}
       
    65 
       
    66 	server.SetPriority(EPriorityHigh);
       
    67 
       
    68 	TRequestStatus stat;
       
    69 	server.Rendezvous(stat);
       
    70 	if (stat != KRequestPending)
       
    71 		{
       
    72 		server.Kill(0);		// abort startup
       
    73 		}
       
    74 	else
       
    75 		{
       
    76 		server.Resume();	// logon OK - start the server
       
    77 		}
       
    78 	User::WaitForRequest(stat);		// wait for start or death
       
    79 	server.Close();
       
    80 	return stat.Int();
       
    81 	}
       
    82 
       
    83 /**
       
    84 Retrieves the time zone rules for the current home time zone.
       
    85 
       
    86 @param aStartTime The start date to generate the time zone rules from.
       
    87 @param aEndTime The end date to generate the time zone rules to.
       
    88 @param aTimeRef Whether to generate the rules relative to UTC or local time. Use 
       
    89 ETzUtcTimeReference to generate from UTC, ETzWallTimeReference to generate from local time.
       
    90 @return Pointer to the time zone rules generated.
       
    91 */
       
    92 EXPORT_C CTzRules* RTz::GetTimeZoneRulesL(const TTime& aStartTime, const TTime& aEndTime, TTzTimeReference aTimeRef) const
       
    93 	{
       
    94 	TInt rulesSize = 0;
       
    95 	TPckg<TTime> startTimeBuffer(aStartTime);
       
    96 	TPckg<TTime> endTimeBuffer(aEndTime);
       
    97 	TPckg<TTzTimeReference> timeRefBuffer(aTimeRef);
       
    98 	TPckg<TInt> rulesSizeBuffer(rulesSize);
       
    99 	TIpcArgs args(&startTimeBuffer, &endTimeBuffer, &timeRefBuffer, &rulesSizeBuffer);
       
   100 	const TInt result = SendReceive(CTzServer::EGetLocalEncodedTimeZoneRulesSize, args);
       
   101 	User::LeaveIfError(result);
       
   102 	
       
   103 	// prepare buffer for tz rules	
       
   104 	CBufFlat* inBuffer = CBufFlat::NewL(rulesSize);
       
   105 	CleanupStack::PushL(inBuffer);  // push #1
       
   106 	inBuffer->ExpandL(0, rulesSize);
       
   107 	TPtr8 inPtr(inBuffer->Ptr(0) );
       
   108 	
       
   109 	// get the rules
       
   110 	TIpcArgs args2(&rulesSizeBuffer,&inPtr);
       
   111 	const TInt result2 = SendReceive(CTzServer::EGetLocalEncodedTimeZoneRules, args2);
       
   112 	User::LeaveIfError(result2);
       
   113 	
       
   114 	RBufReadStream readStream;
       
   115 	readStream.Open(*inBuffer);
       
   116 	
       
   117 	CTzRules* rules = CTzRules::NewL(readStream);
       
   118 	
       
   119 	CleanupStack::PopAndDestroy(inBuffer); // pop #1
       
   120 	return rules;
       
   121 	}
       
   122 	
       
   123 /**
       
   124 Retrieves the time zone rules for a specified time zone.
       
   125 
       
   126 @param aZone The time zone to generate the rules for.
       
   127 @param aStartTime The start date to generate the time zone rules from.
       
   128 @param aEndTime The end date to generate the time zone rules to.
       
   129 @param aTimeRef Whether to generate the rules relative to UTC or local time. Use 
       
   130 ETzUtcTimeReference to generate from UTC, ETzWallTimeReference to generate from local time.
       
   131 @return Pointer to the time zone rules generated.
       
   132 */
       
   133 EXPORT_C CTzRules* RTz::GetTimeZoneRulesL(const CTzId& aZone, const TTime& aStartTime, const TTime& aEndTime, TTzTimeReference aTimeRef) const
       
   134 	{
       
   135 	TInt rulesSize = 0;
       
   136 	TPckg<TTime> startTimeBuffer(aStartTime);
       
   137 	TPckg<TTime> endTimeBuffer(aEndTime);
       
   138 	TPckg<TInt> rulesSizeBuffer(rulesSize);
       
   139 		
       
   140 	// prepare out buffer for zoneid and timeref
       
   141 	CBufFlat* outBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize + sizeof(TTzTimeReference)); 
       
   142 	CleanupStack::PushL(outBuffer); // push #1
       
   143 	
       
   144 	RBufWriteStream writeStream;
       
   145 	writeStream.Open(*outBuffer);
       
   146 	aZone.ExternalizeL(writeStream);
       
   147 	writeStream.WriteInt8L(aTimeRef);
       
   148 	TPtr8 outPtr(outBuffer->Ptr(0) );
       
   149 	
       
   150 	TIpcArgs args(&startTimeBuffer, &endTimeBuffer, &outPtr, &rulesSizeBuffer);
       
   151 	const TInt result = SendReceive(CTzServer::EGetForeignEncodedTimeZoneRulesSize, args);
       
   152 	User::LeaveIfError(result);
       
   153 	
       
   154 	CleanupStack::PopAndDestroy(outBuffer); // pop #1
       
   155 	
       
   156 	// prepare in rules buffer
       
   157 	CBufFlat* inBuffer = CBufFlat::NewL(rulesSize);
       
   158 	CleanupStack::PushL(inBuffer); // push #1
       
   159 	inBuffer->ExpandL(0, rulesSize);
       
   160 	TPtr8 inPtr(inBuffer->Ptr(0) );
       
   161 	
       
   162 	TIpcArgs args2(&rulesSizeBuffer, &inPtr);
       
   163 	const TInt result2 = SendReceive(CTzServer::EGetForeignEncodedTimeZoneRules, args2);
       
   164 	User::LeaveIfError(result2);
       
   165 	
       
   166 	RBufReadStream readStream;
       
   167 	readStream.Open(*inBuffer);
       
   168 	
       
   169 	CTzRules* rules = CTzRules::NewL(readStream);
       
   170 	
       
   171 	CleanupStack::PopAndDestroy(inBuffer); // pop #1
       
   172 	return rules;
       
   173 	}
       
   174 	
       
   175 // Registers to receive notification to time and zone changes in the
       
   176 // Server
       
   177 void RTz::RegisterTzChangeNotifier(TRequestStatus& aStatus) const
       
   178 	{
       
   179 	SendReceive(CTzServer::ERegisterTimeChangeNotifier, aStatus);
       
   180 	}
       
   181 
       
   182 // Cancels a previous request for notification of time zone changes
       
   183 TInt RTz::CancelRequestForNotice() const
       
   184 	{
       
   185 	return (SendReceive(CTzServer::ECancelRequestforNotice));
       
   186 	}
       
   187 
       
   188 // Converts time between UTC and Local for the current selected system time zone
       
   189 void RTz::doConvertL(TTime& aTime, TTzTimeReference aTimerRef) const
       
   190 	{
       
   191 
       
   192 	TPckg<TTime> timeBuffer(aTime);
       
   193 	TPckg<TTime> timeInBuffer(aTime);
       
   194 	TPckg<TTzTimeReference> timerRefBuffer(aTimerRef);
       
   195 
       
   196 	TIpcArgs args(&timeBuffer, &timerRefBuffer, &timeInBuffer);
       
   197 	const TInt result = SendReceive(CTzServer::EConvertLocalZoneTime, args);
       
   198 	User::LeaveIfError(result);
       
   199 
       
   200 	aTime = timeInBuffer();
       
   201 	}
       
   202 
       
   203 // Converts time between UTC and Local for a foreing time zone
       
   204 void RTz::doConvertL(const CTzId& aZone,
       
   205 								TTime& aTime,
       
   206 								TTzTimeReference aTimerRef) const
       
   207 	{
       
   208 	// prepare out zoneid buffer
       
   209 	CBufFlat* outBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize);
       
   210 	CleanupStack::PushL(outBuffer);
       
   211 
       
   212 	RBufWriteStream writeStream;
       
   213 	writeStream.Open(*outBuffer);
       
   214 	aZone.ExternalizeL(writeStream);
       
   215 	TPtr8 outPtr(outBuffer->Ptr(0) );
       
   216 
       
   217 	TPckg<TTime> timeBuffer(aTime);
       
   218 	TPckg<TTime> timeInBuffer(aTime);
       
   219 	TPckg<TTzTimeReference> timerRefBuffer(aTimerRef);
       
   220 
       
   221 	TIpcArgs args(&timeBuffer, &timerRefBuffer, &outPtr, &timeInBuffer);
       
   222 	const TInt result = SendReceive(CTzServer::EConvertForeignZoneTime, args);
       
   223 	CleanupStack::PopAndDestroy(outBuffer);
       
   224 
       
   225 	User::LeaveIfError(result);
       
   226 	aTime = timeInBuffer();
       
   227 	}
       
   228 
       
   229 /**
       
   230 Constructor.
       
   231 */
       
   232 EXPORT_C RTz::RTz() :
       
   233     iRulesHolder (NULL)
       
   234 	{
       
   235 	}
       
   236 
       
   237 /**
       
   238 Destructor. Calls Close().
       
   239 */
       
   240 EXPORT_C RTz::~RTz()
       
   241 	{
       
   242 	Close();
       
   243 	}
       
   244 
       
   245 /** 
       
   246 Connects to the time zone server, attempting to start it if necessary.
       
   247 @return KErrNone if successful, otherwise a system error code.
       
   248 @panic TzServer 1 The attempt to connect to the server failed with an error 
       
   249 code other than KErrNotFound.
       
   250 */
       
   251 EXPORT_C TInt RTz::Connect()
       
   252 	{
       
   253 	// The number of message slots in the RSessionBase::CreateSession() 
       
   254 	// call are delibrately unspecified so the kernel will take messages 
       
   255 	// from a global pool as and when required (the session is allowed
       
   256 	// a maximum of 255 outstanding asynchronous messages)
       
   257 
       
   258 	TInt retry = KNumConnectRetries;
       
   259 	FOREVER
       
   260 		{
       
   261 		TInt err = CreateSession(KTimeZoneServerName,Version());
       
   262 		if (err != KErrNotFound && err!=KErrServerTerminated)
       
   263 			{
       
   264 			return err;
       
   265 			}
       
   266 		// need to restart server
       
   267 		if (--retry == 0)
       
   268 			{
       
   269 			return err;
       
   270 			}
       
   271 		err = StartServer();
       
   272 		if (err != KErrNone && err != KErrAlreadyExists)
       
   273 			{
       
   274 			// Time Zone Server is configurable, so it is possible not to find it
       
   275 			if (err != KErrNotFound)
       
   276 				{
       
   277 				return err;
       
   278 				}
       
   279 			Panic(EPanicServerNotFound);
       
   280 			}
       
   281 		}
       
   282 	}
       
   283 
       
   284 /**
       
   285 Closes the connection to the time zone server.
       
   286 */
       
   287 EXPORT_C void RTz::Close()
       
   288 	{
       
   289 	// Destroy rules before closing session.
       
   290     delete iRulesHolder;
       
   291     iRulesHolder = NULL;
       
   292     
       
   293 	if (Handle())
       
   294 		{
       
   295 		
       
   296 		RSessionBase::Close();
       
   297 		}
       
   298 	}
       
   299 
       
   300 /** 
       
   301 Converts a time from UTC to local (wall-clock) time for the current system 
       
   302 time zone. If caching has been enabled by the CTzConverter class, then the 
       
   303 conversion will be done using the cache instead of issuing a request to the 
       
   304 server.
       
   305 
       
   306 @return KErrNone if successful, otherwise another system error code.
       
   307 @param aTime On entry, contains the UTC time to be converted,
       
   308 and the converted value on exit. 
       
   309 */
       
   310 EXPORT_C TInt RTz::ConvertToLocalTime(TTime& aTime) const
       
   311 	{
       
   312 
       
   313     // Use cached method for conversion if caching enabled, otherwise request 
       
   314     // server to do the conversion.
       
   315     TInt result = KErrNone;
       
   316 	if (iRulesHolder)
       
   317     	{
       
   318         TRAP( result, iRulesHolder->DoConvertL( aTime, ETzUtcTimeReference ) );
       
   319     	}
       
   320     else
       
   321         {
       
   322     	TRAP(result, doConvertL(aTime, ETzUtcTimeReference));
       
   323         }
       
   324 	return result;
       
   325 	}
       
   326 
       
   327 /** 
       
   328 Converts a time from UTC to the local (wall-clock) time 
       
   329 for the specified time zone.
       
   330 @return KErrNone if successful, otherwise another system error code.
       
   331 @param aTime On entry, contains the UTC time to be converted,
       
   332 and the converted value on exit.
       
   333 @param aZone Time zone ID.
       
   334 */
       
   335 EXPORT_C TInt RTz::ConvertToLocalTime(TTime& aTime, const CTzId& aZone) const
       
   336 	{
       
   337 	TRAPD(result, doConvertL(aZone, aTime, ETzUtcTimeReference));
       
   338 	return result;
       
   339 	}
       
   340 
       
   341 /** 
       
   342 Converts a local (wall-clock) time for the current system time zone, to UTC.
       
   343 If caching has been enabled by the CTzConverter class, then the conversion will
       
   344 be done using the cache instead of issuing a request to the server.
       
   345 
       
   346 @param aTime On entry, contains the local time to be converted, and 
       
   347 the converted value on exit. 
       
   348 @return KErrNone if successful, otherwise another system error code.
       
   349 */
       
   350 EXPORT_C TInt RTz::ConvertToUniversalTime(TTime& aTime) const
       
   351 	{
       
   352     // Use cached method for conversion if caching enabled, otherwise request 
       
   353     // server to do the conversion.
       
   354     TInt result = KErrNone;
       
   355 	if (iRulesHolder)
       
   356     	{
       
   357         TRAP( result, iRulesHolder->DoConvertL( aTime, ETzWallTimeReference ) );
       
   358         }
       
   359     else
       
   360         {
       
   361     	TRAP(result, doConvertL(aTime, ETzWallTimeReference));
       
   362         }
       
   363 	return result;
       
   364 	}
       
   365 
       
   366 /** 
       
   367 Converts a local (wall-clock) time for the specified time zone, to UTC.
       
   368 @param aTime On entry, contains the local time to be converted, and 
       
   369 the converted value on exit. 
       
   370 
       
   371 @param aZone The time zone ID of interest.
       
   372 @return KErrNone if successful, otherwise another system error code.
       
   373 */
       
   374 EXPORT_C TInt RTz::ConvertToUniversalTime(TTime& aTime, const CTzId& aZone) const
       
   375 	{
       
   376 	TRAPD(result, doConvertL(aZone, aTime, ETzWallTimeReference));
       
   377 	return result;
       
   378 	}
       
   379 
       
   380 /**
       
   381 Retrieves the UTC offset for an array of numeric time zone ids.
       
   382 The offset is written back into aOffsets.
       
   383 @param aTzNumericIds An array of numeric time zone IDs for which the current
       
   384 UTC offset is required.
       
   385 @param aOffsets An array that, on return, will contain the UTC offsets
       
   386 corresponding to the the time zone IDs in aTzNumericIds.
       
   387 */
       
   388 EXPORT_C void RTz::GetOffsetsForTimeZoneIdsL(const RArray<TInt>& aTzNumericIds, RArray<TInt>& aOffsets) const
       
   389 	{
       
   390 	TInt count 			= aTzNumericIds.Count();
       
   391 	TInt tintSize 		= sizeof(TInt);
       
   392 	TInt idBufLength	= count * tintSize;
       
   393 	TInt pos 			= 0;
       
   394 	idBufLength += tintSize;
       
   395 	TInt x;
       
   396 	//Write the number of elements in the array, followed by
       
   397 	//the time zone id of each element into idBuf.
       
   398 	CBufFlat* idBuf = CBufFlat::NewL(idBufLength);
       
   399 	CleanupStack::PushL(idBuf);
       
   400 	idBuf->ExpandL(pos,idBufLength);
       
   401 		
       
   402 	idBuf->Write(pos,&count,tintSize);
       
   403 	pos += tintSize;
       
   404 	
       
   405 	for (x = 0; x < count; ++x)
       
   406 		{
       
   407 		TInt id = aTzNumericIds[x];
       
   408 		idBuf->Write(pos,&id,tintSize);
       
   409 		pos += tintSize ;
       
   410 		}
       
   411 
       
   412 	TInt size = idBuf->Size();
       
   413 	TPtr8 outPtr(idBuf->Ptr(0) );
       
   414 	TIpcArgs args(size,&outPtr);
       
   415 	const TInt result = SendReceive(CTzServer::EGetOffsetsForTimeZoneIds, args);	
       
   416 	User::LeaveIfError(result);
       
   417 	
       
   418 	// idBuf now contains the offsets INSTEAD of the timezone Ids
       
   419 	pos = 0;
       
   420 	count = 0;
       
   421 	TInt offset = 0;
       
   422 	idBuf->Read(pos,&count,tintSize);
       
   423 	pos += tintSize;
       
   424 	//Loop through aArray again, setting the offsets from idBuf
       
   425 	for (x = 0; x < count; ++x)
       
   426 		{
       
   427 		idBuf->Read(pos,&offset,tintSize);
       
   428 		aOffsets.AppendL(offset);
       
   429 		pos += tintSize;
       
   430 		}
       
   431 	CleanupStack::PopAndDestroy(idBuf);
       
   432 	}
       
   433 
       
   434 /** 
       
   435 Retrieves the time zone ID for the current system time zone.
       
   436 @return Time zone ID. The client takes ownership of the object.
       
   437 @leave KErrNoMemory or another system leave code.
       
   438 @internalTechnology
       
   439 */
       
   440 EXPORT_C CTzId* RTz::GetTimeZoneIdL() const
       
   441 	{
       
   442 	CBufFlat* inBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize);
       
   443 	CleanupStack::PushL(inBuffer);
       
   444 
       
   445 	// reserve the full space
       
   446 	inBuffer->ExpandL(0, KMaxTimeZoneIdSize);
       
   447 
       
   448 	TPtr8 ptr(inBuffer->Ptr(0) );
       
   449 
       
   450 	TIpcArgs args(&ptr);
       
   451 	const TInt result = SendReceive(CTzServer::EGetLocalTimeZoneId, args);
       
   452 	User::LeaveIfError(result);
       
   453 
       
   454 	RBufReadStream readStream;
       
   455 	readStream.Open(*inBuffer);
       
   456 	CTzId* zone = CTzId::NewL(readStream);
       
   457 	CleanupStack::PopAndDestroy(inBuffer);
       
   458 	return zone;
       
   459 	}
       
   460 
       
   461 /** 
       
   462 Sets the current system time zone information to that corresponding to the 
       
   463 supplied time zone ID.
       
   464 @param aZone The time zone ID.
       
   465 @capability WRITE_DEVICE_DATA
       
   466 @internalTechnology
       
   467 */
       
   468 EXPORT_C void RTz::SetTimeZoneL(CTzId& aZone) const
       
   469 	{
       
   470 	CBufFlat* outBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize);
       
   471 	CleanupStack::PushL(outBuffer);
       
   472 
       
   473 	RBufWriteStream writeStream;
       
   474 	writeStream.Open(*outBuffer);
       
   475 
       
   476 	aZone.ExternalizeL(writeStream);
       
   477 
       
   478 	writeStream.CommitL();
       
   479 	writeStream.Close();
       
   480 
       
   481 	CBufFlat* inBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize);
       
   482 	CleanupStack::PushL(inBuffer);
       
   483 
       
   484 	// reserve the full space
       
   485 	inBuffer->ExpandL(0, KMaxTimeZoneIdSize);
       
   486 
       
   487 	TPtr8 outPtr(outBuffer->Ptr(0) );
       
   488 	TPtr8 inPtr(inBuffer->Ptr(0) );
       
   489 	TIpcArgs args(&outPtr, &inPtr);
       
   490 	const TInt result = SendReceive(CTzServer::ESetTimeZone, args);
       
   491 	User::LeaveIfError(result);
       
   492 
       
   493 	RBufReadStream readStream;
       
   494 	readStream.Open(*inBuffer);
       
   495 	aZone.InternalizeL(readStream);
       
   496 
       
   497 	CleanupStack::PopAndDestroy(2, outBuffer);
       
   498 
       
   499     // The time zone changed. Update cache - it is no longer valid.
       
   500 	if (iRulesHolder)
       
   501 	    {
       
   502 	    // This shouldn't leave, it's an implementation error if it does. 
       
   503 	    TRAP_IGNORE( iRulesHolder->NotifyTimeZoneChangeL( 
       
   504 	        ETZSystemTimeZoneChanged ) ); 
       
   505 	    }
       
   506 	}
       
   507 	
       
   508 /**
       
   509 Tells if daylight savings are applied at the specified zone at the current time
       
   510 
       
   511 @param aZone The time zone ID.
       
   512 @return ETrue if the Daylight Saving is on, i.e. if it is summertime.
       
   513 */	
       
   514 EXPORT_C TBool RTz::IsDaylightSavingOnL(CTzId& aZone) const
       
   515 	{
       
   516 	// prepare out zoneid buffer
       
   517 	CBufFlat* outBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize);
       
   518 	CleanupStack::PushL(outBuffer);
       
   519 
       
   520 	RBufWriteStream writeStream;
       
   521 	writeStream.Open(*outBuffer);
       
   522 	aZone.ExternalizeL(writeStream);
       
   523 	
       
   524 	TPckg<TTime> timeBuffer(Time::NullTTime());
       
   525 	
       
   526 	TPtr8 outPtr(outBuffer->Ptr(0) );
       
   527 	TPckgBuf<TInt> package;
       
   528 	TIpcArgs args(&outPtr, &timeBuffer, &package);
       
   529 	const TInt result = SendReceive(CTzServer::EIsDaylightSavingOn, args);
       
   530 	User::LeaveIfError(result);
       
   531 	CleanupStack::PopAndDestroy(outBuffer);
       
   532 	return package();		
       
   533 	}
       
   534 
       
   535 /**
       
   536 Tells if daylight savings are applied at the specified zone at a specified time
       
   537 
       
   538 @param aZone The time zone ID.
       
   539 @param aUTCTime The UTC time at which DST settings are required.
       
   540 @return ETrue if the Daylight Saving is on, i.e. if it is summertime.
       
   541 */	
       
   542 EXPORT_C TBool RTz::IsDaylightSavingOnL(CTzId& aZone, const TTime& aUTCTime) const
       
   543 	{
       
   544 	// prepare out zoneid buffer
       
   545 	CBufFlat* outBuffer = CBufFlat::NewL(KMaxTimeZoneIdSize);
       
   546 	CleanupStack::PushL(outBuffer);
       
   547 
       
   548 	RBufWriteStream writeStream;
       
   549 	writeStream.Open(*outBuffer);
       
   550 	aZone.ExternalizeL(writeStream);
       
   551 		
       
   552 	TPckg<TTime> timeBuffer(aUTCTime);	
       
   553 	
       
   554 	TPtr8 outPtr(outBuffer->Ptr(0) );
       
   555  	TPckgBuf<TInt> package;
       
   556 	TIpcArgs args(&outPtr, &timeBuffer, &package);
       
   557  	const TInt result = SendReceive(CTzServer::EIsDaylightSavingOn, args);
       
   558  	User::LeaveIfError(result);
       
   559  	CleanupStack::PopAndDestroy(outBuffer);
       
   560  	return package();		
       
   561  	}
       
   562 
       
   563 /** 
       
   564 Panics the TzClient or TzServer code.
       
   565 
       
   566 @internalComponent
       
   567 */
       
   568 EXPORT_C void RTz::Panic(TPanic aPanic)
       
   569 	{
       
   570 	_LIT(KTzServer,"TzServer");
       
   571 	User::Panic(KTzServer, aPanic);
       
   572 	}
       
   573 
       
   574 /**
       
   575 Sets the configuration of the UTC Offset auto-update functionality.
       
   576 
       
   577 @param aUpdateEnabled If set to RTz::ETZAutoDSTUpdateOn then the UTC Offset is automatically
       
   578 updated for changes to Daylight Savings Time. If set to RTz::ETZAutoDSTUpdateOff then auto-update
       
   579 is disabled. The RTz::ETZAutoDSTNotificationOnly - Means that the client app needs to confirm that the 
       
   580 time should be updated whenever a DST event occurs.
       
   581 
       
   582 */
       
   583 EXPORT_C void RTz::SetAutoUpdateBehaviorL(TTzAutoDSTUpdateModes aUpdateEnabled)
       
   584     {
       
   585     // Create the message arguments, setting slot zero to the configuration value.
       
   586 	TIpcArgs args(aUpdateEnabled);
       
   587 	
       
   588 	// Send the message.
       
   589 	User::LeaveIfError(SendReceive(CTzServer::EEnableAutoUpdate, args));
       
   590     }
       
   591 
       
   592 /**
       
   593 Retrieves the daylight saving auto-update functionality.
       
   594 @return An error code. KErrNone is expected unless there is an error while trying to retrieve the auto-update setting.
       
   595 */
       
   596 EXPORT_C TInt RTz::AutoUpdateSettingL()
       
   597     {
       
   598     TPckgBuf<TInt> package;
       
   599 	TIpcArgs args(&package);
       
   600 	const TInt result = SendReceive(CTzServer::EAutoUpdate, args);
       
   601 	User::LeaveIfError(result);
       
   602 	return package();	
       
   603     }
       
   604         
       
   605 /**
       
   606 Sets the system time to the given local time. Note that the standard Tz
       
   607 algorithm is used - in the case of an ambiguous time the first occurance of the
       
   608 given local wall-clock time is chosen.
       
   609 
       
   610 An example of an ambiguous time: 01:30 wall-clock time on 31/10/2004 in the UK
       
   611 could map to either 01:30 BST (00:30 GMT) or 01:30 GMT, as the clocks would go
       
   612 back at 02:00 BST (01:00 GMT))
       
   613 
       
   614 @capability WriteDeviceData
       
   615 @param aLocalTime The time to set in wall-clock time.
       
   616 
       
   617 @return An error code. KErrNone is expected unless there is an error in
       
   618 converting the given local time to UTC.
       
   619 
       
   620 */
       
   621 EXPORT_C TInt RTz::SetHomeTime(const TTime& aLocalTime) const
       
   622     {
       
   623 	TPckg<TTime>   timeBuffer(aLocalTime);
       
   624 
       
   625 	TIpcArgs args(&timeBuffer);
       
   626 	return SendReceive(CTzServer::ESetHomeTime, args);
       
   627     }
       
   628 
       
   629 /**
       
   630 Publish notification that the home time zone (as defined in CTzLocalizer) has been changed.
       
   631 This function should only be called from TimeZoneLocalization.
       
   632 
       
   633 @param aChange Time zone change information.
       
   634 */
       
   635 EXPORT_C void RTz::NotifyHomeTimeZoneChangedL(const NTzUpdate::TTimeZoneChange& aChange) const
       
   636 	{
       
   637 	TIpcArgs args(aChange.iNewTimeZoneId, aChange.iOldTimeZoneId);
       
   638 	
       
   639 	// Send the message.
       
   640 	User::LeaveIfError(SendReceive(CTzServer::ENotifyHomeTimeZoneChanged, args));
       
   641 	}
       
   642 
       
   643 /**
       
   644 Sets the UTC time and the wall-clock offset for a zone not defined in the
       
   645 Timezone Database.
       
   646 
       
   647 This is useful when the client wants to specify the UTC time and the wall-clock offset explicitly
       
   648 rather than using time zones. This function should be used instead of User::SetUTCOffset() and 
       
   649 User::SetUTCTimeAndOffset().
       
   650 
       
   651 If this function has been called the time zone server will use the value returned by User::UTCOffset()
       
   652 as the offset value when doing time conversions. Calling User::SetUTCOffset() may therefore cause unexpected
       
   653 results.
       
   654 
       
   655 The fact that the time zone has been set to the unknown time zone is not persisted across time zone server 
       
   656 reboots. So it may be necessary to call this function each time the time zone 
       
   657 server is started. If persistence across reboots is desired the overload 
       
   658 RTz::SetUnknownZoneTimeL(const TTime& aUTCTime, const TInt aUTCOffset, TBool aPersistInCenRep) 
       
   659 should be used.
       
   660 
       
   661 @param aUTCTime Universal Time to set the device time to.
       
   662 @param aUTCOffset Offset (in minutes) in use in the time zone.
       
   663 */
       
   664 EXPORT_C void RTz::SetUnknownZoneTimeL(const TTime& aUTCTime, const TInt aUTCOffset)
       
   665 	{
       
   666 	SetUnknownZoneTimeL(aUTCTime, aUTCOffset, EFalse);
       
   667 	}
       
   668 
       
   669 /**
       
   670 Sets the UTC time and the wall-clock offset for a zone not defined in the
       
   671 Timezone Database.
       
   672 
       
   673 This is useful when the client wants to specify the UTC time and the wall-clock offset explicitly
       
   674 rather than using time zones. This function should be used instead of User::SetUTCOffset() and 
       
   675 User::SetUTCTimeAndOffset().
       
   676 
       
   677 If this function has been called the time zone server will use the value returned by User::UTCOffset()
       
   678 as the offset value when doing time conversions. Calling User::SetUTCOffset() may therefore cause unexpected
       
   679 results.
       
   680 
       
   681 The fact that the time zone has been set to the unknown time zone is persisted across time zone server 
       
   682 reboots only if the aPersistInCenRep argument is set to ETrue. The desired offset however is never persisted 
       
   683 (the value returned by User::UTCOffset() is used). So it may be necessary to call this function each time 
       
   684 the time zone server is started.
       
   685 
       
   686 @param aUTCTime Universal Time to set the device time to.
       
   687 @param aUTCOffset Offset (in minutes) in use in the time zone.
       
   688 @param aPersistInCenRep If ETrue the unknown time zone is persisted across reboots else it is not.
       
   689 */
       
   690 EXPORT_C void RTz::SetUnknownZoneTimeL(const TTime& aUTCTime, const TInt aUTCOffset, TBool aPersistInCenRep)
       
   691 	{
       
   692 	TPckg<TTime> utcTime(aUTCTime);   
       
   693 	TPckg<TInt>  utcOffset(aUTCOffset);
       
   694 	TPckg<TBool> persist(aPersistInCenRep);
       
   695 
       
   696 	TIpcArgs args(&utcTime, &utcOffset, &persist);
       
   697 	User::LeaveIfError(SendReceive(CTzServer::ESetUnknownZoneTime, args));
       
   698 	}
       
   699 
       
   700 /**
       
   701 Reads all the user defined cities stored in the
       
   702 database. If the database is empty the
       
   703 returned array will contain no elements.
       
   704 @param aCities Array of cities to add the user defined to.
       
   705 @internalTechnology
       
   706 */
       
   707 EXPORT_C void RTz::LocalizationReadCitiesL(RPointerArray<CTzLocalizedCityRecord>& aCities)
       
   708 	{
       
   709 	TInt resultSize = 0;
       
   710 	TPckg<TInt> resultSizeBuffer(resultSize);
       
   711 	TIpcArgs args(&resultSizeBuffer);
       
   712 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCitiesSize, args));
       
   713 		
       
   714 	CBufFlat* inBuffer = CBufFlat::NewL(resultSize);
       
   715 	CleanupStack::PushL(inBuffer);
       
   716 	inBuffer->ExpandL(0, resultSize);
       
   717 	TPtr8 inPtr(inBuffer->Ptr(0));
       
   718 	
       
   719 	TIpcArgs args2(&inPtr);
       
   720 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCities, args2));
       
   721 	
       
   722 	RBufReadStream readStream;
       
   723 	readStream.Open(*inBuffer);
       
   724 	CleanupClosePushL(readStream);
       
   725 	CTzLocalizedCityRecord::InternalizeL(readStream, aCities);
       
   726 	CleanupStack::PopAndDestroy(&readStream);
       
   727 	
       
   728 	CleanupStack::PopAndDestroy(inBuffer);
       
   729 	}
       
   730 
       
   731 /**
       
   732 Reads all the user defined cities stored in the database that are members of
       
   733 the time zone referenced by aTimeZoneid.
       
   734 If the database is empty the returned array will contain no elements.
       
   735 @param aCities Array of cities to add the user defined cities to.
       
   736 @param aTimeZoneId A time zone id identifying a time zone
       
   737 @internalTechnology
       
   738 */
       
   739 EXPORT_C void RTz::LocalizationReadCitiesL(RPointerArray<CTzLocalizedCityRecord>& aCities, TInt aTimeZoneId)
       
   740 	{
       
   741 	TInt resultSize = 0;
       
   742 	TPckg<TInt> resultSizeBuffer(resultSize);
       
   743 	TIpcArgs args(&resultSizeBuffer, aTimeZoneId);
       
   744 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCitiesTzIdSize, args));
       
   745 		
       
   746 	CBufFlat* inBuffer = CBufFlat::NewL(resultSize);
       
   747 	CleanupStack::PushL(inBuffer);
       
   748 	inBuffer->ExpandL(0, resultSize);
       
   749 	TPtr8 inPtr(inBuffer->Ptr(0));
       
   750 	
       
   751 	TIpcArgs args2(&inPtr, aTimeZoneId);
       
   752 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCities, args2));
       
   753 		
       
   754 	RBufReadStream readStream;
       
   755 	readStream.Open(*inBuffer);
       
   756 	CleanupClosePushL(readStream);
       
   757 	CTzLocalizedCityRecord::InternalizeL(readStream, aCities);
       
   758 	CleanupStack::PopAndDestroy(&readStream);
       
   759 	
       
   760 	CleanupStack::PopAndDestroy(inBuffer);	
       
   761 	}
       
   762 
       
   763 /**
       
   764 Reads all the user defined cities stored in the database with a matching group id.
       
   765 If the database is empty the returned array will contain no elements.
       
   766 @param aCities Array of cities to add the user defined cities to.
       
   767 @param aGroupId A city group id
       
   768 @internalTechnology
       
   769 */
       
   770 EXPORT_C void RTz::LocalizationReadCitiesInGroupL(RPointerArray<CTzLocalizedCityRecord>& aCities, TUint8 aGroupId)
       
   771 	{
       
   772 	TInt resultSize = 0;
       
   773 	TPckg<TInt> resultSizeBuffer(resultSize);
       
   774 	TIpcArgs args(&resultSizeBuffer, aGroupId);
       
   775 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCitiesInGroupSize, args));
       
   776 		
       
   777 	CBufFlat* inBuffer = CBufFlat::NewL(resultSize);
       
   778 	CleanupStack::PushL(inBuffer);
       
   779 	inBuffer->ExpandL(0, resultSize);
       
   780 	TPtr8 inPtr(inBuffer->Ptr(0));
       
   781 	
       
   782 	TIpcArgs args2(&inPtr, aGroupId);
       
   783 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCities, args2));
       
   784 		
       
   785 	RBufReadStream readStream;
       
   786 	readStream.Open(*inBuffer);
       
   787 	CleanupClosePushL(readStream);
       
   788 	CTzLocalizedCityRecord::InternalizeL(readStream, aCities);
       
   789 	CleanupStack::PopAndDestroy(&readStream);
       
   790 	
       
   791 	CleanupStack::PopAndDestroy(inBuffer);
       
   792 	}
       
   793 
       
   794 /**
       
   795 Retrieves a cached zone from the database.
       
   796 The calling function takes ownership of the returned zone
       
   797 @param aFrequentlyUsedZone - The cached zone to return
       
   798 @return a cached zone from the database
       
   799 @internalTechnology
       
   800 */
       
   801 EXPORT_C CTzLocalizedTimeZoneRecord* RTz::LocalizationReadFrequentlyUsedZoneL(TInt aFrequentlyUsedZone)
       
   802 	{
       
   803 	TInt resultSize = 0;
       
   804 	TPckg<TInt> resultSizeBuffer(resultSize);
       
   805 	TIpcArgs args(&resultSizeBuffer, aFrequentlyUsedZone);
       
   806 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadFrequentlyUsedZoneSize, args));
       
   807 		
       
   808 	CBufFlat* inBuffer = CBufFlat::NewL(resultSize);
       
   809 	CleanupStack::PushL(inBuffer);
       
   810 	inBuffer->ExpandL(0, resultSize);
       
   811 	TPtr8 inPtr(inBuffer->Ptr(0));
       
   812 	
       
   813 	TIpcArgs args2(&inPtr, aFrequentlyUsedZone);
       
   814 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadFrequentlyUsedZone, args2));
       
   815 		
       
   816 	RBufReadStream readStream;
       
   817 	readStream.Open(*inBuffer);
       
   818 	CleanupClosePushL(readStream);
       
   819 	CTzLocalizedTimeZoneRecord* result = CTzLocalizedTimeZoneRecord::NewL(readStream);
       
   820 	CleanupStack::PopAndDestroy(&readStream);
       
   821 	
       
   822 	CleanupStack::PopAndDestroy(inBuffer);	
       
   823 	
       
   824 	return result;
       
   825 	}
       
   826 
       
   827 /**
       
   828 Retrieves the city used to select this time zone if set.  If the time zone was not originally
       
   829 set using a city then the default city for the time zone will be returned instead.
       
   830 @param aFrequentlyUsedZone - The cached zone to find the city for
       
   831 @return	 selected city for the cached zone
       
   832 @internalTechnology
       
   833 */
       
   834 EXPORT_C CTzLocalizedCityRecord* RTz::LocalizationReadCachedTimeZoneCityL(TInt aFrequentlyUsedZone)
       
   835 	{
       
   836 	TInt resultSize = 0;
       
   837 	TPckg<TInt> resultSizeBuffer(resultSize);
       
   838 	TIpcArgs args(&resultSizeBuffer, aFrequentlyUsedZone);
       
   839 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCachedTimeZoneCitySize, args));
       
   840 		
       
   841 	CBufFlat* inBuffer = CBufFlat::NewL(resultSize);
       
   842 	CleanupStack::PushL(inBuffer);
       
   843 	inBuffer->ExpandL(0, resultSize);
       
   844 	TPtr8 inPtr(inBuffer->Ptr(0));
       
   845 	
       
   846 	TIpcArgs args2(&inPtr, aFrequentlyUsedZone);
       
   847 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationReadCachedTimeZoneCity, args2));
       
   848 		
       
   849 	RBufReadStream readStream;
       
   850 	readStream.Open(*inBuffer);
       
   851 	CleanupClosePushL(readStream);
       
   852 	CTzLocalizedCityRecord* result = CTzLocalizedCityRecord::NewL(readStream);
       
   853 	CleanupStack::PopAndDestroy(&readStream);
       
   854 	
       
   855 	CleanupStack::PopAndDestroy(inBuffer);	
       
   856 	
       
   857 	return result;
       
   858 	}
       
   859 
       
   860 EXPORT_C void RTz::LocalizationCloseDbL()
       
   861 	{
       
   862 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationCloseDb));
       
   863 	}
       
   864 
       
   865 EXPORT_C void RTz::LocalizationOpenDbL()
       
   866 	{
       
   867 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationOpenDb));
       
   868 	}
       
   869 
       
   870 /**
       
   871 Adds aCity into the user added cities database table. The city is checked first to prevent
       
   872 two cities with identical names and time zones existing at the same time. Name checking is
       
   873 case sensitive. Cities in different time zones can have the same name.
       
   874 
       
   875 @param aCityName The name of the city to add to the database
       
   876 @param aCityTzId The time zone of the city
       
   877 @param aCityGroupId The group id
       
   878 @param aCityResourceId The resource id
       
   879 
       
   880 @internalTechnology
       
   881 */
       
   882 EXPORT_C void RTz::LocalizationWriteCityL(const TDesC& aCityName, TInt aCityTzId, TUint8 aCityGroupId, TUint aCityResourceId)
       
   883 	{
       
   884 	if (aCityTzId > 0xFFFF)
       
   885 		{
       
   886 		// This is a mess, although most of the API allows for 32 bit tz ids some of them
       
   887 		// only allow for 16 bit tz ids so we accept a TInt but do check that it can fit in 
       
   888 		// 16 bits
       
   889 		User::Leave(KErrArgument);
       
   890 		}
       
   891 	TIpcArgs args(&aCityName, aCityTzId, aCityGroupId, aCityResourceId);
       
   892 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationWriteCity, args));
       
   893 	}
       
   894 
       
   895 /**
       
   896 Deletes aCity from the user added cities database table.
       
   897 The city is checked first to ensure it exists.
       
   898 Name checking is case sensitive.
       
   899 
       
   900 @param aCityName The name of the city to delete from the database.
       
   901 @param aCityTzId The numeric identifier of the city to delete from the database.
       
   902 
       
   903 @internalTechnology
       
   904 */
       
   905 EXPORT_C void RTz::LocalizationDeleteCityL(const TDesC& aCityName, TInt aCityTzId)
       
   906 	{
       
   907 	if (aCityTzId > 0xFFFF)
       
   908 		{
       
   909 		// This is a mess, although most of the API allows for 32 bit tz ids some of them
       
   910 		// only allow for 16 bit tz ids so we accept a TInt but do check that it can fit in 
       
   911 		// 16 bits
       
   912 		User::Leave(KErrArgument);
       
   913 		}
       
   914 	TIpcArgs args(&aCityName, aCityTzId);
       
   915 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationDeleteCity, args));
       
   916 	}
       
   917 
       
   918 /**
       
   919 Stores the localized time zone in the database for easy retrieval.
       
   920 The database keeps track of the two most recently used zones, these are updated every time
       
   921 a new zone is set.  The zone to be replaced becomes recently used zone 1, and recently used zone 1 becomes
       
   922 recently used zone 2.  The old recently used zone 2 is discarded.
       
   923 
       
   924 @param aTimeZone Time zone names information to store in the given frequently
       
   925 used time zone.
       
   926 @param aCity City associated with the time zone names to store in the given
       
   927 frequently used time zone.
       
   928 @param aFrequentlyUsedZone Which frequently used time zone to overwrite in the
       
   929 database.
       
   930 
       
   931 @internalTechnology
       
   932 */
       
   933 EXPORT_C void RTz::LocalizationWriteFrequentlyUsedZoneL(const CTzLocalizedTimeZoneRecord& aTimeZone,
       
   934 	const CTzLocalizedCityRecord& aCity, TInt aFrequentlyUsedZone)
       
   935 	{
       
   936 	TInt bufferSize = aTimeZone.ExternalizeSize() + aCity.ExternalizeSize() + sizeof(TInt32);
       
   937 	CBufFlat* buffer = CBufFlat::NewL(bufferSize);
       
   938 	CleanupStack::PushL(buffer);
       
   939 	RBufWriteStream bufStream;
       
   940 	bufStream.Open(*buffer);
       
   941 	CleanupClosePushL(bufStream);
       
   942 	aTimeZone.ExternalizeL(bufStream);
       
   943 	aCity.ExternalizeL(bufStream);
       
   944 	bufStream.WriteInt32L(aFrequentlyUsedZone);
       
   945 	bufStream.CommitL();
       
   946 	CleanupStack::PopAndDestroy(&bufStream);
       
   947 	TPtr8 bufferPtr = buffer->Ptr(0); 
       
   948 	TIpcArgs args(&bufferPtr);
       
   949 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationWriteFrequentlyUsedZone, args));
       
   950 	CleanupStack::PopAndDestroy(buffer);
       
   951 	}
       
   952 
       
   953 /**
       
   954 @internalTechnology
       
   955 */
       
   956 EXPORT_C void RTz::LocalizationWriteAllFrequentlyUsedZonesL(const RPointerArray<CTzLocalizedTimeZoneRecord>& aTimeZones,
       
   957 		const RPointerArray<CTzLocalizedCityRecord>& aCities)
       
   958 	{
       
   959 	TInt bufferSize = CTzLocalizedTimeZoneRecord::ExternalizeSize(aTimeZones);
       
   960 	bufferSize += CTzLocalizedCityRecord::ExternalizeSize(aCities);
       
   961 	CBufFlat* buffer = CBufFlat::NewL(bufferSize);
       
   962 	CleanupStack::PushL(buffer);
       
   963 	RBufWriteStream bufStream;
       
   964 	bufStream.Open(*buffer);
       
   965 	CleanupClosePushL(bufStream);
       
   966 	CTzLocalizedTimeZoneRecord::ExternalizeL(aTimeZones, bufStream);
       
   967 	CTzLocalizedCityRecord::ExternalizeL(aCities, bufStream);
       
   968 	bufStream.CommitL();
       
   969 	CleanupStack::PopAndDestroy(&bufStream);
       
   970 	TPtr8 bufferPtr = buffer->Ptr(0); 
       
   971 	TIpcArgs args(&bufferPtr);
       
   972 	User::LeaveIfError(SendReceive(CTzServer::ELocalizationWriteAllFrequentlyUsedZones, args));
       
   973 	CleanupStack::PopAndDestroy(buffer);
       
   974 	}
       
   975 
       
   976 /**
       
   977 Called by the installation observer plugin to signal the start of an (un)install log.
       
   978 
       
   979 @internalTechnology
       
   980 */
       
   981 EXPORT_C void RTz::SwiObsBeginL()
       
   982 	{
       
   983 	User::LeaveIfError(SendReceive(CTzServer::ESwiObsBegin));
       
   984 	}
       
   985 
       
   986 /**
       
   987 Called by the installation observer plugin to signal that the rules database or
       
   988 the resource files have been changed.
       
   989 
       
   990 @param aType The type of file that has changed (resource or rules database).
       
   991 
       
   992 @internalTechnology
       
   993 */
       
   994 EXPORT_C void RTz::SwiObsFileChangedL(TSWIObserverFilterIndex aType)
       
   995 	{
       
   996 	TIpcArgs args(aType);
       
   997 	User::LeaveIfError(SendReceive(CTzServer::ESwiObsFileChanged, args));
       
   998 	}
       
   999 
       
  1000 /**
       
  1001 Called by the installation observer plugin to signal the end of an (un)install log.
       
  1002  
       
  1003 @internalTechnology
       
  1004 */
       
  1005 EXPORT_C void RTz::SwiObsEndL()
       
  1006 	{
       
  1007 	User::LeaveIfError(SendReceive(CTzServer::ESwiObsEnd));
       
  1008 	}
       
  1009 
       
  1010 // Enables client side caching of time zone conversions for the local time zone
       
  1011 // if caching is not already enabled. Must be connected to the server before 
       
  1012 // calling.
       
  1013 // Returns ETrue if caching was enabled, EFalse if caching was already enabled.
       
  1014 TBool RTz::StartCachingL()
       
  1015     {
       
  1016     if (!iRulesHolder)
       
  1017         {
       
  1018         iRulesHolder = CTzRuleHolder::NewL( *this );
       
  1019         return ETrue;
       
  1020         }
       
  1021     else
       
  1022         {
       
  1023         return EFalse;
       
  1024         }
       
  1025     }
       
  1026     
       
  1027 // Gets the time zone id associated with the cache. If caching is
       
  1028 // disabled then this returns 0.
       
  1029 // Returns the timezone id.
       
  1030 //
       
  1031 TUint16 RTz::CurrentCachedTzId()
       
  1032 	{
       
  1033 	if (iRulesHolder) 
       
  1034 	    {
       
  1035 	    return iRulesHolder->CurrentTzId();
       
  1036 	    }
       
  1037 	else
       
  1038 		{
       
  1039         return 0;
       
  1040         }
       
  1041 	} 
       
  1042 
       
  1043 
       
  1044 
       
  1045 /*********************************User Defined Time Zone Handling *****************/
       
  1046 
       
  1047 CTzId* RTz::CreateUserTimeZoneL(const CTzRules& aTzUserRules, const CTzUserNames& aTzUserNames)
       
  1048 	{
       
  1049 	TInt size = aTzUserNames.SizeOfObject() + aTzUserRules.SizeOfObject();
       
  1050 
       
  1051 	CBufFlat* inpBuffer = CBufFlat::NewL(size);
       
  1052 	CleanupStack::PushL(inpBuffer);
       
  1053 	inpBuffer->ExpandL(0, size);
       
  1054 
       
  1055 	RBufWriteStream writeStream;
       
  1056 	CleanupClosePushL(writeStream);
       
  1057 	writeStream.Open(*inpBuffer);
       
  1058 	aTzUserRules.ExternalizeL(writeStream);
       
  1059 	aTzUserNames.ExternalizeL(writeStream);
       
  1060 	writeStream.CommitL();
       
  1061 	
       
  1062 	TPtr8 ptrInp(inpBuffer->Ptr(0));
       
  1063 	TPckgBuf<TUint32> idBuffer;
       
  1064 	TIpcArgs args(size, &ptrInp, &idBuffer);
       
  1065 	User::LeaveIfError(SendReceive(CTzServer::ECreateUserTimeZone, args));
       
  1066 	CleanupStack::PopAndDestroy(2, inpBuffer);
       
  1067 	return CTzId::NewL(idBuffer());
       
  1068 	}
       
  1069 
       
  1070 CTzUserNames* RTz::GetUserTimeZoneNamesL(const CTzId& aTzId) const
       
  1071 	{
       
  1072 	TInt nameSize = 0;
       
  1073 	TPckg<TInt> nameSizeBuffer(nameSize);
       
  1074 
       
  1075 	TIpcArgs args(aTzId.TimeZoneNumericID(),&nameSizeBuffer);
       
  1076 	User::LeaveIfError(SendReceive(CTzServer::EGetUserTimeZoneNamesSize, args));
       
  1077 
       
  1078 	CBufFlat* retBuffer = CBufFlat::NewL(nameSize);
       
  1079 	CleanupStack::PushL(retBuffer);
       
  1080 	retBuffer->ExpandL(0, nameSize);
       
  1081 	TPtr8 outPtr(retBuffer->Ptr(0) );
       
  1082 	
       
  1083 	TIpcArgs args2(&outPtr);
       
  1084 	User::LeaveIfError(SendReceive(CTzServer::EGetUserTimeZoneNames, args2));
       
  1085 	
       
  1086 	RBufReadStream readStream;
       
  1087 	CleanupClosePushL(readStream);
       
  1088 	readStream.Open(*retBuffer);
       
  1089 	
       
  1090 	CTzUserNames* names = CTzUserNames::NewL(readStream);
       
  1091 	CleanupStack::PopAndDestroy(2, retBuffer); 
       
  1092 	return names;
       
  1093 	}
       
  1094 	
       
  1095 void RTz::UpdateUserTimeZoneL(const CTzId& aTzId, const CTzRules& aTzUserRules, const CTzUserNames& aTzUserNames)
       
  1096 	{
       
  1097 	TInt size = aTzUserNames.SizeOfObject() + aTzUserRules.SizeOfObject();
       
  1098 	
       
  1099 	CBufFlat* inpBuffer = CBufFlat::NewL(size);
       
  1100 	CleanupStack::PushL(inpBuffer);
       
  1101 	inpBuffer->ExpandL(0, size);
       
  1102 
       
  1103 	RBufWriteStream writeStream;
       
  1104 	CleanupClosePushL(writeStream);
       
  1105 	writeStream.Open(*inpBuffer);
       
  1106 	aTzUserRules.ExternalizeL(writeStream);
       
  1107 	aTzUserNames.ExternalizeL(writeStream);
       
  1108 	writeStream.CommitL();
       
  1109 	
       
  1110 	TPtr8 ptrInp(inpBuffer->Ptr(0) );
       
  1111 	TIpcArgs args(size, &ptrInp, aTzId.TimeZoneNumericID());
       
  1112 	TInt reply = SendReceive(CTzServer::EUpdateUserTimeZone, args);
       
  1113 	User::LeaveIfError(reply);
       
  1114 	CleanupStack::PopAndDestroy(2, inpBuffer);
       
  1115 	}
       
  1116 	
       
  1117 void RTz::DeleteUserTimeZoneL(const CTzId& aTzId)
       
  1118 	{
       
  1119 	TIpcArgs args(aTzId.TimeZoneNumericID());
       
  1120 	User::LeaveIfError(SendReceive(CTzServer::EDeleteUserTimeZone, args));
       
  1121 	}
       
  1122 	
       
  1123 void RTz::GetUserTimeZoneIdsL(RPointerArray<CTzId>& aTzIds) const
       
  1124 	{
       
  1125 	TInt idsSize = 0;
       
  1126 	TPckg<TInt> idsSizeBuffer(idsSize);
       
  1127 
       
  1128 	TIpcArgs args(&idsSizeBuffer);
       
  1129 	User::LeaveIfError(SendReceive(CTzServer::EGetUserTimeZoneIdsSize, args));
       
  1130 
       
  1131 	CBufFlat* retBuffer = CBufFlat::NewL(idsSize);
       
  1132 	CleanupStack::PushL(retBuffer);
       
  1133 	retBuffer->ExpandL(0, idsSize);
       
  1134 	TPtr8 outPtr(retBuffer->Ptr(0) );
       
  1135 	
       
  1136 	TIpcArgs args2(&outPtr);
       
  1137 	User::LeaveIfError(SendReceive(CTzServer::EGetUserTimeZoneIds, args2));
       
  1138 	
       
  1139 	RBufReadStream readStream;
       
  1140 	CleanupClosePushL(readStream);
       
  1141 	readStream.Open(*retBuffer);
       
  1142 	
       
  1143 	TInt count = readStream.ReadInt16L();
       
  1144 	aTzIds.ReserveL(aTzIds.Count()+ count);
       
  1145 	for (TInt ii=0; ii<count; ++ii)
       
  1146 		{
       
  1147 		TUint32 id = readStream.ReadUint32L();
       
  1148 		CTzId* zone = CTzId::NewL(id);
       
  1149 		aTzIds.AppendL(zone);
       
  1150 		}
       
  1151 	CleanupStack::PopAndDestroy(2, retBuffer);
       
  1152 	}
       
  1153 
       
  1154 
       
  1155 #if defined(_DEBUG)
       
  1156 
       
  1157 
       
  1158 /**
       
  1159 Clears timezone information cached at client side.
       
  1160 
       
  1161 @param aRestartCaching Set to ETrue if caching needs to be restarted after
       
  1162 clearing current cache.
       
  1163 
       
  1164 @internalTechnology
       
  1165 */
       
  1166 EXPORT_C void RTz::__dbgClearCacheL(TBool aRestartCaching)
       
  1167 	{
       
  1168 	delete iRulesHolder;
       
  1169 	iRulesHolder = NULL;
       
  1170 	
       
  1171 	if(aRestartCaching)
       
  1172 		{
       
  1173 		StartCachingL();
       
  1174 		}
       
  1175 	}
       
  1176 
       
  1177 
       
  1178 EXPORT_C TInt RTz::__dbgRequestAllocatedCellsL(TInt aHeapSizeInBytes)
       
  1179 	{
       
  1180 	TPckg<TInt> numCells(0);
       
  1181 	TPckg<TInt> sizeOfHeap(aHeapSizeInBytes);
       
  1182 	TIpcArgs args(&numCells, &sizeOfHeap);
       
  1183  	User::LeaveIfError(SendReceive(CTzServer::ESrvOpcodeResourceCount, args));
       
  1184  	return numCells();
       
  1185 	}
       
  1186 
       
  1187 
       
  1188 /**
       
  1189 Set heap allocation failure according the arguments, debug only.
       
  1190 
       
  1191 @param aType An enumeration which indicates how to simulate heap allocation
       
  1192 failure. 
       
  1193 
       
  1194 @param aRate The rate of failure.  When aType is RAllocator::EDeterministic
       
  1195 heap allocation fails every aRate attempt.
       
  1196 
       
  1197 @internalTechnology
       
  1198 */	
       
  1199 EXPORT_C void RTz::__dbgSetHeapFailL(RAllocator::TAllocFail aType, TInt aRate)
       
  1200 	{
       
  1201 	TIpcArgs args(aType, aRate);
       
  1202 	User::LeaveIfError(SendReceive(CTzServer::ESrvOpcodeSetHeapFailure, args));
       
  1203 	}
       
  1204 
       
  1205 	
       
  1206 EXPORT_C void RTz::__dbgResetHeapL()
       
  1207 	{
       
  1208 	User::LeaveIfError(SendReceive(CTzServer::ESrvOpcodeResetHeap));
       
  1209 	}
       
  1210 
       
  1211 	
       
  1212 #else
       
  1213 
       
  1214 
       
  1215 EXPORT_C void RTz::__dbgClearCacheL(TBool /*aRestartCaching*/)
       
  1216 	{
       
  1217 	// Do nothing.
       
  1218 	}
       
  1219 
       
  1220 
       
  1221 EXPORT_C TInt RTz::__dbgRequestAllocatedCellsL(TInt /*aHeapSizeInBytes*/)
       
  1222 	{
       
  1223 	return 0;
       
  1224 	}
       
  1225 
       
  1226 
       
  1227 EXPORT_C void RTz::__dbgSetHeapFailL(RAllocator::TAllocFail /*aType*/,
       
  1228 	TInt /*aRate*/)
       
  1229 	{
       
  1230 	// Do nothing.
       
  1231 	}
       
  1232 
       
  1233 
       
  1234 EXPORT_C void RTz::__dbgResetHeapL()
       
  1235 	{
       
  1236 	// Do nothing.
       
  1237 	}
       
  1238 
       
  1239 
       
  1240 #endif