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