commonappservices/alarmserver/Server/Source/ASSrvAlarmStore.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 "ASSrvAlarmStore.h"
       
    17 
       
    18 // User includes
       
    19 #include "ASSrvDefs.h"
       
    20 #include "ASSrvDataPool.h"
       
    21 #include "ASSrvAlarmQueue.h"
       
    22 #include "ASSrvStaticUtils.h"
       
    23 #include "ASSrvSoundSettings.h"
       
    24 #include "ASSrvServerWideData.h"
       
    25 #include "ASSrvAlarmQueue.h"
       
    26 
       
    27 // Type definitions
       
    28 #define UNUSED_VAR(a) a = a
       
    29 
       
    30 // Constants
       
    31 const TInt KDelayInMicrosecondsBetweenFileOperations = 2000000; // 2 seconds
       
    32 const TInt KDelayInMicrosecondsBetweenFileOperationsLongDelay = 10 * 60 * 1000000; // 10 minutes, allow user time to clear disk space?
       
    33 const TInt KNumberOfAttemptsAtExternalizingFile = 5; // 5 * 2 seconds => 10 seconds
       
    34 const TInt KDelayPeriodBeforeAttemptingAnExternalize = 1000; // 1 seconds
       
    35 
       
    36 // Enumerations
       
    37 
       
    38 // Definitions
       
    39 #define __START_WITH_RESTORED_QUEUE__
       
    40 
       
    41 // Classes referenced
       
    42 
       
    43 //#define VERBOSE_DEBUG
       
    44 
       
    45 #if defined(VERBOSE_DEBUG)
       
    46 #define DEBUG_PRINT1(A)			{ RDebug::Print(A); }
       
    47 #define DEBUG_PRINT2(A,B)		{ RDebug::Print(A,B); }
       
    48 #define DEBUG_PRINT3(A,B,C)		{ RDebug::Print(A,B,C); }
       
    49 #else
       
    50 #define DEBUG_PRINT1(A)
       
    51 #define DEBUG_PRINT2(A,B)
       
    52 #define DEBUG_PRINT3(A,B,C)
       
    53 #endif
       
    54 
       
    55 
       
    56 
       
    57 //
       
    58 // ----> CASSrvAlarmStore (source)
       
    59 //
       
    60 
       
    61 //*************************************************************************************
       
    62 CASSrvAlarmStore::CASSrvAlarmStore(CASSrvServerWideData& aServerWideData)
       
    63 :	CTimer(CActive::EPriorityIdle), iServerWideData(aServerWideData)
       
    64 	{
       
    65 	CActiveScheduler::Add(this);
       
    66 	}
       
    67 
       
    68 
       
    69 //*************************************************************************************
       
    70 CASSrvAlarmStore::~CASSrvAlarmStore()
       
    71 	{
       
    72 #ifndef __WINC__
       
    73 	delete iBackupNotification;	
       
    74 #endif
       
    75 
       
    76 	ServerWideData().Queue().NotificationPoolChangeCancel(*this);
       
    77 
       
    78 	DEBUG_PRINT1(_L("-- -- Alarm Store destructor"));
       
    79 
       
    80 	// is an externalize request still waiting?
       
    81 	if (iFlags.IsSet(ERequestExternalize))
       
    82 		{
       
    83 		Cancel();
       
    84 		// Flush current alarm queue
       
    85 		// (if this fails now there is nothing we can do about it)
       
    86 		Externalize();
       
    87 		}
       
    88 
       
    89 	// no longer interested in these events
       
    90 	ServerWideData().AnyEventManager().MASAnyEventManagerObserverRemove(*this);
       
    91 	}
       
    92 
       
    93 
       
    94 //*************************************************************************************
       
    95 void CASSrvAlarmStore::ConstructL()
       
    96 	{
       
    97 	CTimer::ConstructL();
       
    98 
       
    99 	DEBUG_PRINT1(_L("++ ++ Alarm Store ConstructL"));
       
   100 
       
   101 	TFileName name;
       
   102 	RFs& fsSession = ServerWideData().FsSession();
       
   103 	ASSrvStaticUtils::GetPrivateDirL(fsSession, name);
       
   104 
       
   105 	//Check INI file directory exists
       
   106 	TUint attribs;	//Not used dummy parameter
       
   107 	TInt error = fsSession.Att(name,attribs);
       
   108 	if (error == KErrNotFound || error == KErrPathNotFound)
       
   109 		{
       
   110 		error = fsSession.MkDirAll(name);
       
   111 		}
       
   112 	User::LeaveIfError(error);
       
   113 
       
   114 	ASSrvStaticUtils::GetServerPathL(fsSession, name);
       
   115 
       
   116 #ifndef __WINC__
       
   117 	iBackupNotification = CBackupRestoreNotification::NewL(name, *this);
       
   118 #endif
       
   119 
       
   120 	// Internalize any previously persisted data
       
   121 	error = Internalize(CASSrvAlarmQueue::EStoreInternalizeStartup);
       
   122 	if	(error != KErrNone)
       
   123 		{
       
   124 		error = fsSession.Delete(name);
       
   125 		if	(error != KErrNotFound)
       
   126 			User::LeaveIfError(error);
       
   127 		}
       
   128 
       
   129 	// Ready to watch for "Alarm Added" and other Alarm Queue events
       
   130 	ServerWideData().Queue().NotificationPoolChangeL(*this);
       
   131 
       
   132 	// Ready to watch for Alarm Sound Intervals changing
       
   133 	ServerWideData().AnyEventManager().MASAnyEventManagerObserverAddL(*this);
       
   134 	}
       
   135 
       
   136 
       
   137 //*************************************************************************************
       
   138 CASSrvAlarmStore* CASSrvAlarmStore::NewL(CASSrvServerWideData& aServerWideData)
       
   139 	{
       
   140 	CASSrvAlarmStore* self = new(ELeave) CASSrvAlarmStore(aServerWideData);
       
   141 	CleanupStack::PushL(self);
       
   142 	self->ConstructL();
       
   143 	CleanupStack::Pop(self);
       
   144 	return self;
       
   145 	}
       
   146 
       
   147 
       
   148 //
       
   149 //
       
   150 //
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 //*************************************************************************************
       
   156 /**
       
   157  * @see MASSrvAlarmQueueObserver
       
   158  */
       
   159 void CASSrvAlarmStore::MAlarmQueueObserverHandleEvent(TASSrvAlarmQueueEvent aEvent, TAlarmId /*aAlarmId*/)
       
   160 	{
       
   161 	switch(aEvent)
       
   162 		{
       
   163 	case EASSrvAlarmQueueEventHeadItemChanged:
       
   164 	case EASSrvAlarmQueueEventAlarmAdded:
       
   165 	case EASSrvAlarmQueueEventAlarmChanged:
       
   166 	case EASSrvAlarmQueueEventAlarmDeleted:
       
   167 		// RunL will Externalize all changes in 100ms
       
   168 		ScheduleExternalizeWithRetry(100);
       
   169 		break;
       
   170 
       
   171 	default:
       
   172 		break;
       
   173 		}
       
   174 	}
       
   175 
       
   176 
       
   177 //
       
   178 //
       
   179 //
       
   180 
       
   181 
       
   182 //*************************************************************************************
       
   183 /**
       
   184  * @see MASSrvAnyEventObserver
       
   185  *
       
   186  * Facade interface that notifies observer about event. No real processing done
       
   187  * by this object.
       
   188  */
       
   189 void CASSrvAlarmStore::MASSrvAnyEventHandleChange(TAlarmChangeEvent aEvent, TAlarmId /*aAlarmId*/)
       
   190 	{
       
   191 	switch(aEvent)
       
   192 		{
       
   193 	case EAlarmChangeEventPlayIntervalsChanged:
       
   194 		// The sound intervals associated with sound timing have changed.
       
   195 		// RunL will Externalize all changes in 100ms
       
   196 		ScheduleExternalizeWithRetry(100);
       
   197 		break;
       
   198 
       
   199 	default:
       
   200 		break;
       
   201 		}
       
   202 	}
       
   203 
       
   204 
       
   205 //
       
   206 //
       
   207 //
       
   208 
       
   209 
       
   210 //*************************************************************************************
       
   211 /**
       
   212  * Internalize (non-leaving) the contents of the Alarm Server backup
       
   213  * from the backup file.
       
   214  */
       
   215 TInt CASSrvAlarmStore::Internalize(CASSrvAlarmQueue::TStoreOperation aInternalizeOperation)
       
   216 	{
       
   217 	TInt error = KErrNone;
       
   218 
       
   219 	DEBUG_PRINT1(_L("> Alarm Store Internalize ()"));
       
   220 
       
   221 	// tell Alarm Queue what type of Internalize to perform
       
   222 	error = ServerWideData().Queue().StartAlarmStoreOperation(aInternalizeOperation);
       
   223 
       
   224 	if (!error)
       
   225 		{
       
   226 		// don't watch for change notifications during Internalize
       
   227 		iFlags.Set(EIsInternalizing);
       
   228 
       
   229 		TRAP(error, InternalizeL());
       
   230 
       
   231 		// tell alarm queue that Internalize is complete
       
   232 		ServerWideData().Queue().EndAlarmStoreOperation(error);
       
   233 
       
   234 		// Finished Internalize, Look for notifications again, etc...
       
   235 		iFlags.Clear(EIsInternalizing);
       
   236 		}
       
   237 
       
   238 	DEBUG_PRINT2(_L("< Alarm Store Internalize - error %i"), error);
       
   239 
       
   240 	return error;
       
   241 	}
       
   242 
       
   243 
       
   244 //*************************************************************************************
       
   245 /**
       
   246  * Internalize the contents of the Alarm Server backup
       
   247  * from the backup file.
       
   248  */
       
   249 void CASSrvAlarmStore::InternalizeL()
       
   250 	{
       
   251 	RStoreReadStream stream;
       
   252 	CDirectFileStore* store = OpenStoreLC(EFileRead);
       
   253 	CStreamDictionary* dictionary = OpenDictionaryLC(*store);
       
   254 
       
   255 	// Open the alarm queue stream & internalize
       
   256 #ifdef __START_WITH_RESTORED_QUEUE__
       
   257 	OpenStreamLC(*store, *dictionary, KAlarmStoreStreamUidQueue, stream);
       
   258 	stream >> ServerWideData().Queue();
       
   259 	CleanupStack::PopAndDestroy(&stream);
       
   260 
       
   261 	// Open the alarm data stream & internalize
       
   262 	OpenStreamLC(*store, *dictionary, KAlarmStoreStreamUidData, stream);
       
   263 	stream >> ServerWideData().DataPool();
       
   264 	CleanupStack::PopAndDestroy(&stream);
       
   265 #endif
       
   266 
       
   267 	// Open the sound settings stream & internalize
       
   268 	OpenStreamLC(*store, *dictionary, KAlarmStoreStreamUidSoundSettings, stream);
       
   269 	stream >> ServerWideData().SoundSettings();
       
   270 	CleanupStack::PopAndDestroy(&stream);
       
   271 
       
   272 #ifdef SYMBIAN_SKIPPED_CALENDAR_ALARMS
       
   273 	// Open the missed alarm data stream & internalize
       
   274 	OpenStreamLC(*store, *dictionary, KAlarmStoreStreamUidEnvironmentChangeData, stream);
       
   275 	ServerWideData().Queue().InternalizeLastAlarmedInstanceParamsL(stream);
       
   276 	CleanupStack::PopAndDestroy(&stream);
       
   277 #endif
       
   278 	
       
   279 	// Tidy up
       
   280 	CleanupStack::PopAndDestroy(2, store);
       
   281 	}
       
   282 	
       
   283 //*************************************************************************************
       
   284 /**
       
   285  * Externalize (non-leaving) the contents of the Alarm Server backup
       
   286  * to the backup file.
       
   287  */
       
   288 TInt CASSrvAlarmStore::ExternalizeIfRequested()
       
   289 	{
       
   290 	TInt error = KErrNone;
       
   291 
       
   292 	DEBUG_PRINT2(_L("= Alarm Store Externalize If Requested (%u)"), iFlags.IsSet(ERequestExternalize));
       
   293 
       
   294 	if (iFlags.IsSet(ERequestExternalize))
       
   295 		{
       
   296 		// Don't RunL
       
   297 		Cancel();
       
   298 
       
   299 		error = Externalize();
       
   300 		}
       
   301 
       
   302 	return error;
       
   303 	}
       
   304 
       
   305 
       
   306 //*************************************************************************************
       
   307 /**
       
   308  * Externalize (non-leaving) the contents of the Alarm Server backup
       
   309  * to the backup file.
       
   310  */
       
   311 TInt CASSrvAlarmStore::Externalize()
       
   312 	{
       
   313 	TInt error = KErrNone;
       
   314 	
       
   315 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   316 	if (!iServerWideData.ServerIsReadOnly())
       
   317 		{
       
   318 #endif
       
   319 		DEBUG_PRINT1(_L("> Alarm Store Externalize"));
       
   320 	
       
   321 		// tell Alarm Queue what type of Store operation we want to perform
       
   322 		error = ServerWideData().Queue().StartAlarmStoreOperation(CASSrvAlarmQueue::EStoreExternalize);
       
   323 	
       
   324 		if (!error)
       
   325 			{
       
   326 			TRAP(error, ExternalizeL());
       
   327 	
       
   328 			// tell alarm queue that Externalize is complete
       
   329 			ServerWideData().Queue().EndAlarmStoreOperation(error);
       
   330 			}
       
   331 	
       
   332 		DEBUG_PRINT2(_L("< Alarm Store Externalize - error %i"), error);
       
   333 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   334 		}
       
   335 #endif
       
   336 	
       
   337 	return error;
       
   338 	}
       
   339 
       
   340 
       
   341 //*************************************************************************************
       
   342 /**
       
   343  * Externalize the contents of the Alarm Server backup
       
   344  * to the backup file.
       
   345  */
       
   346 void CASSrvAlarmStore::ExternalizeL()
       
   347 	{
       
   348 	TStreamId streamId;
       
   349 	RStoreWriteStream stream;
       
   350 	CStreamDictionary* dictionary = CStreamDictionary::NewLC();
       
   351 
       
   352 	CDirectFileStore* store = OpenStoreLC(EFileWrite | EFileShareExclusive);
       
   353 
       
   354 	// Create the alarm queue stream & externalize
       
   355 	streamId = stream.CreateLC(*store);
       
   356 	stream << ServerWideData().Queue();
       
   357 	stream.CommitL();
       
   358 	CleanupStack::PopAndDestroy(&stream);
       
   359 	dictionary->AssignL(KAlarmStoreStreamUidQueue, streamId);
       
   360 
       
   361 	// Create the alarm data queue & externalize
       
   362 	streamId = stream.CreateLC(*store);
       
   363 	stream << ServerWideData().DataPool();
       
   364 	stream.CommitL();
       
   365 	CleanupStack::PopAndDestroy(&stream);
       
   366 	dictionary->AssignL(KAlarmStoreStreamUidData, streamId);
       
   367 
       
   368 	// Create the alarm data queue & externalize
       
   369 	streamId = stream.CreateLC(*store);
       
   370 	stream << ServerWideData().SoundSettings();
       
   371 	stream.CommitL();
       
   372 	CleanupStack::PopAndDestroy(&stream);
       
   373 	dictionary->AssignL(KAlarmStoreStreamUidSoundSettings, streamId);
       
   374 
       
   375 #ifdef SYMBIAN_SKIPPED_CALENDAR_ALARMS
       
   376 	// Create the missed alarm data stream & externalize
       
   377 	streamId = stream.CreateLC(*store);
       
   378 	ServerWideData().Queue().ExternalizeLastAlarmedInstanceParamsL(stream);
       
   379 	stream.CommitL();
       
   380 	CleanupStack::PopAndDestroy(&stream);
       
   381 	dictionary->AssignL(KAlarmStoreStreamUidEnvironmentChangeData, streamId);	
       
   382 #endif
       
   383 	
       
   384 	// Create root stream
       
   385 	streamId = stream.CreateLC(*store);
       
   386 	stream << *dictionary;
       
   387 	stream.CommitL();
       
   388 	CleanupStack::PopAndDestroy(&stream);
       
   389 	store->SetRootL(streamId);
       
   390 	store->CommitL();
       
   391 
       
   392 	// clear Externalize request flag now, so another can be requested
       
   393 	iFlags.Clear(ERequestExternalize);
       
   394 
       
   395 	// Tidy up
       
   396 	CleanupStack::PopAndDestroy(2, dictionary);
       
   397 	}
       
   398 
       
   399 
       
   400 //*************************************************************************************
       
   401 /**
       
   402  * Open the backup store (AlarmServer.ini) using the specified
       
   403  * file mode.
       
   404  *
       
   405  * @return A file store object which encapsulates the backup store.
       
   406  */
       
   407 CDirectFileStore* CASSrvAlarmStore::OpenStoreLC(TUint aMode) const
       
   408 	{
       
   409 	CDirectFileStore* store = OpenStoreL(aMode);
       
   410 
       
   411 	CleanupStack::PushL(store);
       
   412 	//
       
   413 	return store;
       
   414 	}
       
   415 
       
   416 
       
   417 /**
       
   418  * Open the backup store (AlarmServer.ini) using the specified
       
   419  * file mode.
       
   420  *
       
   421  * @return A file store object which encapsulates the backup store.
       
   422  */
       
   423 CDirectFileStore* CASSrvAlarmStore::OpenStoreL(TUint aMode) const
       
   424 	{
       
   425 	RFs& fsSession = ServerWideData().FsSession();
       
   426 	TFileName fileName;
       
   427 	ASSrvStaticUtils::GetServerPathL(fsSession, fileName);
       
   428 
       
   429 	CDirectFileStore* store = NULL;
       
   430 	TInt error = KErrNone;
       
   431 	//
       
   432 	if	(aMode == EFileRead)
       
   433 		{
       
   434 		// First try to open the store. If opening fails, then we
       
   435 		// replace the store with a blank one.
       
   436 		TRAP(error, store = CDirectFileStore::OpenL(fsSession, fileName, aMode));
       
   437 		}
       
   438 	//
       
   439 	if	(!store || error != KErrNone)
       
   440 		{
       
   441 		store = CDirectFileStore::ReplaceLC(fsSession, fileName, aMode);
       
   442 		//
       
   443 		const TUidType type(KDirectFileStoreLayoutUid, KAlarmStoreUid, KNullUid);
       
   444 		store->SetTypeL(type);
       
   445 		//
       
   446 		CleanupStack::Pop(store);
       
   447 		}
       
   448 	//
       
   449 	return store;
       
   450 	}
       
   451 
       
   452 
       
   453 //*************************************************************************************
       
   454 /**
       
   455  * Restore the root stream dictionary from the specified store
       
   456  *
       
   457  * @return A stream dictionary object on the cleanup stack
       
   458  */
       
   459 CStreamDictionary* CASSrvAlarmStore::OpenDictionaryLC(CPersistentStore& aStore) const
       
   460 	{
       
   461 	const TStreamId rootId = aStore.Root();
       
   462 	//
       
   463 	CStreamDictionary* dictionary = CStreamDictionary::NewLC();
       
   464 	RStoreReadStream stream;
       
   465 	stream.OpenLC(aStore, rootId);
       
   466 	stream >> *dictionary;
       
   467 	CleanupStack::PopAndDestroy(&stream);
       
   468 	//
       
   469 	return dictionary;
       
   470 	}
       
   471 
       
   472 
       
   473 //*************************************************************************************
       
   474 /**
       
   475  * Open the specified stream in the store
       
   476  */
       
   477 void CASSrvAlarmStore::OpenStreamLC(CPersistentStore& aStore, CStreamDictionary& aDictionary, TUid aStreamUid, RStoreReadStream& aStream) const
       
   478 	{
       
   479 	const TStreamId streamId = aDictionary.At(aStreamUid);
       
   480 	aStream.OpenLC(aStore, streamId);
       
   481 	}
       
   482 
       
   483 
       
   484 //*************************************************************************************
       
   485 /**
       
   486  * Retry a previously requested backup operation
       
   487  */
       
   488 void CASSrvAlarmStore::RetryStoreOperation()
       
   489 	{
       
   490 	if (iFlags.IsSet(ERequestExternalize) && !IsActive())
       
   491 		{
       
   492 		// can RunL now
       
   493 		After(0);
       
   494 		}
       
   495 	}
       
   496 
       
   497 
       
   498 //
       
   499 //
       
   500 //
       
   501 
       
   502 
       
   503 //*************************************************************************************
       
   504 /**
       
   505  * @see CActive
       
   506  */
       
   507 void CASSrvAlarmStore::RunL()
       
   508 	{
       
   509 	TInt error = iStatus.Int();
       
   510 
       
   511 	// operation isn't cancelled
       
   512 	if	(error == KErrNone)
       
   513 		{
       
   514 		// task : Externalize
       
   515 		if (iFlags.IsSet(ERequestExternalize))
       
   516 			{
       
   517 			// Try to Externalize
       
   518 			error = Externalize();
       
   519 
       
   520 			if (error < KErrNone)
       
   521 				{
       
   522 				++iNumberOfAttemptedRetries;
       
   523 
       
   524 				// check retries, and reschedule
       
   525 				if (iNumberOfAttemptedRetries == KNumberOfAttemptsAtExternalizingFile)
       
   526 					{
       
   527 					// Try one last time. Wait for 10 mins and then attempt operation again.
       
   528 					// After that, give up.
       
   529 					//
       
   530 					// Possible reasons for entering this state:
       
   531 					//
       
   532 					// Low disk space, low memory, corrupt file system, etc etc. Don't think
       
   533 					// its acceptable to panic - operation should be failed gracefully. 
       
   534 					After(KDelayInMicrosecondsBetweenFileOperationsLongDelay);
       
   535 					}
       
   536 				else if (iNumberOfAttemptedRetries < KNumberOfAttemptsAtExternalizingFile)
       
   537 					{
       
   538 					// Try again after the delay
       
   539 					After(KDelayInMicrosecondsBetweenFileOperations);
       
   540 					}
       
   541 				else
       
   542 					{
       
   543 					// Tried max number of times already. Give up.
       
   544 					iFlags.Clear(ERequestExternalize);
       
   545 					}
       
   546 				}
       
   547 
       
   548 			}
       
   549 		}
       
   550 	}
       
   551 
       
   552 
       
   553 //*************************************************************************************
       
   554 
       
   555 #ifndef __WINC__
       
   556 void CASSrvAlarmStore::ScheduleExternalizeWithRetry(TUint aTimeMS)
       
   557 #else
       
   558 void CASSrvAlarmStore::ScheduleExternalizeWithRetry(TUint /*aTimeMS*/)
       
   559 #endif
       
   560 	{
       
   561 	// make sure change isn't due to Internalize
       
   562 	if (iFlags.IsClear(EIsInternalizing))
       
   563 		{
       
   564 		DEBUG_PRINT2(_L("*** Schedule Externalize - IsActive() = %u"), IsActive());
       
   565 
       
   566 		iFlags.Set(ERequestExternalize);
       
   567 		iNumberOfAttemptedRetries = 0;
       
   568 
       
   569 #ifndef __WINC__
       
   570 		// set the time to RunL iff not already set to run
       
   571 		//   check that no Backup or Restore is in progress, 
       
   572 		if (!iBackupNotification->BackupInProgress() && 
       
   573 			!iBackupNotification->RestoreInProgress()&& !IsActive())
       
   574 			{
       
   575 			// schedule the actual Externalize 
       
   576 			After(aTimeMS * 1000);
       
   577 			}
       
   578 #endif
       
   579 		}
       
   580 	}
       
   581 
       
   582 
       
   583 //*************************************************************************************
       
   584 /**
       
   585  * @see CActive
       
   586  */
       
   587 TInt CASSrvAlarmStore::RunError(TInt /*aError*/)
       
   588 	{
       
   589 	return KErrNone;
       
   590 	}
       
   591 
       
   592 
       
   593 //*************************************************************************************
       
   594 #ifndef __WINC__
       
   595 
       
   596 /**
       
   597  * @see MBackupRestoreNotificationObserver
       
   598  */
       
   599 
       
   600 void CASSrvAlarmStore::BackupBeginningL()
       
   601 	{
       
   602 	DEBUG_PRINT1(_L("-> Alarm Store => Backup Beginning"));
       
   603 	StartOfBackupOrRestoreL(CASSrvAlarmQueue::EStoreBackup);
       
   604 	}
       
   605 
       
   606 void CASSrvAlarmStore::BackupCompletedL()
       
   607 	{
       
   608 	// End of Backup
       
   609 	DEBUG_PRINT1(_L("-> Alarm Store => Backup Ended"));
       
   610 
       
   611 	// Backup server was reading from the alarm file so
       
   612 	// tell alarm queue that Backup is complete
       
   613 	ServerWideData().Queue().EndAlarmStoreOperation(KErrNone);
       
   614 
       
   615 	// In case Store has been waiting for backup to finish. Now
       
   616 	// attempt to perform deferred operation.
       
   617 	RetryStoreOperation();
       
   618 	}
       
   619 
       
   620 void CASSrvAlarmStore::RestoreBeginningL()
       
   621 	{
       
   622 	// Restore is starting
       
   623 	DEBUG_PRINT1(_L("-> Alarm Store => Restore Beginning"));
       
   624 	StartOfBackupOrRestoreL(CASSrvAlarmQueue::EStoreRestore);
       
   625 }
       
   626 
       
   627 void CASSrvAlarmStore::RestoreCompletedL(TInt aRestoreResult)
       
   628 	{
       
   629 	DEBUG_PRINT1(_L("-> Alarm Store => Restore Ended"));
       
   630 
       
   631 	// If the Backup server successfully wrote to the alarm file, then we should 
       
   632 	// read its contents and restore all alarm data based upon it.
       
   633 	if (aRestoreResult == KErrNone)
       
   634 		{
       
   635 		DEBUG_PRINT1(_L("-- End of Restore ... EEnd"));
       
   636 		// Any error during Internalize must be pretty severe so catch it and leave.
       
   637 		// NB Internalize calls ServerWideData().Queue().EndAlarmStoreOperation();
       
   638 		User::LeaveIfError(Internalize(CASSrvAlarmQueue::EStoreInternalizeRestore));
       
   639 		}
       
   640 	else
       
   641 		{
       
   642 		DEBUG_PRINT1(_L("-- end of Restore ... EAbort"));
       
   643 	
       
   644         ServerWideData().Queue().EndAlarmStoreOperation(KErrGeneral);
       
   645         
       
   646 		// we don't know what state the AlarmServer.Ini file is in
       
   647 		// so want an Externalize() to happen soon
       
   648 		ScheduleExternalizeWithRetry(KDelayPeriodBeforeAttemptingAnExternalize);
       
   649 		}
       
   650 	}
       
   651 
       
   652 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   653 void CASSrvAlarmStore::MHandleSystemStateChange(TState aState)
       
   654 	{
       
   655 	if (aState == EShutdown)
       
   656 		{
       
   657 		ExternalizeIfRequested();
       
   658 		}
       
   659 	}
       
   660 #endif
       
   661 
       
   662 void CASSrvAlarmStore::StartOfBackupOrRestoreL(CASSrvAlarmQueue::TStoreOperation aStoreOperation)
       
   663 	{
       
   664 	// Flush any 'scheduled' Externalize before Restore
       
   665 	ExternalizeIfRequested();
       
   666 
       
   667 	// tell Alarm Queue what type of Store is wanted
       
   668 	User::LeaveIfError(ServerWideData().Queue().StartAlarmStoreOperation(aStoreOperation));
       
   669 	}
       
   670 #endif // #ifndef __WINC__