|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Console redirection server |
|
15 // |
|
16 // |
|
17 |
|
18 #include "testconsole.h" |
|
19 #include <e32svr.h> |
|
20 #include <utf.h> |
|
21 #include <e32cons.h> |
|
22 |
|
23 |
|
24 NONSHARABLE_CLASS(CActiveConsole) : public CActive |
|
25 { |
|
26 public: |
|
27 CActiveConsole(); |
|
28 void ConsoleRead(); |
|
29 static CActiveConsole* NewLC(CConsoleBase* aConsole, CTestConsole * aStream); |
|
30 static CActiveConsole* NewL(CConsoleBase* aConsole, CTestConsole * aStream); |
|
31 void ConstructL(CConsoleBase* aConsole, CTestConsole * aStream); |
|
32 |
|
33 private: |
|
34 void DoCancel(); |
|
35 void RunL(); |
|
36 CTestConsole * iStream; |
|
37 CConsoleBase * iConsole; |
|
38 }; |
|
39 |
|
40 CActiveConsole::CActiveConsole() : CActive(CActive::EPriorityStandard) |
|
41 { |
|
42 } |
|
43 |
|
44 void CActiveConsole::DoCancel() |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 void CActiveConsole::ConsoleRead() |
|
50 { |
|
51 iConsole->Read(iStatus); |
|
52 SetActive(); |
|
53 } |
|
54 |
|
55 void CActiveConsole::RunL() |
|
56 { |
|
57 iStream->DoneReading(iConsole->KeyCode()); |
|
58 } |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 CActiveConsole* CActiveConsole::NewLC(CConsoleBase* aConsole, CTestConsole * aStream) |
|
64 { |
|
65 CActiveConsole* self=new (ELeave) CActiveConsole; |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(aConsole, aStream); |
|
68 return self; |
|
69 } |
|
70 |
|
71 CActiveConsole* CActiveConsole::NewL(CConsoleBase* aConsole, CTestConsole * aStream) |
|
72 { |
|
73 CActiveConsole* self = NewLC(aConsole, aStream); |
|
74 CleanupStack::Pop(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 void CActiveConsole::ConstructL(CConsoleBase* aConsole, CTestConsole * aStream) |
|
79 { |
|
80 iConsole = aConsole; |
|
81 iStream = aStream; |
|
82 CActiveScheduler::Add(this); |
|
83 } |
|
84 |
|
85 |
|
86 CTestConsole::CTestConsole() |
|
87 { |
|
88 #ifdef __MARM |
|
89 TRAPD(r,iConsole=Console::NewL(_L("Redirection Server"),TSize(KConsFullScreen, KConsFullScreen))) |
|
90 #else |
|
91 TRAPD(r,iConsole=Console::NewL(_L("Redirection Server"),TSize(KDefaultConsWidth,KDefaultConsHeight))) |
|
92 #endif |
|
93 __ASSERT_ALWAYS(r==KErrNone,User::Panic(_L("Redirection Server"),0)); |
|
94 |
|
95 //create and add the active object |
|
96 TRAPD(x, iActiveChap=CActiveConsole::NewL(iConsole, this)); |
|
97 __ASSERT_ALWAYS(x==KErrNone,User::Panic(_L("Redirection Server"),0)); |
|
98 |
|
99 } |
|
100 |
|
101 |
|
102 CTestConsole::~CTestConsole() |
|
103 { |
|
104 if (iConsole) |
|
105 { |
|
106 iConsole->Write(_L("Console Closed")); |
|
107 User::After(2*1000000); |
|
108 delete iConsole; |
|
109 } |
|
110 } |
|
111 |
|
112 |
|
113 void CTestConsole::Write(TDes8& aDes) |
|
114 { |
|
115 |
|
116 TBuf<256> str; |
|
117 CnvUtfConverter::ConvertToUnicodeFromUtf8(str, aDes); |
|
118 |
|
119 iConsole->Write(str); |
|
120 |
|
121 } |
|
122 |
|
123 void CTestConsole::Read(const RMessage2& aMessage) |
|
124 { |
|
125 iMessage = aMessage; |
|
126 iActiveChap->ConsoleRead(); //read from the console |
|
127 } |
|
128 |
|
129 |
|
130 void CTestConsole::DoneReading(TKeyCode aKeyCode) |
|
131 { |
|
132 TText8 ch; |
|
133 switch (aKeyCode) |
|
134 { |
|
135 case EKeyEnter: |
|
136 ch = '\n'; |
|
137 break; |
|
138 case EKeyBackspace: |
|
139 ch = 0x08; |
|
140 break; |
|
141 default: |
|
142 ch = (TText8)(aKeyCode&0xFF); |
|
143 break; |
|
144 } |
|
145 |
|
146 //append it to the buffer |
|
147 iBuf.Append(ch); |
|
148 Write(iBuf); |
|
149 |
|
150 CompleteRead(iMessage); |
|
151 } |
|
152 |
|
153 CStreamBase2* CTestConsoleFactory::GetStream() |
|
154 { |
|
155 return new CTestConsole(); |
|
156 } |
|
157 |
|
158 void CTestConsoleFactory::Configure() |
|
159 { |
|
160 } |
|
161 |
|
162 |
|
163 CTestConsoleFactory* CTestConsoleFactory::NewL() |
|
164 { |
|
165 CTestConsoleFactory* f=new(ELeave) CTestConsoleFactory(); |
|
166 |
|
167 return f; |
|
168 } |
|
169 |
|
170 |