|
1 // Copyright (c) 2002-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 // |
|
15 |
|
16 #include "ServerConsole.h" |
|
17 |
|
18 |
|
19 /** |
|
20 * |
|
21 * Static constructor for CServerConsole. |
|
22 * |
|
23 * @param "const TDesC& aName" |
|
24 * Display name for console |
|
25 * |
|
26 * @return "CServerConsole*" |
|
27 * The constructed CServerConsole |
|
28 * |
|
29 * @xxxx |
|
30 * |
|
31 */ |
|
32 CServerConsole* CServerConsole::NewL(const TDesC& aName) |
|
33 { |
|
34 CServerConsole* s = new(ELeave) CServerConsole; |
|
35 CleanupStack::PushL(s); |
|
36 s->ConstructL(aName); |
|
37 CleanupStack::Pop(); |
|
38 return s; |
|
39 } |
|
40 |
|
41 /** |
|
42 * |
|
43 * Destructor for CServerConsole. |
|
44 * Destroys display console and its reader |
|
45 * |
|
46 * @xxxx |
|
47 * |
|
48 */ |
|
49 CServerConsole::~CServerConsole() |
|
50 { |
|
51 Cancel(); |
|
52 delete iConsoleReader; |
|
53 delete iWindowName; |
|
54 delete iInstructions; |
|
55 delete iConsole; |
|
56 } |
|
57 |
|
58 /** |
|
59 * |
|
60 * First-phase constructor for CServerConsole. |
|
61 * Adds itself to the Active Scheduler. |
|
62 * |
|
63 * @xxxx |
|
64 * |
|
65 */ |
|
66 CServerConsole::CServerConsole() |
|
67 :CActive(EPriorityHigh) |
|
68 { |
|
69 CActiveScheduler::Add(this); |
|
70 } |
|
71 |
|
72 /** |
|
73 * |
|
74 * Second-phase constructor for CServerConsole. |
|
75 * Creates the display console and its reader. |
|
76 * |
|
77 * @param "const TDesC& aName" |
|
78 * Display name of console. |
|
79 * |
|
80 * @xxxx |
|
81 * |
|
82 */ |
|
83 void CServerConsole::ConstructL(const TDesC& aName) |
|
84 { |
|
85 iWindowName = aName.AllocL(); |
|
86 iConsole = Console::NewL(*iWindowName, TSize(KConsFullScreen,KConsFullScreen)); |
|
87 iConsoleReader = CConsoleReader::NewL(*iConsole); |
|
88 } |
|
89 |
|
90 /** |
|
91 * |
|
92 * Accessor for base console. |
|
93 * |
|
94 * @return "CConsoleBase*" |
|
95 * The base console. |
|
96 * |
|
97 * @xxxx |
|
98 * |
|
99 */ |
|
100 CConsoleBase* CServerConsole::Console() const |
|
101 { |
|
102 return iConsole; |
|
103 } |
|
104 |
|
105 /** |
|
106 * |
|
107 * Sets and shows displayable instructions. |
|
108 * |
|
109 * @param "const TDesC& aInstructions" |
|
110 * Displayable instruction string. |
|
111 * |
|
112 * @xxxx |
|
113 * |
|
114 */ |
|
115 void CServerConsole::SetInstructionsL(const TDesC& aInstructions) |
|
116 { |
|
117 if (iInstructions) |
|
118 { |
|
119 delete iInstructions; |
|
120 iInstructions = NULL; |
|
121 } |
|
122 iInstructions = aInstructions.AllocL(); |
|
123 iConsole->ClearScreen(); |
|
124 iConsole->Write(*iInstructions); |
|
125 } |
|
126 |
|
127 /** |
|
128 * |
|
129 * Starts the console reader listening for input. |
|
130 * |
|
131 * @param "MConsoleReader& aReader" |
|
132 * The console reader. |
|
133 * |
|
134 * @xxxx |
|
135 * |
|
136 */ |
|
137 void CServerConsole::Read(MConsoleReader& aReader) |
|
138 { |
|
139 iConsoleReader->DoRead(aReader); |
|
140 } |
|
141 |
|
142 /** |
|
143 * |
|
144 * Stops the console reader listening for input. |
|
145 * |
|
146 * |
|
147 * @xxxx |
|
148 * |
|
149 */ |
|
150 void CServerConsole::ReadCancel() |
|
151 { |
|
152 iConsoleReader->Cancel(); |
|
153 } |
|
154 |
|
155 /** |
|
156 * |
|
157 * RunL method for active object CServerConsole. |
|
158 * |
|
159 * @xxxx |
|
160 * |
|
161 */ |
|
162 void CServerConsole::RunL() |
|
163 { |
|
164 User::LeaveIfError(iStatus.Int()); |
|
165 TBool reading = iConsoleReader->IsActive(); |
|
166 iConsoleReader->Cancel(); |
|
167 |
|
168 //listen for key input if we were before... |
|
169 if (reading) |
|
170 iConsoleReader->DoRead(); |
|
171 } |
|
172 |
|
173 /** |
|
174 * |
|
175 * DoCancel method for active object CServerConsole. |
|
176 * |
|
177 * @xxxx |
|
178 * |
|
179 */ |
|
180 void CServerConsole::DoCancel() |
|
181 { |
|
182 ReadCancel(); |
|
183 } |
|
184 |
|
185 /** |
|
186 * |
|
187 * Error handler for active object CServerConsole. |
|
188 * (Currently a stub) |
|
189 * |
|
190 * @param "TInt aError" |
|
191 * The error code |
|
192 * |
|
193 * @return "TInt" |
|
194 * The error code |
|
195 * |
|
196 * @xxxx |
|
197 * |
|
198 */ |
|
199 TInt CServerConsole::RunError(TInt aError) |
|
200 { |
|
201 return aError; |
|
202 } |
|
203 |
|
204 |
|
205 |
|
206 /** |
|
207 * |
|
208 * Static constructor for CConsoleReader. |
|
209 * |
|
210 * @param "CConsoleBase& aConsole" |
|
211 * The console we are to read |
|
212 * |
|
213 * @return "CConsoleReader*" |
|
214 * The constructed CConsoleReader |
|
215 * |
|
216 * @xxxx |
|
217 * |
|
218 */ |
|
219 CConsoleReader* CConsoleReader::NewL(CConsoleBase& aConsole) |
|
220 { |
|
221 CConsoleReader* s = new(ELeave) CConsoleReader(aConsole); |
|
222 return s; |
|
223 } |
|
224 |
|
225 /** |
|
226 * |
|
227 * First-phase constructor for CConsoleReader. |
|
228 * Adds itself to the Active Scheduler. |
|
229 * |
|
230 * @param "CConsoleBase& aConsole" |
|
231 * console to read from |
|
232 * |
|
233 * @xxxx |
|
234 * |
|
235 */ |
|
236 CConsoleReader::CConsoleReader(CConsoleBase& aConsole) : |
|
237 CActive(EPriorityUserInput), |
|
238 iConsole(aConsole) |
|
239 { |
|
240 CActiveScheduler::Add(this); |
|
241 } |
|
242 |
|
243 /** |
|
244 * |
|
245 * Destructor for CConsoleReader. |
|
246 * |
|
247 * @xxxx |
|
248 * |
|
249 */ |
|
250 CConsoleReader::~CConsoleReader() |
|
251 { |
|
252 Cancel(); |
|
253 } |
|
254 |
|
255 /** |
|
256 * |
|
257 * DoRead method for active object CConsoleReader; |
|
258 * sets client and starts reading |
|
259 * |
|
260 * @param "MConsoleReader& aClient" |
|
261 * client MConsoleReader (which will process the input) |
|
262 * |
|
263 * @xxxx |
|
264 * |
|
265 */ |
|
266 void CConsoleReader::DoRead(MConsoleReader& aClient) |
|
267 { |
|
268 iClient = &aClient; |
|
269 DoRead(); |
|
270 } |
|
271 |
|
272 /** |
|
273 * |
|
274 * DoRead method for active object CConsoleReader; |
|
275 * starts reading from current client |
|
276 * |
|
277 * @xxxx |
|
278 * |
|
279 */ |
|
280 void CConsoleReader::DoRead() |
|
281 { |
|
282 iConsole.Read(iStatus); |
|
283 SetActive(); |
|
284 } |
|
285 |
|
286 /** |
|
287 * |
|
288 * RunL method for active object CConsoleReader; |
|
289 * fetches a keystroke and sends it to its client for processing. |
|
290 * |
|
291 * @xxxx |
|
292 * |
|
293 */ |
|
294 void CConsoleReader::RunL() |
|
295 { |
|
296 iKeyStroke = iConsole.KeyCode(); |
|
297 if (iStatus.Int()) |
|
298 iClient->Error(iStatus.Int()); |
|
299 else |
|
300 iClient->InputReceived(iKeyStroke); |
|
301 } |
|
302 |
|
303 /** |
|
304 * |
|
305 * DoCancel method for active object CConsoleReader |
|
306 * |
|
307 * @xxxx |
|
308 * |
|
309 */ |
|
310 void CConsoleReader::DoCancel() |
|
311 { |
|
312 iConsole.ReadCancel(); |
|
313 } |