persistentstorage/centralrepository/convtool/src/consoleprint.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-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 "consoleprint.h"
       
    17 
       
    18 //
       
    19 // static factory method
       
    20 //
       
    21 CConsolePrint* CConsolePrint::NewL(TBool aWaitForAck)
       
    22 	{
       
    23 	CConsolePrint* self = new(ELeave) CConsolePrint(aWaitForAck);
       
    24 	CleanupStack::PushL(self);
       
    25 	self->ConstructL();
       
    26 	CleanupStack::Pop(self);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 //
       
    31 // Constructor
       
    32 //
       
    33 CConsolePrint::CConsolePrint(TBool aWaitForAck)
       
    34 	: iWaitForAck(aWaitForAck)
       
    35 	{
       
    36 	}
       
    37 
       
    38 //
       
    39 // Two phase construct method
       
    40 //
       
    41 void CConsolePrint::ConstructL()
       
    42 	{
       
    43 	iConsole = Console::NewL(KNullDesC, TSize(KConsFullScreen, KConsFullScreen));
       
    44 	}
       
    45 
       
    46 CConsolePrint::~CConsolePrint()
       
    47 	{
       
    48 	delete iConsole;
       
    49 	}
       
    50 
       
    51 // setter
       
    52 void CConsolePrint::SetWaitMode(TBool aWaitForAck)
       
    53 	{
       
    54 	if (iWaitForAck != aWaitForAck)
       
    55 		{
       
    56 		iWaitForAck = aWaitForAck;
       
    57 		}
       
    58 	}
       
    59 
       
    60 // dummy class to toss away overflow
       
    61 class TTruncateOverflow16 : public TDes16Overflow
       
    62     {
       
    63 public:
       
    64     virtual void Overflow(TDes&) { }
       
    65 	};
       
    66 
       
    67 //
       
    68 // Output a message to console
       
    69 void CConsolePrint::Printf(TRefByValue<const TDesC> aFmt, ...)
       
    70 	{
       
    71 	VA_LIST vaList;
       
    72 	VA_START(vaList, aFmt);
       
    73 
       
    74 	TTruncateOverflow16 overflow;
       
    75 	iBuf.Zero();
       
    76 	iBuf.AppendFormatList(aFmt, vaList, &overflow);
       
    77 	iConsole->Write(iBuf);
       
    78 	if (iWaitForAck)
       
    79 		{
       
    80 		_LIT(KPressAKey, "\r\n[press a key to continue...]\r\n");
       
    81 		iConsole->Write(KPressAKey);
       
    82 		WaitForUserAck();
       
    83 		}
       
    84 	}
       
    85 
       
    86 // Wait for either a hit stroke or timeout.
       
    87 void CConsolePrint::WaitForUserAck()
       
    88 	{
       
    89 	TRequestStatus timerStatus, consoleStatus;
       
    90 	RTimer timer;
       
    91 	timer.CreateLocal();
       
    92 	TTimeIntervalMicroSeconds32 interval = KTimeToWait;
       
    93 
       
    94 	iConsole->Read(consoleStatus);
       
    95 	timer.After(timerStatus, interval);
       
    96 	User::WaitForRequest(consoleStatus, timerStatus);
       
    97 
       
    98 	if (consoleStatus == KRequestPending)
       
    99 		{
       
   100 		iConsole->ReadCancel();
       
   101 		}
       
   102 	else
       
   103 		{
       
   104 		timer.Cancel();
       
   105 		User::WaitForRequest(timerStatus);
       
   106 		}
       
   107 	}