plugins/consoles/vt100cons/src/vtc_debugport.cpp
changeset 0 7f656887cf89
child 28 169dfbeff8ee
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // vtc_debugport.cpp
       
     2 // 
       
     3 // Copyright (c) 2007 - 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 <e32twin.h>
       
    14 #include <fshell/vtc_base.h>
       
    15 
       
    16 class CReaderObject;
       
    17 
       
    18 NONSHARABLE_CLASS(CVtcDebugPortConsole) : public CVtcConsoleBase
       
    19 	{
       
    20 public:
       
    21 	CVtcDebugPortConsole();
       
    22 	~CVtcDebugPortConsole();
       
    23 	void ReadComplete(TInt aErr, TKeyCode aCode);
       
    24 
       
    25 protected: // From CVtcConsoleBase.
       
    26 	virtual void ConstructL(const TDesC& aTitle);
       
    27 	TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
       
    28 private: // From MConsoleOutput.
       
    29 	virtual TInt Output(const TDesC8& aDes);
       
    30 private: // From MConsoleInput.
       
    31 	virtual void Input(TDes8& aDes, TRequestStatus& aStatus);
       
    32 	virtual void CancelInput(TRequestStatus& aStatus);
       
    33 private:
       
    34 	friend class CReaderObject;
       
    35 	RConsole iConsole;
       
    36 	CReaderObject* iReader;
       
    37 	TRequestStatus* iClientStatus;
       
    38 	TDes8* iClientDes;
       
    39 	};
       
    40 
       
    41 class CReaderObject : public CActive
       
    42 	{
       
    43 public:
       
    44 	CReaderObject(CVtcDebugPortConsole* aParent) : CActive(CActive::EPriorityStandard), iParent(aParent) { CActiveScheduler::Add(this); }
       
    45 	void RunL() { iParent->ReadComplete(iStatus.Int(), iKey.Code()); }
       
    46 	void DoCancel() { iParent->iConsole.ReadCancel(); }
       
    47 	void Request()
       
    48 		{
       
    49 		iParent->iConsole.Read(iKey, iStatus);
       
    50 		SetActive();
       
    51 		}
       
    52 	
       
    53 	CVtcDebugPortConsole* iParent;
       
    54 	TConsoleKey iKey;
       
    55 	};
       
    56 	
       
    57 extern "C" EXPORT_C TAny* NewConsole()
       
    58 	{
       
    59 	return new CVtcDebugPortConsole;
       
    60 	}
       
    61 
       
    62 CVtcDebugPortConsole::CVtcDebugPortConsole()
       
    63 	{
       
    64 	}
       
    65 
       
    66 CVtcDebugPortConsole::~CVtcDebugPortConsole()
       
    67 	{
       
    68 	if (iReader)
       
    69 		{
       
    70 		iReader->Cancel();
       
    71 		delete iReader;
       
    72 		}
       
    73 	if (iConsole.Handle())
       
    74 		{
       
    75 		iConsole.Destroy(); // Needed?
       
    76 		}
       
    77 	iConsole.Close();
       
    78 	}
       
    79 
       
    80 void CVtcDebugPortConsole::ConstructL(const TDesC& aTitle)
       
    81 	{
       
    82 	iReader = new(ELeave) CReaderObject(this);
       
    83 	User::LeaveIfError(iConsole.Create());
       
    84 	User::LeaveIfError(iConsole.Init(_L("fshell"), TSize(KConsFullScreen,KConsFullScreen)));
       
    85 	CVtcConsoleBase::ConstructL(aTitle);
       
    86 	}
       
    87 	
       
    88 TInt CVtcDebugPortConsole::Output(const TDesC8& aDes)
       
    89 	{
       
    90 	TBuf<128> buf;
       
    91 	TPtrC8 remainder(aDes);
       
    92 	while (remainder.Length())
       
    93 		{
       
    94 		TPtrC8 frag(remainder.Left(Min(remainder.Length(), buf.MaxLength())));
       
    95 		remainder.Set(remainder.Mid(frag.Length()));
       
    96 		buf.Copy(frag);
       
    97 		RDebug::RawPrint(buf);
       
    98 		}
       
    99 	return KErrNone;
       
   100 	}
       
   101 
       
   102 void CVtcDebugPortConsole::Input(TDes8& aDes, TRequestStatus& aStatus)
       
   103 	{
       
   104 	iClientDes = &aDes;
       
   105 	iClientStatus = &aStatus;
       
   106 	iReader->Request();
       
   107 	//iCommPort.ReadOneOrMore(aStatus, aDes);
       
   108 	}
       
   109 
       
   110 void CVtcDebugPortConsole::CancelInput(TRequestStatus&)
       
   111 	{
       
   112 	//iCommPort.ReadCancel();
       
   113 	iReader->Cancel();
       
   114 	User::RequestComplete(iClientStatus, KErrCancel);
       
   115 	}
       
   116 
       
   117 void CVtcDebugPortConsole::ReadComplete(TInt aErr, TKeyCode aCode)
       
   118 	{
       
   119 	iClientDes->SetLength(1);
       
   120 	(*iClientDes)[0] = aCode;
       
   121 	User::RequestComplete(iClientStatus, aErr);
       
   122 	}
       
   123 
       
   124 TInt CVtcDebugPortConsole::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
       
   125 	{
       
   126 	if (aExtensionId == ConsoleMode::KSetConsoleModeExtension)
       
   127 		{
       
   128 		return KErrNotSupported; // The text windowserver swallows certain keypresses so we can't support binary mode
       
   129 		}
       
   130 	else
       
   131 		{
       
   132 		return CVtcConsoleBase::Extension_(aExtensionId, a0, a1);
       
   133 		}
       
   134 	}