commonappservices/alarmserver/ConsoleAlarmAlertServer/Source/ConsoleAlarmAlertConsole.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 "ConsoleAlarmAlertConsole.h"
       
    17 
       
    18 #include <e32twin.h>
       
    19 #include <e32base.h>
       
    20 #include <e32svr.h>
       
    21 #include <calsession.h>
       
    22 #include <calentryview.h>
       
    23 #include <asaltdefs.h>
       
    24 #include "ConsoleAlarmAlertSession.h"
       
    25 
       
    26 CConsoleAlarmAlertConsole::CConsoleAlarmAlertConsole(CConsoleAlarmAlertSession& aSession)
       
    27 :	CActive(CActive::EPriorityLow), iSession(aSession), iInstructionIndex(0)
       
    28 	{
       
    29 	CActiveScheduler::Add(this);
       
    30 	}
       
    31 
       
    32 CConsoleAlarmAlertConsole::~CConsoleAlarmAlertConsole()
       
    33 	{
       
    34 	Cancel();
       
    35 	Hide();
       
    36 	}
       
    37 
       
    38 void CConsoleAlarmAlertConsole::GetKey()
       
    39 	{
       
    40 	if (iWin && !IsActive())
       
    41 		{
       
    42 		SetActive();
       
    43 		iWin->Read(iStatus);
       
    44 		}		
       
    45 	}
       
    46 
       
    47 void CConsoleAlarmAlertConsole::CancelKey()
       
    48 	{
       
    49 	if	(IsActive())
       
    50 		Cancel();
       
    51 	}
       
    52 
       
    53 void CConsoleAlarmAlertConsole::DecCounterL()
       
    54 	{
       
    55 	if	(iTimeInterval > 0)
       
    56 		{
       
    57 		--iTimeInterval;
       
    58 		UpdateDisplayL();
       
    59 		}
       
    60 	}
       
    61 
       
    62 CCAASHelperCallBack::CCAASHelperCallBack()
       
    63 	{
       
    64 	}
       
    65 
       
    66 void CCAASHelperCallBack::Progress(TInt /*aPercentageCompleted*/)
       
    67 	{
       
    68 	}
       
    69 	
       
    70 void CCAASHelperCallBack::Completed(TInt /*aError*/)
       
    71 	{
       
    72 	}
       
    73 	
       
    74 TBool CCAASHelperCallBack::NotifyProgress()
       
    75 	{
       
    76 	return EFalse;
       
    77 	}
       
    78 
       
    79 void CConsoleAlarmAlertConsole::UpdateDisplayL()
       
    80 	{
       
    81 	TBuf<180> buf;
       
    82 	_LIT(KEalwlAlarmSoundOff, "Off");
       
    83 	_LIT(KEalwlAlarmSoundOn, "On");
       
    84 	_LIT(KEalwlStatusEnabled, "Are");
       
    85 	_LIT(KEalwlStatusNotEnabled, "Are Not");
       
    86 	_LIT(KEalwlStatusIs, "Is");
       
    87 	_LIT(KEalwlStatusIsNo, "Is No");
       
    88 	_LIT(KFormatLocalTime,"\nDue Time:%D %H:%T:%S Local Time");
       
    89 	_LIT(KFormatUtcTime,"\nDue Time:%D %H:%T:%S UTC Time");
       
    90 	//
       
    91 	if	(!iWin)
       
    92 		return;
       
    93 	iWin->SetCursorPosAbs(TPoint(0,0));
       
    94 
       
    95 	// MESSAGE
       
    96 	buf.Format(_L("Message : %S"), &iSession.Alarm().Message());
       
    97 	iWin->Write(buf);
       
    98 	iWin->ClearToEndOfLine();	
       
    99 	if (iSession.Alarm().IsFloating())
       
   100 		{
       
   101 		(iSession.Alarm().NextDueTime()).FormatL(buf,KFormatLocalTime);		
       
   102 		}
       
   103 		else
       
   104 		{
       
   105 		(iSession.Alarm().NextDueTime()).FormatL(buf,KFormatUtcTime);		
       
   106 		}	
       
   107 	iWin->Write(buf);
       
   108 	iWin->ClearToEndOfLine();
       
   109 
       
   110 	// DATA
       
   111 	if	(iSession.Alarm().HasAssociatedData())
       
   112 		{
       
   113 		const TAgnAlarmInfo data = iSession.AlarmData();
       
   114 		const TUid KUidAgendaModelAlarmCategory = { 0x101F4A70 };
       
   115 		if (data.iAlarmCategory == KUidAgendaModelAlarmCategory)
       
   116 			{
       
   117 			_LIT(KEalwlAgendaData,"\ndata: agenda filename \"%S\"");
       
   118 			if (data.iFileName.Length() < 40)
       
   119 				{
       
   120 				buf.Format(KEalwlAgendaData,&data.iFileName);
       
   121 				}
       
   122 			else
       
   123 				{
       
   124 				TBuf<40> temp = data.iFileName.Left(40);
       
   125 				buf.Format(KEalwlAgendaData,&temp);
       
   126 				}
       
   127 			}
       
   128 		else
       
   129 			{
       
   130 			buf.Format(_L("\nAlarm has %d data bytes"), iSession.AlarmDataSize());
       
   131 			}
       
   132 		}
       
   133 	else
       
   134 		{
       
   135 		buf = _L("\nAlarm has no associated data");
       
   136 		}
       
   137 	iWin->Write(buf);
       
   138 	iWin->ClearToEndOfLine();
       
   139 
       
   140 	// DEFER TIME
       
   141 	if	(iSession.DeferTime() != Time::NullTTime())
       
   142 		{
       
   143 		TDateTime dateTime(iSession.DeferTime().DateTime());
       
   144 		buf.Format(_L("\nDefer   : %02d:%02d"), dateTime.Hour(), dateTime.Minute());
       
   145 		}
       
   146 	else
       
   147 		buf=_L("\nNULL defer time");
       
   148 	iWin->Write(buf);
       
   149 	iWin->ClearToEndOfLine();
       
   150 
       
   151 	// TIME INTERVAL
       
   152 	buf.Format(_L("\nCurrent time interval is %d minutes"), GetTimeInterval());
       
   153 	iWin->Write(buf);
       
   154 	iWin->ClearToEndOfLine();
       
   155 
       
   156 	// STATE FLAGS
       
   157 	buf.Format(_L("\nAlarm sounds are %S"),(iAlertState&EASAltStateFlagsSilentRunning)?&KEalwlAlarmSoundOff:&KEalwlAlarmSoundOn);
       
   158 	iWin->Write(buf);
       
   159 	iWin->ClearToEndOfLine();
       
   160 	buf.Format(_L("\nAlarm sounds %S paused"),(iAlertState&EASAltStateFlagsSoundIsPaused)?&KEalwlStatusEnabled:&KEalwlStatusNotEnabled);
       
   161 	iWin->Write(buf);
       
   162 	iWin->ClearToEndOfLine();
       
   163 	buf.Format(_L("\nAlarm sounds %S deferred"),(iAlertState&EASAltStateFlagsInQuietPeriod)?&KEalwlStatusEnabled:&KEalwlStatusNotEnabled);
       
   164 	iWin->Write(buf);
       
   165 	iWin->ClearToEndOfLine();
       
   166 	buf.Format(_L("\nThere %S more than one unacknowledged alarms"),(iAlertState&EASAltStateFlagsMoreThanOneDueAlarm)?&KEalwlStatusEnabled:&KEalwlStatusNotEnabled);
       
   167 	iWin->Write(buf);
       
   168 	iWin->ClearToEndOfLine();
       
   169 	buf.Format(_L("\nThere %S memory to snooze alarms"),(iAlertState&EASAltStateFlagsNoMemoryForSnoozeAlarm)?&KEalwlStatusIsNo:&KEalwlStatusIs);
       
   170 	iWin->Write(buf);
       
   171 	iWin->ClearToEndOfLine();
       
   172 	buf.Format(_L("\nThere %S an alarm sound to play"),(iAlertState&EASAltStateFlagsAlarmHasNoSoundFileName)?&KEalwlStatusIsNo:&KEalwlStatusIs);
       
   173 	iWin->Write(buf);
       
   174 	iWin->ClearToEndOfLine();
       
   175 
       
   176 	// COMMAND PROMPTS
       
   177 	iWin->Write(_L("\nENTER = Silence alarm          SPACE = Quiet Period"));
       
   178 	iWin->ClearToEndOfLine();
       
   179 	iWin->Write(_L("\nESCAPE = Acknowledge alarm     A = Acknowledge all"));
       
   180 	iWin->ClearToEndOfLine();
       
   181 	iWin->Write(_L("\nP = Pause alarm sound          TAB = Snooze alarm"));
       
   182 	iWin->ClearToEndOfLine();
       
   183 	iWin->Write(_L("\n1 = 1 min sound interval		 0 = 0 mins sound interval"));
       
   184 	iWin->ClearToEndOfLine();
       
   185 	iWin->Write(_L("\n+ = Increase int. and pause    - = Decrease int. and pause"));
       
   186 	iWin->ClearToEndOfLine();
       
   187 	iWin->Write(_L("\n! = Kill alarm alert server"));
       
   188 	iWin->ClearToEndOfLine();
       
   189 	iWin->Write(_L("\n"));
       
   190 	iWin->ClearToEndOfLine();
       
   191 	iWin->Write(_L("\r"));
       
   192 	//
       
   193 	if(!iSession.InstructionSet()) //Get user input if instruction set unspecified.
       
   194 		GetKey();
       
   195 	else if (iInstructionIndex >= static_cast<RArray<TInt>*>(iSession.InstructionSet())->Count()) //Get user input if program has already iterated thru entire instruction set.
       
   196 		GetKey();
       
   197 	else //Use the command in the instruction set, instead of waiting for user input.
       
   198 		{
       
   199 			if(!IsActive())
       
   200 			{
       
   201 			iStatus = KRequestPending;
       
   202 			TRequestStatus* ptrStatus = &iStatus;
       
   203 			User::RequestComplete( ptrStatus, KErrNone );
       
   204 			SetActive();
       
   205 			}
       
   206 		}
       
   207 	}
       
   208 
       
   209 TInt CConsoleAlarmAlertConsole::GetTimeInterval() const
       
   210 	{
       
   211 	return(iTimeInterval);
       
   212 	}
       
   213 
       
   214 void CConsoleAlarmAlertConsole::SetVisibilityL(TInt aVis)
       
   215 	{
       
   216 	if	(!aVis)
       
   217 		Hide();
       
   218 	else if (!iWin)
       
   219 		{
       
   220 		// Create a new window, since cannot set order of console windows
       
   221 		CreateWinL();
       
   222 		UpdateDisplayL();
       
   223 		}
       
   224 	}
       
   225 
       
   226 void CConsoleAlarmAlertConsole::SetAlertStateL(TInt aFlags)
       
   227 	{
       
   228 	iAlertState = aFlags;
       
   229 	UpdateDisplayL();
       
   230 	}
       
   231 
       
   232 void CConsoleAlarmAlertConsole::RunL()
       
   233 	{
       
   234 	if (iStatus.Int() == KErrCancel)
       
   235 		return;
       
   236 
       
   237 	__ASSERT_DEBUG(iWin, User::Invariant());
       
   238 	TInt key = iWin->KeyCode();
       
   239 	if(iSession.InstructionSet() && iInstructionIndex < static_cast<RArray<TInt>*>(iSession.InstructionSet())->Count())
       
   240 		{
       
   241 		RArray<TInt>* temp = static_cast<RArray<TInt>*>(iSession.InstructionSet());
       
   242 		key = (*temp)[iInstructionIndex++];
       
   243 		GetKey();
       
   244 		}
       
   245 	else
       
   246 		{
       
   247 		GetKey();
       
   248 		if ((key>=EKeyF1 && key<=EKeyF12) || key==EKeyTab)
       
   249 			{
       
   250 			DoDeferTime(EASAltAlertServerResponseSnooze);
       
   251 			}
       
   252 		}
       
   253 
       
   254 	switch (key)
       
   255 		{
       
   256 	// ACKNOWLEDGE CURRENT
       
   257 	case EKeyEscape:
       
   258 		iSession.Notify(EASAltAlertServerResponseClear);
       
   259 		return;
       
   260 	// ACKNOWLEDGE ALL
       
   261 	case 'a':
       
   262 	case 'A':
       
   263 		iSession.Notify(EASAltAlertServerResponseClearAll);
       
   264 		return;
       
   265 	// QUIET PERIOD
       
   266 	case EKeySpace:
       
   267 		DoDeferTime(EASAltAlertServerResponseQuietPeriod);
       
   268 		break;
       
   269 	// PAUSE SOUND
       
   270 	case 'p':
       
   271 	case 'P':
       
   272 		DoDeferTime(EASAltAlertServerResponsePauseSound);
       
   273 		break;
       
   274 	// SILENCE ALL SOUND
       
   275 	case EKeyEnter:
       
   276 		iSession.Notify(EASAltAlertServerResponseSilence);
       
   277 		break;
       
   278 	// INTERVAL 1 MINUTE
       
   279 	case '1':
       
   280 		iTimeInterval=1;
       
   281 		iSession.Notify(EASAltAlertServerResponsePauseSound);
       
   282 		break;
       
   283 	// INTERVAL 0 MINUTES
       
   284 	case '0':
       
   285 		iTimeInterval=0;
       
   286 		iSession.Notify(EASAltAlertServerResponsePauseSound);
       
   287 		break;
       
   288 	// PAUSE +
       
   289 	case '=':
       
   290 	case '+':
       
   291 		iTimeInterval++;
       
   292 		iSession.Notify(EASAltAlertServerResponsePauseSound);
       
   293 		break;
       
   294 	// PAUSE -
       
   295 	case '-':
       
   296 		iTimeInterval--;
       
   297 		iSession.Notify(EASAltAlertServerResponsePauseSound);
       
   298 		break;
       
   299 
       
   300 	// QUIT
       
   301 	case '!':
       
   302 		CActiveScheduler::Stop();
       
   303 		break;
       
   304 		}
       
   305 
       
   306 	TBuf<10> buf;
       
   307 	buf.Format(_L("'%c',"), key);
       
   308 	iWin->Write(buf);
       
   309 	}
       
   310 
       
   311 void CConsoleAlarmAlertConsole::DoCancel()
       
   312 	{
       
   313 	__ASSERT_DEBUG(iWin, User::Invariant());
       
   314 	iWin->ReadCancel();
       
   315 	}
       
   316 
       
   317 void CConsoleAlarmAlertConsole::Hide()
       
   318 	{
       
   319 	if	(iWin)
       
   320 		CancelKey(); 
       
   321 	//
       
   322 	delete iWin;
       
   323 	iWin = NULL;
       
   324 	//
       
   325 	if	(iCountDown)
       
   326 		iCountDown->Cancel();
       
   327 	//
       
   328 	delete iCountDown;
       
   329 	iCountDown=NULL;
       
   330 	}
       
   331 
       
   332 void CConsoleAlarmAlertConsole::CreateWinL()
       
   333 	{
       
   334 	_LIT(KAlarmAlertConsoleCaption, "Test Alarm Alert Server Console");
       
   335 	//
       
   336 	__ASSERT_DEBUG(!iWin, User::Invariant());
       
   337 	__ASSERT_DEBUG(!iCountDown, User::Invariant());
       
   338 	//
       
   339 	TRAPD(trapCheck, iWin = Console::NewL(KAlarmAlertConsoleCaption, TSize(KConsFullScreen, KConsFullScreen)));
       
   340 	if	(trapCheck)
       
   341 		{
       
   342 		iWin=NULL;
       
   343 		return;
       
   344 		}
       
   345 	
       
   346 	TRAP(trapCheck, iCountDown = CPeriodic::NewL(CActive::EPriorityIdle));
       
   347 	if	(trapCheck)
       
   348 		{
       
   349 		iCountDown=NULL;
       
   350 		return;
       
   351 		}
       
   352 	//
       
   353 	const TTimeIntervalMicroSeconds32 interval(60000000);
       
   354 	iCountDown->Start(interval, interval, TCallBack(&CountDownCallBackL, this));
       
   355 	}
       
   356 
       
   357 void CConsoleAlarmAlertConsole::DoDeferTime(TASAltAlertServerResponse aResponse)
       
   358 	{
       
   359 	if	(++iTimeInterval > 60)
       
   360 		{
       
   361 		iTimeInterval = 5;
       
   362 		User::Beep(440, 12);
       
   363 		}
       
   364 	//
       
   365 	TTime now;
       
   366 	now.UniversalTime();
       
   367 	now += TTimeIntervalMinutes(iTimeInterval);
       
   368 	//
       
   369 	iSession.Notify(aResponse, now);
       
   370 	}
       
   371 
       
   372 TBool CConsoleAlarmAlertConsole::CountDownCallBackL(TAny* aSelf)
       
   373 	{
       
   374 	CConsoleAlarmAlertConsole& self = *reinterpret_cast<CConsoleAlarmAlertConsole*>(aSelf);
       
   375 	self.DecCounterL();
       
   376 	//
       
   377 	return EFalse;
       
   378 	}