|
1 // Copyright (c) 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 "activecallbackconsole.h" |
|
17 |
|
18 CActiveCallBackConsole::CActiveCallBackConsole(TInt(*aFunction)(TAny *aPtr, TChar aKey), TAny* aPtr) |
|
19 : CActive(EPriorityStandard), iFunction(aFunction), iPtr(aPtr) |
|
20 { |
|
21 CActiveScheduler::Add(this); |
|
22 } |
|
23 |
|
24 |
|
25 CActiveCallBackConsole::~CActiveCallBackConsole() |
|
26 { |
|
27 Cancel(); |
|
28 delete iConsole; |
|
29 } |
|
30 |
|
31 CActiveCallBackConsole* CActiveCallBackConsole::NewL(TInt(*aFunction)(TAny *aPtr, TChar aKey), TAny* aPtr, const TDesC& aTitle,const TSize& aSize) |
|
32 { |
|
33 CActiveCallBackConsole* console = new (ELeave) CActiveCallBackConsole(aFunction, aPtr); |
|
34 CleanupStack::PushL(console); |
|
35 console->ConstructL(aTitle,aSize); |
|
36 CleanupStack::Pop(); |
|
37 return console; |
|
38 } |
|
39 |
|
40 void CActiveCallBackConsole::ConstructL(const TDesC& aTitle,const TSize& aSize) |
|
41 { |
|
42 iConsole = Console::NewL(aTitle,aSize); |
|
43 } |
|
44 |
|
45 void CActiveCallBackConsole::DoCancel() |
|
46 { |
|
47 iConsole->ReadCancel(); |
|
48 } |
|
49 |
|
50 void CActiveCallBackConsole::RequestKey() |
|
51 { |
|
52 DrawCursor(); |
|
53 iConsole->Read(iStatus); |
|
54 SetActive(); |
|
55 } |
|
56 |
|
57 void CActiveCallBackConsole::DrawCursor() |
|
58 { |
|
59 iConsole->Printf(_L(">>")); |
|
60 } |
|
61 |
|
62 void CActiveCallBackConsole::RunL() |
|
63 { |
|
64 // key has been pressed |
|
65 TChar ch = iConsole->KeyCode(); |
|
66 (*iFunction)(iPtr, ch); |
|
67 } |
|
68 |
|
69 TInt CActiveCallBackConsole::RunError(TInt aError) |
|
70 { |
|
71 iConsole->Printf(_L("Console error %d\nTrying again...\n"), aError); |
|
72 RequestKey(); |
|
73 return KErrNone; |
|
74 } |