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