usbmgmt/usbmgrtest/t_usb_charging/src/activeconsole.cpp
author hgs
Thu, 16 Sep 2010 12:03:29 +0800
changeset 49 93c0009bd947
permissions -rw-r--r--
201036_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
93c0009bd947 201036_01
hgs
parents:
diff changeset
     1
/*
93c0009bd947 201036_01
hgs
parents:
diff changeset
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
93c0009bd947 201036_01
hgs
parents:
diff changeset
     3
* All rights reserved.
93c0009bd947 201036_01
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
93c0009bd947 201036_01
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
93c0009bd947 201036_01
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
93c0009bd947 201036_01
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
93c0009bd947 201036_01
hgs
parents:
diff changeset
     8
*
93c0009bd947 201036_01
hgs
parents:
diff changeset
     9
* Initial Contributors:
93c0009bd947 201036_01
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
93c0009bd947 201036_01
hgs
parents:
diff changeset
    11
*
93c0009bd947 201036_01
hgs
parents:
diff changeset
    12
* Contributors:
93c0009bd947 201036_01
hgs
parents:
diff changeset
    13
*
93c0009bd947 201036_01
hgs
parents:
diff changeset
    14
* Description:
93c0009bd947 201036_01
hgs
parents:
diff changeset
    15
*
93c0009bd947 201036_01
hgs
parents:
diff changeset
    16
*/
93c0009bd947 201036_01
hgs
parents:
diff changeset
    17
93c0009bd947 201036_01
hgs
parents:
diff changeset
    18
#include <e32twin.h>
93c0009bd947 201036_01
hgs
parents:
diff changeset
    19
#include <e32svr.h>
93c0009bd947 201036_01
hgs
parents:
diff changeset
    20
#include "activeconsole.h"
93c0009bd947 201036_01
hgs
parents:
diff changeset
    21
#include "testbase.h"
93c0009bd947 201036_01
hgs
parents:
diff changeset
    22
#include "tests.h"
93c0009bd947 201036_01
hgs
parents:
diff changeset
    23
#include "OstTraceDefinitions.h"
93c0009bd947 201036_01
hgs
parents:
diff changeset
    24
#ifdef OST_TRACE_COMPILER_IN_USE
93c0009bd947 201036_01
hgs
parents:
diff changeset
    25
#include "activeconsoleTraces.h"
93c0009bd947 201036_01
hgs
parents:
diff changeset
    26
#endif
93c0009bd947 201036_01
hgs
parents:
diff changeset
    27
93c0009bd947 201036_01
hgs
parents:
diff changeset
    28
93c0009bd947 201036_01
hgs
parents:
diff changeset
    29
CActiveConsole::CActiveConsole(CConsoleBase& aConsole)
93c0009bd947 201036_01
hgs
parents:
diff changeset
    30
 :	CActive(CActive::EPriorityStandard),
93c0009bd947 201036_01
hgs
parents:
diff changeset
    31
	iConsole(aConsole)
93c0009bd947 201036_01
hgs
parents:
diff changeset
    32
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    33
	OstTraceFunctionEntry0( CACTIVECONSOLE_CACTIVECONSOLE_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    34
	CActiveScheduler::Add(this);
93c0009bd947 201036_01
hgs
parents:
diff changeset
    35
	OstTraceFunctionExit0( CACTIVECONSOLE_CACTIVECONSOLE_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    36
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    37
93c0009bd947 201036_01
hgs
parents:
diff changeset
    38
CActiveConsole* CActiveConsole::NewLC(CConsoleBase& aConsole)
93c0009bd947 201036_01
hgs
parents:
diff changeset
    39
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    40
	OstTraceFunctionEntry0( CACTIVECONSOLE_NEWLC_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    41
93c0009bd947 201036_01
hgs
parents:
diff changeset
    42
	CActiveConsole* self = new(ELeave) CActiveConsole(aConsole);
93c0009bd947 201036_01
hgs
parents:
diff changeset
    43
	CleanupStack::PushL(self);
93c0009bd947 201036_01
hgs
parents:
diff changeset
    44
	self->ConstructL();
93c0009bd947 201036_01
hgs
parents:
diff changeset
    45
#ifdef COMMANDLINE_PARAM	
93c0009bd947 201036_01
hgs
parents:
diff changeset
    46
	self->DisplayMainMenu();
93c0009bd947 201036_01
hgs
parents:
diff changeset
    47
#endif	
93c0009bd947 201036_01
hgs
parents:
diff changeset
    48
	OstTraceFunctionExit0( CACTIVECONSOLE_NEWLC_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    49
	return self;
93c0009bd947 201036_01
hgs
parents:
diff changeset
    50
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    51
93c0009bd947 201036_01
hgs
parents:
diff changeset
    52
void CActiveConsole::ConstructL()
93c0009bd947 201036_01
hgs
parents:
diff changeset
    53
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    54
	OstTraceFunctionEntry0( CACTIVECONSOLE_CONSTRUCTL_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    55
	// Launch of FDTest test.
93c0009bd947 201036_01
hgs
parents:
diff changeset
    56
	iTest = gTestDefinitions[0].iFactoryL(*this);
93c0009bd947 201036_01
hgs
parents:
diff changeset
    57
	OstTraceFunctionExit0( CACTIVECONSOLE_CONSTRUCTL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    58
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    59
93c0009bd947 201036_01
hgs
parents:
diff changeset
    60
CActiveConsole::~CActiveConsole()
93c0009bd947 201036_01
hgs
parents:
diff changeset
    61
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    62
	OstTraceFunctionEntry0( DUP1_CACTIVECONSOLE_CACTIVECONSOLE_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    63
	Cancel();
93c0009bd947 201036_01
hgs
parents:
diff changeset
    64
93c0009bd947 201036_01
hgs
parents:
diff changeset
    65
	StopCurrentTest();
93c0009bd947 201036_01
hgs
parents:
diff changeset
    66
	OstTraceFunctionExit0( DUP1_CACTIVECONSOLE_CACTIVECONSOLE_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    67
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    68
93c0009bd947 201036_01
hgs
parents:
diff changeset
    69
void CActiveConsole::DoCancel()
93c0009bd947 201036_01
hgs
parents:
diff changeset
    70
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    71
	OstTraceFunctionEntry0( CACTIVECONSOLE_DOCANCEL_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    72
	iConsole.ReadCancel();
93c0009bd947 201036_01
hgs
parents:
diff changeset
    73
	OstTraceFunctionExit0( CACTIVECONSOLE_DOCANCEL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    74
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    75
93c0009bd947 201036_01
hgs
parents:
diff changeset
    76
void CActiveConsole::StopCurrentTest()
93c0009bd947 201036_01
hgs
parents:
diff changeset
    77
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    78
	OstTraceFunctionEntry0( CACTIVECONSOLE_STOPCURRENTTEST_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    79
	delete iTest;
93c0009bd947 201036_01
hgs
parents:
diff changeset
    80
	iTest = NULL;
93c0009bd947 201036_01
hgs
parents:
diff changeset
    81
	OstTraceFunctionExit0( CACTIVECONSOLE_STOPCURRENTTEST_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    82
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    83
93c0009bd947 201036_01
hgs
parents:
diff changeset
    84
void CActiveConsole::RunL()
93c0009bd947 201036_01
hgs
parents:
diff changeset
    85
// Only process when we get a return, otherwise cache- i.e. support multi-character selections
93c0009bd947 201036_01
hgs
parents:
diff changeset
    86
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    87
	OstTraceFunctionEntry0( CACTIVECONSOLE_RUNL_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    88
	DoActionKeyL(iConsole.KeyCode());
93c0009bd947 201036_01
hgs
parents:
diff changeset
    89
93c0009bd947 201036_01
hgs
parents:
diff changeset
    90
	// Repost asynchronous request.
93c0009bd947 201036_01
hgs
parents:
diff changeset
    91
	RequestCharacter();
93c0009bd947 201036_01
hgs
parents:
diff changeset
    92
	OstTraceFunctionExit0( CACTIVECONSOLE_RUNL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    93
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
    94
93c0009bd947 201036_01
hgs
parents:
diff changeset
    95
void CActiveConsole::DoActionKeyL(TKeyCode aKeyCode)
93c0009bd947 201036_01
hgs
parents:
diff changeset
    96
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
    97
	OstTraceFunctionEntry0( CACTIVECONSOLE_DOACTIONKEYL_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
    98
	WriteNoReturn(_L8("%c"), aKeyCode);
93c0009bd947 201036_01
hgs
parents:
diff changeset
    99
93c0009bd947 201036_01
hgs
parents:
diff changeset
   100
	// Examine the key that just came in.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   101
	switch ( TUint(aKeyCode) )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   102
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   103
	case EKeyEscape:
93c0009bd947 201036_01
hgs
parents:
diff changeset
   104
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   105
		Write(_L8("Exiting"));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   106
		CActiveScheduler::Stop();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   107
		OstTraceFunctionExit0( CACTIVECONSOLE_DOACTIONKEYL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   108
		return;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   109
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   110
93c0009bd947 201036_01
hgs
parents:
diff changeset
   111
	case EKeyEnter:
93c0009bd947 201036_01
hgs
parents:
diff changeset
   112
		// Tell the test about what's in the buffer so far, if anything.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   113
		Write(_L8("You entered \'%S\'"), &iInputBuffer);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   114
		switch ( iInputBuffer.Length() )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   115
			{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   116
		case 0:
93c0009bd947 201036_01
hgs
parents:
diff changeset
   117
			// Don't pass anything on- nothing to pass on.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   118
			break;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   119
93c0009bd947 201036_01
hgs
parents:
diff changeset
   120
		case 1:
93c0009bd947 201036_01
hgs
parents:
diff changeset
   121
			if ( 	iInputBuffer == _L8("S") 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   122
				||	iInputBuffer == _L8("s") 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   123
				)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   124
				{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   125
				StopCurrentTest();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   126
				}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   127
			else
93c0009bd947 201036_01
hgs
parents:
diff changeset
   128
				{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   129
				// Tell the test via the old 'single character' interface.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   130
				// If there is a test, then let it process the key. If there isn't a 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   131
				// test, we process it to (possibly) create and run a new test object.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   132
				if ( iTest )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   133
					{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   134
					TRAPD(err, iTest->ProcessKeyL((TKeyCode)iInputBuffer[0]));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   135
					if ( err )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   136
						{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   137
						Write(_L8("CTestBase::ProcessKeyL left with %d"), err);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   138
						StopCurrentTest();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   139
						}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   140
					}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   141
				else
93c0009bd947 201036_01
hgs
parents:
diff changeset
   142
					{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   143
					SelectTestL();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   144
					}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   145
				}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   146
			iInputBuffer = KNullDesC8();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   147
			break;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   148
		
93c0009bd947 201036_01
hgs
parents:
diff changeset
   149
		default:
93c0009bd947 201036_01
hgs
parents:
diff changeset
   150
			// Tell the test via the new 'multi character' interface.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   151
			// If there is a test, then let it process the key. If there isn't a 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   152
			// test, we process it to (possibly) create and run a new test object.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   153
			if ( iTest )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   154
				{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   155
				TRAPD(err, iTest->ProcessKeyL(iInputBuffer));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   156
				if ( err )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   157
					{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   158
					Write(_L8("CTestBase::ProcessKeyL left with %d"), err);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   159
					StopCurrentTest();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   160
					}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   161
				}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   162
			else
93c0009bd947 201036_01
hgs
parents:
diff changeset
   163
				{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   164
				SelectTestL();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   165
				}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   166
			iInputBuffer = KNullDesC8();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   167
			break;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   168
			}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   169
		DisplayMainMenu();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   170
		break;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   171
93c0009bd947 201036_01
hgs
parents:
diff changeset
   172
	default:
93c0009bd947 201036_01
hgs
parents:
diff changeset
   173
		iInputBuffer.Append(aKeyCode);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   174
		break;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   175
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   176
	OstTraceFunctionExit0( DUP1_CACTIVECONSOLE_DOACTIONKEYL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   177
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   178
93c0009bd947 201036_01
hgs
parents:
diff changeset
   179
void CActiveConsole::RequestCharacter()
93c0009bd947 201036_01
hgs
parents:
diff changeset
   180
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   181
	OstTraceFunctionEntry0( CACTIVECONSOLE_REQUESTCHARACTER_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   182
	iConsole.Read(iStatus);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   183
	SetActive();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   184
	OstTraceFunctionExit0( CACTIVECONSOLE_REQUESTCHARACTER_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   185
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   186
93c0009bd947 201036_01
hgs
parents:
diff changeset
   187
void CActiveConsole::DisplayMainMenu()
93c0009bd947 201036_01
hgs
parents:
diff changeset
   188
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   189
	OstTraceFunctionEntry0( CACTIVECONSOLE_DISPLAYMAINMENU_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   190
	Write(KNullDesC8);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   191
93c0009bd947 201036_01
hgs
parents:
diff changeset
   192
	// If there's a current test, display its step menu. Otherwise, display 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   193
	// all the available tests.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   194
	if ( iTest )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   195
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   196
		iTest->DisplayTestSpecificMenu();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   197
		Write(_L8("s - stop and close current test"));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   198
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   199
	else
93c0009bd947 201036_01
hgs
parents:
diff changeset
   200
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   201
		const TUint numberOfTests = sizeof(gTestDefinitions) / sizeof(TTestDefinition);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   202
		for ( TUint ii = 0 ; ii < numberOfTests ; ii ++ )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   203
			{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   204
			Write(_L8("%d - %S"), ii, &gTestDefinitions[ii].iDescription);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   205
			}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   206
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   207
93c0009bd947 201036_01
hgs
parents:
diff changeset
   208
	Write(_L8("Escape - exit program"));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   209
	Write(KNullDesC8);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   210
 	OstTraceFunctionExit0( CACTIVECONSOLE_DISPLAYMAINMENU_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   211
 	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   212
93c0009bd947 201036_01
hgs
parents:
diff changeset
   213
void CActiveConsole::Write(TRefByValue<const TDesC8> aFmt, ...)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   214
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   215
	OstTraceFunctionEntry0( CACTIVECONSOLE_WRITE_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   216
	VA_LIST list;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   217
	VA_START(list, aFmt);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   218
93c0009bd947 201036_01
hgs
parents:
diff changeset
   219
	TBuf8<0x100> buf;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   220
	buf.AppendFormatList(aFmt, list);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   221
	TBuf<0x100> wideBuf;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   222
	wideBuf.Copy(buf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   223
	iConsole.Write(wideBuf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   224
	iConsole.Write(_L("\n"));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   225
93c0009bd947 201036_01
hgs
parents:
diff changeset
   226
	RDebug::Print(wideBuf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   227
	OstTraceFunctionExit0( CACTIVECONSOLE_WRITE_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   228
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   229
93c0009bd947 201036_01
hgs
parents:
diff changeset
   230
void CActiveConsole::WriteNoReturn(TRefByValue<const TDesC8> aFmt, ...)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   231
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   232
	OstTraceFunctionEntry0( CACTIVECONSOLE_WRITENORETURN_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   233
	VA_LIST list;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   234
	VA_START(list, aFmt);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   235
93c0009bd947 201036_01
hgs
parents:
diff changeset
   236
	TBuf8<0x100> buf;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   237
	buf.AppendFormatList(aFmt, list);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   238
	TBuf<0x100> wideBuf;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   239
	wideBuf.Copy(buf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   240
	iConsole.Write(wideBuf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   241
93c0009bd947 201036_01
hgs
parents:
diff changeset
   242
	RDebug::Print(wideBuf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   243
	OstTraceFunctionExit0( CACTIVECONSOLE_WRITENORETURN_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   244
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   245
93c0009bd947 201036_01
hgs
parents:
diff changeset
   246
TKeyCode CActiveConsole::Getch()
93c0009bd947 201036_01
hgs
parents:
diff changeset
   247
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   248
	OstTraceFunctionEntry0( CACTIVECONSOLE_GETCH_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   249
	return iConsole.Getch();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   250
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   251
93c0009bd947 201036_01
hgs
parents:
diff changeset
   252
void CActiveConsole::SelectTestL()
93c0009bd947 201036_01
hgs
parents:
diff changeset
   253
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   254
	OstTraceFunctionEntry0( CACTIVECONSOLE_SELECTTESTL_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   255
	StopCurrentTest();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   256
93c0009bd947 201036_01
hgs
parents:
diff changeset
   257
	// Pick a test out of the global array of tests.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   258
	const TUint numberOfTests = sizeof(gTestDefinitions) / sizeof (TTestDefinition);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   259
	TLex8 lex(iInputBuffer);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   260
	TUint index;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   261
	TInt err = lex.Val(index);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   262
93c0009bd947 201036_01
hgs
parents:
diff changeset
   263
	if (	err == KErrNone
93c0009bd947 201036_01
hgs
parents:
diff changeset
   264
		&&	index < numberOfTests
93c0009bd947 201036_01
hgs
parents:
diff changeset
   265
		)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   266
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   267
		iTest = gTestDefinitions[index].iFactoryL(*this);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   268
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   269
	else
93c0009bd947 201036_01
hgs
parents:
diff changeset
   270
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   271
		Write(_L8("Unknown selection"));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   272
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   273
	OstTraceFunctionExit0( CACTIVECONSOLE_SELECTTESTL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   274
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   275
93c0009bd947 201036_01
hgs
parents:
diff changeset
   276
void CActiveConsole::TestFinished()
93c0009bd947 201036_01
hgs
parents:
diff changeset
   277
/**
93c0009bd947 201036_01
hgs
parents:
diff changeset
   278
 * Called by the test when it has finished. Results in the destruction of the 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   279
 * test.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   280
 */
93c0009bd947 201036_01
hgs
parents:
diff changeset
   281
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   282
	OstTraceFunctionEntry0( CACTIVECONSOLE_TESTFINISHED_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   283
	StopCurrentTest();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   284
	OstTraceFunctionExit0( CACTIVECONSOLE_TESTFINISHED_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   285
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   286
93c0009bd947 201036_01
hgs
parents:
diff changeset
   287
TInt CActiveConsole::RunError(TInt aError)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   288
/**
93c0009bd947 201036_01
hgs
parents:
diff changeset
   289
 * Called by the Active Scheduler when a RunL in this active object leaves.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   290
 */
93c0009bd947 201036_01
hgs
parents:
diff changeset
   291
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   292
	OstTraceFunctionEntry0( CACTIVECONSOLE_RUNERROR_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   293
	// This actually happens when a test object fails to construct properly.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   294
	Write(_L8("Error creating test object: %d"), aError);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   295
93c0009bd947 201036_01
hgs
parents:
diff changeset
   296
	iInputBuffer = KNullDesC8();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   297
	DisplayMainMenu();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   298
93c0009bd947 201036_01
hgs
parents:
diff changeset
   299
	// It's OK to carry on with the program itself, so repost asynchronous 
93c0009bd947 201036_01
hgs
parents:
diff changeset
   300
	// request.
93c0009bd947 201036_01
hgs
parents:
diff changeset
   301
	RequestCharacter();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   302
93c0009bd947 201036_01
hgs
parents:
diff changeset
   303
	OstTraceFunctionExit0( CACTIVECONSOLE_RUNERROR_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   304
	return KErrNone;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   305
	}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   306
93c0009bd947 201036_01
hgs
parents:
diff changeset
   307
void CActiveConsole::GetNumberL(TUint& aNumber)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   308
	{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   309
	OstTraceFunctionEntry0( CACTIVECONSOLE_GETNUMBERL_ENTRY );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   310
	TBuf<12> addrAsText;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   311
	addrAsText.Zero();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   312
	if ( aNumber != 0 )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   313
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   314
		addrAsText.Format(_L("%d"), aNumber);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   315
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   316
	WriteNoReturn(_L8("Enter a number: "));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   317
	if ( addrAsText.Length() > 0 )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   318
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   319
		TBuf8<100> narrowBuf;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   320
		narrowBuf.Copy(addrAsText);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   321
		WriteNoReturn(narrowBuf);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   322
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   323
	TKeyCode code;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   324
	TBuf<1> character;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   325
	FOREVER
93c0009bd947 201036_01
hgs
parents:
diff changeset
   326
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   327
		code = Getch();
93c0009bd947 201036_01
hgs
parents:
diff changeset
   328
		character.SetLength(0);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   329
		character.Append(code);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   330
	
93c0009bd947 201036_01
hgs
parents:
diff changeset
   331
		// If <CR> finish editing string
93c0009bd947 201036_01
hgs
parents:
diff changeset
   332
		if (code == 0x0d)
93c0009bd947 201036_01
hgs
parents:
diff changeset
   333
			break;
93c0009bd947 201036_01
hgs
parents:
diff changeset
   334
		
93c0009bd947 201036_01
hgs
parents:
diff changeset
   335
		// if <BS> remove last character
93c0009bd947 201036_01
hgs
parents:
diff changeset
   336
		if ((code == 0x08)&&(addrAsText.Length() != 0))
93c0009bd947 201036_01
hgs
parents:
diff changeset
   337
			{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   338
			WriteNoReturn(_L8("%S"),&character);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   339
			addrAsText.SetLength((addrAsText.Length()-1));
93c0009bd947 201036_01
hgs
parents:
diff changeset
   340
			}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   341
		else
93c0009bd947 201036_01
hgs
parents:
diff changeset
   342
			{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   343
			if (addrAsText.Length() < addrAsText.MaxLength())
93c0009bd947 201036_01
hgs
parents:
diff changeset
   344
				{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   345
				WriteNoReturn(_L8("%S"),&character);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   346
				addrAsText.Append(code);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   347
				}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   348
			}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   349
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   350
	//now extract the new address from the string...
93c0009bd947 201036_01
hgs
parents:
diff changeset
   351
	if( !addrAsText.Length() )
93c0009bd947 201036_01
hgs
parents:
diff changeset
   352
		{
93c0009bd947 201036_01
hgs
parents:
diff changeset
   353
		addrAsText.Append('0'); //null string causes TLex::Val to return an error
93c0009bd947 201036_01
hgs
parents:
diff changeset
   354
		}
93c0009bd947 201036_01
hgs
parents:
diff changeset
   355
	TLex lex(addrAsText);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   356
	TInt err = lex.Val(aNumber, EDecimal);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   357
	User::LeaveIfError(err);
93c0009bd947 201036_01
hgs
parents:
diff changeset
   358
	OstTraceFunctionExit0( CACTIVECONSOLE_GETNUMBERL_EXIT );
93c0009bd947 201036_01
hgs
parents:
diff changeset
   359
	}