commonappservices/alarmserver/Server/Source/ASSrvSessionEngine.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 "ASSrvSessionEngine.h"
       
    17 
       
    18 // System includes
       
    19 
       
    20 // User includes
       
    21 #include "ASSrvAlarmStore.h"
       
    22 #include "ASSrvAlarmQueue.h"
       
    23 #include "ASSrvStaticUtils.h"
       
    24 #include "ASSrvServerWideData.h"
       
    25 #include "ASSrvAnyEventManager.h"
       
    26 #include "ASSrvIteratorByState.h"
       
    27 #include "ASSrvIteratorByStatus.h"
       
    28 #include "ASSrvSessionCollection.h"
       
    29 #include "ASSrvIteratorByCategory.h"
       
    30 #include "ASSrvIteratorBySessionId.h"
       
    31 
       
    32 // Type definitions
       
    33 
       
    34 // Constants
       
    35 const TAlarmCategory KCalendarCategeory = {0x101F4A70};
       
    36 
       
    37 // Enumerations
       
    38 
       
    39 // Classes referenced
       
    40 
       
    41 
       
    42 //
       
    43 // ----> CASSrvSessionEngine (source)
       
    44 //
       
    45 
       
    46 //*************************************************************************************
       
    47 CASSrvSessionEngine::CASSrvSessionEngine(CASSrvServerWideData& aServerWideData, MASSrvAnyEventObserver& aChangeObserver, MASSrvSession& aSession)
       
    48 :	iServerWideData(aServerWideData), iChangeObserver(aChangeObserver), iSession(aSession)
       
    49 	{
       
    50 	}
       
    51 
       
    52 
       
    53 //*************************************************************************************
       
    54 CASSrvSessionEngine::~CASSrvSessionEngine()
       
    55 	{
       
    56 	ServerData().SessionCollection().MASSessionCollectionDetach(*this);
       
    57 	ServerData().AnyEventManager().MASAnyEventManagerObserverRemove(*this);
       
    58 	}
       
    59 
       
    60 
       
    61 //*************************************************************************************
       
    62 void CASSrvSessionEngine::ConstructL()
       
    63 	{
       
    64 	ServerData().AnyEventManager().MASAnyEventManagerObserverAddL(*this);
       
    65 	iSessionId = ServerData().SessionCollection().MASSessionCollectionAttachL(*this);
       
    66 	}
       
    67 
       
    68 
       
    69 //*************************************************************************************
       
    70 CASSrvSessionEngine* CASSrvSessionEngine::NewL(CASSrvServerWideData& aServerWideData, MASSrvAnyEventObserver& aChangeObserver, MASSrvSession& aSession)
       
    71 	{
       
    72 	CASSrvSessionEngine* self = new(ELeave) CASSrvSessionEngine(aServerWideData, aChangeObserver, aSession);
       
    73 	CleanupStack::PushL(self);
       
    74 	self->ConstructL();
       
    75 	CleanupStack::Pop(self);
       
    76 	return self;
       
    77 	}
       
    78 
       
    79 
       
    80 //
       
    81 //
       
    82 //
       
    83 
       
    84 
       
    85 //*************************************************************************************
       
    86 /**
       
    87  * @see MASSrvAnyEventObserver
       
    88  *
       
    89  * Facade interface that notifies observer about event. No real processing done
       
    90  * by this object.
       
    91  */
       
    92 void CASSrvSessionEngine::MASSrvAnyEventHandleChange(TAlarmChangeEvent aEvent, TAlarmId aAlarmId)
       
    93 	{
       
    94 	iChangeObserver.MASSrvAnyEventHandleChange(aEvent, aAlarmId);
       
    95 	}
       
    96 
       
    97 
       
    98 //
       
    99 //
       
   100 //
       
   101 
       
   102 
       
   103 //*************************************************************************************
       
   104 /**
       
   105  * @see MASSrvSession
       
   106  *
       
   107  * Facade to the real session
       
   108  */
       
   109 TASSrvSessionId CASSrvSessionEngine::MASSrvSessionId() const
       
   110 	{
       
   111 	return iSessionId;
       
   112 	}
       
   113 
       
   114 
       
   115 //*************************************************************************************
       
   116 /**
       
   117  * @see MASSrvSession
       
   118  *
       
   119  * Facade to the real session
       
   120  */
       
   121 void CASSrvSessionEngine::MASSrvSessionFullName(TDes& aDes) const
       
   122 	{
       
   123 	iSession.MASSrvSessionFullName(aDes);
       
   124 	}
       
   125 
       
   126 
       
   127 //
       
   128 //
       
   129 //
       
   130 
       
   131 
       
   132 //*************************************************************************************
       
   133 /**
       
   134  * Add an alarm to the alarm server
       
   135  */
       
   136 void CASSrvSessionEngine::AlarmAddL(TASSrvAlarm& aAlarm, TAlarmId aSpecificAlarmId)
       
   137 	{
       
   138 	// Must clear this - all alarms will have their Id's allocated later
       
   139 	aAlarm.Id() = KNullAlarmId;	
       
   140 	
       
   141 	// clear associateddata, session and state flags
       
   142 	aAlarm.ClearFlags();
       
   143 
       
   144 	// Check the alarm
       
   145 	const TInt error = ASSrvStaticUtils::ValidateAlarm(aAlarm);
       
   146 	User::LeaveIfError(error);
       
   147 
       
   148 	// Assign session id
       
   149 	aAlarm.SetOriginatingSessionId(MASSrvSessionId());
       
   150 
       
   151 	// Reset alarm state
       
   152 	aAlarm.SetState(EAlarmStateInPreparation);
       
   153 
       
   154 	// Add the alarm to the queue. This will update the timer if this
       
   155 	// new alarm is now the next alarm.
       
   156 	ServerData().Queue().QueueAlarmAndAllocateIdL(aAlarm, aSpecificAlarmId);
       
   157 	}
       
   158 
       
   159 
       
   160 //*************************************************************************************
       
   161 /**
       
   162  * Return information about an alarm
       
   163  */
       
   164 void CASSrvSessionEngine::AlarmDetailsL(TAlarmId aAlarmId, TASSrvAlarm& aAlarm) const
       
   165 	{
       
   166 	// Fetch the alarm details if the specified alarm exists.
       
   167 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, aAlarm));
       
   168 	}
       
   169 
       
   170 
       
   171 //*************************************************************************************
       
   172 /**
       
   173  * Delete an alarm from the alarm server
       
   174  */
       
   175 void CASSrvSessionEngine::AlarmDeleteL(TAlarmId aAlarmId)
       
   176 	{
       
   177 	TASSrvAlarm alarm(ServerData());
       
   178 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   179 
       
   180 	// If the alarm has a notification request outstanding against
       
   181 	// it, then we don't allow it to be deleted (the only way of
       
   182 	// removing the alarm is by cancelling the session notification).
       
   183 	if	(alarm.HasNotificationRequestPending())
       
   184 		User::Leave(KErrAccessDenied);
       
   185 	ServerData().Queue().DeQueueAlarm(alarm);
       
   186 	}
       
   187 
       
   188 
       
   189 //*************************************************************************************
       
   190 /**
       
   191  * Return the category of a given alarm
       
   192  */
       
   193 TAlarmCategory CASSrvSessionEngine::AlarmCategoryL(TAlarmId aAlarmId) const
       
   194 	{
       
   195 	TASSrvAlarm alarm(ServerData());
       
   196 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   197 	return alarm.Category();
       
   198 	}
       
   199 
       
   200 
       
   201 //*************************************************************************************
       
   202 /**
       
   203  * Set the status of an alarm
       
   204  */
       
   205 void CASSrvSessionEngine::SetAlarmStatusL(TAlarmId aAlarmId, TAlarmStatus aStatus)
       
   206 	{
       
   207 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   208 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   209 	User::LeaveIfError(alarm.SetStatus(aStatus));
       
   210 	}
       
   211 
       
   212 //*************************************************************************************
       
   213 
       
   214 void CASSrvSessionEngine::SetAlarmStatusForCalendarFileL(const TDesC& aCalendarFileName, TAlarmStatus aStatus)
       
   215     {
       
   216     CASSrvAlarmQueue& queue = ServerData().Queue();
       
   217     
       
   218     RArray<TAlarmId>* calendarAlarmIds = AlarmIdListByCategoryLC(KCalendarCategeory);
       
   219     const TInt KCalendarAlarmCount(calendarAlarmIds->Count());
       
   220     
       
   221     for (TInt i(0) ; i < KCalendarAlarmCount ; ++i)
       
   222         {
       
   223         TASSrvAlarm* alarm = queue.QueueAlarmById((*calendarAlarmIds)[i]);
       
   224                 
       
   225         const TAgnAlarmInfo* alarmInfo = reinterpret_cast<const TAgnAlarmInfo*>(alarm->DataL().Ptr());
       
   226         TBool correctFile = (alarmInfo->iFileName.CompareF(aCalendarFileName) == 0);
       
   227         if(correctFile)
       
   228             {
       
   229             alarm->SetStatus(aStatus);
       
   230             }
       
   231         }
       
   232      CleanupStack::PopAndDestroy(calendarAlarmIds);
       
   233      // coverity[leaked_storage]
       
   234     }
       
   235 
       
   236 //*************************************************************************************
       
   237 /**
       
   238  * Return the status of a given alarm
       
   239  */
       
   240 TAlarmStatus CASSrvSessionEngine::AlarmStatusL(TAlarmId aAlarmId) const
       
   241 	{
       
   242 	TASSrvAlarm alarm(ServerData());
       
   243 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   244 	return alarm.Status();
       
   245 	}
       
   246 
       
   247 
       
   248 //*************************************************************************************
       
   249 /**
       
   250  * Set the day/timed status of an alarm
       
   251  */
       
   252 void CASSrvSessionEngine::SetAlarmDayOrTimedL(TAlarmId aAlarmId, TAlarmDayOrTimed aDayOrTimed)
       
   253 	{
       
   254 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   255 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   256 	alarm.DayOrTimed() = aDayOrTimed;
       
   257 	}
       
   258 
       
   259 
       
   260 //*************************************************************************************
       
   261 /**
       
   262  * Return the day/timed status of a given alarm
       
   263  */
       
   264 TAlarmDayOrTimed CASSrvSessionEngine::AlarmDayOrTimedL(TAlarmId aAlarmId) const
       
   265 	{
       
   266 	TASSrvAlarm alarm(ServerData());
       
   267 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   268 	return alarm.DayOrTimed();
       
   269 	}
       
   270 
       
   271 
       
   272 //*************************************************************************************
       
   273 /**
       
   274  * Set the characteristics of an alarm
       
   275  */
       
   276 void CASSrvSessionEngine::SetAlarmCharacteristicsL(TAlarmId aAlarmId, TAlarmCharacteristicsFlags aCharacteristics)
       
   277 	{
       
   278 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   279 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   280 	alarm.SetCharacteristicsL(aCharacteristics, MASSrvSessionId());
       
   281 	}
       
   282 
       
   283 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   284 void CASSrvSessionEngine::SetWakeupL(TAlarmId aAlarmId, TBool aEnable)
       
   285 	{
       
   286 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   287 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   288 	alarm.SetWakeupAndNotifyQueueL(aEnable);
       
   289 	}
       
   290 #endif
       
   291 
       
   292 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
   293 void CASSrvSessionEngine::SetAlarmDaysL(TAlarmId aAlarmId, TUint8 aAlarmDays)
       
   294 	{
       
   295 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   296 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   297 	alarm.SetAlarmDaysL(aAlarmDays);
       
   298 	}
       
   299 
       
   300 TUint8 CASSrvSessionEngine::AlarmDaysL(TAlarmId aAlarmId) const
       
   301 	{
       
   302 	TASSrvAlarm alarm(ServerData());
       
   303 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   304 	return alarm.AlarmDays();
       
   305 	}
       
   306 
       
   307 void CASSrvSessionEngine::SetContinuousL(TAlarmId aAlarmId, TBool aContinuous)
       
   308 	{
       
   309 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   310 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   311 	alarm.SetContinuous(aContinuous);
       
   312 	}
       
   313 
       
   314 TBool CASSrvSessionEngine::ContinuousL(TAlarmId aAlarmId) const
       
   315 	{
       
   316 	TASSrvAlarm alarm(ServerData());
       
   317 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   318 	return alarm.Continuous();
       
   319 	}
       
   320 
       
   321 #endif
       
   322 
       
   323 void CASSrvSessionEngine::SetAlarmOrphanedL(TAlarmId aAlarmId)
       
   324 	{
       
   325 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   326 	TASSrvAlarm& alarm = queue.QueueAlarmByIdL(aAlarmId);
       
   327 	alarm.SetAlarmOrphaned();
       
   328 	}
       
   329 
       
   330 
       
   331 //*************************************************************************************
       
   332 /**
       
   333  * Return the characteristics of an alarm
       
   334  */
       
   335 TAlarmCharacteristicsFlags CASSrvSessionEngine::AlarmCharacteristicsL(TAlarmId aAlarmId) const
       
   336 	{
       
   337 	TASSrvAlarm alarm(ServerData());
       
   338 	User::LeaveIfError(ServerData().Queue().QueueAlarmById(aAlarmId, alarm));
       
   339 	return alarm.Characteristics();
       
   340 	}
       
   341 
       
   342 
       
   343 //
       
   344 //
       
   345 //
       
   346 
       
   347 //*************************************************************************************
       
   348 void CASSrvSessionEngine::AlarmDataAttachL(TAlarmId aAlarmId, HBufC8* aData)
       
   349 	{
       
   350 	// Give ownership of the data to the alarm. This will leave with 
       
   351 	// KErrInUse should the specified alarm already have attached data.
       
   352 	TASSrvAlarm& alarm = ServerData().Queue().QueueAlarmByIdL(aAlarmId);
       
   353 	alarm.DataAttachL(aData);
       
   354 	}
       
   355 
       
   356 
       
   357 //*************************************************************************************
       
   358 void CASSrvSessionEngine::AlarmDataDetachL(TAlarmId aAlarmId)
       
   359 	{
       
   360 	// Remove the data from the pool - if the specified alarm doesn't exist
       
   361 	// within the data pool, then this will leave with KErrNotFound.
       
   362 	TASSrvAlarm& alarm = ServerData().Queue().QueueAlarmByIdL(aAlarmId);
       
   363 	alarm.DataDetachL();	
       
   364 	}
       
   365 
       
   366 
       
   367 
       
   368 //*************************************************************************************
       
   369 /**
       
   370  * Change all alarms of a given category to have the specified status
       
   371  */
       
   372 void CASSrvSessionEngine::SetAlarmStatusByCategoryL(TAlarmCategory aCategory, TAlarmStatus aStatus)
       
   373 	{
       
   374 	//
       
   375 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   376 	RASSrvIteratorByCategory iterator(queue, aCategory);
       
   377 	iterator.Open();
       
   378 	//
       
   379 	while(iterator.NextAlarmAvailable())
       
   380 		{
       
   381 		TASSrvAlarm* alarm = queue.QueueAlarmById(iterator.NextAlarm().Id());
       
   382 		User::LeaveIfError(alarm->SetStatus(aStatus));
       
   383 		}
       
   384 	}
       
   385 
       
   386 
       
   387 //*************************************************************************************
       
   388 /**
       
   389  * Return the number of alarms within the alarm server queue that
       
   390  * have the specified category identifier.
       
   391  */
       
   392 TInt CASSrvSessionEngine::AlarmCountByCategory(TAlarmCategory aCategory) const
       
   393 	{
       
   394 	TInt count = 0;
       
   395 	//
       
   396 	RASSrvIteratorByCategory iterator(ServerData().Queue(), aCategory);
       
   397 	iterator.Open();
       
   398 	//
       
   399 	while(iterator.NextAlarmAvailable())
       
   400 		{
       
   401 		iterator.NextAlarm();
       
   402 		++count;
       
   403 		}
       
   404 	return count;
       
   405 	}
       
   406 
       
   407 
       
   408 //*************************************************************************************
       
   409 /**
       
   410  * Return the number of alarms within the alarm server that 
       
   411  * have the specified state.
       
   412  */
       
   413 TInt CASSrvSessionEngine::AlarmCountByState(TAlarmState aState) const
       
   414 	{
       
   415 	TInt count = 0;
       
   416 	//
       
   417 	RASSrvIteratorByState iterator(ServerData().Queue(), aState);
       
   418 	iterator.Open();
       
   419 	//
       
   420 	while(iterator.NextAlarmAvailable())
       
   421 		{
       
   422 		iterator.NextAlarm();
       
   423 		++count;
       
   424 		}
       
   425 	return count;
       
   426 	}
       
   427 
       
   428 
       
   429 //*************************************************************************************
       
   430 /**
       
   431  * Delete all of the alarms within the alarm server queue which
       
   432  * match that of the specified category and alarm's state
       
   433  */
       
   434 void CASSrvSessionEngine::DeleteAllAlarmsByCategoryL(TAlarmCategory aCategory, TBool aRestrictToOrphanedAlarms, TDeleteType aWhatToDelete)
       
   435  	{
       
   436 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   437 	RArray<TAlarmId>* alarmToDeleteIds = AlarmIdListByCategoryLC(aCategory);
       
   438 	TInt count = alarmToDeleteIds->Count();
       
   439 	//
       
   440 	for (TInt i=0; i<count; ++i)
       
   441 		{
       
   442 		const TASSrvAlarm* alarm = queue.QueueAlarmById((*alarmToDeleteIds)[i]);
       
   443 		const TBool isOrphanedAndDeletable = aRestrictToOrphanedAlarms && alarm->HasBecomeOrphaned();
       
   444 		TBool toDelete=EFalse;
       
   445 		if (!aRestrictToOrphanedAlarms || isOrphanedAndDeletable)
       
   446 			{
       
   447 			if(!aWhatToDelete)
       
   448 				toDelete=ETrue;
       
   449 			else
       
   450 				{
       
   451 				switch (alarm->State())
       
   452 					{
       
   453 					case EAlarmStateInPreparation:
       
   454 						{
       
   455 						toDelete=ETrue;
       
   456 						break;
       
   457 						}
       
   458 
       
   459 					case EAlarmStateQueued:
       
   460 						{
       
   461 						if (aWhatToDelete&EFuture)
       
   462 							{
       
   463 							toDelete=ETrue;
       
   464 							}
       
   465 						break;
       
   466 						}
       
   467 					case EAlarmStateNotified:
       
   468 						{
       
   469 						if (aWhatToDelete&EExpired)
       
   470 							{
       
   471 							toDelete=ETrue;
       
   472 							}
       
   473 						break;
       
   474 						}
       
   475 
       
   476 					case EAlarmStateSnoozed:
       
   477 					case EAlarmStateWaitingToNotify:
       
   478 					case EAlarmStateNotifying:
       
   479 						{
       
   480 						if (aWhatToDelete&EActive)
       
   481 							{
       
   482 							toDelete=ETrue;
       
   483 							}
       
   484 						break;
       
   485 						}
       
   486 
       
   487 					default:
       
   488 						__ASSERT_DEBUG(EFalse, ASSrvStaticUtils::Fault(ASSrvStaticUtils::EASSrvFaultAlarmStateNotHandled));
       
   489 					break;
       
   490 					}
       
   491 				}
       
   492 			 if (toDelete)
       
   493 				{
       
   494 				queue.DeQueueAlarm(*alarm);
       
   495 				}
       
   496 			}
       
   497 		}
       
   498 	alarmToDeleteIds->Close();
       
   499 	CleanupStack::PopAndDestroy(alarmToDeleteIds);
       
   500 	// coverity [leaked_storage]
       
   501 	}
       
   502 
       
   503 //*************************************************************************************
       
   504 /**
       
   505  * Delete all of the alarms within the alarm server queue which
       
   506  * match that of the specified calendar file name and alarm's state
       
   507  */
       
   508 void CASSrvSessionEngine::DeleteAllAlarmsByCalendarFileL(const TDesC& aCalendarFileName, TDeleteType aWhatToDelete)
       
   509     {
       
   510     RDebug::Print(_L("CASSrvSessionEngine::DeleteAllAlarmsByCalendarFileL"));
       
   511     
       
   512     CASSrvAlarmQueue& queue = ServerData().Queue();
       
   513     RArray<TAlarmId>* calendarAlarmIds = AlarmIdListByCategoryLC(KCalendarCategeory);
       
   514     const TInt KCalendarAlarmCount(calendarAlarmIds->Count());
       
   515     
       
   516     for (TInt i(0) ; i < KCalendarAlarmCount ; ++i)
       
   517         {
       
   518         const TASSrvAlarm* alarm = queue.QueueAlarmById((*calendarAlarmIds)[i]);
       
   519         TBool correctDeleteType(ETrue);
       
   520         
       
   521         const TAgnAlarmInfo* alarmInfo = reinterpret_cast<const TAgnAlarmInfo*>(alarm->DataL().Ptr());
       
   522         TBool correctFile = (alarmInfo->iFileName.CompareF(aCalendarFileName) == 0);
       
   523                 
       
   524         if (aWhatToDelete && correctFile)
       
   525             {
       
   526             switch (alarm->State())
       
   527                 {
       
   528                 case EAlarmStateInPreparation:
       
   529                     {
       
   530                     correctDeleteType = ETrue;
       
   531                     break;
       
   532                     }
       
   533                 case EAlarmStateQueued:
       
   534                     {
       
   535                     correctDeleteType = aWhatToDelete & EFuture;
       
   536                     break;
       
   537                     }
       
   538                 case EAlarmStateNotified:
       
   539                     {
       
   540                     correctDeleteType = aWhatToDelete & EExpired;
       
   541                     break;
       
   542                     }
       
   543                 case EAlarmStateSnoozed:
       
   544                 case EAlarmStateWaitingToNotify:
       
   545                 case EAlarmStateNotifying:
       
   546                     {
       
   547                     correctDeleteType = aWhatToDelete & EActive;
       
   548                     break;
       
   549                     }
       
   550                 default:
       
   551                     {
       
   552                     __ASSERT_DEBUG(EFalse, ASSrvStaticUtils::Fault(ASSrvStaticUtils::EASSrvFaultAlarmStateNotHandled));
       
   553                     }
       
   554                     break;
       
   555                 }
       
   556             }
       
   557         
       
   558          if (correctDeleteType && correctFile)
       
   559             {
       
   560             queue.DeQueueAlarm(*alarm);
       
   561             }
       
   562         }
       
   563     
       
   564     calendarAlarmIds->Close();
       
   565     CleanupStack::PopAndDestroy(calendarAlarmIds);
       
   566     // coverity [leaked_storage]
       
   567     }
       
   568 
       
   569 
       
   570 
       
   571 //*************************************************************************************
       
   572 /**
       
   573  * Return a list of all alarm categories currently in use within
       
   574  * the alarm server queue.
       
   575  */
       
   576 RArray<TAlarmCategory>* CASSrvSessionEngine::AlarmCategoryListLC() const
       
   577 	{
       
   578 	TLinearOrder<TAlarmCategory> order(ASSrvStaticUtils::CompareCategories);
       
   579 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   580 	//
       
   581 	RArray<TAlarmCategory>* list = new(ELeave) RArray<TAlarmCategory>(4);
       
   582 	CleanupStack::PushL(TCleanupItem(ASSrvStaticUtils::CleanupCloseDeleteCategoryArray, list));
       
   583 	//
       
   584 	const TInt count = queue.QueueAlarmCount();
       
   585 	for(TInt i=0; i<count; i++)
       
   586 		{
       
   587 		// Is this category already present in the list?
       
   588 		const TAlarmCategory category(queue.QueueAlarmAt(i).Category());
       
   589 		if	(list->FindInOrder(category, order) == KErrNotFound)
       
   590 			{
       
   591 			// Add this category to the list
       
   592 			User::LeaveIfError(list->InsertInOrder(category, order));
       
   593 			}
       
   594 		}
       
   595 	//
       
   596 	return list;
       
   597 	}
       
   598 
       
   599 
       
   600 //*************************************************************************************
       
   601 /**
       
   602  * Return a list of alarm ids for a given category
       
   603  */
       
   604 RArray<TAlarmId>* CASSrvSessionEngine::AlarmIdListByCategoryLC(TAlarmCategory aCategory) const
       
   605 	{
       
   606 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   607 	RASSrvIteratorByCategory iterator(queue, aCategory);
       
   608 	iterator.Open();
       
   609 	//coverity[return_alloc_fn]
       
   610 	return AlarmIdListFromIteratorLC(iterator);
       
   611 	}
       
   612 
       
   613 
       
   614 //*************************************************************************************
       
   615 /**
       
   616  * Return a list of alarm ids for a given alarm state
       
   617  */
       
   618 RArray<TAlarmId>* CASSrvSessionEngine::AlarmIdListByStateLC(TAlarmState aState) const
       
   619 	{
       
   620 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   621 	RASSrvIteratorByState iterator(queue, aState);
       
   622 	iterator.Open();
       
   623 	//
       
   624 	return AlarmIdListFromIteratorLC(iterator);
       
   625 	}
       
   626 
       
   627 
       
   628 //*************************************************************************************
       
   629 /**
       
   630  * Return all alarm ids currently used within the alarm server
       
   631  * queue.
       
   632  */
       
   633 RArray<TAlarmId>* CASSrvSessionEngine::AlarmIdListLC() const
       
   634 	{
       
   635 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   636 	RASSrvIteratorBase iterator(queue);
       
   637 	iterator.Open();
       
   638 	//
       
   639 	return AlarmIdListFromIteratorLC(iterator);
       
   640 	}
       
   641 
       
   642 
       
   643 //*************************************************************************************
       
   644 /**
       
   645  * Return the number of active alarms, that is, enabled, queued or snoozed 
       
   646  * alarms
       
   647  */
       
   648 TInt CASSrvSessionEngine::NumberOfActiveAlarmsInQueue() const
       
   649 	{
       
   650 	CASSrvAlarmQueue& queue = ServerData().Queue();
       
   651 	//
       
   652 	RASSrvIteratorByStatus status(queue, EAlarmStatusEnabled);
       
   653 	status.Open();
       
   654 	//
       
   655 	RASSrvIteratorByState state(queue, EAlarmStateQueued, EAlarmStateSnoozed);
       
   656 	status.IteratorAttach(state);
       
   657 	//
       
   658 	TInt count = 0;
       
   659 	while(status.NextAlarmAvailable())
       
   660 		{
       
   661 		++count;
       
   662 		status.NextAlarm();
       
   663 		}
       
   664 	return count;
       
   665 	}
       
   666 
       
   667 
       
   668 //
       
   669 //
       
   670 //
       
   671 
       
   672 
       
   673 //*************************************************************************************
       
   674 /**
       
   675  * Return a list of alarm ids which is generated by navigating the specified iterator
       
   676  */
       
   677 RArray<TAlarmId>* CASSrvSessionEngine::AlarmIdListFromIteratorLC(RASSrvIteratorBase& aIterator) const
       
   678 	{
       
   679 	RArray<TAlarmId>* list = new(ELeave) RArray<TAlarmId>(4);
       
   680 	CleanupStack::PushL(TCleanupItem(ASSrvStaticUtils::CleanupCloseDeleteAlarmIdArray, list));
       
   681 	//
       
   682 	while(aIterator.NextAlarmAvailable())
       
   683 		{
       
   684 		const TASShdAlarm& alarm = aIterator.NextAlarm();
       
   685 		list->AppendL(alarm.Id());
       
   686 		}
       
   687 	//
       
   688 	return list;
       
   689 	}
       
   690 
       
   691