Refactored CVtcConsoleBase::Message() into separate helper for use by non-VT100 consoles
authorTom Sutcliffe <thomas.sutcliffe@accenture.com>
Thu, 12 Aug 2010 16:38:42 +0100
changeset 30 35cb3fe43f60
parent 29 9a2198517f48
child 31 d0e1c40de386
Refactored CVtcConsoleBase::Message() into separate helper for use by non-VT100 consoles
build/common/common.mmh
commands/grabscreen/grabscreen.cpp
plugins/consoles/common/bld.inf
plugins/consoles/common/bwins/consoleextensions.def
plugins/consoles/common/consoleextensions.cpp
plugins/consoles/common/consoleextensions.h
plugins/consoles/common/consoleextensions.mmp
plugins/consoles/common/eabi/consoleextensions.def
plugins/consoles/vt100cons/bwins/vt100u.def
plugins/consoles/vt100cons/eabi/vt100u.def
plugins/consoles/vt100cons/group/vt100.mmp
plugins/consoles/vt100cons/group/vt100btcons.mmp
plugins/consoles/vt100cons/group/vt100busdevcons.mmp
plugins/consoles/vt100cons/group/vt100cons.mmp
plugins/consoles/vt100cons/group/vt100serial.mmp
plugins/consoles/vt100cons/group/vt100tcpcons.mmp
plugins/consoles/vt100cons/group/vt100usbcons.mmp
plugins/consoles/vt100cons/inc/vtc_base.h
plugins/consoles/vt100cons/src/tcp/vtc_tcp.cpp
plugins/consoles/vt100cons/src/vt100/vtc_base.cpp
plugins/consoles/win32cons/group/win32cons.mmp
plugins/consoles/win32cons/src/console.cpp
plugins/consoles/win32cons/src/console.h
--- a/build/common/common.mmh	Wed Aug 11 12:57:25 2010 +0100
+++ b/build/common/common.mmh	Thu Aug 12 16:38:42 2010 +0100
@@ -523,6 +523,7 @@
 #define FSHELL_UID_MEMSPY                     0x10286F70
 #define FSHELL_UID_EXTRABTRACEK               0x10286F71
 #define FSHELL_UID_TESTEXECUTE                0x10286F72
+#define FSHELL_UID_CONSOLEEXTENSIONS          0x10286F73
 
 #else // Not FSHELL_PROTECTED_UIDS
 
@@ -654,6 +655,7 @@
 #define FSHELL_UID_MEMSPY                     0xE0286F70
 #define FSHELL_UID_EXTRABTRACEK               0xE0286F71
 #define FSHELL_UID_TESTEXECUTE                0xE0286F72
+#define FSHELL_UID_CONSOLEEXTENSIONS          0xE0286F73
 
 #endif // FSHELL_PROTECTED_UIDS
 
--- a/commands/grabscreen/grabscreen.cpp	Wed Aug 11 12:57:25 2010 +0100
+++ b/commands/grabscreen/grabscreen.cpp	Thu Aug 12 16:38:42 2010 +0100
@@ -166,8 +166,8 @@
 		CleanupStack::PushL(imageData);
 		imageData->iSampleScheme = iGreyscale ? TJpegImageData::EMonochrome : TJpegImageData::EColor444;
 		imageData->iQualityFactor = iQuality;
-		iFrameImageData = CFrameImageData::NewL();
-		User::LeaveIfError(iFrameImageData->AppendImageData(imageData));
+		TRAPL(iFrameImageData = CFrameImageData::NewL(), _L("Couldn't create CFrameImageData"));
+		LeaveIfErr(iFrameImageData->AppendImageData(imageData), _L("Failed to write image data to TJpegImageData"));
 		CleanupStack::Pop(imageData);
 		}
 	else if (aEncodingUid == KImageTypeGIFUid)
@@ -225,7 +225,7 @@
 	
 void CCmdGrabscreen::RunL()
 	{
-	User::LeaveIfError(iStatus.Int());
+	LeaveIfErr(iStatus.Int(), _L("Error returned from CImageEncoder::Convert"));
 	if (!iArguments.IsPresent(0))
 		{
 		User::LeaveIfNull(iImageData);
--- a/plugins/consoles/common/bld.inf	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/common/bld.inf	Thu Aug 12 16:38:42 2010 +0100
@@ -30,6 +30,7 @@
 
 PRJ_MMPFILES
 
+.\consoleextensions.mmp
 ..\consoleproxy\group\consoleproxy.mmp
 ..\defcons\src\defcons.mmp
 ..\iocons\group\iocons.mmp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/consoles/common/bwins/consoleextensions.def	Thu Aug 12 16:38:42 2010 +0100
@@ -0,0 +1,10 @@
+EXPORTS
+	?WriteStdErr@MIosrvConsoleHelper@@MAEHABVTDesC16@@@Z @ 1 NONAME ; int MIosrvConsoleHelper::WriteStdErr(class TDesC16 const &)
+	?Message@MIosrvConsoleHelper@@IAAXW4TVerbosity@1@V?$TRefByValue@$$CBVTDesC16@@@@ZZ @ 2 NONAME ; void MIosrvConsoleHelper::Message(enum MIosrvConsoleHelper::TVerbosity, class TRefByValue<class TDesC16 const >, ...)
+	?Debug@MIosrvConsoleHelper@@IBEHXZ @ 3 NONAME ; int MIosrvConsoleHelper::Debug(void) const
+	?SetDebug@MIosrvConsoleHelper@@IAEXH@Z @ 4 NONAME ; void MIosrvConsoleHelper::SetDebug(int)
+	?HandleConsoleCreationError@MIosrvConsoleHelper@@IAEXABVTDesC16@@H@Z @ 5 NONAME ; void MIosrvConsoleHelper::HandleConsoleCreationError(class TDesC16 const &, int)
+	?MIosrvConsoleHelper_Extension@MIosrvConsoleHelper@@IAEHIAAPAXPAX@Z @ 6 NONAME ; int MIosrvConsoleHelper::MIosrvConsoleHelper_Extension(unsigned int, void * &, void *)
+	?CleanupUnderlyingConsole@MIosrvConsoleHelper@@IAEXXZ @ 7 NONAME ; void MIosrvConsoleHelper::CleanupUnderlyingConsole(void)
+	?UnderlyingConsole@MIosrvConsoleHelper@@IBEPAVCConsoleBase@@XZ @ 8 NONAME ; class CConsoleBase * MIosrvConsoleHelper::UnderlyingConsole(void) const
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/consoles/common/consoleextensions.cpp	Thu Aug 12 16:38:42 2010 +0100
@@ -0,0 +1,121 @@
+// consoleextensions.cpp
+// 
+// Copyright (c) 2010 Accenture. All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of the "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+// 
+// Initial Contributors:
+// Accenture - Initial contribution
+//
+
+#include <fshell/consoleextensions.h>
+#include <e32debug.h>
+#include <e32cons.h>
+
+class TOverflowTruncate : public TDes16Overflow
+	{
+public:
+	virtual void Overflow(TDes16&) {}
+	};
+_LIT(KNewLine, "\r\n");
+
+
+EXPORT_C void MIosrvConsoleHelper::Message(TVerbosity aVerbosity, TRefByValue<const TDesC> aFmt, ...)
+	{
+	if (Debug() || (aVerbosity == EInformation) || (aVerbosity == EError))
+		{
+		TOverflowTruncate overflow;
+		VA_LIST list;
+		VA_START(list, aFmt);
+		TBuf<0x100> buf;
+		buf.AppendFormatList(aFmt, list, &overflow);
+		
+		if (iUnderlyingConsole)
+			{
+			iUnderlyingConsole->Write(buf);
+			iUnderlyingConsole->Write(KNewLine);
+			}
+		else
+			{
+			// Cover all the bases as best we can
+			User::InfoPrint(buf);
+			RDebug::Print(buf);
+			}
+		}
+	}
+
+EXPORT_C TBool MIosrvConsoleHelper::Debug() const
+	{
+	return iDebug;
+	}
+
+EXPORT_C void MIosrvConsoleHelper::SetDebug(TBool aDebug)
+	{
+	iDebug = aDebug;
+	}
+
+EXPORT_C TInt MIosrvConsoleHelper::WriteStdErr(const TDesC& /*aDes*/)
+	{
+	return KErrExtensionNotSupported;
+	}
+
+EXPORT_C TInt MIosrvConsoleHelper::MIosrvConsoleHelper_Extension(TUint aExtensionId, TAny*& /*a0*/, TAny* a1)
+	{
+	if (aExtensionId == UnderlyingConsole::KSetUnderlyingConsoleExtension)
+		{
+		iUnderlyingConsole = (CConsoleBase*)a1;
+		return KErrNone;
+		}
+	else if (aExtensionId == ConsoleStdErr::KWriteStdErrConsoleExtension)
+		{
+		const TDesC* des = (const TDesC*)a1;
+		return WriteStdErr(*des);
+		}
+	else
+		{
+		return KErrExtensionNotSupported;
+		}
+	}
+
+EXPORT_C void MIosrvConsoleHelper::HandleConsoleCreationError(const TDesC& aConsoleName, TInt aError)
+	{
+	if (aError)
+		{
+		TBuf<512> message;
+		message.Format(_L("Failed to create console %S (%d)."), &aConsoleName, aError);
+			
+		if (iUnderlyingConsole && (LazyConsole::IsConstructed(iUnderlyingConsole) || !LazyConsole::IsLazy(iUnderlyingConsole)))
+		// if we have an underlyconsole, which is either not lazy or is lazy but already constructed, then print the error to it.
+			{
+			iUnderlyingConsole->Write(message);
+			iUnderlyingConsole->Write(KNewLine);
+			}
+		else
+		// else display a dialog
+			{
+			RNotifier notifier;
+			if (notifier.Connect() == KErrNone)
+				{
+				TInt buttonVal;
+				TRequestStatus notifierStatus;
+				notifier.Notify(aConsoleName, message, _L("OK"), KNullDesC, buttonVal, notifierStatus);
+				User::WaitForRequest(notifierStatus);
+				notifier.Close();
+				}
+			}
+		}
+	Message(EDebug, _L("%S console create completed with err=%d"), &aConsoleName, aError);
+	}
+
+EXPORT_C void MIosrvConsoleHelper::CleanupUnderlyingConsole()
+	{
+	delete iUnderlyingConsole; // In case of leave during construction, this might still be non-null
+	iUnderlyingConsole = NULL;
+	}
+
+EXPORT_C CConsoleBase* MIosrvConsoleHelper::UnderlyingConsole() const
+	{
+	return iUnderlyingConsole;
+	}
--- a/plugins/consoles/common/consoleextensions.h	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/common/consoleextensions.h	Thu Aug 12 16:38:42 2010 +0100
@@ -119,7 +119,33 @@
 	*/
 	static inline TInt Write(CBase* aConsole, const TDesC& aDes);
 	};
+
+// BC on this interface is not guaranteed - only for use by things inside /fshell/plugins/consoles
+class MIosrvConsoleHelper
+	{
+protected:
+	enum TVerbosity
+		{
+		EInformation,
+		EError,
+		EDebug,
+		};
+	IMPORT_C void Message(TVerbosity aVerbosity, TRefByValue<const TDesC> aFmt, ...);
+	IMPORT_C TBool Debug() const;
+	IMPORT_C void SetDebug(TBool aDebug);
+	IMPORT_C void HandleConsoleCreationError(const TDesC& aConsoleName, TInt aError);
+	IMPORT_C void CleanupUnderlyingConsole();
+	IMPORT_C CConsoleBase* UnderlyingConsole() const;
+
+	IMPORT_C TInt MIosrvConsoleHelper_Extension(TUint aExtensionId, TAny*& a0, TAny* a1);
 	
+	IMPORT_C virtual TInt WriteStdErr(const TDesC& aDes); // Default returns KErrExtensionNotSupported
+	
+private:
+	TBool iDebug;
+	CConsoleBase* iUnderlyingConsole;
+	};
+
 #include <fshell/consoleextensions.inl>
 	
 #endif //__CONSOLEEXTENSIONS_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/consoles/common/consoleextensions.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -0,0 +1,30 @@
+// consoleextensions.mmp
+// 
+// Copyright (c) 2010 Accenture. All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of the "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+// 
+// Initial Contributors:
+// Accenture - Initial contribution
+//
+
+#include <fshell/common.mmh>
+
+target			consoleextensions.dll
+targettype		DLL
+uid				0x1000008d FSHELL_UID_CONSOLEEXTENSIONS
+capability		FSHELL_CAP_MMP_NORMAL
+
+sourcepath		.
+userinclude		.
+#include <fshell/fsh_system_include.mmh>
+
+source			consoleextensions.cpp
+
+library			euser.lib
+library			econs.lib
+
+nostrictdef
+deffile			.\~\consoleextensions.def
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/consoles/common/eabi/consoleextensions.def	Thu Aug 12 16:38:42 2010 +0100
@@ -0,0 +1,12 @@
+EXPORTS
+	_ZN19MIosrvConsoleHelper11WriteStdErrERK7TDesC16 @ 1 NONAME
+	_ZN19MIosrvConsoleHelper24CleanupUnderlyingConsoleEv @ 2 NONAME
+	_ZN19MIosrvConsoleHelper26HandleConsoleCreationErrorERK7TDesC16i @ 3 NONAME
+	_ZN19MIosrvConsoleHelper29MIosrvConsoleHelper_ExtensionEjRPvS0_ @ 4 NONAME
+	_ZN19MIosrvConsoleHelper7MessageENS_10TVerbosityE11TRefByValueIK7TDesC16Ez @ 5 NONAME
+	_ZN19MIosrvConsoleHelper8SetDebugEi @ 6 NONAME
+	_ZNK19MIosrvConsoleHelper5DebugEv @ 7 NONAME
+	_ZTI19MIosrvConsoleHelper @ 8 NONAME
+	_ZTV19MIosrvConsoleHelper @ 9 NONAME
+	_ZNK19MIosrvConsoleHelper17UnderlyingConsoleEv @ 10 NONAME
+
--- a/plugins/consoles/vt100cons/bwins/vt100u.def	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/bwins/vt100u.def	Thu Aug 12 16:38:42 2010 +0100
@@ -31,9 +31,9 @@
 	?NewL@CVtConsoleInputController@@SAPAV1@AAVMConsoleInputObserver@@@Z @ 30 NONAME ABSENT ; class CVtConsoleInputController * CVtConsoleInputController::NewL(class MConsoleInputObserver &)
 	?NewLC@CVtConsoleInputController@@SAPAV1@AAVMConsoleInputObserver@@@Z @ 31 NONAME ABSENT ; class CVtConsoleInputController * CVtConsoleInputController::NewLC(class MConsoleInputObserver &)
 	?QueueBufL@CVtConsoleInputController@@QAEXABVTDesC8@@@Z @ 32 NONAME ABSENT ; void CVtConsoleInputController::QueueBufL(class TDesC8 const &)
-	?Debug@CVtcConsoleBase@@IAEHXZ @ 33 NONAME ; int CVtcConsoleBase::Debug(void)
-	?Message@CVtcConsoleBase@@IAAXW4TVerbosity@1@V?$TRefByValue@$$CBVTDesC16@@@@ZZ @ 34 NONAME ; void CVtcConsoleBase::Message(enum CVtcConsoleBase::TVerbosity, class TRefByValue<class TDesC16 const >, ...)
-	?SetDebug@CVtcConsoleBase@@IAEXH@Z @ 35 NONAME ; void CVtcConsoleBase::SetDebug(int)
+	?Debug@CVtcConsoleBase@@IAEHXZ @ 33 NONAME ABSENT; int CVtcConsoleBase::Debug(void)
+	?Message@CVtcConsoleBase@@IAAXW4TVerbosity@1@V?$TRefByValue@$$CBVTDesC16@@@@ZZ @ 34 NONAME ABSENT ; void CVtcConsoleBase::Message(enum CVtcConsoleBase::TVerbosity, class TRefByValue<class TDesC16 const >, ...)
+	?SetDebug@CVtcConsoleBase@@IAEXH@Z @ 35 NONAME ABSENT ; void CVtcConsoleBase::SetDebug(int)
 	?SetAttributes@CVtConsoleOutputController@@QAEHIW4TColor@ConsoleAttributes@@0@Z @ 36 NONAME ; int CVtConsoleOutputController::SetAttributes(unsigned int, enum ConsoleAttributes::TColor, enum ConsoleAttributes::TColor)
 	?ResetAttributes@CVtConsoleOutputController@@QAEHXZ @ 37 NONAME ; int CVtConsoleOutputController::ResetAttributes(void)
 	?ReadKeywordValuePair@CVtcConsoleBase@@KAHAAVTLex16@@AAVTPtrC16@@1@Z @ 38 NONAME ; int CVtcConsoleBase::ReadKeywordValuePair(class TLex16 &, class TPtrC16 &, class TPtrC16 &)
--- a/plugins/consoles/vt100cons/eabi/vt100u.def	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/eabi/vt100u.def	Thu Aug 12 16:38:42 2010 +0100
@@ -39,9 +39,9 @@
 	_ZN25CVtConsoleInputController4NewLER21MConsoleInputObserver @ 38 NONAME ABSENT
 	_ZN25CVtConsoleInputController5NewLCER21MConsoleInputObserver @ 39 NONAME ABSENT
 	_ZN25CVtConsoleInputController9QueueBufLERK6TDesC8 @ 40 NONAME ABSENT
-	_ZN15CVtcConsoleBase5DebugEv @ 41 NONAME
-	_ZN15CVtcConsoleBase7MessageENS_10TVerbosityE11TRefByValueIK7TDesC16Ez @ 42 NONAME
-	_ZN15CVtcConsoleBase8SetDebugEi @ 43 NONAME
+	_ZN15CVtcConsoleBase5DebugEv @ 41 NONAME ABSENT
+	_ZN15CVtcConsoleBase7MessageENS_10TVerbosityE11TRefByValueIK7TDesC16Ez @ 42 NONAME ABSENT
+	_ZN15CVtcConsoleBase8SetDebugEi @ 43 NONAME ABSENT
 	_ZN26CVtConsoleOutputController13SetAttributesEjN17ConsoleAttributes6TColorES1_ @ 44 NONAME
 	_ZN26CVtConsoleOutputController15ResetAttributesEv @ 45 NONAME
 	_ZN15CVtcConsoleBase20ReadKeywordValuePairER6TLex16R7TPtrC16S3_ @ 46 NONAME
--- a/plugins/consoles/vt100cons/group/vt100.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -28,5 +28,6 @@
 
 library			euser.lib
 library			ltkutils.lib
+library			consoleextensions.lib
 
 deffile			vt100.def
--- a/plugins/consoles/vt100cons/group/vt100btcons.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100btcons.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -27,5 +27,6 @@
 library			euser.lib
 library			btincomingserial.lib bluetooth.lib
 library			vt100.lib
+library			consoleextensions.lib
 
 deffile			vt100btcons.def
--- a/plugins/consoles/vt100cons/group/vt100busdevcons.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100busdevcons.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -26,5 +26,6 @@
 library			euser.lib
 library			econs.lib
 library			vt100.lib
+library			consoleextensions.lib
 
 deffile			vt100cons.def
--- a/plugins/consoles/vt100cons/group/vt100cons.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100cons.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -27,5 +27,6 @@
 library			euser.lib
 library			vt100serial.lib
 library			vt100.lib
+library			consoleextensions.lib
 
 deffile			vt100cons.def
--- a/plugins/consoles/vt100cons/group/vt100serial.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100serial.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -27,5 +27,6 @@
 library			euser.lib
 library			c32.lib
 library			vt100.lib
+library			consoleextensions.lib
 
 deffile			vt100serial.def
--- a/plugins/consoles/vt100cons/group/vt100tcpcons.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100tcpcons.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -29,5 +29,6 @@
 library			vt100.lib
 library			insock.lib
 library			commdb.lib
+library			consoleextensions.lib
 
 deffile			vt100cons.def
--- a/plugins/consoles/vt100cons/group/vt100usbcons.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/group/vt100usbcons.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -28,5 +28,6 @@
 library			usbman.lib
 library			vt100.lib
 library			vt100serial.lib
+library			consoleextensions.lib
 
 deffile			vt100usbcons.def
--- a/plugins/consoles/vt100cons/inc/vtc_base.h	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/inc/vtc_base.h	Thu Aug 12 16:38:42 2010 +0100
@@ -17,8 +17,9 @@
 #include <e32cons.h>
 #include <fshell/settings.h>
 #include <fshell/vtc_controller.h>
+#include <fshell/consoleextensions.h>
 
-class CVtcConsoleBase : public CConsoleBase, public MConsoleOutput, public MConsoleInput
+class CVtcConsoleBase : public CConsoleBase, public MConsoleOutput, public MConsoleInput, public MIosrvConsoleHelper
 	{
 public:
 	IMPORT_C virtual ~CVtcConsoleBase();
@@ -38,17 +39,6 @@
 	IMPORT_C virtual TUint KeyModifiers() const;
 	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
 protected:
-	enum TVerbosity
-		{
-		EInformation,
-		EError,
-		EDebug,
-		};
-protected:
-	IMPORT_C void Message(TVerbosity aVerbosity, TRefByValue<const TDesC> aFmt, ...);
-	IMPORT_C TBool Debug();
-	IMPORT_C void SetDebug(TBool aDebug);
-protected:
 	IMPORT_C CVtcConsoleBase();
 	IMPORT_C virtual void ConstructL(const TDesC& aTitle);
 	IMPORT_C void ConstructL(const TDesC& aTitle, TBool aConsoleSupportsSizeDetect); // Note this is NOT virtual, only used for baseclasses to call up to from their overload of ConstructL(const TDesC&) if they explicitly don't support console size detect
@@ -63,9 +53,6 @@
 	CVtConsoleOutputController* iOutputController;
 	CVtConsoleInputController* iInputController;
 	LtkUtils::CIniFile* iIniFile;
-	TInt iDebug;
-protected:
-	CConsoleBase* iUnderlyingConsole;
 	};
 
 
--- a/plugins/consoles/vt100cons/src/tcp/vtc_tcp.cpp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/src/tcp/vtc_tcp.cpp	Thu Aug 12 16:38:42 2010 +0100
@@ -102,7 +102,7 @@
 	TBuf<0x100> buf;
 	buf.AppendFormatList(aFmt, list, &overflow);
 
-	if (iUnderlyingConsole)
+	if (UnderlyingConsole())
 		{
 		Message(EInformation, buf);
 		// when using a console, the accept can be cancelled by hitting ctrl-c
--- a/plugins/consoles/vt100cons/src/vt100/vtc_base.cpp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/vt100cons/src/vt100/vtc_base.cpp	Thu Aug 12 16:38:42 2010 +0100
@@ -17,14 +17,6 @@
 _LIT(KIniDesciptionFile, "\\resource\\vt100.idf");
 _LIT(KAttConsoleSizeDetect, "console_size_detect");
 
-_LIT(KNewLine, "\r\n");
-
-class TOverflowTruncate : public TDes16Overflow
-	{
-public:
-	virtual void Overflow(TDes16&) {}
-	};
-	
 EXPORT_C CVtcConsoleBase::CVtcConsoleBase()
 	{
 	}
@@ -34,38 +26,13 @@
 	delete iIniFile;
 	delete iInputController;
 	delete iOutputController;
-	delete iUnderlyingConsole; // In case of leave during construction, this might still be non-null
+	CleanupUnderlyingConsole();
 	}
 
 EXPORT_C TInt CVtcConsoleBase::Create(const TDesC& aTitle, TSize /*aSize*/)
 	{
 	TRAPD(err, ConstructL(aTitle));
-	if (err)
-		{
-		TBuf<512> message;
-		message.Format(_L("Failed to create console (%d)."), err);
-			
-		if (iUnderlyingConsole && (LazyConsole::IsConstructed(iUnderlyingConsole) || !LazyConsole::IsLazy(iUnderlyingConsole)))
-		// if we have an underlyconsole, which is either not lazy or is lazy but already constructed, then print the error to it.
-			{
-			iUnderlyingConsole->Write(message);
-			iUnderlyingConsole->Write(KNewLine);
-			}
-		else
-		// else display a dialog
-			{
-			RNotifier notifier;
-			if (notifier.Connect() == KErrNone)
-				{
-				TInt buttonVal;
-				TRequestStatus notifierStatus;
-				notifier.Notify(_L("vt100"), message, _L("OK"), KNullDesC, buttonVal, notifierStatus);
-				User::WaitForRequest(notifierStatus);
-				notifier.Close();
-				}
-			}
-		}
-	Message(EDebug, _L("VT100 console create completed with err=%d"), err);
+	HandleConsoleCreationError(_L("VT100"), err);
 	return err;
 	}
 
@@ -86,8 +53,7 @@
 	iOutputController = CVtConsoleOutputController::NewL(*this, *iIniFile, screenSize);
 	iInputController = CVtConsoleInputController::NewL(*this, *iIniFile);
 	ClearScreen();
-	delete iUnderlyingConsole;
-	iUnderlyingConsole = NULL;
+	CleanupUnderlyingConsole();
 	}
 	
 EXPORT_C TInt CVtcConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
@@ -99,11 +65,6 @@
 		iOutputController->SetMode(mode);
 		return KErrNone;
 		}
-	else if (aExtensionId == UnderlyingConsole::KSetUnderlyingConsoleExtension)
-		{
-		iUnderlyingConsole = (CConsoleBase*)a1;
-		return KErrNone;
-		}
 	else if (aExtensionId == ConsoleAttributes::KSetConsoleAttributesExtension)
 		{
 		ConsoleAttributes::TAttributes* attributes = (ConsoleAttributes::TAttributes*)a1;
@@ -111,43 +72,14 @@
 		}
 	else
 		{
-		return CConsoleBase::Extension_(aExtensionId, a0, a1);
-		}
-	}
-
-EXPORT_C void CVtcConsoleBase::Message(TVerbosity aVerbosity, TRefByValue<const TDesC> aFmt, ...)
-	{
-	if (Debug() || (aVerbosity == EInformation) || (aVerbosity == EError))
-		{
-		TOverflowTruncate overflow;
-		VA_LIST list;
-		VA_START(list, aFmt);
-		TBuf<0x100> buf;
-		buf.AppendFormatList(aFmt, list, &overflow);
-		
-		if (iUnderlyingConsole)
+		TInt ret = MIosrvConsoleHelper_Extension(aExtensionId, a0, a1);
+		if (ret == KErrExtensionNotSupported)
 			{
-			iUnderlyingConsole->Write(buf);
-			iUnderlyingConsole->Write(KNewLine);
+			ret = CConsoleBase::Extension_(aExtensionId, a0, a1);
 			}
-		else
-			{
-			// Cover all the bases
-			User::InfoPrint(buf);
-			RDebug::Print(buf);
-			}
+		return ret;
 		}
 	}
-	
-EXPORT_C TBool CVtcConsoleBase::Debug()
-	{
-	return iDebug;
-	}
-	
-EXPORT_C void CVtcConsoleBase::SetDebug(TBool aDebug)
-	{
-	iDebug = aDebug;
-	}
 		
 EXPORT_C void CVtcConsoleBase::Read(TRequestStatus& aStatus)
 	{
--- a/plugins/consoles/win32cons/group/win32cons.mmp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/win32cons/group/win32cons.mmp	Thu Aug 12 16:38:42 2010 +0100
@@ -20,12 +20,13 @@
 sourcepath		..\src
 userinclude		..\src
 #include <fshell/fsh_system_include.mmh>
-systeminclude	\epoc32\build\fshell/win32cons\generated
+systeminclude	\epoc32\build\fshell\win32cons\generated
 
 source			console.cpp win32cons.cpp keymappings.cpp
 
 library			euser.lib
 library			emulator.lib
+library			consoleextensions.lib
 
 deffile			win32cons.def
 
--- a/plugins/consoles/win32cons/src/console.cpp	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/win32cons/src/console.cpp	Thu Aug 12 16:38:42 2010 +0100
@@ -81,9 +81,10 @@
 	iWin32.Write(aDes.Ptr(), aDes.Length());
 	}
 	
-void CWin32Console::WriteStdErr(const TDesC& aDes)
+TInt CWin32Console::WriteStdErr(const TDesC& aDes)
 	{
 	iWin32.WriteStdErr(aDes.Ptr(), aDes.Length());
+	return KErrNone;
 	}
 
 TPoint CWin32Console::CursorPos() const
@@ -159,13 +160,7 @@
 
 TInt CWin32Console::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
 	{
-	if (aExtensionId == ConsoleStdErr::KWriteStdErrConsoleExtension)
-		{
-		TDesC* des = (TDesC*)a1;
-		WriteStdErr(*des);
-		return KErrNone;
-		}
-	else if (aExtensionId == ConsoleAttributes::KSetConsoleAttributesExtension)
+	if (aExtensionId == ConsoleAttributes::KSetConsoleAttributesExtension)
 		{
 		ConsoleAttributes::TAttributes* attributes = (ConsoleAttributes::TAttributes*)a1;
 		int res = iWin32.SetAttributes(attributes->iAttributes, (TWin32Console::TColor)attributes->iForegroundColor, (TWin32Console::TColor)attributes->iBackgroundColor);
@@ -173,7 +168,12 @@
 		}
 	else
 		{
-		return CConsoleBase::Extension_(aExtensionId, a0, a1);
+		TInt ret = MIosrvConsoleHelper_Extension(aExtensionId, a0, a1);
+		if (ret == KErrExtensionNotSupported)
+			{
+			ret = CConsoleBase::Extension_(aExtensionId, a0, a1);
+			}
+		return ret;
 		}
 	
 	}
--- a/plugins/consoles/win32cons/src/console.h	Wed Aug 11 12:57:25 2010 +0100
+++ b/plugins/consoles/win32cons/src/console.h	Thu Aug 12 16:38:42 2010 +0100
@@ -49,12 +49,7 @@
   
 Piping into the emulator process via this console is as yet untested.
 */
-#ifdef EKA2
-NONSHARABLE_CLASS(CWin32Console)
-#else
-class CWin32Console
-#endif
-	 : public CConsoleBase
+NONSHARABLE_CLASS(CWin32Console) : public CConsoleBase, public MIosrvConsoleHelper
 	{
 public:
 	CWin32Console();
@@ -76,7 +71,9 @@
 	virtual TUint KeyModifiers() const;
 	virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
 	
-	virtual void WriteStdErr(const TDesC& aDes);
+private: // From MIosrvConsoleHelper
+	TInt WriteStdErr(const TDesC& aDes);
+
 private:
 	TInt CreateNewConsole(const TDesC& aTitle, TSize aSize);
 	TInt FindClientThreadId(TThreadId& aThreadId);