commonappservices/alarmservertest/TestMultipleAlarmsSuite/src/DummyAlarmControl.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-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 // Contains implementation of CDummyAlarmControl class 
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 // User Includes
       
    24 #include "DummyAlarmControl.h"
       
    25 
       
    26 /*@{*/
       
    27 // < and > escape encoded as &lt; and &gt; as TestExecuteLogEngine
       
    28 // does not do it for us.
       
    29 _LIT(KNotKnown, "&lt;message not known yet&gt;");
       
    30 /*@}*/
       
    31 	
       
    32 /**
       
    33 Constructor
       
    34 @param aSupervisor Pointer to the supervisor corresponding to this alarm 
       
    35 control
       
    36 @param aAlarmControlsManager Pointer to the alarm controls manager
       
    37 @internalTechnology
       
    38 @test
       
    39 */
       
    40 CDummyAlarmControl::CDummyAlarmControl(CEikAlmControlSupervisor* aSupervisor, CAlarmControlsManager* aAlarmControlsManager) 
       
    41 : iSupervisor(aSupervisor), iMyManager(aAlarmControlsManager), iAlarmMessage(KNotKnown)
       
    42 	{
       
    43 	}
       
    44 	
       
    45 /**
       
    46 Destructor
       
    47 @internalTechnology
       
    48 @test
       
    49 */
       
    50 CDummyAlarmControl::~CDummyAlarmControl()	
       
    51 	{
       
    52 	delete iAlarmSoundName;
       
    53 	}
       
    54 	
       
    55 //
       
    56 // MEikServAlarm callbacks Impelementations start
       
    57 //
       
    58 
       
    59 /**
       
    60 MEikServAlarm implementation. Prints that it was called.
       
    61 Asks its manager to remove it from his list. Deletes itself
       
    62 @internalTechnology
       
    63 @test
       
    64 */
       
    65 void CDummyAlarmControl::Release()
       
    66 	{
       
    67 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::ERelease));
       
    68 	
       
    69 	iMyManager->RemoveFromList(this);
       
    70 	delete this;
       
    71 	}
       
    72 
       
    73 /**
       
    74 MEikServAlarm implementation. Prints that it was called.
       
    75 Asks its manager to increment the number of currently notifying alarms if
       
    76 it had not already been showing
       
    77 @internalTechnology
       
    78 @test
       
    79 */
       
    80 void CDummyAlarmControl::ShowAlarm()
       
    81 	{
       
    82 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EShowAlarm));
       
    83 	
       
    84 	// KNullAlarmId check is done to be safe in case of Single Alarm mode,
       
    85 	// where some call backs occur before we have the alarm info. In such a 
       
    86 	// case, no alarm is considered to be notifying
       
    87 	if(iAlarm.Id() != KNullAlarmId && !iIsShowing)
       
    88 		{
       
    89 		iMyManager->IncrementNoOfCurrentlyNotifyingAlarms();
       
    90 		}
       
    91 	
       
    92 	iIsShowing = ETrue;
       
    93 	}
       
    94 
       
    95 /**
       
    96 MEikServAlarm implementation. Prints that it was called.
       
    97 Asks its manager to decrement the number of currently notifying alarms if
       
    98 it has been showing. Marks itself as not showing
       
    99 @internalTechnology
       
   100 @test
       
   101 */
       
   102 void CDummyAlarmControl::HideAlarm()
       
   103 	{
       
   104 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EHideAlarm));
       
   105 	if(iAlarm.Id() != KNullAlarmId && iIsShowing)
       
   106 		{
       
   107 		iMyManager->DecrementNoOfCurrentlyNotifyingAlarms();
       
   108 		}
       
   109 	iIsShowing = EFalse;
       
   110 	
       
   111 	// If the alarm has been StopPlayAlarm-ed and HideAlarm is now being
       
   112 	// called, it means, this alarm is being hidden as a result of a 
       
   113 	// snooze or a clear. Hence it must not be consiedered the 
       
   114 	// CurrentlyPlayingAlarm. We check for iIsPlaying just to make sure
       
   115 	// that if HideAlarm has been erroneously called before StopPlayAlarm
       
   116 	// it will get trapped by the TestAlarmControlState step somewhere
       
   117 	
       
   118 	// We dont do this in StopPlayAlarm itself, because, if the alarm is
       
   119 	// left unattended it will stop and start playing periodically, and 
       
   120 	// we must not consider that this alarm is not the currently notifying one
       
   121 	// in that case
       
   122 	if(!iIsPlaying)
       
   123 		{
       
   124 		iMyManager->UpdateCurrentlyPlayingAlarmId(KNullAlarmId);
       
   125 		}
       
   126 	
       
   127 	// If in single alarm mode, then we remove the record of the alarm message
       
   128 	// when the alarm is snoozed or cleared	
       
   129 	if(iMyManager->CurrentMaxAlarms() == 1)
       
   130 		{
       
   131 		iAlarmMessage.Set(KNotKnown);
       
   132 		}
       
   133 	}
       
   134 	
       
   135 /**
       
   136 MEikServAlarm implementation. Prints that it was called.
       
   137 Returns the current state of the alarm control object.
       
   138 @return The current state of the alarm control object.
       
   139 @internalTechnology
       
   140 @test
       
   141 */
       
   142 TInt CDummyAlarmControl::CurrentServerState() const
       
   143 	{
       
   144 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::ECurrentServerState));
       
   145 	return iCurrentAlarmServerState;
       
   146 	}
       
   147 	
       
   148 /**
       
   149 MEikServAlarm implementation. Prints that it was called.
       
   150 Marks itself as Snoozing
       
   151 @param aMinutes Is not used
       
   152 @internalTechnology
       
   153 @test
       
   154 */
       
   155 void CDummyAlarmControl::UpdateSoundPauseTimeInterval(TInt aMinutes)
       
   156 	{
       
   157 	_LIT(KPrintMinsToSnooze, "Mins to snooze = ");
       
   158 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EUpdateSoundPauseTimeInterval));
       
   159 	TBuf<20> message(KPrintMinsToSnooze);
       
   160 	message.AppendNum(aMinutes);
       
   161 	iMyManager->PrintLog(message);
       
   162 	iMinsToSnooze = aMinutes;
       
   163 	iIsSnoozed = ETrue; 
       
   164 	}
       
   165 		
       
   166 /**
       
   167 MEikServAlarm implementation. Prints that it was called.
       
   168 Updates its current alarm server state flag
       
   169 @param aNewAlarmServerState The new alarm server state.
       
   170 @internalTechnology
       
   171 @test
       
   172 */
       
   173 void CDummyAlarmControl::UpdateForAlarmServerState(TInt aNewAlarmServerState)
       
   174 	{
       
   175 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EUpdateForAlarmServerState));
       
   176 	iCurrentAlarmServerState = aNewAlarmServerState;
       
   177 	}
       
   178 
       
   179 /**
       
   180 MEikServAlarm implementation. 
       
   181 Updates its alarm message flag, which will later identify this alarm control 
       
   182 object. Prints that it was called in the end, as then there is an advantage of 
       
   183 knowing the alarm message
       
   184 @param aAlarm The Alarm object that carries the alarm's details
       
   185 @param aOwner The owner of the alarm. Not used
       
   186 @internalTechnology
       
   187 @test
       
   188 */
       
   189 void CDummyAlarmControl::UpdateAlarmInfo(const TASShdAlarm& aAlarm,const TFullName& /* aOwner */)
       
   190 	{
       
   191 	// I got notified now
       
   192 	iMyNotificationTime.UniversalTime();
       
   193 	
       
   194 	iAlarm = aAlarm;
       
   195 	
       
   196 	// I should have been notified at:
       
   197 	iOrigExpTime = iAlarm.OriginalExpiryTime();
       
   198 	
       
   199 	iAlarmMessage.Set(iAlarm.Message());
       
   200 	// In this function we print in the end, as we know iAlarmMessage henceforth
       
   201 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EUpdateAlarmInfo));
       
   202 	}
       
   203 
       
   204 /**
       
   205 MEikServAlarm implementation. Prints that it was called.
       
   206 Asks its manager to upadte the flag identifying the id of the currently playing 
       
   207 alarm and marks itself as Playing.
       
   208 @param aAlarmSoundName The alarm sound name to play
       
   209 @internalTechnology
       
   210 @test
       
   211 */
       
   212 void CDummyAlarmControl::StartPlayAlarmL(const TDesC& aAlarmSoundName)
       
   213 	{
       
   214 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EStartPlayAlarm));
       
   215 	iMyManager->UpdateCurrentlyPlayingAlarmId(iAlarm.Id());
       
   216 	iIsSnoozed = EFalse;
       
   217 	iIsPlaying = ETrue;
       
   218 	
       
   219 	if(iAlarmSoundName)
       
   220 		{
       
   221 		delete iAlarmSoundName;
       
   222 		iAlarmSoundName = NULL;
       
   223 		}
       
   224 	iAlarmSoundName = aAlarmSoundName.AllocL();
       
   225 	}
       
   226 	
       
   227 /**
       
   228 MEikServAlarm implementation. Prints that it was called.
       
   229 Marks itself as Not-Playing.
       
   230 @internalTechnology
       
   231 @test
       
   232 */
       
   233 void CDummyAlarmControl::StopPlayAlarm()
       
   234 	{
       
   235 	TRAP_IGNORE(PrintWhoWasCalledL(TestMultipleAlarms::EStopPlayAlarm));
       
   236 	iIsPlaying = EFalse;
       
   237 	}
       
   238 	
       
   239 //
       
   240 // MEikServAlarm callbacks Impelementations end
       
   241 //
       
   242 	
       
   243 	
       
   244 /**
       
   245 Returns the alarm-message of the alarm associated with this object
       
   246 @return The alarm-message of the alarm associated with this object
       
   247 @internalTechnology
       
   248 @test
       
   249 */
       
   250 const TDesC& CDummyAlarmControl::AlarmMessage()
       
   251 	{
       
   252 	return iAlarmMessage;
       
   253 	}
       
   254 	
       
   255 /**
       
   256 Returns the alarm-sound name of the alarm associated with this object
       
   257 @return The alarm-sound name of the alarm associated with this object
       
   258 @internalTechnology
       
   259 @test
       
   260 */
       
   261 const TDesC& CDummyAlarmControl::AlarmSoundName()
       
   262 	{
       
   263 	return *iAlarmSoundName;
       
   264 	}
       
   265 
       
   266 /**
       
   267 Returns a pointer to the supervisor associated with this alarm control object
       
   268 @return A pointer to the supervisor associated with this alarm control object
       
   269 @internalTechnology
       
   270 @test
       
   271 */
       
   272 CEikAlmControlSupervisor* CDummyAlarmControl::Supervisor()	
       
   273 	{
       
   274 	return iSupervisor;
       
   275 	}
       
   276 	
       
   277 /**
       
   278 Returns the alarm object associated with this alarm control object
       
   279 @return The alarm object associated with this alarm control object
       
   280 @internalTechnology
       
   281 @test
       
   282 */
       
   283 const TASShdAlarm& CDummyAlarmControl::AlarmObject()
       
   284 	{
       
   285 	return iAlarm;
       
   286 	}
       
   287 
       
   288 /**
       
   289 Returns the IsSnoozed flag of this object
       
   290 @return The IsSnoozed flag of this object
       
   291 @internalTechnology
       
   292 @test
       
   293 */
       
   294 TBool CDummyAlarmControl::IsSnoozed()
       
   295 	{
       
   296 	return iIsSnoozed;
       
   297 	}
       
   298 
       
   299 /**
       
   300 Returns the IsShowing flag of this object
       
   301 @return The IsShowing flag of this object
       
   302 @internalTechnology
       
   303 @test
       
   304 */
       
   305 TBool CDummyAlarmControl::IsShowing()
       
   306 	{
       
   307 	return iIsShowing;
       
   308 	}
       
   309 	
       
   310 /**
       
   311 Returns the actual time the alarm corresponding to this object got notified
       
   312 @return The actual time the alarm corresponding to this object got notified
       
   313 @internalTechnology
       
   314 @test
       
   315 */
       
   316 TTime CDummyAlarmControl::ActualNotificationTime()	
       
   317 	{
       
   318 	return iMyNotificationTime;
       
   319 	}
       
   320 
       
   321 /**
       
   322 Returns the original expiry time of the alarm corresponding to this object
       
   323 @return The original expiry time of the alarm corresponding to this object
       
   324 @internalTechnology
       
   325 @test
       
   326 */
       
   327 TTime CDummyAlarmControl::OriginalExpiryTime()	
       
   328 	{
       
   329 	return iOrigExpTime;
       
   330 	}
       
   331 	
       
   332 /**
       
   333 Returns the minutes to snooze value
       
   334 @return The minutes to snooze value
       
   335 @internalTechnology
       
   336 @test
       
   337 */
       
   338 TInt CDummyAlarmControl::MinsToSnooze()	
       
   339 	{
       
   340 	return iMinsToSnooze;
       
   341 	}
       
   342 
       
   343 	
       
   344 /**
       
   345 Prints which call-back was called by the alert server
       
   346 @param aAlarmControlState The enumeration identifying the call-back
       
   347 @internalTechnology
       
   348 @test
       
   349 */
       
   350 void CDummyAlarmControl::PrintWhoWasCalledL(TestMultipleAlarms::TAlarmControlState aAlarmControlState) const
       
   351 	{
       
   352 	_LIT(KLineFeed, "\n");
       
   353 	_LIT(KWasCalledOn, "*** DUMMY ALARM CONTROL *** :- %S was called on %S");
       
   354 	TPtrC callBackName = iMyManager->GetFunctionName(aAlarmControlState);
       
   355 	HBufC* message = HBufC::NewL(KWasCalledOn().Length() + callBackName.Length() + iAlarmMessage.Length());
       
   356 	message->Des().Format(KWasCalledOn(), &callBackName, &iAlarmMessage);
       
   357 	message->Des().Insert(0, KLineFeed);
       
   358 	message->Des().Append(KLineFeed);
       
   359 	iMyManager->PrintLog(message->Des());
       
   360 	delete message;
       
   361 	}
       
   362