252 GLDEF_C TInt FManBaseThreadFunction(TAny* aPtr) |
252 GLDEF_C TInt FManBaseThreadFunction(TAny* aPtr) |
253 // |
253 // |
254 // Initialise New thread |
254 // Initialise New thread |
255 // |
255 // |
256 { |
256 { |
257 |
257 TInt r = KErrNoMemory; // return value if a trap harness cannot be created |
258 CTrapCleanup* cleanup=CTrapCleanup::New(); |
258 CTrapCleanup* cleanup=CTrapCleanup::New(); |
259 if (cleanup==NULL) |
|
260 return(KErrNoMemory); |
|
261 CFileBase& fMan=*(CFileBase*)aPtr; |
259 CFileBase& fMan=*(CFileBase*)aPtr; |
262 fMan.iSynchronizer.Wait(); |
260 |
263 TRAPD(ret,DoFManBaseOperationL(aPtr)); |
261 if (cleanup != NULL) |
264 if (ret==KErrNone) |
262 { |
265 ret=fMan.iLastError; |
263 fMan.iSynchronizer.Wait(); |
266 delete cleanup; |
264 TRAP(r,DoFManBaseOperationL(aPtr)); |
|
265 if (r == KErrNone) |
|
266 r = fMan.iLastError; |
|
267 delete cleanup; |
|
268 } |
|
269 |
267 fMan.iSwitches=0; |
270 fMan.iSwitches=0; |
268 fMan.iFs=fMan.iFsOld; |
271 fMan.iFs=fMan.iFsOld; |
269 fMan.iStatus=NULL; |
272 fMan.iStatus=NULL; |
270 fMan.iFManThread.Close(); |
273 fMan.iFManThread.Close(); |
271 return(ret); |
274 return (r); |
272 } |
275 } |
273 |
276 |
274 |
277 |
275 |
278 |
276 |
279 |
279 Creates a separate thread to run the command. |
282 Creates a separate thread to run the command. |
280 |
283 |
281 @param aThreadFunction The thread function. |
284 @param aThreadFunction The thread function. |
282 */ |
285 */ |
283 { |
286 { |
284 iSwitches|=KFManBusyFlag; |
|
285 User::LeaveIfError(iFManThread.Create(KNullDesC,aThreadFunction,KDefaultStackSize,NULL,this)); |
|
286 iFManThread.SetPriority(EPriorityMuchLess); |
|
287 TFileName sessionPath; |
287 TFileName sessionPath; |
288 User::LeaveIfError(iFs.SessionPath(sessionPath)); |
288 User::LeaveIfError(iFs.SessionPath(sessionPath)); |
289 if (iSessionPath==NULL) |
289 if (iSessionPath==NULL) |
290 iSessionPath=HBufC::NewL((sessionPath.Length())); |
290 iSessionPath=HBufC::NewL((sessionPath.Length())); |
291 else if (iSessionPath->Des().MaxLength()<sessionPath.Length()) |
291 else if (iSessionPath->Des().MaxLength()<sessionPath.Length()) |
292 iSessionPath=iSessionPath->ReAllocL(IncPathLength(sessionPath.Length())); |
292 iSessionPath=iSessionPath->ReAllocL(IncPathLength(sessionPath.Length())); |
293 iSessionPath->Des()=sessionPath; |
293 iSessionPath->Des()=sessionPath; |
|
294 |
|
295 User::LeaveIfError(iFManThread.Create(KNullDesC,aThreadFunction,KDefaultStackSize,NULL,this)); |
|
296 |
|
297 // The code won't leave anymore after this. |
|
298 // The effect of any further state changes to this instance |
|
299 // should be undone / completed by the thread function. |
|
300 iFManThread.SetPriority(EPriorityMuchLess); |
|
301 iSwitches|=KFManBusyFlag; |
294 iFsOld=iFs; |
302 iFsOld=iFs; |
295 iLastError=KErrNone; |
303 iLastError=KErrNone; |
296 iFManThread.Logon(*iStatus); |
304 iFManThread.Logon(*iStatus); |
297 iFManThread.Resume(); |
305 iFManThread.Resume(); |
298 } |
306 } |