84 cpix_DocFieldEnum_destroy( static_cast<cpix_DocFieldEnum*>( aCpixDocFieldEnum ) ); |
84 cpix_DocFieldEnum_destroy( static_cast<cpix_DocFieldEnum*>( aCpixDocFieldEnum ) ); |
85 } |
85 } |
86 |
86 |
87 } // namespace |
87 } // namespace |
88 |
88 |
|
89 |
|
90 Cpt::Mutex CCPixIdxDb::idxMutex_; |
|
91 |
89 CCPixIdxDb* CCPixIdxDb::NewL() |
92 CCPixIdxDb* CCPixIdxDb::NewL() |
90 { |
93 { |
91 CCPixIdxDb* self = CCPixIdxDb::NewLC(); |
94 CCPixIdxDb* self = CCPixIdxDb::NewLC(); |
92 CleanupStack::Pop(self); |
95 CleanupStack::Pop(self); |
93 return self; |
96 return self; |
128 } |
131 } |
129 |
132 |
130 void CCPixIdxDb::CompletionCallback(void *aCookie, cpix_JobId aJobId) |
133 void CCPixIdxDb::CompletionCallback(void *aCookie, cpix_JobId aJobId) |
131 { |
134 { |
132 CCPixIdxDb* object = (CCPixIdxDb*)aCookie; |
135 CCPixIdxDb* object = (CCPixIdxDb*)aCookie; |
133 |
136 |
|
137 { |
|
138 Cpt::SyncRegion |
|
139 sr(idxMutex_); |
134 // Sanity check |
140 // Sanity check |
135 if (object == NULL || |
141 if (object == NULL || |
136 object->iPendingJobId != aJobId) |
142 object->iPendingJobId != aJobId) |
137 return; |
143 return; |
|
144 |
|
145 } |
138 |
146 |
139 // Call the asyncronizers completion code |
147 // Call the asyncronizers completion code |
140 CCPixAsyncronizer* asyncronizer = object->iAsyncronizer; |
148 CCPixAsyncronizer* asyncronizer = object->iAsyncronizer; |
141 asyncronizer->CompletionCallback(); |
149 asyncronizer->CompletionCallback(); |
142 } |
150 } |
297 document = ConvertToCpixDocumentLC(aDocument); |
305 document = ConvertToCpixDocumentLC(aDocument); |
298 |
306 |
299 OstTrace0( TRACE_NORMAL, CCPIXIDXDB_ADDL, "CCPixIdxDb::AddL" ); |
307 OstTrace0( TRACE_NORMAL, CCPIXIDXDB_ADDL, "CCPixIdxDb::AddL" ); |
300 CPIXLOGSTRING("CCPixIdxDb::AddL"); |
308 CPIXLOGSTRING("CCPixIdxDb::AddL"); |
301 DumpDocument(aDocument); |
309 DumpDocument(aDocument); |
|
310 { |
|
311 Cpt::SyncRegion |
|
312 sr(idxMutex_); |
302 iPendingJobId = cpix_IdxDb_asyncAdd(iIdxDb, document, iAnalyzer, (void*)this, &CompletionCallback); |
313 iPendingJobId = cpix_IdxDb_asyncAdd(iIdxDb, document, iAnalyzer, (void*)this, &CompletionCallback); |
303 CleanupStack::PopAndDestroy(document); |
314 CleanupStack::PopAndDestroy(document); |
304 SearchServerHelper::CheckCpixErrorL(iIdxDb, KErrCannotAddDocument); |
315 SearchServerHelper::CheckCpixErrorL(iIdxDb, KErrCannotAddDocument); |
305 iIsPending = ETrue; |
316 iIsPending = ETrue; |
306 |
317 |
307 iAsyncronizer->Start(ECPixTaskTypeAdd, aObserver, aMessage); |
318 iAsyncronizer->Start(ECPixTaskTypeAdd, aObserver, aMessage); |
|
319 } |
308 } |
320 } |
309 |
321 |
310 void CCPixIdxDb::AddCompleteL() |
322 void CCPixIdxDb::AddCompleteL() |
311 { |
323 { |
312 iIsPending = EFalse; |
324 iIsPending = EFalse; |
323 document = ConvertToCpixDocumentLC(aDocument); |
335 document = ConvertToCpixDocumentLC(aDocument); |
324 |
336 |
325 OstTrace0( TRACE_NORMAL, CCPIXIDXDB_UPDATEL, "CCPixIdxDb::UpdateL" ); |
337 OstTrace0( TRACE_NORMAL, CCPIXIDXDB_UPDATEL, "CCPixIdxDb::UpdateL" ); |
326 CPIXLOGSTRING("CCPixIdxDb::UpdateL"); |
338 CPIXLOGSTRING("CCPixIdxDb::UpdateL"); |
327 DumpDocument(aDocument); |
339 DumpDocument(aDocument); |
|
340 { |
|
341 Cpt::SyncRegion |
|
342 sr(idxMutex_); |
328 iPendingJobId = cpix_IdxDb_asyncUpdate(iIdxDb, document, iAnalyzer, (void*)this, &CompletionCallback); |
343 iPendingJobId = cpix_IdxDb_asyncUpdate(iIdxDb, document, iAnalyzer, (void*)this, &CompletionCallback); |
329 CleanupStack::PopAndDestroy(document); |
344 CleanupStack::PopAndDestroy(document); |
330 SearchServerHelper::CheckCpixErrorL(iIdxDb,KErrCannotUpdateDocument); |
345 SearchServerHelper::CheckCpixErrorL(iIdxDb,KErrCannotUpdateDocument); |
331 iIsPending = ETrue; |
346 iIsPending = ETrue; |
332 |
347 |
333 iAsyncronizer->Start(ECPixTaskTypeUpdate, aObserver, aMessage); |
348 iAsyncronizer->Start(ECPixTaskTypeUpdate, aObserver, aMessage); |
|
349 } |
334 } |
350 } |
335 |
351 |
336 void CCPixIdxDb::UpdateCompleteL() |
352 void CCPixIdxDb::UpdateCompleteL() |
337 { |
353 { |
338 iIsPending = EFalse; |
354 iIsPending = EFalse; |
353 docUidPtr.Copy(aDocUid); |
369 docUidPtr.Copy(aDocUid); |
354 |
370 |
355 const wchar_t* cDocumentId = reinterpret_cast<const wchar_t*>(docUidPtr.PtrZ()); |
371 const wchar_t* cDocumentId = reinterpret_cast<const wchar_t*>(docUidPtr.PtrZ()); |
356 |
372 |
357 iIsPending = ETrue; |
373 iIsPending = ETrue; |
|
374 { |
|
375 Cpt::SyncRegion |
|
376 sr(idxMutex_); |
358 iPendingJobId = cpix_IdxDb_asyncDeleteDocuments(iIdxDb, cDocumentId, (void*)this, &CompletionCallback); |
377 iPendingJobId = cpix_IdxDb_asyncDeleteDocuments(iIdxDb, cDocumentId, (void*)this, &CompletionCallback); |
359 SearchServerHelper::CheckCpixErrorL(iIdxDb, KErrCannotDeleteDocument); |
378 SearchServerHelper::CheckCpixErrorL(iIdxDb, KErrCannotDeleteDocument); |
360 CleanupStack::PopAndDestroy(docUid); |
379 CleanupStack::PopAndDestroy(docUid); |
361 |
380 |
362 iAsyncronizer->Start(ECPixTaskTypeDelete, aObserver, aMessage); |
381 iAsyncronizer->Start(ECPixTaskTypeDelete, aObserver, aMessage); |
|
382 } |
363 } |
383 } |
364 |
384 |
365 void CCPixIdxDb::DeleteDocumentsCompleteL() |
385 void CCPixIdxDb::DeleteDocumentsCompleteL() |
366 { |
386 { |
367 iIsPending = EFalse; |
387 iIsPending = EFalse; |
419 void CCPixIdxDb::FlushL(MCPixAsyncronizerObserver* aObserver, const RMessage2& aMessage) |
439 void CCPixIdxDb::FlushL(MCPixAsyncronizerObserver* aObserver, const RMessage2& aMessage) |
420 { |
440 { |
421 if (iIsPending) |
441 if (iIsPending) |
422 User::Leave(KErrInUse); |
442 User::Leave(KErrInUse); |
423 |
443 |
424 |
444 { |
|
445 Cpt::SyncRegion |
|
446 sr(idxMutex_); |
425 iPendingJobId = cpix_IdxDb_asyncFlush(iIdxDb, (void*)this, &CompletionCallback); |
447 iPendingJobId = cpix_IdxDb_asyncFlush(iIdxDb, (void*)this, &CompletionCallback); |
426 SearchServerHelper::CheckCpixErrorL(iIdxDb, KErrDatabaseFlushFailed); |
448 SearchServerHelper::CheckCpixErrorL(iIdxDb, KErrDatabaseFlushFailed); |
427 iIsPending = ETrue; |
449 iIsPending = ETrue; |
428 |
450 |
429 iAsyncronizer->Start(ECPixTaskTypeFlush, aObserver, aMessage); |
451 iAsyncronizer->Start(ECPixTaskTypeFlush, aObserver, aMessage); |
|
452 } |
430 } |
453 } |
431 |
454 |
432 const char* CCPixIdxDb::GetFieldCStrLC(const CSearchDocument& aDocument, const TDesC& aFieldName ) |
455 const char* CCPixIdxDb::GetFieldCStrLC(const CSearchDocument& aDocument, const TDesC& aFieldName ) |
433 { |
456 { |
434 const CDocumentField* field = aDocument.Field( aFieldName ); |
457 const CDocumentField* field = aDocument.Field( aFieldName ); |
484 CleanupStack::PopAndDestroy(4); |
507 CleanupStack::PopAndDestroy(4); |
485 |
508 |
486 if (!doc) |
509 if (!doc) |
487 { |
510 { |
488 SearchServerHelper::LogErrorL(*result.err_); |
511 SearchServerHelper::LogErrorL(*result.err_); |
489 cpix_ClearError(doc); |
|
490 User::Leave(KErrCannotCreateDocument); |
512 User::Leave(KErrCannotCreateDocument); |
491 } |
513 } |
492 // document created, push to cleanup stack. |
514 // document created, push to cleanup stack. |
493 CleanupStack::PushL( TCleanupItem (CpixDocumentDestroyer, doc) ); |
515 CleanupStack::PushL( TCleanupItem (CpixDocumentDestroyer, doc) ); |
494 |
516 |