sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "consoleprint.h"
|
sl@0
|
17 |
|
sl@0
|
18 |
//
|
sl@0
|
19 |
// static factory method
|
sl@0
|
20 |
//
|
sl@0
|
21 |
CConsolePrint* CConsolePrint::NewL(TBool aWaitForAck)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
CConsolePrint* self = new(ELeave) CConsolePrint(aWaitForAck);
|
sl@0
|
24 |
CleanupStack::PushL(self);
|
sl@0
|
25 |
self->ConstructL();
|
sl@0
|
26 |
CleanupStack::Pop(self);
|
sl@0
|
27 |
return self;
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
//
|
sl@0
|
31 |
// Constructor
|
sl@0
|
32 |
//
|
sl@0
|
33 |
CConsolePrint::CConsolePrint(TBool aWaitForAck)
|
sl@0
|
34 |
: iWaitForAck(aWaitForAck)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
//
|
sl@0
|
39 |
// Two phase construct method
|
sl@0
|
40 |
//
|
sl@0
|
41 |
void CConsolePrint::ConstructL()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
iConsole = Console::NewL(KNullDesC, TSize(KConsFullScreen, KConsFullScreen));
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
CConsolePrint::~CConsolePrint()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
delete iConsole;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
// setter
|
sl@0
|
52 |
void CConsolePrint::SetWaitMode(TBool aWaitForAck)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
if (iWaitForAck != aWaitForAck)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
iWaitForAck = aWaitForAck;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
// dummy class to toss away overflow
|
sl@0
|
61 |
class TTruncateOverflow16 : public TDes16Overflow
|
sl@0
|
62 |
{
|
sl@0
|
63 |
public:
|
sl@0
|
64 |
virtual void Overflow(TDes&) { }
|
sl@0
|
65 |
};
|
sl@0
|
66 |
|
sl@0
|
67 |
//
|
sl@0
|
68 |
// Output a message to console
|
sl@0
|
69 |
void CConsolePrint::Printf(TRefByValue<const TDesC> aFmt, ...)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
VA_LIST vaList;
|
sl@0
|
72 |
VA_START(vaList, aFmt);
|
sl@0
|
73 |
|
sl@0
|
74 |
TTruncateOverflow16 overflow;
|
sl@0
|
75 |
iBuf.Zero();
|
sl@0
|
76 |
iBuf.AppendFormatList(aFmt, vaList, &overflow);
|
sl@0
|
77 |
iConsole->Write(iBuf);
|
sl@0
|
78 |
if (iWaitForAck)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
_LIT(KPressAKey, "\r\n[press a key to continue...]\r\n");
|
sl@0
|
81 |
iConsole->Write(KPressAKey);
|
sl@0
|
82 |
WaitForUserAck();
|
sl@0
|
83 |
}
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
// Wait for either a hit stroke or timeout.
|
sl@0
|
87 |
void CConsolePrint::WaitForUserAck()
|
sl@0
|
88 |
{
|
sl@0
|
89 |
TRequestStatus timerStatus, consoleStatus;
|
sl@0
|
90 |
RTimer timer;
|
sl@0
|
91 |
timer.CreateLocal();
|
sl@0
|
92 |
TTimeIntervalMicroSeconds32 interval = KTimeToWait;
|
sl@0
|
93 |
|
sl@0
|
94 |
iConsole->Read(consoleStatus);
|
sl@0
|
95 |
timer.After(timerStatus, interval);
|
sl@0
|
96 |
User::WaitForRequest(consoleStatus, timerStatus);
|
sl@0
|
97 |
|
sl@0
|
98 |
if (consoleStatus == KRequestPending)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
iConsole->ReadCancel();
|
sl@0
|
101 |
}
|
sl@0
|
102 |
else
|
sl@0
|
103 |
{
|
sl@0
|
104 |
timer.Cancel();
|
sl@0
|
105 |
User::WaitForRequest(timerStatus);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
}
|