author | Mike Kinghan <mikek@symbian.org> |
Thu, 25 Nov 2010 14:35:45 +0000 | |
branch | GCC_SURGE |
changeset 305 | 1ba12ef4ef89 |
parent 15 | 4122176ea935 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
0 | 3 |
* All rights reserved. |
4 |
* This component and the accompanying materials are made available |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
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 |
* |
|
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
14 |
* Description: |
0 | 15 |
* |
16 |
*/ |
|
17 |
||
15
4122176ea935
Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
0
diff
changeset
|
18 |
|
0 | 19 |
/** |
20 |
@test |
|
21 |
@internalComponent |
|
22 |
||
23 |
This contains CT_FormatData |
|
24 |
*/ |
|
25 |
||
26 |
// User includes |
|
27 |
#include "T_FormatData.h" |
|
28 |
||
29 |
/*@{*/ |
|
30 |
/// Parameters |
|
31 |
_LIT(KRFsName, "RFs"); |
|
32 |
_LIT(KDrive, "drive"); |
|
33 |
_LIT(KFormat, "format"); |
|
34 |
_LIT(KSpecialInfo, "specialinfo"); |
|
35 |
_LIT(KAsync, "async"); |
|
36 |
_LIT(KEnd, "end"); |
|
37 |
_LIT(KCount, "count"); |
|
38 |
||
39 |
// Format mode |
|
40 |
_LIT(KFormatHighDensity, "EHighDensity"); |
|
41 |
_LIT(KFormatLowDensity, "ELowDensity"); |
|
42 |
_LIT(KFormatFullFormat, "EFullFormat"); |
|
43 |
_LIT(KFormatQuickFormat, "EQuickFormat"); |
|
44 |
_LIT(KFormatSpecialFormat, "ESpecialFormat"); |
|
45 |
_LIT(KFormatForceErase, "EForceErase"); |
|
46 |
||
47 |
/// Commands |
|
48 |
_LIT(KCmdNew, "new"); |
|
49 |
_LIT(KCmdDestructor, "~"); |
|
50 |
_LIT(KCmdOpen, "Open"); |
|
51 |
_LIT(KCmdClose, "Close"); |
|
52 |
_LIT(KCmdNext, "Next"); |
|
53 |
/*@}*/ |
|
54 |
||
55 |
CT_FormatData* CT_FormatData::NewL() |
|
56 |
/** |
|
57 |
* Two phase constructor |
|
58 |
*/ |
|
59 |
{ |
|
60 |
CT_FormatData* ret = new ( ELeave ) CT_FormatData(); |
|
61 |
CleanupStack::PushL( ret ); |
|
62 |
ret->ConstructL(); |
|
63 |
CleanupStack::Pop( ret ); |
|
64 |
return ret; |
|
65 |
} |
|
66 |
||
67 |
CT_FormatData::CT_FormatData() |
|
68 |
: iFormat( NULL ) |
|
69 |
, iNext( NULL ) |
|
70 |
, iCount( 0 ) |
|
71 |
, iCountNextEnd( 0 ) |
|
72 |
/** |
|
73 |
* Protected constructor. First phase construction |
|
74 |
*/ |
|
75 |
{ |
|
76 |
} |
|
77 |
||
78 |
void CT_FormatData::ConstructL() |
|
79 |
/** |
|
80 |
* Protected constructor. Second phase construction |
|
81 |
*/ |
|
82 |
{ |
|
83 |
iNext = CActiveCallback::NewL( *this ); |
|
84 |
} |
|
85 |
||
86 |
CT_FormatData::~CT_FormatData() |
|
87 |
/** |
|
88 |
* Destructor. |
|
89 |
*/ |
|
90 |
{ |
|
91 |
delete iNext; |
|
92 |
iNext = NULL; |
|
93 |
DoCleanup(); |
|
94 |
} |
|
95 |
||
96 |
void CT_FormatData::DoCleanup() |
|
97 |
/** |
|
98 |
* Contains cleanup implementation |
|
99 |
*/ |
|
100 |
{ |
|
101 |
//Deleting RFormat. |
|
102 |
if(iFormat != NULL) |
|
103 |
{ |
|
104 |
INFO_PRINTF1( _L("Deleting current RFormat") ); |
|
105 |
delete iFormat; |
|
106 |
iFormat = NULL; |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
TAny* CT_FormatData::GetObject() |
|
111 |
/** |
|
112 |
* Return a pointer to the object that the data wraps |
|
113 |
* |
|
114 |
* @return pointer to the object that the data wraps |
|
115 |
*/ |
|
116 |
{ |
|
117 |
return iFormat; |
|
118 |
} |
|
119 |
||
120 |
TBool CT_FormatData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex ) |
|
121 |
/** |
|
122 |
* Process a command read from the ini file |
|
123 |
* |
|
124 |
* @param aCommand requiring command to be processed |
|
125 |
* @param aSection the section in the ini file requiring the command to be processed |
|
126 |
* @param aAsyncErrorIndex the index of asynchronous command error code belongs to. |
|
127 |
* |
|
128 |
* @leave system wide error |
|
129 |
* |
|
130 |
* @return ETrue if the command is processed |
|
131 |
*/ |
|
132 |
{ |
|
133 |
TBool retVal = ETrue; |
|
134 |
||
135 |
if ( aCommand == KCmdNew ) |
|
136 |
{ |
|
137 |
DoCmdNewL(); |
|
138 |
} |
|
139 |
else if ( aCommand == KCmdDestructor ) |
|
140 |
{ |
|
141 |
DoCmdDestructor(); |
|
142 |
} |
|
143 |
else if ( aCommand == KCmdOpen ) |
|
144 |
{ |
|
145 |
DoCmdOpenL( aSection ); |
|
146 |
} |
|
147 |
else if ( aCommand == KCmdClose ) |
|
148 |
{ |
|
149 |
DoCmdClose(); |
|
150 |
} |
|
151 |
else if ( aCommand == KCmdNext ) |
|
152 |
{ |
|
153 |
DoCmdNext( aSection, aAsyncErrorIndex ); |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
retVal = EFalse; |
|
158 |
} |
|
159 |
return retVal; |
|
160 |
} |
|
161 |
||
162 |
void CT_FormatData::DoCmdNewL() |
|
163 |
/** |
|
164 |
* Creates new RFormat class instance |
|
165 |
*/ |
|
166 |
{ |
|
167 |
//Deletes previous RFormat class instance if it was already created. |
|
168 |
DoCleanup(); |
|
169 |
||
170 |
INFO_PRINTF1( _L("Create new RFormat class instance") ); |
|
171 |
||
172 |
// do create |
|
173 |
TRAPD( err, iFormat = new ( ELeave ) RFormat() ); |
|
174 |
if ( err != KErrNone ) |
|
175 |
{ |
|
176 |
ERR_PRINTF2( _L("new error %d"), err ); |
|
177 |
SetError( err ); |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
void CT_FormatData::DoCmdDestructor() |
|
182 |
/** |
|
183 |
* Destroy RFormat the object |
|
184 |
*/ |
|
185 |
{ |
|
186 |
DoCleanup(); |
|
187 |
} |
|
188 |
||
189 |
void CT_FormatData::DoCmdOpenL( const TDesC& aSection ) |
|
190 |
/** |
|
191 |
* RFormat::Open |
|
192 |
* |
|
193 |
* @leave system wide error |
|
194 |
*/ |
|
195 |
{ |
|
196 |
TBool dataOk = ETrue; |
|
197 |
||
198 |
RFs* rfsObject = NULL; |
|
199 |
TPtrC rfsObjectName; |
|
200 |
if ( GET_MANDATORY_STRING_PARAMETER( KRFsName, aSection, rfsObjectName ) ) |
|
201 |
{ |
|
202 |
TRAPD( err, rfsObject = ( RFs* )GetDataObjectL( rfsObjectName )); |
|
203 |
||
204 |
if ( err != KErrNone ) |
|
205 |
{ |
|
206 |
ERR_PRINTF1( _L("Error with fileserver")); |
|
207 |
SetBlockResult( EFail ); |
|
208 |
} |
|
209 |
} |
|
210 |
else |
|
211 |
{ |
|
212 |
dataOk = EFalse; |
|
213 |
} |
|
214 |
||
215 |
TPtrC drive; |
|
216 |
if ( !GET_MANDATORY_STRING_PARAMETER( KDrive, aSection, drive ) ) |
|
217 |
{ |
|
218 |
dataOk = EFalse; |
|
219 |
} |
|
220 |
||
221 |
TUint formatMode = 0; |
|
222 |
if ( !GetFormatMode( KFormat, aSection, formatMode ) ) |
|
223 |
{ |
|
224 |
dataOk = EFalse; |
|
225 |
} |
|
226 |
||
227 |
if ( dataOk ) |
|
228 |
{ |
|
229 |
TInt err = KErrNone; |
|
230 |
||
231 |
TPtrC specialInfo; |
|
232 |
if ( GET_OPTIONAL_STRING_PARAMETER( KSpecialInfo, aSection, specialInfo ) ) |
|
233 |
{ |
|
234 |
HBufC8* buf = HBufC8::NewLC( specialInfo.Length() ); |
|
235 |
buf->Des().Copy( specialInfo ); |
|
236 |
err = iFormat->Open( *rfsObject, drive, formatMode, iCount, buf->Des() ); |
|
237 |
CleanupStack::PopAndDestroy( buf ); |
|
238 |
} |
|
239 |
else |
|
240 |
{ |
|
241 |
err = iFormat->Open( *rfsObject, drive, formatMode, iCount ); |
|
242 |
} |
|
243 |
INFO_PRINTF2( _L("iCount %d"), iCount ); |
|
244 |
iCountPckg = iCount; |
|
245 |
if ( err != KErrNone ) |
|
246 |
{ |
|
247 |
ERR_PRINTF2( _L("Open() error %d"), err ); |
|
248 |
SetError( err ); |
|
249 |
} |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
void CT_FormatData::DoCmdClose() |
|
254 |
/** |
|
255 |
* RFormat::Close |
|
256 |
*/ |
|
257 |
{ |
|
258 |
iFormat->Close(); |
|
259 |
} |
|
260 |
||
261 |
void CT_FormatData::DoCmdNext( const TDesC& aSection, const TInt aAsyncErrorIndex ) |
|
262 |
/** |
|
263 |
* RFormat::Next |
|
264 |
*/ |
|
265 |
{ |
|
266 |
TBool async = EFalse; |
|
267 |
GET_OPTIONAL_BOOL_PARAMETER( KAsync, aSection, async ); |
|
268 |
||
269 |
iCountNextEnd = 0; |
|
270 |
GET_OPTIONAL_INT_PARAMETER( KEnd, aSection, iCountNextEnd ); |
|
271 |
||
272 |
GET_OPTIONAL_INT_PARAMETER( KCount, aSection, iCount ); |
|
273 |
||
274 |
if ( async ) |
|
275 |
{ |
|
276 |
iFormat->Next( iCountPckg, iNext->iStatus ); |
|
277 |
iNext->Activate( aAsyncErrorIndex ); |
|
278 |
IncOutstanding(); |
|
279 |
} |
|
280 |
else |
|
281 |
{ |
|
282 |
TInt err = KErrNone; |
|
283 |
while ( ( iCount > iCountNextEnd ) && ( err == KErrNone ) ) |
|
284 |
{ |
|
285 |
err = iFormat->Next( iCount ); |
|
286 |
INFO_PRINTF2( _L("iCount %d"), iCount ); |
|
287 |
} |
|
288 |
if ( err != KErrNone ) |
|
289 |
{ |
|
290 |
ERR_PRINTF2( _L("Next() error %d"), err ); |
|
291 |
SetError( err ); |
|
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
TBool CT_FormatData::GetFormatMode( const TDesC& aParameterName, const TDesC& aSection, TUint& aFormatMode ) |
|
297 |
{ |
|
298 |
aFormatMode = 0; |
|
299 |
||
300 |
TPtrC formatStr; |
|
301 |
TBool ret = GET_MANDATORY_STRING_PARAMETER( aParameterName, aSection, formatStr ); |
|
302 |
if ( ret ) |
|
303 |
{ |
|
304 |
if ( !ConvertToFormatMode( formatStr, aFormatMode ) ) |
|
305 |
{ |
|
306 |
TInt intTemp; |
|
307 |
ret = GET_MANDATORY_INT_PARAMETER( aParameterName, aSection, intTemp ); |
|
308 |
if ( ret ) |
|
309 |
{ |
|
310 |
aFormatMode = intTemp; |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
return ret; |
|
316 |
} |
|
317 |
||
318 |
TBool CT_FormatData::ConvertToFormatMode( const TDesC& aFormatModeStr, TUint& aFormatMode ) |
|
319 |
{ |
|
320 |
TBool ret = ETrue; |
|
321 |
if ( aFormatModeStr == KFormatHighDensity ) |
|
322 |
{ |
|
323 |
aFormatMode = EHighDensity; |
|
324 |
} |
|
325 |
else if ( aFormatModeStr == KFormatLowDensity ) |
|
326 |
{ |
|
327 |
aFormatMode = ELowDensity; |
|
328 |
} |
|
329 |
else if ( aFormatModeStr == KFormatFullFormat ) |
|
330 |
{ |
|
331 |
aFormatMode = EFullFormat; |
|
332 |
} |
|
333 |
else if ( aFormatModeStr == KFormatQuickFormat ) |
|
334 |
{ |
|
335 |
aFormatMode = EQuickFormat; |
|
336 |
} |
|
337 |
else if ( aFormatModeStr == KFormatSpecialFormat ) |
|
338 |
{ |
|
339 |
aFormatMode = ESpecialFormat; |
|
340 |
} |
|
341 |
else if ( aFormatModeStr == KFormatForceErase ) |
|
342 |
{ |
|
343 |
aFormatMode = EForceErase; |
|
344 |
} |
|
345 |
else |
|
346 |
{ |
|
347 |
TInt location = aFormatModeStr.Match( _L("*|*") ); |
|
348 |
if( location != KErrNotFound ) |
|
349 |
{ |
|
350 |
//Converting Left part of the data |
|
351 |
TPtrC tempStr = aFormatModeStr.Left( location ); |
|
352 |
ret = ConvertToFormatMode( tempStr, aFormatMode ); |
|
353 |
||
354 |
//Converting right data can be with another "|" |
|
355 |
tempStr.Set( aFormatModeStr.Mid( location + 1 ) ); |
|
356 |
||
357 |
TUint formatModeTmp; |
|
358 |
if ( ConvertToFormatMode( tempStr, formatModeTmp ) ) |
|
359 |
{ |
|
360 |
aFormatMode |= formatModeTmp; |
|
361 |
} |
|
362 |
else |
|
363 |
{ |
|
364 |
ret = EFalse; |
|
365 |
} |
|
366 |
} |
|
367 |
else |
|
368 |
{ |
|
369 |
ret = EFalse; |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
return ret; |
|
374 |
} |
|
375 |
||
376 |
void CT_FormatData::RunL( CActive* aActive, TInt aIndex ) |
|
377 |
{ |
|
378 |
if ( aActive == iNext ) |
|
379 |
{ |
|
380 |
TInt err = aActive->iStatus.Int(); |
|
381 |
if( err != KErrNone ) |
|
382 |
{ |
|
383 |
ERR_PRINTF2( _L("DoCancel Error %d"), err ); |
|
384 |
SetAsyncError( aIndex, err ); |
|
385 |
DecOutstanding(); |
|
386 |
} |
|
387 |
else |
|
388 |
{ |
|
389 |
// Reset the outstanding request state |
|
390 |
INFO_PRINTF2( _L("RunL iCount %d"), iCountPckg() ); |
|
391 |
if ( iCountPckg() > iCountNextEnd ) |
|
392 |
{ |
|
393 |
iFormat->Next( iCountPckg, iNext->iStatus ); |
|
394 |
iNext->Activate( aIndex ); |
|
395 |
} |
|
396 |
else |
|
397 |
{ |
|
398 |
DecOutstanding(); |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
402 |
else |
|
403 |
{ |
|
404 |
ERR_PRINTF1( _L("Stray RunL signal") ); |
|
405 |
SetBlockResult( EFail ); |
|
406 |
} |
|
407 |
} |
|
408 |
||
409 |
void CT_FormatData::DoCancel( CActive* aActive, TInt aIndex ) |
|
410 |
{ |
|
411 |
if ( aActive == iNext ) |
|
412 |
{ |
|
413 |
TInt err = aActive->iStatus.Int(); |
|
414 |
if( err != KErrNone ) |
|
415 |
{ |
|
416 |
ERR_PRINTF2( _L("DoCancel Error %d"), err ); |
|
417 |
SetAsyncError( aIndex, err ); |
|
418 |
} |
|
419 |
||
420 |
// Reset the outstanding request state |
|
421 |
DecOutstanding(); |
|
422 |
} |
|
423 |
else |
|
424 |
{ |
|
425 |
ERR_PRINTF1( _L("Stray RunL signal") ); |
|
426 |
SetBlockResult( EFail ); |
|
427 |
} |
|
428 |
} |