|
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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "T_DataWsBitmap.h" |
|
19 #include "T_GraphicsUtil.h" |
|
20 |
|
21 /*@{*/ |
|
22 _LIT(KDataClassname, "CWsBitmap"); |
|
23 |
|
24 //Commands |
|
25 _LIT(KCmdnew, "new"); |
|
26 _LIT(KCmdDestructor, "~CWsBitmap"); |
|
27 _LIT(KCmdDestructorGeneral, "~"); |
|
28 _LIT(KCmdCreate, "Create"); |
|
29 _LIT(KCmdDuplicate, "Duplicate"); |
|
30 _LIT(KCmdLoad, "Load"); |
|
31 _LIT(KCmdInternalizeL, "InternalizeL"); |
|
32 _LIT(KCmdReset, "Reset"); |
|
33 |
|
34 // Fields |
|
35 _LIT(KFldDispMode, "dispmode"); |
|
36 _LIT(KFldFileName, "filename"); |
|
37 _LIT(KFldHandle, "handle"); |
|
38 _LIT(KFldHandle_Name, "handle_name"); |
|
39 _LIT(KFldId, "id"); |
|
40 _LIT(KFldShareIfLoaded, "shareifloaded"); |
|
41 _LIT(KFldSizeInPixels, "sizeinpixels"); |
|
42 _LIT(KFldUseClosedStream, "use_closed_stream"); |
|
43 _LIT(KFldWs, "ws"); |
|
44 |
|
45 /// Logging |
|
46 _LIT(KLogError, "Error=%d"); |
|
47 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
48 /*@}*/ |
|
49 |
|
50 ////////////////////////////////////////////////////////////////////// |
|
51 // Construction/Destruction |
|
52 ////////////////////////////////////////////////////////////////////// |
|
53 |
|
54 CT_DataWsBitmap* CT_DataWsBitmap::NewL() |
|
55 { |
|
56 CT_DataWsBitmap* ret=new (ELeave) CT_DataWsBitmap(); |
|
57 CleanupStack::PushL(ret); |
|
58 ret->ConstructL(); |
|
59 CleanupStack::Pop(ret); |
|
60 return ret; |
|
61 } |
|
62 |
|
63 CT_DataWsBitmap::CT_DataWsBitmap() |
|
64 : CT_DataFbsBitmap() |
|
65 , iWsBitmap(NULL) |
|
66 { |
|
67 } |
|
68 |
|
69 void CT_DataWsBitmap::ConstructL() |
|
70 { |
|
71 CT_DataFbsBitmap::ConstructL(); |
|
72 } |
|
73 |
|
74 CT_DataWsBitmap::~CT_DataWsBitmap() |
|
75 { |
|
76 DestroyData(); |
|
77 } |
|
78 |
|
79 void CT_DataWsBitmap::SetObjectL(TAny* aAny) |
|
80 { |
|
81 DestroyData(); |
|
82 iWsBitmap = static_cast<CWsBitmap*> (aAny); |
|
83 } |
|
84 |
|
85 void CT_DataWsBitmap::DestroyData() |
|
86 { |
|
87 delete iWsBitmap; |
|
88 iWsBitmap=NULL; |
|
89 } |
|
90 |
|
91 void CT_DataWsBitmap::DisownObjectL() |
|
92 { |
|
93 iWsBitmap = NULL; |
|
94 } |
|
95 |
|
96 MWsClientClass* CT_DataWsBitmap::GetClientClass() const |
|
97 { |
|
98 return iWsBitmap; |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 * Process a command read from the ini file |
|
104 * |
|
105 * @param aCommand the command to process |
|
106 * @param aSection the entry in the ini file requiring the command to be processed |
|
107 * @param aAsyncErrorIndex index of command. used for async calls |
|
108 * |
|
109 * @return ETrue if the command is processed |
|
110 */ |
|
111 TBool CT_DataWsBitmap::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
112 { |
|
113 TBool ret = ETrue; |
|
114 |
|
115 if ( aCommand==KCmdDestructor || aCommand==KCmdDestructorGeneral ) |
|
116 { |
|
117 DoCmdDestructor(); |
|
118 } |
|
119 else if ( aCommand==KCmdnew || aCommand==KDataClassname ) |
|
120 { |
|
121 DoCmdnewL(aSection); |
|
122 } |
|
123 else if ( aCommand==KCmdCreate ) |
|
124 { |
|
125 DoCmdCreate(aSection); |
|
126 } |
|
127 else if ( aCommand==KCmdDuplicate ) |
|
128 { |
|
129 DoCmdDuplicateL(aSection); |
|
130 } |
|
131 else if ( aCommand==KCmdLoad ) |
|
132 { |
|
133 DoCmdLoad(aSection); |
|
134 } |
|
135 else if ( aCommand==KCmdInternalizeL ) |
|
136 { |
|
137 DoCmdInternalizeL(aSection); |
|
138 } |
|
139 else if ( aCommand==KCmdReset ) |
|
140 { |
|
141 DoCmdReset(); |
|
142 } |
|
143 else if ( !CT_DataWsClientClass::DoCommandL(*this, aCommand, aSection, aAsyncErrorIndex) ) |
|
144 { |
|
145 CT_DataFbsBitmap::SetObjectL(iWsBitmap); |
|
146 ret = CT_DataFbsBitmap::DoCommandL(aCommand, aSection, aAsyncErrorIndex); |
|
147 CT_DataFbsBitmap::DisownObjectL(); |
|
148 } |
|
149 |
|
150 return ret; |
|
151 } |
|
152 |
|
153 |
|
154 void CT_DataWsBitmap::DoCmdnewL(const TDesC& aSection) |
|
155 { |
|
156 DestroyData(); |
|
157 |
|
158 // Get test data for command input parameter(s) |
|
159 TPtrC wsName; |
|
160 RWsSession* ws=NULL; |
|
161 if ( GetStringFromConfig(aSection, KFldWs, wsName) ) |
|
162 { |
|
163 ws = static_cast<RWsSession*>(GetDataObjectL(wsName)); |
|
164 } |
|
165 |
|
166 TInt err=KErrNone; |
|
167 if ( ws!=NULL ) |
|
168 { |
|
169 // Execute command and log parameters |
|
170 INFO_PRINTF1(_L("execute new CWsBitmap(RWsSession)")); |
|
171 TRAP( err, iWsBitmap = new (ELeave) CWsBitmap(*ws)); |
|
172 } |
|
173 else |
|
174 { |
|
175 // Execute command and log parameters |
|
176 INFO_PRINTF1(_L("execute new CWsBitmap()")); |
|
177 TRAP( err, iWsBitmap = new (ELeave) CWsBitmap()); |
|
178 } |
|
179 |
|
180 if ( err!=KErrNone ) |
|
181 { |
|
182 ERR_PRINTF2(KLogError, err); |
|
183 SetError(err); |
|
184 } |
|
185 } |
|
186 |
|
187 |
|
188 void CT_DataWsBitmap::DoCmdDestructor() |
|
189 { |
|
190 // Execute command and log parameters |
|
191 INFO_PRINTF1(_L("execute ~CWsBitmap()")); |
|
192 delete iWsBitmap; |
|
193 iWsBitmap=NULL; |
|
194 } |
|
195 |
|
196 |
|
197 void CT_DataWsBitmap::DoCmdCreate(const TDesC& aSection) |
|
198 { |
|
199 TBool dataOk=ETrue; |
|
200 |
|
201 // Get test data for command input parameter(s) |
|
202 TSize datSizeInPixels; |
|
203 if ( !GetSizeFromConfig(aSection, KFldSizeInPixels, datSizeInPixels) ) |
|
204 { |
|
205 dataOk=EFalse; |
|
206 ERR_PRINTF2(KLogMissingParameter, &KFldSizeInPixels); |
|
207 SetBlockResult(EFail); |
|
208 } |
|
209 |
|
210 TDisplayMode datDispMode; |
|
211 if ( !CT_GraphicsUtil::ReadDisplayMode(*this, aSection, KFldDispMode, datDispMode) ) |
|
212 { |
|
213 dataOk=EFalse; |
|
214 ERR_PRINTF2(KLogMissingParameter, &KFldDispMode); |
|
215 SetBlockResult(EFail); |
|
216 } |
|
217 |
|
218 if ( dataOk ) |
|
219 { |
|
220 // Execute command and log parameters |
|
221 INFO_PRINTF1(_L("execute Create(TSize, TDisplayMode)")); |
|
222 TInt returnCode = iWsBitmap->Create (datSizeInPixels, datDispMode); |
|
223 |
|
224 // Check the command return code, if !=KErrNone then stop this command |
|
225 if ( returnCode!=KErrNone ) |
|
226 { |
|
227 ERR_PRINTF2(KLogError, returnCode); |
|
228 SetError(returnCode); |
|
229 } |
|
230 } |
|
231 } |
|
232 |
|
233 |
|
234 void CT_DataWsBitmap::DoCmdDuplicateL(const TDesC& aSection) |
|
235 { |
|
236 INFO_PRINTF1(_L("Calls CFbsBitmap::Duplicate()")); |
|
237 TInt handle=GetHandle(); |
|
238 TPtrC objectName; |
|
239 if ( GetStringFromConfig(aSection, KFldHandle_Name(), objectName) ) |
|
240 { |
|
241 CDataWrapperBase* wrapper=static_cast<CDataWrapperBase*>(GetDataWrapperL(objectName)); |
|
242 handle=wrapper->GetHandle(); |
|
243 } |
|
244 else |
|
245 { |
|
246 GetIntFromConfig(aSection, KFldHandle(), handle); |
|
247 } |
|
248 |
|
249 // call Duplicate() |
|
250 TInt err = iWsBitmap->Duplicate(handle); |
|
251 if (err != KErrNone) |
|
252 { |
|
253 ERR_PRINTF2(_L("Duplicate error: %d"), err); |
|
254 SetError(err); |
|
255 } |
|
256 } |
|
257 |
|
258 |
|
259 void CT_DataWsBitmap::DoCmdLoad(const TDesC& aSection) |
|
260 { |
|
261 TBool dataOk=ETrue; |
|
262 |
|
263 // Get test data for command input parameter(s) |
|
264 TPtrC datFileName; |
|
265 if ( !GetStringFromConfig(aSection, KFldFileName, datFileName) ) |
|
266 { |
|
267 dataOk=EFalse; |
|
268 ERR_PRINTF2(KLogMissingParameter, &KFldFileName); |
|
269 SetBlockResult(EFail); |
|
270 } |
|
271 |
|
272 TInt datId; |
|
273 if ( !GetIntFromConfig(aSection, KFldId, datId) ) |
|
274 { |
|
275 dataOk=EFalse; |
|
276 ERR_PRINTF2(KLogMissingParameter, &KFldId); |
|
277 SetBlockResult(EFail); |
|
278 } |
|
279 |
|
280 TBool datShareIfLoaded; |
|
281 if ( !GetBoolFromConfig(aSection, KFldShareIfLoaded, datShareIfLoaded) ) |
|
282 { |
|
283 dataOk=EFalse; |
|
284 ERR_PRINTF2(KLogMissingParameter, &KFldShareIfLoaded); |
|
285 SetBlockResult(EFail); |
|
286 } |
|
287 |
|
288 if ( dataOk ) |
|
289 { |
|
290 // Execute command and log parameters |
|
291 INFO_PRINTF1(_L("execute Load(TDesC, TInt32, TBool)")); |
|
292 TInt returnCode = iWsBitmap->Load(datFileName, datId, datShareIfLoaded); |
|
293 |
|
294 // Check the command return code, if !=KErrNone then stop this command |
|
295 if ( returnCode!=KErrNone ) |
|
296 { |
|
297 ERR_PRINTF2(KLogError, returnCode); |
|
298 SetError(returnCode); |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 |
|
304 void CT_DataWsBitmap::DoCmdInternalizeL(const TDesC& aSection) |
|
305 { |
|
306 // Get test data for command input parameter(s) |
|
307 TBool datUseClosedStream=EFalse; |
|
308 GetBoolFromConfig(aSection, KFldUseClosedStream, datUseClosedStream); |
|
309 |
|
310 TPtrC datFileName; |
|
311 if ( !GetStringFromConfig(aSection, KFldFileName, datFileName) ) |
|
312 { |
|
313 ERR_PRINTF2(KLogMissingParameter, &KFldUseClosedStream); |
|
314 SetBlockResult(EFail); |
|
315 } |
|
316 else |
|
317 { |
|
318 CDirectFileStore* readstore = CDirectFileStore::OpenL(FileServer(), datFileName, EFileStream | EFileRead); |
|
319 CleanupStack::PushL(readstore); |
|
320 TInt popCount=1; |
|
321 |
|
322 TStreamId headerid = readstore->Root(); |
|
323 RStoreReadStream readstrm; |
|
324 if ( !datUseClosedStream ) |
|
325 { |
|
326 readstrm.OpenL(*readstore, headerid); |
|
327 CleanupClosePushL(readstrm); |
|
328 popCount=2; |
|
329 } |
|
330 |
|
331 // Execute command and log parameters |
|
332 INFO_PRINTF1(_L("execute InternalizeL(RReadStream)")); |
|
333 TRAPD(err, iWsBitmap->InternalizeL(readstrm)); |
|
334 if ( err!=KErrNone ) |
|
335 { |
|
336 ERR_PRINTF2(KLogError, err); |
|
337 SetError(err); |
|
338 } |
|
339 |
|
340 // Cleanup |
|
341 CleanupStack::PopAndDestroy(popCount, readstore); |
|
342 } |
|
343 } |
|
344 |
|
345 |
|
346 void CT_DataWsBitmap::DoCmdReset() |
|
347 { |
|
348 // Execute command and log parameters |
|
349 INFO_PRINTF1(_L("execute Reset()")); |
|
350 iWsBitmap->Reset(); |
|
351 } |