Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "contentIterator.h"
22 #include "FileContentIterator.h"
23 #include "contentiteratordata.h"
25 using ContentAccess::CContentIterator;
26 using ContentAccess::TVirtualPathPtr;
28 _LIT(KIteratorThread,"ContentIterator");
29 EXPORT_C CContentIterator* CContentIterator::NewL(const TDesC& aPath, TBool aRecursive, const TDesC8& aMimeType)
31 CContentIterator* self = new (ELeave) CContentIterator();
32 CleanupStack::PushL(self);
33 self->ConstructL(aPath, aRecursive, aMimeType);
38 CContentIterator::CContentIterator() : CActive(EPriorityStandard)
42 CContentIterator::~CContentIterator()
44 // tell thread to cancel and shutdown
47 // close thread handle
48 iWorkerThread.Close();
52 void CContentIterator::ConstructL(const TDesC& aPath, TBool aRecursive, const TDesC8& aMimeType)
54 // This data buffer will be shared between the client and the worker thread
55 info = CContentIteratorData::NewL(aPath,aRecursive,aMimeType);
57 // create the thread, need a big heap and stack for recursively searching through directories
58 User::LeaveIfError(iWorkerThread.Create(KIteratorThread(),CContentIterator::ThreadEntry,32768, KMinHeapSize, 131072, (void *) info , EOwnerProcess));
60 // add ourselves to active scheduler
61 CActiveScheduler::Add(this);
63 // Set up notification in case the thread panics etc
64 iStatus = KRequestPending;
65 iWorkerThread.Logon(iStatus);
69 iWorkerThread.Resume();
73 void CContentIterator::DoCancel()
75 // Wait until thread finishes whatever it's doing
78 // Signal for the thread to close
79 info->RunThreadFunction(EIteratorShutdownThread);
82 void CContentIterator::RunL()
84 // Thread must have completed
85 if(iWorkerThread.ExitType() == EExitPanic)
87 // Thread panicd, better panic our thread
88 User::Panic(KCafPanicString, ECafPanicContentIteratorThreadPanic);
92 EXPORT_C TVirtualPathPtr CContentIterator::VirtualPath()
94 // Wait until thread finishes whatever it's doing
96 iFileName.Copy(info->Path());
97 iUniqueId.Copy(info->UniqueId());
99 return TVirtualPathPtr(iFileName, iUniqueId);
102 EXPORT_C const TDesC& CContentIterator::Name()
104 // Wait until thread finishes whatever it's doing
106 iName.Copy(info->Name());
111 EXPORT_C const TDesC8& CContentIterator::MimeType()
113 // Wait until thread finishes whatever it's doing
115 iMimeType.Copy(info->MimeType());
120 EXPORT_C void CContentIterator::Next(TRequestStatus &aStatus)
122 // Wait until thread finishes whatever it's doing
125 // Remember which thread and TRequestStatus to notify
126 TThreadId id = RThread().Id();
127 info->SetClientRequest(id, aStatus);
129 // Tell it to find the next iteration
130 info->RunThreadFunction(EIteratorFindNextContentObject);
134 TInt CContentIterator::ThreadEntry(TAny* aAny)
136 TBool exitNow = EFalse;
138 CFileContentIterator* iterator = NULL;
139 RThread clientThread;
140 CContentIteratorData* info = reinterpret_cast <CContentIteratorData *> (aAny);
142 // create a trap handler
143 CTrapCleanup* cleanup = CTrapCleanup::New();
147 // Thread will wait here until signaled by other CContentIterator functions
148 switch(info->ThreadWait())
150 // Client thread has asked us to shutdown, exit loop
151 case EIteratorShutdownThread:
154 // Client thread is asking us to find the next object
155 case EIteratorFindNextContentObject:
158 TRAP(err, iterator = CFileContentIterator::NewL(info->Path(), info->IsRecursive(), info->MimeType()));
159 info->SetData(KNullDesC(), KNullDesC(), KNullDesC(), KNullDesC8());
163 err = iterator->Next();
168 // If a content object was found, write the value back
169 // into the other thread while the info is still locked
170 info->SetData(iterator->FileName(),iterator->UniqueId(), iterator->Name(), iterator->MimeType());
173 // Complete the clients asynchronous request
174 info->CompleteClientRequest(err);
177 User::Panic(KCafPanicString, ECafPanicContentIteratorUnknownRequest);
181 // Allow the client to post a new request