plugins/consoles/vt100cons/src/vt100/vtc_base.cpp
changeset 30 35cb3fe43f60
parent 28 169dfbeff8ee
equal deleted inserted replaced
29:9a2198517f48 30:35cb3fe43f60
    15 
    15 
    16 _LIT(KIniFileName, "\\system\\console\\vt100.ini");
    16 _LIT(KIniFileName, "\\system\\console\\vt100.ini");
    17 _LIT(KIniDesciptionFile, "\\resource\\vt100.idf");
    17 _LIT(KIniDesciptionFile, "\\resource\\vt100.idf");
    18 _LIT(KAttConsoleSizeDetect, "console_size_detect");
    18 _LIT(KAttConsoleSizeDetect, "console_size_detect");
    19 
    19 
    20 _LIT(KNewLine, "\r\n");
       
    21 
       
    22 class TOverflowTruncate : public TDes16Overflow
       
    23 	{
       
    24 public:
       
    25 	virtual void Overflow(TDes16&) {}
       
    26 	};
       
    27 	
       
    28 EXPORT_C CVtcConsoleBase::CVtcConsoleBase()
    20 EXPORT_C CVtcConsoleBase::CVtcConsoleBase()
    29 	{
    21 	{
    30 	}
    22 	}
    31 
    23 
    32 EXPORT_C CVtcConsoleBase::~CVtcConsoleBase()
    24 EXPORT_C CVtcConsoleBase::~CVtcConsoleBase()
    33 	{
    25 	{
    34 	delete iIniFile;
    26 	delete iIniFile;
    35 	delete iInputController;
    27 	delete iInputController;
    36 	delete iOutputController;
    28 	delete iOutputController;
    37 	delete iUnderlyingConsole; // In case of leave during construction, this might still be non-null
    29 	CleanupUnderlyingConsole();
    38 	}
    30 	}
    39 
    31 
    40 EXPORT_C TInt CVtcConsoleBase::Create(const TDesC& aTitle, TSize /*aSize*/)
    32 EXPORT_C TInt CVtcConsoleBase::Create(const TDesC& aTitle, TSize /*aSize*/)
    41 	{
    33 	{
    42 	TRAPD(err, ConstructL(aTitle));
    34 	TRAPD(err, ConstructL(aTitle));
    43 	if (err)
    35 	HandleConsoleCreationError(_L("VT100"), err);
    44 		{
       
    45 		TBuf<512> message;
       
    46 		message.Format(_L("Failed to create console (%d)."), err);
       
    47 			
       
    48 		if (iUnderlyingConsole && (LazyConsole::IsConstructed(iUnderlyingConsole) || !LazyConsole::IsLazy(iUnderlyingConsole)))
       
    49 		// if we have an underlyconsole, which is either not lazy or is lazy but already constructed, then print the error to it.
       
    50 			{
       
    51 			iUnderlyingConsole->Write(message);
       
    52 			iUnderlyingConsole->Write(KNewLine);
       
    53 			}
       
    54 		else
       
    55 		// else display a dialog
       
    56 			{
       
    57 			RNotifier notifier;
       
    58 			if (notifier.Connect() == KErrNone)
       
    59 				{
       
    60 				TInt buttonVal;
       
    61 				TRequestStatus notifierStatus;
       
    62 				notifier.Notify(_L("vt100"), message, _L("OK"), KNullDesC, buttonVal, notifierStatus);
       
    63 				User::WaitForRequest(notifierStatus);
       
    64 				notifier.Close();
       
    65 				}
       
    66 			}
       
    67 		}
       
    68 	Message(EDebug, _L("VT100 console create completed with err=%d"), err);
       
    69 	return err;
    36 	return err;
    70 	}
    37 	}
    71 
    38 
    72 EXPORT_C void CVtcConsoleBase::ConstructL(const TDesC& aTitle)
    39 EXPORT_C void CVtcConsoleBase::ConstructL(const TDesC& aTitle)
    73 	{
    40 	{
    84 		DetectScreenSizeL(screenSize);
    51 		DetectScreenSizeL(screenSize);
    85 		}
    52 		}
    86 	iOutputController = CVtConsoleOutputController::NewL(*this, *iIniFile, screenSize);
    53 	iOutputController = CVtConsoleOutputController::NewL(*this, *iIniFile, screenSize);
    87 	iInputController = CVtConsoleInputController::NewL(*this, *iIniFile);
    54 	iInputController = CVtConsoleInputController::NewL(*this, *iIniFile);
    88 	ClearScreen();
    55 	ClearScreen();
    89 	delete iUnderlyingConsole;
    56 	CleanupUnderlyingConsole();
    90 	iUnderlyingConsole = NULL;
       
    91 	}
    57 	}
    92 	
    58 	
    93 EXPORT_C TInt CVtcConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
    59 EXPORT_C TInt CVtcConsoleBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
    94 	{
    60 	{
    95 	if (aExtensionId == ConsoleMode::KSetConsoleModeExtension)
    61 	if (aExtensionId == ConsoleMode::KSetConsoleModeExtension)
    97 		ConsoleMode::TMode mode = (ConsoleMode::TMode)(TInt)a1;
    63 		ConsoleMode::TMode mode = (ConsoleMode::TMode)(TInt)a1;
    98 		iInputController->SetMode(mode);
    64 		iInputController->SetMode(mode);
    99 		iOutputController->SetMode(mode);
    65 		iOutputController->SetMode(mode);
   100 		return KErrNone;
    66 		return KErrNone;
   101 		}
    67 		}
   102 	else if (aExtensionId == UnderlyingConsole::KSetUnderlyingConsoleExtension)
       
   103 		{
       
   104 		iUnderlyingConsole = (CConsoleBase*)a1;
       
   105 		return KErrNone;
       
   106 		}
       
   107 	else if (aExtensionId == ConsoleAttributes::KSetConsoleAttributesExtension)
    68 	else if (aExtensionId == ConsoleAttributes::KSetConsoleAttributesExtension)
   108 		{
    69 		{
   109 		ConsoleAttributes::TAttributes* attributes = (ConsoleAttributes::TAttributes*)a1;
    70 		ConsoleAttributes::TAttributes* attributes = (ConsoleAttributes::TAttributes*)a1;
   110 		return iOutputController->SetAttributes(attributes->iAttributes, attributes->iForegroundColor, attributes->iBackgroundColor);
    71 		return iOutputController->SetAttributes(attributes->iAttributes, attributes->iForegroundColor, attributes->iBackgroundColor);
   111 		}
    72 		}
   112 	else
    73 	else
   113 		{
    74 		{
   114 		return CConsoleBase::Extension_(aExtensionId, a0, a1);
    75 		TInt ret = MIosrvConsoleHelper_Extension(aExtensionId, a0, a1);
   115 		}
    76 		if (ret == KErrExtensionNotSupported)
   116 	}
    77 			{
   117 
    78 			ret = CConsoleBase::Extension_(aExtensionId, a0, a1);
   118 EXPORT_C void CVtcConsoleBase::Message(TVerbosity aVerbosity, TRefByValue<const TDesC> aFmt, ...)
    79 			}
   119 	{
    80 		return ret;
   120 	if (Debug() || (aVerbosity == EInformation) || (aVerbosity == EError))
    81 		}
   121 		{
       
   122 		TOverflowTruncate overflow;
       
   123 		VA_LIST list;
       
   124 		VA_START(list, aFmt);
       
   125 		TBuf<0x100> buf;
       
   126 		buf.AppendFormatList(aFmt, list, &overflow);
       
   127 		
       
   128 		if (iUnderlyingConsole)
       
   129 			{
       
   130 			iUnderlyingConsole->Write(buf);
       
   131 			iUnderlyingConsole->Write(KNewLine);
       
   132 			}
       
   133 		else
       
   134 			{
       
   135 			// Cover all the bases
       
   136 			User::InfoPrint(buf);
       
   137 			RDebug::Print(buf);
       
   138 			}
       
   139 		}
       
   140 	}
       
   141 	
       
   142 EXPORT_C TBool CVtcConsoleBase::Debug()
       
   143 	{
       
   144 	return iDebug;
       
   145 	}
       
   146 	
       
   147 EXPORT_C void CVtcConsoleBase::SetDebug(TBool aDebug)
       
   148 	{
       
   149 	iDebug = aDebug;
       
   150 	}
    82 	}
   151 		
    83 		
   152 EXPORT_C void CVtcConsoleBase::Read(TRequestStatus& aStatus)
    84 EXPORT_C void CVtcConsoleBase::Read(TRequestStatus& aStatus)
   153 	{
    85 	{
   154 	iInputController->GetKeyPress(iKeyPress, aStatus);
    86 	iInputController->GetKeyPress(iKeyPress, aStatus);