|
1 // Copyright (c) 2005-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 "tcsy.h" |
|
17 |
|
18 // ---------------------------------------------------------------------------- |
|
19 // CActiveConsoleBase |
|
20 // ---------------------------------------------------------------------------- |
|
21 |
|
22 |
|
23 CActiveConsoleBase::CActiveConsoleBase(CConsoleBase& aConsole) |
|
24 : CActive(EPriorityStandard), iConsole(aConsole) |
|
25 { |
|
26 CActiveScheduler::Add(this); |
|
27 } |
|
28 |
|
29 CActiveConsoleBase::~CActiveConsoleBase() |
|
30 { |
|
31 Cancel(); |
|
32 } |
|
33 |
|
34 void CActiveConsoleBase::DoCancel() |
|
35 { |
|
36 iConsole.ReadCancel(); |
|
37 } |
|
38 |
|
39 void CActiveConsoleBase::RequestKey() |
|
40 { |
|
41 DrawCursor(); |
|
42 iConsole.Read(iStatus); |
|
43 SetActive(); |
|
44 } |
|
45 |
|
46 void CActiveConsoleBase::DrawCursor() |
|
47 { |
|
48 iConsole.Printf(_L(">>")); |
|
49 } |
|
50 |
|
51 |
|
52 TInt CActiveConsoleBase::RunError(TInt /*aError*/) |
|
53 { |
|
54 __DEBUGGER(); |
|
55 return KErrNone; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CActiveRootConsole |
|
60 // ---------------------------------------------------------------------------- |
|
61 |
|
62 void CActiveRootConsole::DrawMenu() |
|
63 { |
|
64 iConsole.Printf(_L("Choose action...\n\n")); |
|
65 iConsole.Printf(_L("n.\t\tStart RComm\n")); |
|
66 iConsole.Printf(_L("x.\t\tDelete all RComm\n")); |
|
67 iConsole.Printf(_L("a.\t\tAuto\n")); |
|
68 iConsole.Printf(_L("e.\t\tStart exclusive session\n")); |
|
69 iConsole.Printf(_L("f.\t\tStop exclusive session\n")); |
|
70 iConsole.Printf(_L("u.\t\tMark C32 User Heap\n")); |
|
71 iConsole.Printf(_L("v.\t\tMark-end C32 User Heap\n")); |
|
72 iConsole.Printf(_L("0.\t\tAccess Violation\n")); |
|
73 iConsole.Printf(_L("P.\t\tPanic\n")); |
|
74 iConsole.Printf(_L("T.\t\tHTTP Get\n")); |
|
75 iConsole.Printf(_L("Esc.\tStop\n")); |
|
76 RequestKey(); |
|
77 } |
|
78 |
|
79 |
|
80 CActiveRootConsole::CActiveRootConsole(CConsoleBase& aConsole, CCSYApp& aApp) |
|
81 : CActiveConsoleBase(aConsole), iApp(aApp) |
|
82 { |
|
83 } |
|
84 |
|
85 CActiveRootConsole* CActiveRootConsole::NewL(CConsoleBase& aConsole, CCSYApp& aApp) |
|
86 { |
|
87 CActiveRootConsole* console = new (ELeave) CActiveRootConsole(aConsole, aApp); |
|
88 // CleanupStack::PushL(console); |
|
89 // console->ConstructL(); |
|
90 // CleanupStack::Pop(); |
|
91 console->DrawMenu(); |
|
92 return console; |
|
93 } |
|
94 |
|
95 |
|
96 void CActiveRootConsole::RunL() |
|
97 { |
|
98 // key has been pressed |
|
99 |
|
100 TChar ch = iConsole.KeyCode(); |
|
101 switch (ch) |
|
102 { |
|
103 case 'n': |
|
104 TimePrint(); |
|
105 iConsole.Printf(_L("Starting RComm...\n")); |
|
106 iApp.NewCSYL(); |
|
107 break; |
|
108 |
|
109 case 'x': |
|
110 TimePrint(); |
|
111 iConsole.Printf(_L("Deleting all RComm...\n")); |
|
112 iApp.DeleteAllConnections(); |
|
113 break; |
|
114 |
|
115 case 'a': |
|
116 TimePrint(); |
|
117 iConsole.Printf(_L("Auto mode...\n")); |
|
118 iApp.AutoMode(); |
|
119 break; |
|
120 |
|
121 case 'e': |
|
122 { |
|
123 TimePrint(); |
|
124 iConsole.Printf(_L("Starting an exclusive session\n")); |
|
125 iApp.StartExclusiveSessionL(); |
|
126 break; |
|
127 } |
|
128 |
|
129 case 'f': |
|
130 { |
|
131 TimePrint(); |
|
132 iConsole.Printf(_L("Stopping the exclusive session\n")); |
|
133 iApp.StopExclusiveSession(); |
|
134 break; |
|
135 } |
|
136 |
|
137 case 'u': |
|
138 { |
|
139 TimePrint(); |
|
140 iConsole.Printf(_L("Mark C32 User Heap\n")); |
|
141 iApp.C32UHeapMark(); |
|
142 break; |
|
143 } |
|
144 |
|
145 case 'v': |
|
146 { |
|
147 TimePrint(); |
|
148 iConsole.Printf(_L("Mark-end C32 User Heap\n")); |
|
149 iApp.C32UHeapMarkEnd(); |
|
150 break; |
|
151 } |
|
152 |
|
153 case '0': |
|
154 { |
|
155 iConsole.Printf(_L("Deref-ing NULL...\n")); |
|
156 TInt* boom = NULL; |
|
157 TInt detritus = *boom; |
|
158 (void)(detritus != NULL); // keep the compiler happy by taking detritus as an r-value |
|
159 break; |
|
160 } |
|
161 |
|
162 case 'P': |
|
163 { |
|
164 iConsole.Printf(_L("Panic!\n")); |
|
165 User::Panic(_L("PANIC!!"), 0x1234); |
|
166 } |
|
167 |
|
168 case 'T': |
|
169 { |
|
170 iConsole.Printf(_L("Doing a HTTP Get...\n")); |
|
171 iApp.FetchWebPageL(); |
|
172 } |
|
173 |
|
174 case EKeyEscape: |
|
175 { |
|
176 iApp.Stop(); |
|
177 goto end; |
|
178 } |
|
179 |
|
180 |
|
181 default: |
|
182 iConsole.Printf(_L("Unknown command\r\n")); |
|
183 } |
|
184 // schedule another key press |
|
185 RequestKey(); |
|
186 |
|
187 end: |
|
188 return; |
|
189 } |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // CActiveCommConsole |
|
196 // ---------------------------------------------------------------------------- |
|
197 |
|
198 CActiveCommConsole::CActiveCommConsole(CConsoleBase& aConsole, CCSY& aCSY) |
|
199 : CActiveConsoleBase(aConsole), iComm(aCSY) |
|
200 { |
|
201 } |
|
202 |
|
203 |
|
204 CActiveCommConsole* CActiveCommConsole::NewL(CConsoleBase& aConsole, CCSY& aCSY) |
|
205 { |
|
206 CActiveCommConsole* console = new (ELeave) CActiveCommConsole(aConsole, aCSY); |
|
207 // CleanupStack::PushL(console); |
|
208 // console->ConstructL(); |
|
209 // CleanupStack::Pop(); |
|
210 console->DrawMenu(); |
|
211 return console; |
|
212 } |
|
213 |
|
214 void CActiveCommConsole::RunL() |
|
215 { |
|
216 // key has been pressed |
|
217 |
|
218 TChar ch = iConsole.KeyCode(); |
|
219 TBool reque = ETrue; |
|
220 |
|
221 switch (ch) |
|
222 { |
|
223 case 'c': |
|
224 iConsole.Printf(_L("Cancel RComm...\n")); |
|
225 // iComm.CancelCSY(); |
|
226 break; |
|
227 |
|
228 case 'r': |
|
229 iConsole.Printf(_L("RComm::Read...\n")); |
|
230 iComm.Read(); |
|
231 break; |
|
232 |
|
233 case 'w': |
|
234 iConsole.Printf(_L("RComm::Write...\n")); |
|
235 break; |
|
236 |
|
237 case 'x': |
|
238 iComm.Destroy(); |
|
239 reque = EFalse; |
|
240 break; |
|
241 |
|
242 |
|
243 default: |
|
244 iConsole.Printf(_L("Unknown command\r\n")); |
|
245 } |
|
246 if (reque) |
|
247 RequestKey(); // schedule another key press |
|
248 return; |
|
249 } |
|
250 |
|
251 void CActiveCommConsole::DrawMenu() |
|
252 { |
|
253 iConsole.Printf(_L("c.\t\tCancel RComm \n")); |
|
254 iConsole.Printf(_L("r.\t\tRComm::Read\n")); |
|
255 iConsole.Printf(_L("w.\t\tRComm::Write\n")); |
|
256 iConsole.Printf(_L("q.\t\tRComm::Close\n")); |
|
257 |
|
258 iConsole.Printf(_L("x.\t\tDelete RComm\n")); |
|
259 RequestKey(); |
|
260 } |
|
261 |
|
262 |
|
263 void CActiveConsoleBase::TimePrint() |
|
264 { |
|
265 TBuf<16> time; |
|
266 |
|
267 iTime.HomeTime(); |
|
268 |
|
269 TRAPD(err, iTime.FormatL(time, KDateFormatter)); |
|
270 __ASSERT_ALWAYS(err==KErrNone, User::Panic(_L("Test thread"), 0x666)); |
|
271 |
|
272 iConsole.Printf(_L("%S: "), &time); |
|
273 } |