os/persistentdata/persistentstorage/centralrepository/convtool/src/consoleprint.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/centralrepository/convtool/src/consoleprint.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,107 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "consoleprint.h"
1.20 +
1.21 +//
1.22 +// static factory method
1.23 +//
1.24 +CConsolePrint* CConsolePrint::NewL(TBool aWaitForAck)
1.25 + {
1.26 + CConsolePrint* self = new(ELeave) CConsolePrint(aWaitForAck);
1.27 + CleanupStack::PushL(self);
1.28 + self->ConstructL();
1.29 + CleanupStack::Pop(self);
1.30 + return self;
1.31 + }
1.32 +
1.33 +//
1.34 +// Constructor
1.35 +//
1.36 +CConsolePrint::CConsolePrint(TBool aWaitForAck)
1.37 + : iWaitForAck(aWaitForAck)
1.38 + {
1.39 + }
1.40 +
1.41 +//
1.42 +// Two phase construct method
1.43 +//
1.44 +void CConsolePrint::ConstructL()
1.45 + {
1.46 + iConsole = Console::NewL(KNullDesC, TSize(KConsFullScreen, KConsFullScreen));
1.47 + }
1.48 +
1.49 +CConsolePrint::~CConsolePrint()
1.50 + {
1.51 + delete iConsole;
1.52 + }
1.53 +
1.54 +// setter
1.55 +void CConsolePrint::SetWaitMode(TBool aWaitForAck)
1.56 + {
1.57 + if (iWaitForAck != aWaitForAck)
1.58 + {
1.59 + iWaitForAck = aWaitForAck;
1.60 + }
1.61 + }
1.62 +
1.63 +// dummy class to toss away overflow
1.64 +class TTruncateOverflow16 : public TDes16Overflow
1.65 + {
1.66 +public:
1.67 + virtual void Overflow(TDes&) { }
1.68 + };
1.69 +
1.70 +//
1.71 +// Output a message to console
1.72 +void CConsolePrint::Printf(TRefByValue<const TDesC> aFmt, ...)
1.73 + {
1.74 + VA_LIST vaList;
1.75 + VA_START(vaList, aFmt);
1.76 +
1.77 + TTruncateOverflow16 overflow;
1.78 + iBuf.Zero();
1.79 + iBuf.AppendFormatList(aFmt, vaList, &overflow);
1.80 + iConsole->Write(iBuf);
1.81 + if (iWaitForAck)
1.82 + {
1.83 + _LIT(KPressAKey, "\r\n[press a key to continue...]\r\n");
1.84 + iConsole->Write(KPressAKey);
1.85 + WaitForUserAck();
1.86 + }
1.87 + }
1.88 +
1.89 +// Wait for either a hit stroke or timeout.
1.90 +void CConsolePrint::WaitForUserAck()
1.91 + {
1.92 + TRequestStatus timerStatus, consoleStatus;
1.93 + RTimer timer;
1.94 + timer.CreateLocal();
1.95 + TTimeIntervalMicroSeconds32 interval = KTimeToWait;
1.96 +
1.97 + iConsole->Read(consoleStatus);
1.98 + timer.After(timerStatus, interval);
1.99 + User::WaitForRequest(consoleStatus, timerStatus);
1.100 +
1.101 + if (consoleStatus == KRequestPending)
1.102 + {
1.103 + iConsole->ReadCancel();
1.104 + }
1.105 + else
1.106 + {
1.107 + timer.Cancel();
1.108 + User::WaitForRequest(timerStatus);
1.109 + }
1.110 + }