sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "consoleprint.h" sl@0: sl@0: // sl@0: // static factory method sl@0: // sl@0: CConsolePrint* CConsolePrint::NewL(TBool aWaitForAck) sl@0: { sl@0: CConsolePrint* self = new(ELeave) CConsolePrint(aWaitForAck); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: // sl@0: // Constructor sl@0: // sl@0: CConsolePrint::CConsolePrint(TBool aWaitForAck) sl@0: : iWaitForAck(aWaitForAck) sl@0: { sl@0: } sl@0: sl@0: // sl@0: // Two phase construct method sl@0: // sl@0: void CConsolePrint::ConstructL() sl@0: { sl@0: iConsole = Console::NewL(KNullDesC, TSize(KConsFullScreen, KConsFullScreen)); sl@0: } sl@0: sl@0: CConsolePrint::~CConsolePrint() sl@0: { sl@0: delete iConsole; sl@0: } sl@0: sl@0: // setter sl@0: void CConsolePrint::SetWaitMode(TBool aWaitForAck) sl@0: { sl@0: if (iWaitForAck != aWaitForAck) sl@0: { sl@0: iWaitForAck = aWaitForAck; sl@0: } sl@0: } sl@0: sl@0: // dummy class to toss away overflow sl@0: class TTruncateOverflow16 : public TDes16Overflow sl@0: { sl@0: public: sl@0: virtual void Overflow(TDes&) { } sl@0: }; sl@0: sl@0: // sl@0: // Output a message to console sl@0: void CConsolePrint::Printf(TRefByValue aFmt, ...) sl@0: { sl@0: VA_LIST vaList; sl@0: VA_START(vaList, aFmt); sl@0: sl@0: TTruncateOverflow16 overflow; sl@0: iBuf.Zero(); sl@0: iBuf.AppendFormatList(aFmt, vaList, &overflow); sl@0: iConsole->Write(iBuf); sl@0: if (iWaitForAck) sl@0: { sl@0: _LIT(KPressAKey, "\r\n[press a key to continue...]\r\n"); sl@0: iConsole->Write(KPressAKey); sl@0: WaitForUserAck(); sl@0: } sl@0: } sl@0: sl@0: // Wait for either a hit stroke or timeout. sl@0: void CConsolePrint::WaitForUserAck() sl@0: { sl@0: TRequestStatus timerStatus, consoleStatus; sl@0: RTimer timer; sl@0: timer.CreateLocal(); sl@0: TTimeIntervalMicroSeconds32 interval = KTimeToWait; sl@0: sl@0: iConsole->Read(consoleStatus); sl@0: timer.After(timerStatus, interval); sl@0: User::WaitForRequest(consoleStatus, timerStatus); sl@0: sl@0: if (consoleStatus == KRequestPending) sl@0: { sl@0: iConsole->ReadCancel(); sl@0: } sl@0: else sl@0: { sl@0: timer.Cancel(); sl@0: User::WaitForRequest(timerStatus); sl@0: } sl@0: }