os/kernelhwsrv/kernel/eka/euser/cbase/ub_cons.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1995-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 the License "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
// e32\euser\cbase\ub_cons.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "ub_std.h"
sl@0
    19
#include <e32uid.h>
sl@0
    20
#include <e32wins.h>
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
/**
sl@0
    25
Default constructor.
sl@0
    26
*/
sl@0
    27
EXPORT_C CConsoleBase::CConsoleBase()
sl@0
    28
	{
sl@0
    29
	}
sl@0
    30
sl@0
    31
sl@0
    32
sl@0
    33
/**
sl@0
    34
Destructor.
sl@0
    35
*/
sl@0
    36
EXPORT_C CConsoleBase::~CConsoleBase()
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
sl@0
    41
sl@0
    42
sl@0
    43
/**
sl@0
    44
Gets a character from the console.
sl@0
    45
sl@0
    46
@return the key code from the console.
sl@0
    47
*/
sl@0
    48
EXPORT_C TKeyCode CConsoleBase::Getch()
sl@0
    49
	{
sl@0
    50
sl@0
    51
	TRequestStatus s;
sl@0
    52
	Read(s);
sl@0
    53
	User::WaitForRequest(s);
sl@0
    54
	__ASSERT_ALWAYS(s==KErrNone,Panic(EConsGetchFailed));
sl@0
    55
	return(KeyCode());
sl@0
    56
	}
sl@0
    57
sl@0
    58
sl@0
    59
sl@0
    60
sl@0
    61
/**
sl@0
    62
Prints characters to the console window.
sl@0
    63
sl@0
    64
@param aFmt             The  non-modifiable descriptor containing the
sl@0
    65
                        format string. The TRefByValue class provides a
sl@0
    66
                        constructor which takes a TDesC type. 
sl@0
    67
sl@0
    68
@param ...              A variable number of arguments to be converted to text
sl@0
    69
                        as dictated by the format string. 
sl@0
    70
*/
sl@0
    71
EXPORT_C void CConsoleBase::Printf(TRefByValue<const TDesC> aFmt,...)
sl@0
    72
	{
sl@0
    73
sl@0
    74
	TestOverflowTruncate overflow;
sl@0
    75
	// coverity[var_decl]
sl@0
    76
	VA_LIST list;
sl@0
    77
	VA_START(list,aFmt);
sl@0
    78
	TBuf<0x100> aBuf;
sl@0
    79
	// coverity[uninit_use_in_call]
sl@0
    80
	TRAP_IGNORE(aBuf.AppendFormatList(aFmt,list,&overflow)); // ignore leave in TTimeOverflowLeave::Overflow()
sl@0
    81
	Write(aBuf);
sl@0
    82
	}
sl@0
    83
sl@0
    84
sl@0
    85
sl@0
    86
/**
sl@0
    87
Sets the cursor's x-position.
sl@0
    88
sl@0
    89
@param aX The x-position.
sl@0
    90
*/
sl@0
    91
EXPORT_C void CConsoleBase::SetPos(TInt aX)
sl@0
    92
	{
sl@0
    93
sl@0
    94
	SetCursorPosAbs(TPoint(aX,WhereY()));
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
sl@0
    99
sl@0
   100
/**
sl@0
   101
Sets the cursor's x-position and y-position.
sl@0
   102
sl@0
   103
@param aX The x-position.
sl@0
   104
@param aY The y-position.
sl@0
   105
*/
sl@0
   106
EXPORT_C void CConsoleBase::SetPos(TInt aX,TInt aY)
sl@0
   107
	{
sl@0
   108
sl@0
   109
	SetCursorPosAbs(TPoint(aX,aY));
sl@0
   110
	}
sl@0
   111
sl@0
   112
sl@0
   113
sl@0
   114
sl@0
   115
/**
sl@0
   116
Gets the cursor's x-position.
sl@0
   117
sl@0
   118
@return The cursor's x-position.
sl@0
   119
*/
sl@0
   120
EXPORT_C TInt CConsoleBase::WhereX() const
sl@0
   121
	{
sl@0
   122
sl@0
   123
	return(CursorPos().iX);
sl@0
   124
	}
sl@0
   125
sl@0
   126
sl@0
   127
sl@0
   128
/**
sl@0
   129
Gets the cursor's y-position.
sl@0
   130
sl@0
   131
@return The cursor's y-position.
sl@0
   132
*/
sl@0
   133
EXPORT_C TInt CConsoleBase::WhereY() const
sl@0
   134
	{
sl@0
   135
sl@0
   136
	return(CursorPos().iY);
sl@0
   137
	}
sl@0
   138
sl@0
   139
sl@0
   140
/**
sl@0
   141
Extension function
sl@0
   142
sl@0
   143
sl@0
   144
*/
sl@0
   145
EXPORT_C TInt CConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
sl@0
   146
	{
sl@0
   147
	return CBase::Extension_(aExtensionId, a0, a1);
sl@0
   148
	}
sl@0
   149
sl@0
   150
sl@0
   151
void CColorConsoleBase::SetTextAttribute(TTextAttribute /*anAttribute*/)
sl@0
   152
//
sl@0
   153
//
sl@0
   154
//
sl@0
   155
	{
sl@0
   156
	}
sl@0
   157
sl@0
   158
sl@0
   159
/**
sl@0
   160
Extension function
sl@0
   161
sl@0
   162
sl@0
   163
*/
sl@0
   164
EXPORT_C TInt CColorConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
sl@0
   165
	{
sl@0
   166
	return CConsoleBase::Extension_(aExtensionId, a0, a1);
sl@0
   167
	}
sl@0
   168
sl@0
   169
sl@0
   170
NONSHARABLE_CLASS(CProxyConsole) : public CColorConsoleBase
sl@0
   171
	{
sl@0
   172
public:
sl@0
   173
	~CProxyConsole();
sl@0
   174
	TInt Construct(const TDesC& aImplDll);
sl@0
   175
public:
sl@0
   176
// implement for CConsoleBase
sl@0
   177
	TInt Create(const TDesC &aTitle,TSize aSize);
sl@0
   178
	void Read(TRequestStatus &aStatus);
sl@0
   179
	void ReadCancel();
sl@0
   180
	void Write(const TDesC &aDes);
sl@0
   181
	TPoint CursorPos() const;
sl@0
   182
	void SetCursorPosAbs(const TPoint &aPoint);
sl@0
   183
	void SetCursorPosRel(const TPoint &aPoint);
sl@0
   184
	void SetCursorHeight(TInt aPercentage);
sl@0
   185
	void SetTitle(const TDesC &aTitle);
sl@0
   186
	void ClearScreen();
sl@0
   187
	void ClearToEndOfLine();
sl@0
   188
	TSize ScreenSize() const;
sl@0
   189
	TKeyCode KeyCode() const;
sl@0
   190
	TUint KeyModifiers() const;
sl@0
   191
// implement for CColorConsoleBase
sl@0
   192
	void SetTextAttribute(TTextAttribute anAttribute); 
sl@0
   193
	virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
sl@0
   194
private:
sl@0
   195
	RLibrary iLib;
sl@0
   196
	CColorConsoleBase* iConsole;
sl@0
   197
	};
sl@0
   198
sl@0
   199
TInt CProxyConsole::Construct(const TDesC& aImplDll)
sl@0
   200
	{
sl@0
   201
	const TUidType type(KNullUid, KSharedLibraryUid, KConsoleDllUid);
sl@0
   202
	TInt r=iLib.Load(aImplDll,type);
sl@0
   203
	if (r==KErrNone)
sl@0
   204
		{
sl@0
   205
		iConsole=(CColorConsoleBase*)(iLib.Lookup(1)());
sl@0
   206
		if (!iConsole)
sl@0
   207
			r=KErrNoMemory;
sl@0
   208
		}
sl@0
   209
	return r;
sl@0
   210
	}
sl@0
   211
sl@0
   212
CProxyConsole::~CProxyConsole()
sl@0
   213
	{
sl@0
   214
	delete iConsole;
sl@0
   215
	iLib.Close();
sl@0
   216
	}
sl@0
   217
sl@0
   218
TInt CProxyConsole::Create(const TDesC &aTitle,TSize aSize)
sl@0
   219
	{
sl@0
   220
	return iConsole->Create(aTitle,aSize);
sl@0
   221
	}
sl@0
   222
	
sl@0
   223
void CProxyConsole::Read(TRequestStatus &aStatus)
sl@0
   224
	{
sl@0
   225
	iConsole->Read(aStatus);
sl@0
   226
	}
sl@0
   227
	
sl@0
   228
void CProxyConsole::ReadCancel()
sl@0
   229
	{
sl@0
   230
	iConsole->ReadCancel();
sl@0
   231
	}
sl@0
   232
	
sl@0
   233
void CProxyConsole::Write(const TDesC &aDes)
sl@0
   234
	{
sl@0
   235
	iConsole->Write(aDes);
sl@0
   236
	}
sl@0
   237
	
sl@0
   238
TPoint CProxyConsole::CursorPos() const
sl@0
   239
	{
sl@0
   240
	return iConsole->CursorPos();
sl@0
   241
	}
sl@0
   242
	
sl@0
   243
void CProxyConsole::SetCursorPosAbs(const TPoint &aPoint)
sl@0
   244
	{
sl@0
   245
	iConsole->SetCursorPosAbs(aPoint);
sl@0
   246
	}
sl@0
   247
	
sl@0
   248
void CProxyConsole::SetCursorPosRel(const TPoint &aPoint)
sl@0
   249
	{
sl@0
   250
	iConsole->SetCursorPosRel(aPoint);
sl@0
   251
	}
sl@0
   252
	
sl@0
   253
void CProxyConsole::SetCursorHeight(TInt aPercentage)
sl@0
   254
	{
sl@0
   255
	iConsole->SetCursorHeight(aPercentage);
sl@0
   256
	}
sl@0
   257
	
sl@0
   258
void CProxyConsole::SetTitle(const TDesC &aTitle)
sl@0
   259
	{
sl@0
   260
	iConsole->SetTitle(aTitle);
sl@0
   261
	}
sl@0
   262
	
sl@0
   263
void CProxyConsole::ClearScreen()
sl@0
   264
	{
sl@0
   265
	iConsole->ClearScreen();
sl@0
   266
	}
sl@0
   267
	
sl@0
   268
void CProxyConsole::ClearToEndOfLine()
sl@0
   269
	{
sl@0
   270
	iConsole->ClearToEndOfLine();
sl@0
   271
	}
sl@0
   272
	
sl@0
   273
TSize CProxyConsole::ScreenSize() const
sl@0
   274
	{
sl@0
   275
	return iConsole->ScreenSize();
sl@0
   276
	}
sl@0
   277
	
sl@0
   278
TKeyCode CProxyConsole::KeyCode() const
sl@0
   279
	{
sl@0
   280
	return iConsole->KeyCode();
sl@0
   281
	}
sl@0
   282
	
sl@0
   283
TUint CProxyConsole::KeyModifiers() const
sl@0
   284
	{
sl@0
   285
	return iConsole->KeyModifiers();
sl@0
   286
	}
sl@0
   287
	
sl@0
   288
void CProxyConsole::SetTextAttribute(TTextAttribute anAttribute)
sl@0
   289
	{
sl@0
   290
	iConsole->SetTextAttribute(anAttribute);
sl@0
   291
	}
sl@0
   292
sl@0
   293
TInt CProxyConsole::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
sl@0
   294
	{
sl@0
   295
	return iConsole->Extension_(aExtensionId, a0, a1);
sl@0
   296
	}
sl@0
   297
sl@0
   298
sl@0
   299
_LIT(KConsImpl,"econs");
sl@0
   300
#ifdef __WINS__
sl@0
   301
_LIT(KConsGuiImpl,"econseik");
sl@0
   302
_LIT(KConsNoGuiImpl,"econsnogui");
sl@0
   303
_LIT(KConsWservImpl, "econswserv");
sl@0
   304
#endif
sl@0
   305
sl@0
   306
sl@0
   307
sl@0
   308
/**
sl@0
   309
Creates a new console object.
sl@0
   310
sl@0
   311
@param aTitle The title text for the console.
sl@0
   312
              This should not be longer than 256 characters.
sl@0
   313
@param aSize  The size of the console window.
sl@0
   314
sl@0
   315
@return A pointer to the new console object.
sl@0
   316
sl@0
   317
@see CConsoleBase::Create() 
sl@0
   318
*/
sl@0
   319
EXPORT_C CConsoleBase *Console::NewL(const TDesC &aTitle,TSize aSize)
sl@0
   320
	{
sl@0
   321
	CProxyConsole *pC=new(ELeave) CProxyConsole;
sl@0
   322
	TInt r=pC->Construct(KConsImpl);
sl@0
   323
	if (r==KErrNone)
sl@0
   324
		r=pC->Create(aTitle,aSize);
sl@0
   325
#ifdef __WINS__
sl@0
   326
	if (r!=KErrNone)
sl@0
   327
		{
sl@0
   328
		delete pC;
sl@0
   329
		pC=new(ELeave) CProxyConsole;
sl@0
   330
		if (EmulatorNoGui())
sl@0
   331
			{
sl@0
   332
			// try and create a dummy console via ECONSNOGUI
sl@0
   333
			r=pC->Construct(KConsNoGuiImpl);
sl@0
   334
			}
sl@0
   335
		else if (EmulatorMiniGui())
sl@0
   336
			{
sl@0
   337
			// try and create Wserv console via ECONSWSERV
sl@0
   338
			r=pC->Construct(KConsWservImpl);
sl@0
   339
			}
sl@0
   340
		else
sl@0
   341
			{
sl@0
   342
			// try and create a GUI console via ECONSEIK instead
sl@0
   343
			r=pC->Construct(KConsGuiImpl);
sl@0
   344
			}
sl@0
   345
		if (r==KErrNone)
sl@0
   346
			r=pC->Create(aTitle,aSize);
sl@0
   347
		}
sl@0
   348
#endif
sl@0
   349
	if (r!=KErrNone)
sl@0
   350
		{
sl@0
   351
		delete pC;
sl@0
   352
		User::Leave(r);
sl@0
   353
		}
sl@0
   354
	return(pC);
sl@0
   355
	}