|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: Juha Kauppinen, Mika Hokkanen |
|
13 * |
|
14 * Description: Photo Browser |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include <e32base.h> |
|
20 #include <aknnotewrappers.h> |
|
21 |
|
22 #include "IEThreadEngine.h" |
|
23 #include "IEImageFinder.h" |
|
24 #include "ImagicConsts.h" |
|
25 |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // CFileFinderThread::CFileFinderThread(CSharedIntermediator* aSMediator) |
|
29 // |
|
30 // Constructor. |
|
31 // ---------------------------------------------------------------------------- |
|
32 CFileFinderThread::CFileFinderThread( |
|
33 CIEFileLoader* aFileLoader, |
|
34 RArray<CImageData*>& aFileNameData, |
|
35 RArray<CImageData*>& aFaceFileNameData, |
|
36 RCriticalSection* aCritical, |
|
37 TDesC& aFileName) : |
|
38 iCreatedThreads(EFalse), |
|
39 iFileLoader(aFileLoader), |
|
40 iFileNameData(aFileNameData), |
|
41 iFaceFileNameData(aFaceFileNameData), |
|
42 iCritical(aCritical) |
|
43 { |
|
44 iFilename.Copy(aFileName); |
|
45 } |
|
46 |
|
47 // ---------------------------------------------------------------------------- |
|
48 // CFileFinderThread::~CFileFinderThread(void) |
|
49 // |
|
50 // Destructor. |
|
51 // ---------------------------------------------------------------------------- |
|
52 CFileFinderThread::~CFileFinderThread(void) |
|
53 { |
|
54 DP0_IMAGIC(_L("CFileFinderThread::~CFileFinderThread++")); |
|
55 |
|
56 if(iSMediator) |
|
57 { |
|
58 delete iSMediator; |
|
59 iSMediator = NULL; |
|
60 } |
|
61 |
|
62 // Thread should be killed allready, if thread is already killed this does nothing |
|
63 iThreadOne.Kill(KErrNone); |
|
64 |
|
65 // Handles should be closed |
|
66 iThreadOne.Close(); |
|
67 DP0_IMAGIC(_L("CFileFinderThread::~CFileFinderThread--")); |
|
68 } |
|
69 |
|
70 CFileFinderThread* CFileFinderThread::NewL( |
|
71 CIEFileLoader* aFileLoader, |
|
72 RArray<CImageData*>& aFileNameData, |
|
73 RArray<CImageData*>& aFaceFileNameData, |
|
74 RCriticalSection* aCritical, |
|
75 TDesC& aFileName) |
|
76 { |
|
77 CFileFinderThread* self = CFileFinderThread::NewLC( |
|
78 aFileLoader, |
|
79 aFileNameData, |
|
80 aFaceFileNameData, |
|
81 aCritical, |
|
82 aFileName); |
|
83 CleanupStack::Pop(self); |
|
84 return self; |
|
85 } |
|
86 |
|
87 CFileFinderThread* CFileFinderThread::NewLC( |
|
88 CIEFileLoader* aFileLoader, |
|
89 RArray<CImageData*>& aFileNameData, |
|
90 RArray<CImageData*>& aFaceFileNameData, |
|
91 RCriticalSection* aCritical, |
|
92 TDesC& aFileName) |
|
93 { |
|
94 CFileFinderThread* self = new (ELeave) CFileFinderThread( |
|
95 aFileLoader, |
|
96 aFileNameData, |
|
97 aFaceFileNameData, |
|
98 aCritical, |
|
99 aFileName); |
|
100 CleanupStack::PushL(self); |
|
101 self->ConstructL(); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // Standard Symbian OS 2nd phase constructor |
|
106 void CFileFinderThread::ConstructL() |
|
107 { |
|
108 DP0_IMAGIC(_L("CFileFinderThread::ConstructL ++ --")); |
|
109 } |
|
110 |
|
111 void CFileFinderThread::StartL() |
|
112 { |
|
113 DP0_IMAGIC(_L("CFileFinderThread::Start++")); |
|
114 // Create threads only once |
|
115 if ( iCreatedThreads == EFalse ) |
|
116 { |
|
117 CreateThreadsL(); |
|
118 } |
|
119 DP0_IMAGIC(_L("CFileFinderThread::Start--")); |
|
120 } |
|
121 |
|
122 |
|
123 void CFileFinderThread::Stop() |
|
124 { |
|
125 //TRequestStatus aStatus; |
|
126 //iThreadOne.Logon(aStatus); |
|
127 //iThreadOne.Suspend(); |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CFileFinderThread::ExecuteThread(TAny *aPtr) |
|
132 // |
|
133 // Threadfunction of threadOne. Executed only by threadOne. |
|
134 // ---------------------------------------------------------------------------- |
|
135 TInt CFileFinderThread::ExecuteThreadOne(TAny *aPtr) |
|
136 { |
|
137 DP0_IMAGIC(_L("CFileFinderThread::ExecuteThreadOne++")); |
|
138 |
|
139 CMediator* aSMediator = static_cast<CMediator*>( aPtr ); |
|
140 |
|
141 //Create cleanupstack |
|
142 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
143 |
|
144 //Test cleanup stack, additional cleanup stack must be prosessed under |
|
145 //TRAP |
|
146 //We can't use low level cleanup stack handling |
|
147 TRAPD(error, CFileFinderThread::CreateFileFinderL(aSMediator)); |
|
148 |
|
149 delete cleanupStack; |
|
150 |
|
151 DP0_IMAGIC(_L("CFileFinderThread::ExecuteThreadOne--")); |
|
152 |
|
153 return 0; |
|
154 } |
|
155 |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // CFileFinderThread::CreateActiveScheduler(CSharedIntermediator* aSMediator) |
|
159 // |
|
160 // Create ActiveScheduler for thread1. |
|
161 // ---------------------------------------------------------------------------- |
|
162 void CFileFinderThread::CreateFileFinderL(CMediator* aSMediator) |
|
163 { |
|
164 DP0_IMAGIC(_L("CFileFinderThread::CreateFileFinderL++")); |
|
165 // create a new active scheduler |
|
166 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler; |
|
167 CleanupStack::PushL(activeScheduler); |
|
168 |
|
169 // use static function Install to install previously created scheduler |
|
170 CActiveScheduler::Install(activeScheduler); |
|
171 |
|
172 //Create and use iTNImageFinder to handle in backround AO iFileNameData array filling |
|
173 CIEImageFinder* TNImageFinder = new (ELeave) CIEImageFinder( |
|
174 aSMediator->iFileLoader, |
|
175 *aSMediator->iFileNameData, |
|
176 *aSMediator->iFaceFileNameData, |
|
177 aSMediator->iCritical); |
|
178 |
|
179 CleanupStack::PushL(TNImageFinder); |
|
180 TNImageFinder->ConstructL(); |
|
181 TNImageFinder->StartFinderL(KFileString); |
|
182 |
|
183 DP0_IMAGIC(_L("CFileFinderThread::CreateFileFinderL finder ended")); |
|
184 aSMediator->iFileLoader->ImageFinderStopped(); |
|
185 aSMediator->iFileLoader->AllFilesAddedToFilenameArray(); |
|
186 |
|
187 // Start active scheduler |
|
188 //CActiveScheduler::Start(); |
|
189 |
|
190 // Remove and delete scheduler and the rest. |
|
191 CleanupStack::PopAndDestroy(2); |
|
192 DP0_IMAGIC(_L("CFileFinderThread::CreateFileFinderL--")); |
|
193 } |
|
194 |
|
195 |
|
196 // ---------------------------------------------------------------------------- |
|
197 // CFileFinderThread::CreateThreadsL() |
|
198 // |
|
199 // Create thread1 and resume it. Activate thread1 listener. |
|
200 // ---------------------------------------------------------------------------- |
|
201 void CFileFinderThread::CreateThreadsL() |
|
202 { |
|
203 DP0_IMAGIC(_L("CFileFinderThread::CreateThreadsL++")); |
|
204 iSMediator = new (ELeave) CMediator(); |
|
205 |
|
206 iSMediator->iFileLoader = iFileLoader; |
|
207 iSMediator->iFileNameData = &iFileNameData; |
|
208 iSMediator->iFaceFileNameData = &iFaceFileNameData; |
|
209 iSMediator->iCritical = iCritical; |
|
210 iSMediator->iFileName = iFilename; |
|
211 |
|
212 // Create thread which uses the same heap as main program. |
|
213 iThreadOne.Create(_L("FileFinderThread"), ExecuteThreadOne, 12040, NULL, iSMediator); |
|
214 //EPriorityNormal, EPriorityLess, EPriorityMuchLess |
|
215 iThreadOne.SetPriority(EPriorityMuchLess); |
|
216 iThreadOne.Resume(); |
|
217 |
|
218 iCreatedThreads = ETrue; |
|
219 DP0_IMAGIC(_L("CFileFinderThread::CreateThreadsL--")); |
|
220 } |
|
221 |