|
1 /* |
|
2 * Copyright (c) 2005-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 #include <apgtask.h> |
|
18 #include "T_GraphicsUtil.h" |
|
19 #include "T_DataDirectScreenAccess.h" |
|
20 #include "T_DataFbsScreenDevice.h" |
|
21 #include "T_DataFbsBitGc.h" |
|
22 |
|
23 _LIT(KDataClassname, "CDirectScreenAccess"); |
|
24 _LIT(KCmdDestructor, "~CDirectScreenAccess"); |
|
25 _LIT(KCmdDestructorGeneral, "~"); |
|
26 |
|
27 //command |
|
28 _LIT( KCmdNewL, "NewL" ); |
|
29 _LIT( KCmdStart, "StartL" ); |
|
30 _LIT( KCmdGc, "Gc" ); |
|
31 _LIT( KCmdScreenDevice, "ScreenDevice" ); |
|
32 _LIT( KCmdDrawRegion, "DrawingRegion" ); |
|
33 _LIT( KCmdSetPriority, "SetPriority" ); |
|
34 _LIT( KCmdBringAppFg, "Util_BringAppFg" ); |
|
35 |
|
36 // Fields |
|
37 _LIT( KRWsSessionObj, "ws"); |
|
38 _LIT( KCWsScreenDeviceObj, "scrdev"); |
|
39 _LIT( KRWindowObj, "win"); |
|
40 _LIT( KAppName, "app"); |
|
41 _LIT( KPriorityObj, "Priority"); |
|
42 _LIT( KFldGc, "gc"); |
|
43 _LIT( KFldScreenDevice, "ScreenDevice"); |
|
44 _LIT( KFldDrawRegion, "region1"); |
|
45 _LIT( KWantedReasonObj, "reason"); |
|
46 |
|
47 //Error |
|
48 _LIT( KErrNewL, "Create CDirectScreenAccess object failed."); |
|
49 _LIT( KErrGc, "Execute CDirectScreenAccess::Gc failed. return value is NULL"); |
|
50 _LIT( KErrScreenDevice, "Execute CDirectScreenAccess::ScreenDevices failed. return value is NULL"); |
|
51 _LIT( KErrDrawRegion, "Execute CDirectScreenAccess::DrawRegion failed. return value is NULL"); |
|
52 _LIT( KErrDrawRegionSetting, "Set DrawRegion failed."); |
|
53 _LIT( KErrAbortNowReason, "the AbortNow's reason do not match the expected value."); |
|
54 _LIT( KErrRestartReason, "the Restart's reason do not match the expected value."); |
|
55 _LIT( KLogMissingParameter, "Missing parameter '%S'"); |
|
56 _LIT( KLogMissingWrapper,"Missing Wrapper class '%S'"); |
|
57 |
|
58 //info |
|
59 _LIT( KInfoNewL, "NewL() has been called."); |
|
60 _LIT( KInfoStartL, "StartL() has been called"); |
|
61 _LIT( KInfoGc, "Gc() has been called" ); |
|
62 _LIT( KInfoScreenDevice, "ScreenDevice() has been called" ); |
|
63 _LIT( KInfoDrawRegion, "DrawingRegion() has been called" ); |
|
64 _LIT( KInfoSetPriority, "SetPriority() has been called" ); |
|
65 _LIT( KInfoAbortNow, "AbortNow has been called, with the reason=%d"); |
|
66 _LIT( KInfoRestart, "Restart has been called, with the reason=%d"); |
|
67 _LIT( KInfoDestructor, "execute ~CDirectScreenAccess()"); |
|
68 |
|
69 const RDirectScreenAccess::TTerminationReasons KDefaultReason = RDirectScreenAccess::ETerminateRegion; |
|
70 |
|
71 ////////////////////////////////////////////////////////////////////// |
|
72 // Construction/Destruction |
|
73 ////////////////////////////////////////////////////////////////////// |
|
74 /** |
|
75 * Protected constructor. First phase construction |
|
76 */ |
|
77 CT_DataDirectScreenAccess::CT_DataDirectScreenAccess() : |
|
78 iDirectScreenAccess(NULL), |
|
79 iWantedReason(KDefaultReason) |
|
80 { |
|
81 } |
|
82 /** |
|
83 * Public destructor |
|
84 */ |
|
85 CT_DataDirectScreenAccess::~CT_DataDirectScreenAccess() |
|
86 { |
|
87 DestroyData(); |
|
88 } |
|
89 |
|
90 /** |
|
91 * Two phase constructor |
|
92 */ |
|
93 CT_DataDirectScreenAccess* CT_DataDirectScreenAccess::NewL() |
|
94 { |
|
95 CT_DataDirectScreenAccess* self = new (ELeave) CT_DataDirectScreenAccess(); |
|
96 CleanupStack::PushL(self); |
|
97 self->ConstructL(); |
|
98 CleanupStack::Pop(self); |
|
99 return self; |
|
100 } |
|
101 |
|
102 /** |
|
103 * Second phase construction |
|
104 */ |
|
105 void CT_DataDirectScreenAccess::ConstructL() |
|
106 { |
|
107 //nothing to do here. |
|
108 } |
|
109 |
|
110 /** |
|
111 * Set the object that the data wraps |
|
112 * |
|
113 * @param aObject object that the wrapper is testing |
|
114 * |
|
115 */ |
|
116 void CT_DataDirectScreenAccess::SetObjectL(TAny* aAny) |
|
117 { |
|
118 DestroyData(); |
|
119 iDirectScreenAccess = static_cast<CDirectScreenAccess*> (aAny); |
|
120 } |
|
121 |
|
122 /** |
|
123 * The object will no longer be owned by this |
|
124 * |
|
125 * @leave KErrNotSupported if the the function is not supported |
|
126 */ |
|
127 void CT_DataDirectScreenAccess::DisownObjectL() |
|
128 { |
|
129 iDirectScreenAccess = NULL; |
|
130 } |
|
131 |
|
132 void CT_DataDirectScreenAccess::DestroyData() |
|
133 { |
|
134 delete iDirectScreenAccess; |
|
135 iDirectScreenAccess = NULL; |
|
136 } |
|
137 |
|
138 /** |
|
139 * Process a command read from the ini file |
|
140 * |
|
141 * @param aCommand the command to process |
|
142 * @param aSection the entry in the ini file requiring the command to be processed |
|
143 * @param aAsyncErrorIndex index of command. used for async calls |
|
144 * |
|
145 * @return ETrue if the command is processed |
|
146 */ |
|
147 TBool CT_DataDirectScreenAccess::DoCommandL(const TTEFFunction& aCommand, |
|
148 const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
149 { |
|
150 TBool result = ETrue; |
|
151 |
|
152 if ( !aCommand.Compare( KCmdNewL ) || !aCommand.Compare( KDataClassname ) ) |
|
153 { |
|
154 DoCmdnewL(aSection); |
|
155 } |
|
156 else if ( !aCommand.Compare(KCmdDestructor) || !aCommand.Compare(KCmdDestructorGeneral ) ) |
|
157 { |
|
158 DoCmdDestructor(); |
|
159 } |
|
160 else if ( !aCommand.Compare( KCmdStart ) ) |
|
161 { |
|
162 DoCmdStartL(aSection); |
|
163 } |
|
164 else if ( !aCommand.Compare( KCmdGc ) ) |
|
165 { |
|
166 DoCmdGcL(aSection); |
|
167 } |
|
168 else if ( !aCommand.Compare( KCmdScreenDevice ) ) |
|
169 { |
|
170 DoCmdScreenDeviceL(aSection); |
|
171 } |
|
172 else if ( !aCommand.Compare( KCmdDrawRegion ) ) |
|
173 { |
|
174 DoCmdDrawRegion(aSection); |
|
175 } |
|
176 else if ( !aCommand.Compare( KCmdSetPriority ) ) |
|
177 { |
|
178 DoCmdSetPriority(aSection); |
|
179 } |
|
180 else if ( !aCommand.Compare( KCmdBringAppFg ) ) |
|
181 { |
|
182 DoCmdBringAppFgL(aSection); |
|
183 } |
|
184 else |
|
185 { |
|
186 CDataWrapperActive::DoCommandL(aCommand, aSection, aAsyncErrorIndex); |
|
187 } |
|
188 |
|
189 return result; |
|
190 } |
|
191 |
|
192 /** |
|
193 * test AbortNow() |
|
194 */ |
|
195 void CT_DataDirectScreenAccess::AbortNow(RDirectScreenAccess::TTerminationReasons aReason) |
|
196 { |
|
197 INFO_PRINTF2(KInfoAbortNow , aReason); |
|
198 DecOutstanding(); |
|
199 if( iWantedReason != aReason ) |
|
200 { |
|
201 ERR_PRINTF1(KErrAbortNowReason); |
|
202 SetBlockResult(EFail); |
|
203 } |
|
204 |
|
205 } |
|
206 |
|
207 /** |
|
208 * Test Restart() |
|
209 */ |
|
210 void CT_DataDirectScreenAccess::Restart(RDirectScreenAccess::TTerminationReasons aReason) |
|
211 { |
|
212 INFO_PRINTF2(KInfoRestart , aReason); |
|
213 DecOutstanding(); |
|
214 if( iWantedReason != aReason ) |
|
215 { |
|
216 ERR_PRINTF1(KErrRestartReason); |
|
217 SetBlockResult(EFail); |
|
218 } |
|
219 |
|
220 } |
|
221 |
|
222 /** |
|
223 * Helper method to get RWsSession |
|
224 */ |
|
225 RWsSession* CT_DataDirectScreenAccess::GetRWSessionL(const TDesC& aSection) |
|
226 { |
|
227 RWsSession* iClient( NULL ); //Window Session Client |
|
228 TPtrC objectName; |
|
229 |
|
230 if ( GetStringFromConfig(aSection, KRWsSessionObj(), objectName) ) |
|
231 { |
|
232 iClient = static_cast<RWsSession*>(GetDataObjectL(objectName)); |
|
233 } |
|
234 |
|
235 return iClient; |
|
236 } |
|
237 |
|
238 /** |
|
239 * Helper method to get CWsScreenDevice |
|
240 */ |
|
241 CWsScreenDevice* CT_DataDirectScreenAccess::GetDevicesL(const TDesC& aSection) |
|
242 { |
|
243 CWsScreenDevice* device = NULL; |
|
244 |
|
245 if ( !CT_GraphicsUtil::GetWsScreenDeviceL(*this, aSection, KCWsScreenDeviceObj, device) ) |
|
246 { |
|
247 ERR_PRINTF2(KLogMissingParameter , &KCWsScreenDeviceObj); |
|
248 SetBlockResult(EFail); |
|
249 } |
|
250 |
|
251 return device; |
|
252 } |
|
253 |
|
254 |
|
255 /** |
|
256 * Helper method to get RWindow |
|
257 */ |
|
258 RWindow* CT_DataDirectScreenAccess::GetWindowL(const TDesC& aSection) |
|
259 { |
|
260 RWindow* window( NULL ); |
|
261 TPtrC objectName; |
|
262 |
|
263 if( GetStringFromConfig(aSection, KRWindowObj, objectName)) |
|
264 { |
|
265 window = static_cast<RWindow*>(GetDataObjectL(objectName)); |
|
266 } |
|
267 |
|
268 return window; |
|
269 |
|
270 } |
|
271 |
|
272 |
|
273 /** |
|
274 * Test NewL() |
|
275 */ |
|
276 void CT_DataDirectScreenAccess::DoCmdnewL(const TDesC& aSection) |
|
277 { |
|
278 // Execute command and log parameters |
|
279 DestroyData(); |
|
280 INFO_PRINTF1(KInfoNewL); |
|
281 iDirectScreenAccess = CDirectScreenAccess::NewL(*GetRWSessionL(aSection), |
|
282 *GetDevicesL(aSection), *GetWindowL(aSection), *this ); |
|
283 |
|
284 if(!iDirectScreenAccess) |
|
285 { |
|
286 ERR_PRINTF1(KErrNewL); |
|
287 SetBlockResult(EFail); |
|
288 } |
|
289 |
|
290 } |
|
291 |
|
292 /** |
|
293 * Test Destructor() |
|
294 */ |
|
295 void CT_DataDirectScreenAccess::DoCmdDestructor() |
|
296 { |
|
297 INFO_PRINTF1(KInfoDestructor); |
|
298 delete iDirectScreenAccess; |
|
299 iDirectScreenAccess = NULL; |
|
300 } |
|
301 |
|
302 /** |
|
303 * Test StartL() |
|
304 */ |
|
305 void CT_DataDirectScreenAccess::DoCmdStartL(const TDesC& aSection) |
|
306 { |
|
307 INFO_PRINTF1(KInfoStartL); |
|
308 if ( !CT_GraphicsUtil::ReadTerminateReason(*this , aSection , KWantedReasonObj, iWantedReason) ) |
|
309 { |
|
310 ERR_PRINTF2(KLogMissingParameter , &KWantedReasonObj); |
|
311 SetBlockResult(EFail); |
|
312 } |
|
313 |
|
314 iDirectScreenAccess->StartL(); |
|
315 IncOutstanding(); |
|
316 } |
|
317 |
|
318 /** |
|
319 * Test Gc() |
|
320 */ |
|
321 void CT_DataDirectScreenAccess::DoCmdGcL(const TDesC& aSection) |
|
322 { |
|
323 // Execute command and log parameters |
|
324 INFO_PRINTF1(KInfoGc); |
|
325 |
|
326 TPtrC aGcName; |
|
327 if(GetStringFromConfig(aSection, KFldGc, aGcName) ) |
|
328 { |
|
329 CFbsBitGc* iGc = iDirectScreenAccess->Gc(); |
|
330 if(!iGc) |
|
331 { |
|
332 INFO_PRINTF1(KErrGc); |
|
333 SetError(KErrNotFound); |
|
334 } |
|
335 else |
|
336 { |
|
337 SetDataObjectL(aGcName , iGc); |
|
338 } |
|
339 } |
|
340 else |
|
341 { |
|
342 ERR_PRINTF2(KLogMissingParameter , &KFldGc); |
|
343 } |
|
344 |
|
345 } |
|
346 |
|
347 /** |
|
348 * Test ScreenDevice() |
|
349 */ |
|
350 void CT_DataDirectScreenAccess::DoCmdScreenDeviceL(const TDesC& aSection) |
|
351 { |
|
352 // Execute command and log parameters |
|
353 INFO_PRINTF1(KInfoScreenDevice); |
|
354 TPtrC aScreenDeviceName; |
|
355 if(GetStringFromConfig(aSection, KFldScreenDevice, aScreenDeviceName)) |
|
356 { |
|
357 CFbsScreenDevice* aScreenDevice = iDirectScreenAccess->ScreenDevice(); |
|
358 if(!aScreenDevice) |
|
359 { |
|
360 ERR_PRINTF1(KErrScreenDevice); |
|
361 SetError(KErrNotFound); |
|
362 } |
|
363 else |
|
364 { |
|
365 SetDataObjectL(aScreenDeviceName , aScreenDevice); |
|
366 } |
|
367 |
|
368 } |
|
369 else |
|
370 { |
|
371 ERR_PRINTF2(KLogMissingParameter , &KFldScreenDevice); |
|
372 } |
|
373 |
|
374 } |
|
375 |
|
376 /** |
|
377 * Test DrawRegion() |
|
378 */ |
|
379 void CT_DataDirectScreenAccess::DoCmdDrawRegion(const TDesC& aSection) |
|
380 { |
|
381 // Execute command and log parameters |
|
382 INFO_PRINTF1(KInfoDrawRegion); |
|
383 TRegion* region; |
|
384 region = iDirectScreenAccess->DrawingRegion(); |
|
385 |
|
386 if(!region) |
|
387 { |
|
388 ERR_PRINTF1(KErrDrawRegion); |
|
389 SetError(KErrNotFound); |
|
390 } |
|
391 // Compare the region. |
|
392 // read the exepected region size |
|
393 TRect temp; |
|
394 if( GetRectFromConfig(aSection ,KFldDrawRegion, temp )) |
|
395 { |
|
396 //compare the region |
|
397 TRect temp2 = (*region)[0]; |
|
398 |
|
399 if(temp != temp2) |
|
400 { |
|
401 ERR_PRINTF1(KErrDrawRegionSetting); |
|
402 SetBlockResult(EFail); |
|
403 } |
|
404 } |
|
405 |
|
406 } |
|
407 |
|
408 /** |
|
409 * Test AbortNow() and Restart() by SetPriority() |
|
410 */ |
|
411 void CT_DataDirectScreenAccess::DoCmdSetPriority(const TDesC& aSection) |
|
412 { |
|
413 INFO_PRINTF1(KInfoSetPriority); |
|
414 CActive::TPriority priority; |
|
415 IncOutstanding(); |
|
416 if ( !CT_GraphicsUtil::ReadPriority(*this , aSection , KPriorityObj, priority) ) |
|
417 { |
|
418 ERR_PRINTF2(KLogMissingParameter , &KPriorityObj); |
|
419 SetBlockResult(EFail); |
|
420 } |
|
421 iDirectScreenAccess->SetPriority(priority); |
|
422 } |
|
423 |
|
424 /** |
|
425 * Test AbortNow() and Restart() by bring a app to foreground |
|
426 */ |
|
427 void CT_DataDirectScreenAccess::DoCmdBringAppFgL(const TDesC& aSection) |
|
428 { |
|
429 // Execute command and log parameters |
|
430 TPtrC sessionKeyName(KRWsSessionObj); |
|
431 TPtrC appKeyName(KAppName); |
|
432 IncOutstanding(); |
|
433 if ( !CT_GraphicsUtil::BringAppForegroundL(*this , aSection , sessionKeyName, appKeyName) ) |
|
434 { |
|
435 ERR_PRINTF2(KLogMissingParameter , &sessionKeyName); |
|
436 SetBlockResult(EFail); |
|
437 } |
|
438 } |
|
439 |