|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32cons.h> |
|
19 #include <e32debug.h> |
|
20 |
|
21 #include "e32svr.h" |
|
22 #include <e32keys.h> |
|
23 |
|
24 #include <e32property.h> |
|
25 |
|
26 #include "controlappbinder.h" |
|
27 |
|
28 |
|
29 |
|
30 #define LOG(A,B) RDebug::Print(_L("UsbControlAppBinder: " L##A),B) |
|
31 |
|
32 #define PNT(A) RDebug::Print(_L("UsbControlAppBinder: " L##A)) |
|
33 |
|
34 #define PANIC Panic(__LINE__) |
|
35 |
|
36 void Panic(TInt aLine) |
|
37 { |
|
38 RDebug::Printf("UsbControlAppBinder: PANIC line=%d", aLine); |
|
39 User::Panic(_L("UsbControlAppBinder"), aLine); |
|
40 } |
|
41 |
|
42 |
|
43 void RunAppL() |
|
44 { |
|
45 CUsbControlAppBinderConsole* binderapp = CUsbControlAppBinderConsole::NewLC(); |
|
46 binderapp->Start(); |
|
47 CleanupStack::PopAndDestroy(binderapp); |
|
48 } |
|
49 |
|
50 |
|
51 TInt E32Main() |
|
52 { |
|
53 __UHEAP_MARK; |
|
54 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
55 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
56 TInt err = KErrNoMemory; |
|
57 if(cleanup && activeScheduler) |
|
58 { |
|
59 CActiveScheduler::Install(activeScheduler); |
|
60 PNT("*** UsbControlAppBinder E32Main ***\n"); |
|
61 TRAP(err, RunAppL()); |
|
62 } |
|
63 delete activeScheduler; |
|
64 delete cleanup; |
|
65 __UHEAP_MARKEND; |
|
66 return err; |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 CUsbControlAppBinderConsole* CUsbControlAppBinderConsole::NewLC() |
|
72 { |
|
73 CUsbControlAppBinderConsole* self = new(ELeave) CUsbControlAppBinderConsole; |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(); |
|
76 PNT("Constructed USB Control App Binder\n"); |
|
77 return self; |
|
78 } |
|
79 |
|
80 CUsbControlAppBinderConsole::~CUsbControlAppBinderConsole() |
|
81 { |
|
82 PNT("Closing USB Control App Binder\n"); |
|
83 delete iKeys; |
|
84 delete iConsole; |
|
85 } |
|
86 |
|
87 CUsbControlAppBinderConsole::CUsbControlAppBinderConsole() |
|
88 { |
|
89 } |
|
90 |
|
91 void CUsbControlAppBinderConsole::ConstructL() |
|
92 { |
|
93 iConsole = Console::NewL(KUsbControlAppBinderTitle, TSize(KBinderWindowWidth, KBinderWindowDepth)); |
|
94 |
|
95 Move((KScreenWidth-KBinderWindowWidth-2)/2,1); |
|
96 |
|
97 // After everything else, enable interactivity. |
|
98 iKeys = CUsbControlAppBinderKeys::NewL(*this); |
|
99 |
|
100 Draw(); |
|
101 } |
|
102 |
|
103 void CUsbControlAppBinderConsole::Move(TInt aX, TInt aY) |
|
104 { |
|
105 TRawEvent event; |
|
106 |
|
107 event.Set(TRawEvent::EKeyDown, EStdKeyLeftShift); |
|
108 UserSvr::AddEvent(event); |
|
109 |
|
110 if (aX) |
|
111 { |
|
112 if ( aX > 0 ) |
|
113 { |
|
114 // Move to the right... |
|
115 for(TInt i=aX; i; i--) |
|
116 { |
|
117 event.Set(TRawEvent::EKeyDown, EStdKeyRightArrow); |
|
118 UserSvr::AddEvent(event); |
|
119 event.Set(TRawEvent::EKeyUp, EStdKeyRightArrow); |
|
120 UserSvr::AddEvent(event); |
|
121 } |
|
122 } |
|
123 else |
|
124 { |
|
125 // Move to the Left... |
|
126 for(TInt i=aX; i; i++) |
|
127 { |
|
128 event.Set(TRawEvent::EKeyDown, EStdKeyLeftArrow); |
|
129 UserSvr::AddEvent(event); |
|
130 event.Set(TRawEvent::EKeyUp, EStdKeyLeftArrow); |
|
131 UserSvr::AddEvent(event); |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 if (aY) |
|
137 { |
|
138 if ( aY > 0 ) |
|
139 { |
|
140 // Move downwards... |
|
141 for(TInt i=aY; i; i--) |
|
142 { |
|
143 event.Set(TRawEvent::EKeyDown, EStdKeyDownArrow); |
|
144 UserSvr::AddEvent(event); |
|
145 event.Set(TRawEvent::EKeyUp, EStdKeyDownArrow); |
|
146 UserSvr::AddEvent(event); |
|
147 } |
|
148 } |
|
149 else |
|
150 { |
|
151 // Move upwards... |
|
152 for(TInt i=aY; i; i++) |
|
153 { |
|
154 event.Set(TRawEvent::EKeyDown, EStdKeyUpArrow); |
|
155 UserSvr::AddEvent(event); |
|
156 event.Set(TRawEvent::EKeyUp, EStdKeyUpArrow); |
|
157 UserSvr::AddEvent(event); |
|
158 } |
|
159 } |
|
160 } |
|
161 |
|
162 event.Set(TRawEvent::EKeyUp, EStdKeyLeftShift); |
|
163 UserSvr::AddEvent(event); |
|
164 } |
|
165 |
|
166 void CUsbControlAppBinderConsole::Start() |
|
167 { |
|
168 // Get everything running |
|
169 CActiveScheduler::Start(); |
|
170 } |
|
171 |
|
172 void CUsbControlAppBinderConsole::Stop() const |
|
173 { |
|
174 CActiveScheduler::Stop(); |
|
175 } |
|
176 |
|
177 void CUsbControlAppBinderConsole::Draw() |
|
178 { |
|
179 iConsole->ClearScreen(); |
|
180 |
|
181 iConsole->Printf |
|
182 ( _L( "\r\n" |
|
183 L"'A'\r\n" |
|
184 L"\r\n" |
|
185 L"\r\n" |
|
186 L"\r\n" |
|
187 L"'C'\r\n" |
|
188 L"\r\n" |
|
189 L"\r\n" |
|
190 L"\r\n" |
|
191 L"'V'\r\n" |
|
192 L"\r\n" |
|
193 L"\r\n" |
|
194 L"\r\n" |
|
195 L"'*'\r\n" |
|
196 L"\r\n" |
|
197 L"\r\n" |
|
198 L"\r\n" |
|
199 L"'Q'\r\n" |
|
200 ) |
|
201 ); |
|
202 } |
|
203 |
|
204 void CUsbControlAppBinderConsole::StartAwareApp() |
|
205 { |
|
206 PNT("Start Aware Program\n"); |
|
207 RProcess iAwareApp; |
|
208 TInt err = iAwareApp.Create(_L("testusbawareapp.exe"), KNullDesC); |
|
209 |
|
210 if (err != KErrNone) |
|
211 { |
|
212 LOG("Failed to create Aware program, err=%d",err); |
|
213 iAwareApp.Close(); |
|
214 } |
|
215 else |
|
216 { |
|
217 iAwareApp.Resume(); |
|
218 } |
|
219 } |
|
220 |
|
221 void CUsbControlAppBinderConsole::StartControlApp() |
|
222 { |
|
223 PNT("Start Control Program\n"); |
|
224 RProcess iControlApp; |
|
225 TInt err = iControlApp.Create(_L("exampleusbcontrolapp.exe"), KNullDesC); |
|
226 |
|
227 if (err != KErrNone) |
|
228 { |
|
229 LOG("Failed to create Control program, err=%d",err); |
|
230 iControlApp.Close(); |
|
231 } |
|
232 else |
|
233 { |
|
234 iControlApp.Resume(); |
|
235 } |
|
236 } |
|
237 |
|
238 void CUsbControlAppBinderConsole::StartViewerApp() |
|
239 { |
|
240 PNT("Start Viewer Program\n"); |
|
241 RProcess iViewerApp; |
|
242 TInt err = iViewerApp.Create(_L("usbviewer.exe"), KNullDesC); |
|
243 |
|
244 if (err != KErrNone) |
|
245 { |
|
246 LOG("Failed to create Viewer program, err=%d",err); |
|
247 iViewerApp.Close(); |
|
248 } |
|
249 else |
|
250 { |
|
251 iViewerApp.Resume(); |
|
252 } |
|
253 } |
|
254 |
|
255 |
|
256 |
|
257 CUsbControlAppBinderKeys* CUsbControlAppBinderKeys::NewL(CUsbControlAppBinderConsole& aUsbControlAppBinderConsole) |
|
258 { |
|
259 CUsbControlAppBinderKeys* self = new(ELeave) CUsbControlAppBinderKeys(aUsbControlAppBinderConsole); |
|
260 CleanupStack::PushL(self); |
|
261 self->ConstructL(); |
|
262 CleanupStack::Pop(self); |
|
263 return self; |
|
264 } |
|
265 |
|
266 CUsbControlAppBinderKeys::~CUsbControlAppBinderKeys() |
|
267 { |
|
268 Cancel(); |
|
269 } |
|
270 |
|
271 CUsbControlAppBinderKeys::CUsbControlAppBinderKeys(CUsbControlAppBinderConsole& aUsbControlAppBinderConsole) |
|
272 : CActive(EPriorityStandard) |
|
273 , iUsbControlAppBinderConsole(aUsbControlAppBinderConsole) |
|
274 { |
|
275 CActiveScheduler::Add(this); |
|
276 } |
|
277 |
|
278 void CUsbControlAppBinderKeys::ConstructL() |
|
279 { |
|
280 TInt err = RProperty::Define(KUidUsbControlAppCategory, KUsbControlAppShutdownKey, RProperty::EInt); |
|
281 LOG("CUsbControlAppBinderKeys::ConstructL() RProperty::Define() err=%d", err); |
|
282 if(err) |
|
283 { |
|
284 PNT("CUsbControlAppBinderKeys::ConstructL() RProperty::Define() Property probably already defined\n"); |
|
285 } |
|
286 err = RProperty::Set(KUidUsbControlAppCategory, KUsbControlAppShutdownKey, 0); |
|
287 LOG("CUsbControlAppBinderKeys::ConstructL() RProperty::Set() err=%d", err); |
|
288 User::LeaveIfError(err); |
|
289 // Allow keyboard input |
|
290 iUsbControlAppBinderConsole.iConsole->Read(iStatus); |
|
291 SetActive(); |
|
292 } |
|
293 |
|
294 #define SECONDS(t) (t*1000000) |
|
295 |
|
296 void CUsbControlAppBinderKeys::RunL() |
|
297 { |
|
298 User::LeaveIfError(iStatus.Int()); |
|
299 |
|
300 TKeyCode theKey = iUsbControlAppBinderConsole.iConsole->KeyCode(); |
|
301 |
|
302 switch(theKey) |
|
303 { |
|
304 case 'a': case 'A': |
|
305 iUsbControlAppBinderConsole.StartAwareApp(); |
|
306 break; |
|
307 |
|
308 case 'c': case 'C': |
|
309 iUsbControlAppBinderConsole.StartControlApp(); |
|
310 break; |
|
311 |
|
312 case 'v': case 'V': |
|
313 iUsbControlAppBinderConsole.StartViewerApp(); |
|
314 break; |
|
315 |
|
316 case '*': |
|
317 PNT("Start Everything\n"); |
|
318 iUsbControlAppBinderConsole.StartControlApp(); |
|
319 User::After(SECONDS(4)); |
|
320 iUsbControlAppBinderConsole.StartViewerApp(); |
|
321 User::After(SECONDS(4)); |
|
322 iUsbControlAppBinderConsole.StartAwareApp(); |
|
323 break; |
|
324 |
|
325 case 'q': case 'Q': |
|
326 { |
|
327 TInt err = RProperty::Set(KUidUsbControlAppCategory, KUsbControlAppShutdownKey, 1); |
|
328 LOG("CUsbAwareAppKeys::RunL() RProperty::Set() err=%d", err); |
|
329 User::LeaveIfError(err); |
|
330 iUsbControlAppBinderConsole.Stop(); |
|
331 return; |
|
332 } |
|
333 |
|
334 default: |
|
335 LOG("Unexpected Key [%c]",theKey); |
|
336 break; |
|
337 } |
|
338 |
|
339 iUsbControlAppBinderConsole.iConsole->Read(iStatus); |
|
340 SetActive(); |
|
341 } |
|
342 |
|
343 void CUsbControlAppBinderKeys::DoCancel() |
|
344 { |
|
345 iUsbControlAppBinderConsole.iConsole->ReadCancel(); |
|
346 } |
|
347 |
|
348 |
|
349 |
|
350 |