plugins/consoles/common/consoleextensions.cpp
changeset 30 35cb3fe43f60
child 100 706c7a69e448
equal deleted inserted replaced
29:9a2198517f48 30:35cb3fe43f60
       
     1 // consoleextensions.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <fshell/consoleextensions.h>
       
    14 #include <e32debug.h>
       
    15 #include <e32cons.h>
       
    16 
       
    17 class TOverflowTruncate : public TDes16Overflow
       
    18 	{
       
    19 public:
       
    20 	virtual void Overflow(TDes16&) {}
       
    21 	};
       
    22 _LIT(KNewLine, "\r\n");
       
    23 
       
    24 
       
    25 EXPORT_C void MIosrvConsoleHelper::Message(TVerbosity aVerbosity, TRefByValue<const TDesC> aFmt, ...)
       
    26 	{
       
    27 	if (Debug() || (aVerbosity == EInformation) || (aVerbosity == EError))
       
    28 		{
       
    29 		TOverflowTruncate overflow;
       
    30 		VA_LIST list;
       
    31 		VA_START(list, aFmt);
       
    32 		TBuf<0x100> buf;
       
    33 		buf.AppendFormatList(aFmt, list, &overflow);
       
    34 		
       
    35 		if (iUnderlyingConsole)
       
    36 			{
       
    37 			iUnderlyingConsole->Write(buf);
       
    38 			iUnderlyingConsole->Write(KNewLine);
       
    39 			}
       
    40 		else
       
    41 			{
       
    42 			// Cover all the bases as best we can
       
    43 			User::InfoPrint(buf);
       
    44 			RDebug::Print(buf);
       
    45 			}
       
    46 		}
       
    47 	}
       
    48 
       
    49 EXPORT_C TBool MIosrvConsoleHelper::Debug() const
       
    50 	{
       
    51 	return iDebug;
       
    52 	}
       
    53 
       
    54 EXPORT_C void MIosrvConsoleHelper::SetDebug(TBool aDebug)
       
    55 	{
       
    56 	iDebug = aDebug;
       
    57 	}
       
    58 
       
    59 EXPORT_C TInt MIosrvConsoleHelper::WriteStdErr(const TDesC& /*aDes*/)
       
    60 	{
       
    61 	return KErrExtensionNotSupported;
       
    62 	}
       
    63 
       
    64 EXPORT_C TInt MIosrvConsoleHelper::MIosrvConsoleHelper_Extension(TUint aExtensionId, TAny*& /*a0*/, TAny* a1)
       
    65 	{
       
    66 	if (aExtensionId == UnderlyingConsole::KSetUnderlyingConsoleExtension)
       
    67 		{
       
    68 		iUnderlyingConsole = (CConsoleBase*)a1;
       
    69 		return KErrNone;
       
    70 		}
       
    71 	else if (aExtensionId == ConsoleStdErr::KWriteStdErrConsoleExtension)
       
    72 		{
       
    73 		const TDesC* des = (const TDesC*)a1;
       
    74 		return WriteStdErr(*des);
       
    75 		}
       
    76 	else
       
    77 		{
       
    78 		return KErrExtensionNotSupported;
       
    79 		}
       
    80 	}
       
    81 
       
    82 EXPORT_C void MIosrvConsoleHelper::HandleConsoleCreationError(const TDesC& aConsoleName, TInt aError)
       
    83 	{
       
    84 	if (aError)
       
    85 		{
       
    86 		TBuf<512> message;
       
    87 		message.Format(_L("Failed to create console %S (%d)."), &aConsoleName, aError);
       
    88 			
       
    89 		if (iUnderlyingConsole && (LazyConsole::IsConstructed(iUnderlyingConsole) || !LazyConsole::IsLazy(iUnderlyingConsole)))
       
    90 		// if we have an underlyconsole, which is either not lazy or is lazy but already constructed, then print the error to it.
       
    91 			{
       
    92 			iUnderlyingConsole->Write(message);
       
    93 			iUnderlyingConsole->Write(KNewLine);
       
    94 			}
       
    95 		else
       
    96 		// else display a dialog
       
    97 			{
       
    98 			RNotifier notifier;
       
    99 			if (notifier.Connect() == KErrNone)
       
   100 				{
       
   101 				TInt buttonVal;
       
   102 				TRequestStatus notifierStatus;
       
   103 				notifier.Notify(aConsoleName, message, _L("OK"), KNullDesC, buttonVal, notifierStatus);
       
   104 				User::WaitForRequest(notifierStatus);
       
   105 				notifier.Close();
       
   106 				}
       
   107 			}
       
   108 		}
       
   109 	Message(EDebug, _L("%S console create completed with err=%d"), &aConsoleName, aError);
       
   110 	}
       
   111 
       
   112 EXPORT_C void MIosrvConsoleHelper::CleanupUnderlyingConsole()
       
   113 	{
       
   114 	delete iUnderlyingConsole; // In case of leave during construction, this might still be non-null
       
   115 	iUnderlyingConsole = NULL;
       
   116 	}
       
   117 
       
   118 EXPORT_C CConsoleBase* MIosrvConsoleHelper::UnderlyingConsole() const
       
   119 	{
       
   120 	return iUnderlyingConsole;
       
   121 	}