First public contribution.
1 // Copyright (c) 1997-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Simple implementation of stdin/stdout/stderr class which uses a console, created on demand.
19 #include <e32cons.h> // for CConsoleBase
20 #include <sys/ioctl.h>
22 void CTtyDesc::CheckConsoleCreated()
26 TRAPD(r,iConsole=Console::NewL(_L("STDOUT"),TSize(KConsFullScreen,KConsFullScreen)))
27 __ASSERT_ALWAYS(r==KErrNone,User::Panic(_L("ESTLIB Console"),0));
33 CConsoleBase *it = iConsole;
38 TInt CTtyDesc::FinalClose()
40 CConsoleBase *it = iConsole;
44 // it->SetTitle(_L("Console closed - press any key"));
45 it->Printf(_L("Console closed - press any key"));
52 void CTtyDesc::Read(TDes8& /*aDesc*/, TRequestStatus& aStatus)
54 CheckConsoleCreated();
55 // See implemention of Getch() in E32\UBAS\UB_CONS.CPP
56 iConsole->Read(aStatus);
59 void CTtyDesc::ReadCancel()
62 iConsole->ReadCancel();
65 TInt CTtyDesc::ReadCompletion(TDes8& aDesc, TInt aStatus)
67 MapCodeAndEcho(aDesc, iConsole->KeyCode());
71 void CTtyDesc::Write(TDes8 &aDesc, TRequestStatus& aStatus)
74 Complete(aStatus, KErrNone);
77 #if !defined(_UNICODE)
78 void CTtyDesc::Write(TDes8 &aDesc)
80 CheckConsoleCreated();
81 iConsole->Write(aDesc);
84 void CTtyDesc::Write(TDes8 &aDesc)
86 CheckConsoleCreated();
88 TInt remaining = aDesc.Length();
89 const TText8* cp = aDesc.Ptr();
93 TInt len = Min(remaining, 256);
94 buffer.Copy(TPtrC8(cp, len));
96 iConsole->Write(buffer);
104 void CTtyDesc::MapCodeAndEcho(TDes8& aDesc, TKeyCode aCode)
111 case EKeyPrintScreen:
112 return; // unknowable keycodes are ignored
119 ch=(TText8)(aCode&0xff); // who knows - it's not documented
123 // Could suppress echoing at this point
128 void CTtyDesc::Ioctl(int /*aCmd*/, void* /*aParam*/, TRequestStatus& aStatus)
130 // bodge for now - this will become more complicated if we develop a better
131 // terminal device implementation
132 Complete(aStatus,KErrNone);
135 TInt CTtyDesc::IoctlCompletion(int aCmd, void* aParam, TInt aStatus)
140 int *param=REINTERPRET_CAST(int*,aParam);
144 *param=1; // claim that there is always data available
147 *param=(*param)&(E32SELECT_READ|E32SELECT_WRITE);
150 ret=KErrNotSupported;