sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004-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 the License "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 "contentiteratordata.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
using namespace ContentAccess;
|
sl@0
|
22 |
|
sl@0
|
23 |
CContentIteratorData* CContentIteratorData::NewL(const TDesC& aSearchPath, TBool aRecursive, const TDesC8& aMimeType)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CContentIteratorData* self = new (ELeave) CContentIteratorData();
|
sl@0
|
26 |
CleanupStack::PushL(self);
|
sl@0
|
27 |
self->ConstructL(aSearchPath, aRecursive, aMimeType);
|
sl@0
|
28 |
CleanupStack::Pop(self);
|
sl@0
|
29 |
return self;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
CContentIteratorData::CContentIteratorData()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
CContentIteratorData::~CContentIteratorData()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
// release semaphore
|
sl@0
|
39 |
iThreadSemaphore.Signal();
|
sl@0
|
40 |
|
sl@0
|
41 |
iDataLockSemaphore.Close();
|
sl@0
|
42 |
iThreadSemaphore.Close();
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
void CContentIteratorData::ConstructL(const TDesC& aSearchPath, TBool aRecursive, const TDesC8& aMimeType)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
// Remember search parameters, the CContentIterator::ThreadEntry()
|
sl@0
|
48 |
// will ask for these later
|
sl@0
|
49 |
iPath.Copy(aSearchPath);
|
sl@0
|
50 |
iRecursive = aRecursive;
|
sl@0
|
51 |
iMimeType.Copy(aMimeType);
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
// Create semaphores
|
sl@0
|
55 |
User::LeaveIfError(iDataLockSemaphore.CreateLocal(1, EOwnerProcess));
|
sl@0
|
56 |
User::LeaveIfError(iThreadSemaphore.CreateLocal(1, EOwnerProcess));
|
sl@0
|
57 |
|
sl@0
|
58 |
// Grab semaphore so CContentIterator::ThreadEntry function can't enter the loop yet
|
sl@0
|
59 |
iThreadSemaphore.Wait();
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
|
sl@0
|
63 |
void CContentIteratorData::Lock()
|
sl@0
|
64 |
{
|
sl@0
|
65 |
iDataLockSemaphore.Wait();
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
void CContentIteratorData::Unlock()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
iDataLockSemaphore.Signal();
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
void CContentIteratorData::CompleteClientRequest(TInt aError)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
RThread clientThread;
|
sl@0
|
76 |
clientThread.Open(iClientThreadId);
|
sl@0
|
77 |
clientThread.RequestComplete(iClientRequest, aError);
|
sl@0
|
78 |
clientThread.Close();
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
void CContentIteratorData::SetClientRequest(TThreadId& aClientThreadId, TRequestStatus& aStatus)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
// Remember the thread and TRequestStatus that must be completed later
|
sl@0
|
85 |
iClientThreadId = aClientThreadId;
|
sl@0
|
86 |
iClientRequest = &aStatus;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
void CContentIteratorData::RunThreadFunction(TFileIteratorOperation aFunction)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
// Unblock the CContentIterator::ThreadEntry() function and allow it to run
|
sl@0
|
92 |
iFunction = aFunction;
|
sl@0
|
93 |
iThreadSemaphore.Signal();
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
TFileIteratorOperation CContentIteratorData::ThreadWait()
|
sl@0
|
97 |
{
|
sl@0
|
98 |
// Called by CContentIterator::ThreadEntry() to block execution until RunThreadFunction() is called
|
sl@0
|
99 |
iThreadSemaphore.Wait();
|
sl@0
|
100 |
return iFunction;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
|
sl@0
|
104 |
void CContentIteratorData::SetData(const TDesC& aPath, const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
// Set the results found in the search
|
sl@0
|
107 |
iPath.Copy(aPath);
|
sl@0
|
108 |
iMimeType.Copy(aMimeType);
|
sl@0
|
109 |
iUniqueId.Copy(aUniqueId);
|
sl@0
|
110 |
iName.Copy(aName);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
const TDesC& CContentIteratorData::Path() const
|
sl@0
|
114 |
{
|
sl@0
|
115 |
return iPath;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
const TDesC8& CContentIteratorData::MimeType() const
|
sl@0
|
119 |
{
|
sl@0
|
120 |
return iMimeType;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
const TDesC& CContentIteratorData::UniqueId() const
|
sl@0
|
124 |
{
|
sl@0
|
125 |
return iUniqueId;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
const TDesC& CContentIteratorData::Name() const
|
sl@0
|
129 |
{
|
sl@0
|
130 |
return iName;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
TBool CContentIteratorData::IsRecursive() const
|
sl@0
|
134 |
{
|
sl@0
|
135 |
return iRecursive;
|
sl@0
|
136 |
}
|