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 |
#include "T_OpenFileScanData.h" |
20 |
#include "FileserverUtil.h" |
|
21 |
||
22 |
//Constants |
|
23 |
const TInt KBufferLength = 64; |
|
24 |
||
25 |
||
26 |
// Commands |
|
27 |
_LIT( KCmdDestructor, "~" ); |
|
28 |
_LIT( KCmdNew, "new" ); |
|
29 |
_LIT( KCmdNextL, "NextL" ); |
|
30 |
_LIT( KCmdThreadId, "ThreadId" ); |
|
31 |
||
32 |
// Parameters |
|
33 |
_LIT( KParamFileSession, "FileSession" ); |
|
34 |
_LIT( KParamExpectedFileName, "expected_filename%d"); |
|
35 |
_LIT( KParamDirWrapper, "wrapper"); |
|
36 |
||
37 |
||
38 |
CT_OpenFileScanData* CT_OpenFileScanData::NewL() |
|
39 |
/** |
|
40 |
* Two phase constructor |
|
41 |
*/ |
|
42 |
{ |
|
43 |
CT_OpenFileScanData* ret = new (ELeave) CT_OpenFileScanData(); |
|
44 |
CleanupStack::PushL( ret ); |
|
45 |
ret->ConstructL(); |
|
46 |
CleanupStack::Pop( ret ); |
|
47 |
return ret; |
|
48 |
} |
|
49 |
||
50 |
CT_OpenFileScanData::CT_OpenFileScanData() |
|
51 |
: iOpenFileScan(NULL) |
|
52 |
/** |
|
53 |
* Protected constructor. First phase construction |
|
54 |
*/ |
|
55 |
{ |
|
56 |
} |
|
57 |
||
58 |
void CT_OpenFileScanData::ConstructL() |
|
59 |
/** |
|
60 |
* Protected constructor. Second phase construction |
|
61 |
*/ |
|
62 |
{ |
|
63 |
} |
|
64 |
||
65 |
CT_OpenFileScanData::~CT_OpenFileScanData() |
|
66 |
/** |
|
67 |
* Destructor. |
|
68 |
*/ |
|
69 |
{ |
|
70 |
DoCleanup(); |
|
71 |
} |
|
72 |
||
73 |
void CT_OpenFileScanData::DoCleanup() |
|
74 |
/** |
|
75 |
* Contains cleanup implementation |
|
76 |
*/ |
|
77 |
{ |
|
78 |
delete iOpenFileScan; |
|
79 |
iOpenFileScan = NULL; |
|
80 |
} |
|
81 |
||
82 |
TAny* CT_OpenFileScanData::GetObject() |
|
83 |
/** |
|
84 |
* Return a pointer to the object that the data wraps |
|
85 |
* |
|
86 |
* @return pointer to the object that the data wraps |
|
87 |
*/ |
|
88 |
{ |
|
89 |
return iOpenFileScan; |
|
90 |
} |
|
91 |
||
92 |
TBool CT_OpenFileScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
93 |
/** |
|
94 |
* Process a command read from the ini file |
|
95 |
* |
|
96 |
* @param aCommand the command to process |
|
97 |
* @param aSection the entry in the ini file requiring the command to be processed |
|
98 |
* |
|
99 |
* @return ETrue if the command is processed |
|
100 |
*/ |
|
101 |
{ |
|
102 |
TBool retVal = ETrue; |
|
103 |
||
104 |
if ( aCommand == KCmdDestructor ) |
|
105 |
{ |
|
106 |
DoCleanup(); |
|
107 |
} |
|
108 |
else if ( aCommand == KCmdNew ) |
|
109 |
{ |
|
110 |
DoCmdNew( aSection ); |
|
111 |
} |
|
112 |
else if ( aCommand == KCmdNextL ) |
|
113 |
{ |
|
114 |
DoCmdNextL( aSection ); |
|
115 |
} |
|
116 |
else if ( aCommand == KCmdThreadId ) |
|
117 |
{ |
|
118 |
DoCmdThreadId( aSection ); |
|
119 |
} |
|
120 |
else |
|
121 |
{ |
|
122 |
retVal = EFalse; |
|
123 |
} |
|
124 |
||
125 |
return retVal; |
|
126 |
} |
|
127 |
||
128 |
void CT_OpenFileScanData::DoCmdNew( const TDesC& aSection ) |
|
129 |
/** Creates new TOpenFileScan class instance */ |
|
130 |
{ |
|
131 |
TPtrC rfsName; |
|
132 |
RFs* rfs = NULL; |
|
133 |
if ( GetRfsParam( aSection, rfs, rfsName ) ) |
|
134 |
{ |
|
135 |
INFO_PRINTF2( _L( "Create new TOpenFileScan(%S) class instance." ), &rfsName ); |
|
136 |
||
137 |
// do create |
|
138 |
TRAPD( err, iOpenFileScan = new (ELeave) TOpenFileScan( *rfs ) ); |
|
139 |
if ( err != KErrNone ) |
|
140 |
{ |
|
141 |
ERR_PRINTF3( _L( "new TOpenFileScan(%S) error=%d" ), &rfsName, err ); |
|
142 |
SetError( err ); |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
void CT_OpenFileScanData::DoCmdNextL( const TDesC& aSection ) |
|
148 |
/** Calls NextL() function */ |
|
149 |
{ |
|
150 |
RPointerArray<TPath> pathsToFind; |
|
151 |
CleanupResetAndDestroyPushL(pathsToFind); |
|
152 |
||
153 |
// Read expected file names into array |
|
154 |
TBool eof = EFalse; |
|
155 |
TInt index = 0; |
|
156 |
do |
|
157 |
{ |
|
158 |
TBuf<KBufferLength> tempStore; |
|
159 |
tempStore.Format(KParamExpectedFileName(), ++index); |
|
160 |
TPtrC fileName; |
|
161 |
eof = !GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName); |
|
162 |
if (!eof) |
|
163 |
{ |
|
164 |
TPath* path = new(ELeave) TPath(fileName); |
|
165 |
CleanupStack::PushL(path); |
|
166 |
pathsToFind.AppendL(path); |
|
167 |
CleanupStack::Pop(); |
|
168 |
} |
|
169 |
} |
|
170 |
while (!eof); |
|
171 |
||
172 |
TInt err = KErrNone; |
|
173 |
||
174 |
CFileList* fileList = NULL; |
|
175 |
if(pathsToFind.Count() == 0) |
|
176 |
{ |
|
177 |
TRAP( err, iOpenFileScan->NextL( fileList )); |
|
178 |
||
179 |
if( fileList) |
|
180 |
{ |
|
181 |
CleanupStack::PushL(fileList); |
|
182 |
// NB! CDir == CFileList |
|
183 |
TPtrC wrapperName; |
|
184 |
if (!err && GET_OPTIONAL_STRING_PARAMETER(KParamDirWrapper, aSection, wrapperName)) |
|
185 |
{ |
|
186 |
CT_DirData *wrapper = NULL; |
|
187 |
||
188 |
TRAPD( error, wrapper = static_cast<CT_DirData*>(GetDataWrapperL(wrapperName))) |
|
189 |
||
190 |
if( wrapper && (error==KErrNone) ) |
|
191 |
{ |
|
192 |
wrapper->SetObjectL(fileList); |
|
193 |
fileList = NULL; |
|
194 |
} |
|
195 |
else |
|
196 |
{ |
|
197 |
ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &wrapperName ); |
|
198 |
SetBlockResult( EFail ); |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
CleanupStack::Pop(); |
|
203 |
delete fileList; |
|
204 |
fileList = NULL; |
|
205 |
} |
|
206 |
} |
|
207 |
else |
|
208 |
{ |
|
209 |
// Check expected file names |
|
210 |
for( eof = EFalse ; !eof && (pathsToFind.Count() > 0); ) |
|
211 |
{ |
|
212 |
iOpenFileScan->NextL(fileList); |
|
213 |
if( fileList) |
|
214 |
{ |
|
215 |
for ( TInt i = 0; i < fileList->Count(); i++ ) |
|
216 |
{ |
|
217 |
INFO_PRINTF1((*fileList)[i].iName ); |
|
218 |
for(TInt j = pathsToFind.Count() - 1 ; j >= 0; j--) |
|
219 |
{ |
|
220 |
if( *(pathsToFind[j]) == (*fileList)[i].iName ) |
|
221 |
{ |
|
222 |
TPath* elemForRemove = pathsToFind[j]; |
|
223 |
pathsToFind.Remove(j); |
|
224 |
delete elemForRemove; |
|
225 |
} |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
delete fileList; |
|
230 |
fileList = NULL; |
|
231 |
} |
|
232 |
else |
|
233 |
{ |
|
234 |
eof = ETrue; |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
// Some file names are not found |
|
239 |
if (pathsToFind.Count() > 0) |
|
240 |
{ |
|
241 |
for(TInt i = 0; i < pathsToFind.Count(); i++) |
|
242 |
{ |
|
243 |
ERR_PRINTF2( _L( "File %S haven't been found" ), pathsToFind[i] ); |
|
244 |
} |
|
245 |
SetBlockResult( EFail ); |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
if ( err != KErrNone ) |
|
250 |
{ |
|
251 |
ERR_PRINTF2( _L( "NextL() error=%d" ), err ); |
|
252 |
SetError( err ); |
|
253 |
} |
|
254 |
||
255 |
//Free massive |
|
256 |
CleanupStack::PopAndDestroy(&pathsToFind); |
|
257 |
} |
|
258 |
||
259 |
// Calls ThreadId() function |
|
260 |
void CT_OpenFileScanData::DoCmdThreadId( const TDesC& aSection ) |
|
261 |
{ |
|
262 |
TPtrC rfsName; |
|
263 |
||
264 |
if(GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, rfsName)) |
|
265 |
{ |
|
266 |
CT_FsData *fsData = NULL; |
|
267 |
||
268 |
TRAPD(err,fsData = static_cast<CT_FsData*>(GetDataWrapperL(rfsName))); |
|
269 |
||
270 |
if( err==KErrNone ) |
|
271 |
{ |
|
272 |
//Recieving thread ids. |
|
273 |
TUint64 rfsThreadId = fsData->ThreadId(); |
|
274 |
TUint64 id = iOpenFileScan->ThreadId().Id(); |
|
275 |
//Comparing id's |
|
276 |
if(rfsThreadId != id) |
|
277 |
{ |
|
278 |
ERR_PRINTF3( _L( "Diffrent thread id's %u %u"),rfsThreadId,id); |
|
279 |
SetBlockResult( EFail ); |
|
280 |
} |
|
281 |
} |
|
282 |
else |
|
283 |
{ |
|
284 |
ERR_PRINTF2( _L( "Wrong session name:%S"),&rfsName); |
|
285 |
SetBlockResult( EFail ); |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
} |
|
290 |
||
291 |
TBool CT_OpenFileScanData::GetRfsParam( const TDesC& aSection, RFs*& aRfs, TPtrC& aRfsName ) |
|
292 |
/** this function retrieves the "rfs" current command parameter using |
|
293 |
* GET_MANDATORY_STRING_PAREMETER macro |
|
294 |
* |
|
295 |
* @param aSection - the entry in the ini file requiring the command to be processed |
|
296 |
* @param aRfs - the returned RFs pointer |
|
297 |
* @param aRfsName - the returned RFs's name as stated in ini file |
|
298 |
* |
|
299 |
* @return ETrue - if the the parameter has been successfully read and interpreted |
|
300 |
* EFalse - otherwise |
|
301 |
*/ |
|
302 |
{ |
|
303 |
TBool result = EFalse; |
|
304 |
||
305 |
if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, aRfsName ) ) |
|
306 |
{ |
|
307 |
TRAPD( err, aRfs = (RFs*)GetDataObjectL( aRfsName ) ); |
|
308 |
||
309 |
if ( err != KErrNone ) |
|
310 |
{ |
|
311 |
ERR_PRINTF3( _L( "Unrecognized object name: %S (error = %d)" ), &aRfsName, err ); |
|
312 |
SetBlockResult( EFail ); |
|
313 |
} |
|
314 |
else |
|
315 |
{ |
|
316 |
result = ETrue; |
|
317 |
} |
|
318 |
} |
|
319 |
||
320 |
return result; |
|
321 |
} |
|
322 |