|
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 |
|
18 #include "T_GraphicsUtil.h" |
|
19 #include "T_DataDsaSession.h" |
|
20 |
|
21 _LIT(KDataClassname, "RDirectScreenAccess"); |
|
22 //command |
|
23 _LIT( KCmdnewL, "new" ); |
|
24 _LIT( KCmdConstruct, "Construct" ); |
|
25 _LIT( KCmdClose, "Close" ); |
|
26 _LIT( KCmdRequest, "Request" ); |
|
27 _LIT( KCmdCompleted, "Completed" ); |
|
28 _LIT( KCmdCancel, "Cancel" ); |
|
29 _LIT( KCmdEatupMemory, "Util_EatupMemory" ); |
|
30 _LIT( KCmdFreeEatenMemory, "Util_FreeEatenMemory" ); |
|
31 // Fields |
|
32 _LIT( KRWsSessionObj, "ws"); |
|
33 _LIT( KRWindowObj, "win"); |
|
34 _LIT( KFldRegion, "region1"); |
|
35 _LIT( KFldMemLeft, "memleft"); |
|
36 |
|
37 //Error |
|
38 _LIT( KErrNewL, "Create RDirectScreenAccess() failed."); |
|
39 _LIT( KErrRequestRegionMatch, "Execute RDirectScreenAccess::Request() failed, Error: region size not match."); |
|
40 _LIT( KLogMissingParameter, "Missing parameter '%S'"); |
|
41 _LIT( KLogError, "Error=%d"); |
|
42 _LIT( KStraySignal, "Stray signal"); |
|
43 |
|
44 //Info |
|
45 _LIT( KRdsaNew1, "RDSA::new() has been called"); |
|
46 _LIT( KRdsaNew2, "RDSA::new(session) has been called"); |
|
47 _LIT( KInfoConstruct, "Construct() has been called" ); |
|
48 _LIT( KInfoClose, "Close() has been called" ); |
|
49 _LIT( KInfoRequest, "Request() has been called" ); |
|
50 _LIT( KInfoCompleted, "Completed() has been called" ); |
|
51 _LIT( KInfoCancel, "Cancel() has been called" ); |
|
52 _LIT( KRunRequestReady, "RunRequestReady %d"); |
|
53 |
|
54 ////////////////////////////////////////////////////////////////////// |
|
55 // Construction/Destruction |
|
56 ////////////////////////////////////////////////////////////////////// |
|
57 CT_DataDsaSession::CT_DataDsaSession() : |
|
58 iDsaSession(NULL), |
|
59 iActiveRequestReady(NULL) |
|
60 { |
|
61 } |
|
62 |
|
63 void CT_DataDsaSession::ConstructL() |
|
64 { |
|
65 iActiveRequestReady = CActiveCallback::NewL(*this); |
|
66 } |
|
67 |
|
68 CT_DataDsaSession::~CT_DataDsaSession() |
|
69 { |
|
70 this->DestroyData(); |
|
71 } |
|
72 |
|
73 CT_DataDsaSession* CT_DataDsaSession::NewL() |
|
74 { |
|
75 CT_DataDsaSession* self = new (ELeave) CT_DataDsaSession(); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop(self); |
|
79 return self; |
|
80 } |
|
81 |
|
82 void CT_DataDsaSession::SetObjectL(TAny* aAny) |
|
83 { |
|
84 this->DestroyData(); |
|
85 iDsaSession = static_cast<RDirectScreenAccess*>(aAny); |
|
86 } |
|
87 |
|
88 void CT_DataDsaSession::DisownObjectL() |
|
89 { |
|
90 iDsaSession = NULL; |
|
91 } |
|
92 |
|
93 void CT_DataDsaSession::DestroyData() |
|
94 { |
|
95 delete iDsaSession; |
|
96 iDsaSession = NULL; |
|
97 delete iActiveRequestReady; |
|
98 iActiveRequestReady = NULL; |
|
99 } |
|
100 |
|
101 MWsClientClass* CT_DataDsaSession::GetClientClass() const |
|
102 { |
|
103 return iDsaSession; |
|
104 } |
|
105 |
|
106 /** |
|
107 * Process a command read from the ini file |
|
108 * |
|
109 * @param aCommand the command to process |
|
110 * @param aSection the entry in the ini file requiring the command to be processed |
|
111 * @param aAsyncErrorIndex index of command. used for async calls |
|
112 * |
|
113 * @return ETrue if the command is processed |
|
114 */ |
|
115 TBool CT_DataDsaSession::DoCommandL(const TTEFFunction& aCommand, const |
|
116 TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
117 { |
|
118 TBool result( ETrue ); |
|
119 INFO_PRINTF1(aCommand); |
|
120 |
|
121 if ( !aCommand.Compare( KCmdnewL ) || !aCommand.Compare( KDataClassname ) ) |
|
122 { |
|
123 DoCmdnewL(aSection); |
|
124 } |
|
125 else if ( !aCommand.Compare( KCmdConstruct ) ) |
|
126 { |
|
127 DoCmdConstruct(); |
|
128 } |
|
129 else if ( !aCommand.Compare( KCmdClose ) ) |
|
130 { |
|
131 DoCmdClose(); |
|
132 } |
|
133 else if ( !aCommand.Compare( KCmdRequest) ) |
|
134 { |
|
135 DoCmdRequestL(aSection , aAsyncErrorIndex); |
|
136 } |
|
137 else if ( !aCommand.Compare( KCmdCompleted ) ) |
|
138 { |
|
139 DoCmdCompleted(); |
|
140 } |
|
141 else if ( !aCommand.Compare( KCmdCancel ) ) |
|
142 { |
|
143 DoCmdCancel(); |
|
144 } |
|
145 else if ( !aCommand.Compare(KCmdEatupMemory)) |
|
146 { |
|
147 DoCmdEatupMemory(aSection); |
|
148 } |
|
149 else if (!aCommand.Compare(KCmdFreeEatenMemory)) |
|
150 { |
|
151 DoCmdFreeEatenMemory(); |
|
152 } |
|
153 else |
|
154 { |
|
155 result = EFalse; |
|
156 } |
|
157 |
|
158 return result; |
|
159 } |
|
160 |
|
161 /** |
|
162 * Helper method to get RWsSession |
|
163 */ |
|
164 RWsSession* CT_DataDsaSession::GetRWSessionL(const TDesC& aSection) |
|
165 { |
|
166 RWsSession* iClient = NULL; //Window Session Client |
|
167 TPtrC objectName; |
|
168 |
|
169 if ( GetStringFromConfig(aSection, KRWsSessionObj(), objectName) ) |
|
170 { |
|
171 iClient = static_cast<RWsSession*>(GetDataObjectL(objectName)); |
|
172 } |
|
173 |
|
174 return iClient; |
|
175 } |
|
176 |
|
177 /** |
|
178 * Test NewL(); |
|
179 */ |
|
180 void CT_DataDsaSession::DoCmdnewL(const TDesC& aSection) |
|
181 { |
|
182 RWsSession* session = GetRWSessionL(aSection); |
|
183 |
|
184 if(!session) |
|
185 { |
|
186 //no parameter. |
|
187 iDsaSession = new (ELeave) RDirectScreenAccess(); |
|
188 INFO_PRINTF1(KRdsaNew1); |
|
189 } |
|
190 else |
|
191 { |
|
192 //with parameter |
|
193 iDsaSession = new (ELeave) RDirectScreenAccess(*session); |
|
194 INFO_PRINTF1(KRdsaNew2); |
|
195 } |
|
196 |
|
197 if(!iDsaSession) |
|
198 { |
|
199 ERR_PRINTF1(KErrNewL); |
|
200 SetBlockResult(EFail); |
|
201 } |
|
202 |
|
203 } |
|
204 |
|
205 |
|
206 /** |
|
207 * Test ConstructL(); |
|
208 */ |
|
209 void CT_DataDsaSession::DoCmdConstruct() |
|
210 { |
|
211 INFO_PRINTF1(KInfoConstruct); |
|
212 TInt result = iDsaSession->Construct(); |
|
213 |
|
214 if(result) |
|
215 { |
|
216 ERR_PRINTF2(KLogError, result); |
|
217 SetBlockResult(EFail); |
|
218 } |
|
219 |
|
220 } |
|
221 |
|
222 |
|
223 /** |
|
224 * Test Close(); |
|
225 */ |
|
226 void CT_DataDsaSession::DoCmdClose() |
|
227 { |
|
228 INFO_PRINTF1(KInfoClose); |
|
229 iDsaSession->Close(); |
|
230 } |
|
231 |
|
232 |
|
233 /** |
|
234 * Test RequestL(); |
|
235 */ |
|
236 void CT_DataDsaSession::DoCmdRequestL(const TDesC& aSection, const TInt aAsyncErrorIndex) |
|
237 { |
|
238 INFO_PRINTF1(KInfoRequest); |
|
239 RWindowBase* iWindow = NULL; |
|
240 TPtrC objectName; |
|
241 |
|
242 if ( GetStringFromConfig(aSection, KRWindowObj(), objectName)) |
|
243 { |
|
244 iWindow = static_cast<RWindowBase*> (GetDataObjectL(objectName)); |
|
245 } |
|
246 |
|
247 if(!iWindow) |
|
248 { |
|
249 ERR_PRINTF2(KLogMissingParameter , &KRWindowObj); |
|
250 SetBlockResult(EFail); |
|
251 } |
|
252 |
|
253 RRegion* aRegion = NULL; |
|
254 |
|
255 TInt result = iDsaSession->Request(aRegion, iActiveRequestReady->iStatus, *iWindow); |
|
256 if(result) |
|
257 { |
|
258 ERR_PRINTF2(KLogError, result); |
|
259 SetError(result); |
|
260 } |
|
261 else |
|
262 { |
|
263 TRect temp; |
|
264 if( GetRectFromConfig(aSection ,KFldRegion, temp ) && aRegion->Count()) |
|
265 { |
|
266 //compare the region |
|
267 TRect temp2 = (*aRegion)[0]; |
|
268 if(temp != temp2) |
|
269 { |
|
270 ERR_PRINTF1(KErrRequestRegionMatch); |
|
271 SetBlockResult(EFail); |
|
272 } |
|
273 |
|
274 } |
|
275 |
|
276 iActiveRequestReady->Activate(aAsyncErrorIndex); |
|
277 IncOutstanding(); |
|
278 } |
|
279 |
|
280 } |
|
281 |
|
282 /** |
|
283 * Test Completed(); |
|
284 */ |
|
285 void CT_DataDsaSession::DoCmdCompleted() |
|
286 { |
|
287 INFO_PRINTF1(KInfoCompleted); |
|
288 iDsaSession->Completed(); |
|
289 } |
|
290 |
|
291 /** |
|
292 * Test Cancel(); |
|
293 */ |
|
294 void CT_DataDsaSession::DoCmdCancel() |
|
295 { |
|
296 INFO_PRINTF1(KInfoCancel); |
|
297 iDsaSession->Cancel(); |
|
298 } |
|
299 |
|
300 void CT_DataDsaSession::DoCmdEatupMemory(const TDesC& aSection) |
|
301 { |
|
302 CT_GraphicsUtil::EatupMemory(*this,aSection,KFldMemLeft); |
|
303 } |
|
304 void CT_DataDsaSession::DoCmdFreeEatenMemory() |
|
305 { |
|
306 CT_GraphicsUtil::FreeEatenMemory(*this); |
|
307 } |
|
308 |
|
309 void CT_DataDsaSession::RunL(CActive* aActive, TInt aIndex) |
|
310 { |
|
311 if ( iActiveRequestReady == aActive ) |
|
312 { |
|
313 RunRequestReady(aIndex); |
|
314 } |
|
315 else |
|
316 { |
|
317 ERR_PRINTF1(KStraySignal); |
|
318 SetBlockResult(EFail); |
|
319 } |
|
320 |
|
321 } |
|
322 |
|
323 void CT_DataDsaSession::RunRequestReady( const TInt aIndex) |
|
324 { |
|
325 DecOutstanding(); |
|
326 TInt err = iActiveRequestReady->iStatus.Int(); |
|
327 INFO_PRINTF2(KRunRequestReady, err); |
|
328 |
|
329 if ( KErrNone != err ) |
|
330 { |
|
331 ERR_PRINTF2(KLogError, err); |
|
332 SetAsyncError(aIndex, err); |
|
333 } |
|
334 |
|
335 } |
|
336 |
|
337 void CT_DataDsaSession::DoCancel(CActive* /*aActive*/, TInt /*aIndex*/) |
|
338 { |
|
339 //nothing. |
|
340 } |
|
341 |
|
342 |