72 // ----------------------------------------------------------------------------- |
73 // ----------------------------------------------------------------------------- |
73 // |
74 // |
74 void CMdeObjectQueueManager::ConstructL() |
75 void CMdeObjectQueueManager::ConstructL() |
75 { |
76 { |
76 CActiveScheduler::Add(this); |
77 CActiveScheduler::Add(this); |
|
78 User::LeaveIfError(iFs.Connect()); |
77 User::LeaveIfError(iTimer.CreateLocal()); |
79 User::LeaveIfError(iTimer.CreateLocal()); |
78 iHState = EStateResume; |
80 iHState = EStateResume; |
79 } |
81 } |
80 |
82 |
81 // ----------------------------------------------------------------------------- |
83 // ----------------------------------------------------------------------------- |
123 if (iJobQueue.Count() > INDEXING_QUEUE_MAX) |
125 if (iJobQueue.Count() > INDEXING_QUEUE_MAX) |
124 { |
126 { |
125 // Maximum is exceeded, force the write immediately |
127 // Maximum is exceeded, force the write immediately |
126 if (iState == EStateWaiting) |
128 if (iState == EStateWaiting) |
127 { |
129 { |
128 iTimer.Cancel(); // RunL will be called with iStatus of KErrCancelled |
130 if(IsActive()) |
|
131 iTimer.Cancel(); // RunL will be called with iStatus of KErrCancelled |
129 } |
132 } |
130 else if (iState == EStateNone) |
133 else if (iState == EStateNone) |
131 { |
134 { |
132 SetActive(); |
135 if(!IsActive()) |
133 TRequestStatus* status = &iStatus; |
136 { |
134 User::RequestComplete(status, KErrNone); // RunL will be called with iStatus of KErrNone |
137 SetActive(); |
|
138 TRequestStatus* status = &iStatus; |
|
139 User::RequestComplete(status, KErrNone); // RunL will be called with iStatus of KErrNone |
|
140 } |
135 } |
141 } |
136 } |
142 } |
137 else |
143 else |
138 { |
144 { |
139 // Maximum is not exceeded, keep waiting |
145 // Maximum is not exceeded, keep waiting |
140 if (iState == EStateNone) |
146 if (iState == EStateNone) |
141 { |
147 { |
142 iState = EStateWaiting; |
148 if(!IsActive()) |
143 iTimer.After(iStatus, INDEXING_DELAY); // Wait 5 seconds before putting this to index |
149 { |
144 SetActive(); |
150 iState = EStateWaiting; |
|
151 iTimer.After(iStatus, INDEXING_DELAY); // Wait 5 seconds before putting this to index |
|
152 SetActive(); |
|
153 } |
145 } |
154 } |
146 } |
155 } |
147 } |
156 } |
148 } |
157 } |
149 // ----------------------------------------------------------------------------- |
158 // ----------------------------------------------------------------------------- |
158 { |
167 { |
159 iState = EStateNone; |
168 iState = EStateNone; |
160 CPIXLOGSTRING("END CMdeObjectQueueManager::RunL as Harvester in Pause state"); |
169 CPIXLOGSTRING("END CMdeObjectQueueManager::RunL as Harvester in Pause state"); |
161 return; |
170 return; |
162 } |
171 } |
163 while (iJobQueue.Count()>0 ) |
172 while (iJobQueue.Count()>0 && iHState == EStateResume ) |
164 { |
173 { |
165 TMdeActionRecord object = iJobQueue[0]; |
174 TMdeActionRecord object = iJobQueue[0]; |
166 //iJobQueue.Remove(0); |
175 //iJobQueue.Remove(0); |
167 //Let the indexer handle this object TRAP it as it can leave |
176 //Let the indexer handle this object TRAP it as it can leave |
168 TRAPD(err,iMdeObjectHandler->HandleMdeItemL(object.iObjectId, object.iAction)); |
177 TRAPD(err,iMdeObjectHandler->HandleMdeItemL(object.iObjectId, object.iAction)); |
186 } |
195 } |
187 #ifdef __PERFORMANCE_DATA |
196 #ifdef __PERFORMANCE_DATA |
188 iMdeObjectHandler->UpdateLogL(); |
197 iMdeObjectHandler->UpdateLogL(); |
189 #endif |
198 #endif |
190 // Everything is indexed no need to be waiting anymore |
199 // Everything is indexed no need to be waiting anymore |
191 iState = EStateNone; |
200 iState = EStateNone; |
|
201 |
|
202 if(iJobQueue.Count() <= 0) |
|
203 { |
|
204 if( BaflUtils::FileExists( iFs, iFilePath )) |
|
205 BaflUtils::DeleteFile( iFs, iFilePath ); |
|
206 } |
192 CPIXLOGSTRING("END CMdeObjectQueueManager::RunL"); |
207 CPIXLOGSTRING("END CMdeObjectQueueManager::RunL"); |
193 } |
208 } |
194 |
209 |
195 // ----------------------------------------------------------------------------- |
210 // ----------------------------------------------------------------------------- |
196 // CCPixIndexerUtils::DoCancel() |
211 // CCPixIndexerUtils::DoCancel() |
227 { |
242 { |
228 iHState = EStateResume; |
243 iHState = EStateResume; |
229 ActivateAO(); |
244 ActivateAO(); |
230 } |
245 } |
231 |
246 |
|
247 void CMdeObjectQueueManager::SetFilePath(const TDesC& aFilePath) |
|
248 { |
|
249 iFilePath.Copy(aFilePath); |
|
250 } |
|
251 |
|
252 void CMdeObjectQueueManager::SaveQueuedItems() |
|
253 { |
|
254 if( iJobQueue.Count() <= 0) |
|
255 return; |
|
256 // Open the stream |
|
257 RFile file; |
|
258 User::LeaveIfError(file.Replace(iFs, iFilePath, EFileWrite)); |
|
259 CleanupClosePushL(file); |
|
260 |
|
261 RFileWriteStream wr(file); |
|
262 wr.PushL(); |
|
263 |
|
264 // Write harvester count |
|
265 wr.WriteInt32L(iJobQueue.Count()); |
|
266 |
|
267 for (TInt i=0; i<iJobQueue.Count(); i++) |
|
268 { |
|
269 wr.WriteUint32L(iJobQueue[i].iObjectId); |
|
270 wr.WriteInt16L(iJobQueue[i].iAction); |
|
271 } |
|
272 // Commit and cleanup |
|
273 wr.CommitL(); |
|
274 CleanupStack::PopAndDestroy(2, &file); |
|
275 } |
|
276 |
|
277 void CMdeObjectQueueManager::LoadQueuedItems() |
|
278 { |
|
279 // Open the stream |
|
280 RFile file; |
|
281 User::LeaveIfError(file.Open(iFs, iFilePath, EFileRead)); |
|
282 CleanupClosePushL(file); |
|
283 RFileReadStream rd(file); |
|
284 rd.PushL(); |
|
285 |
|
286 // Read harvester count |
|
287 TInt count = rd.ReadInt32L(); |
|
288 // Read the harvesters |
|
289 for (TInt i=0; i<count; i++) |
|
290 { |
|
291 TItemId iObjId= rd.ReadUint32L(); |
|
292 TCPixActionType iActionType = static_cast<TCPixActionType> ( rd.ReadInt16L()); |
|
293 AddMdeItemToQueueL( iObjId, iActionType ); |
|
294 } |
|
295 // Cleanup |
|
296 CleanupStack::PopAndDestroy(2, &file); |
|
297 } |
232 //End of file |
298 //End of file |