void CEventQueue::QueueEvent(const TContactDbObserverEventV2 &aEvent) { // Flush the queue - there's no point in sending out all the preceeding // events when the an Unknown Changes event is being sent. // Unknown changes means that there are too many events to propagate and // the client should resync all its cached data. if (aEvent.iType == EContactDbObserverEventUnknownChanges) { Flush(); } // Is the queue in order, if not then return (no event will be sent) if (Flag(EQueueError)) { return; } // Can we send the event right away, i.e. do we have an outstanding request if (Flag(EValidEventMsg)) { SendEvent(aEvent, aEvent.iAdditionalContactIds); }// Is the queue full? If so set flag EQueueError and return else if (iEvents.Count() > KMaxNumberOfEventsInEventQueue) { DEBUG_PRINTDN2(__VERBOSE_DEBUG__,_L("[CNTMODEL] ->X"), aEvent); Flush(); SetFlag(EQueueError); }// Otherwise can we add the request to the queue else if (Append(aEvent)!=KErrNone) { SetFlag(EQueueError); } #if defined(__VERBOSE_DEBUG__) else { // If added then add it to log DebugLogNotification(_L("[CNTMODEL] ->Q"), aEvent); } #endif }
/** Database event handler. @param aEvent the database event. */ void CContactLocalView::HandleDatabaseEventL(TContactDbObserverEvent aEvent) { // handle Backup / Restore notifications before checking View State switch (aEvent.iType) { case EContactDbObserverEventBackupBeginning: case EContactDbObserverEventRestoreBeginning: #if defined(__VERBOSE_DEBUG__) RDebug::Print(_L("[CNTMODEL] CContactLocalView{ViewPrefs = 0x%08X}::HandleDatabaseEventL -> Backup/Restore Beginning, state = %i\r\n"), iViewPreferences, iState); #endif if (iState == EReady) { SetState(ENotReady); } else { // stop sorting iViewCntMgr->StopSortL(); } return; case EContactDbObserverEventBackupRestoreCompleted: #if defined(__VERBOSE_DEBUG__) RDebug::Print(_L("[CNTMODEL] CContactLocalView{ViewPrefs = 0x%08X}::HandleDatabaseEventL -> Backup/Restore Completed, state = %i, old sort error %i\r\n"), iViewPreferences, iState, iExtension->iError); #endif if (iState == ENotReady && iExtension->iError == KErrNone) { // view was ready before tables were closed SetState(EReady); } else // view was Initializing (sorting) before tables were closed { // re-read database and sort SafeResort(); } return; default: // other events dealt with below break; } if (iState!=EReady) { if (iViewCntMgr->IsICCSynchronised()) { /* * View events are only queued when the ICC has been synchronised. This prevents * duplicate contacts in an ICC view because add events are not queued until the * SIM is fully synchronised. * * See LUD-5EBHZF "ICC contacts view broadcasts add item events after view is * ready" for more detail. */ #if defined(__VERBOSE_DEBUG__) DebugLogNotification(_L("[CNTMODEL] . . . . . Queueing Database Event "), aEvent); #endif iOutstandingEvents.AppendL(aEvent); // The view state is set to ENotReady when a recovery takes place, and also when the tables // are closed, so set ready here. if (iState == ENotReady && (aEvent.iType == EContactDbObserverEventRecover || aEvent.iType == EContactDbObserverEventTablesOpened)) { SetState(EReady); } // view was Initializing (sorting) before recovery or compression started! if (iState == EInitializing && (aEvent.iType == EContactDbObserverEventRecover || aEvent.iType == EContactDbObserverEventCompress)) { // re-read database and sort SafeResort(); } } #if defined(__VERBOSE_DEBUG__) else { DebugLogNotification(_L("[CNTMODEL] . . . . . Discarding Database Event "), aEvent); } #endif } else { TContactViewEvent event; event.iInt = KErrNone; switch(aEvent.iType) { case EContactDbObserverEventGroupChanged: case EContactDbObserverEventContactChanged: case EContactDbObserverEventOwnCardChanged: { if (aEvent.iType == EContactDbObserverEventGroupChanged) { //Groups are a special case the base view may not contain the group //but a sub view may be such a group and need to know its changed event.iEventType=TContactViewEvent::EGroupChanged; event.iContactId=aEvent.iContactId; NotifyObservers(event); } // Remove from old position, and notify. TRAPD(err,event.iInt=RemoveL(aEvent.iContactId)); if (err == KErrNone && event.iInt != KErrNotFound) { event.iEventType=TContactViewEvent::EItemRemoved; event.iContactId=aEvent.iContactId; NotifyObservers(event); } // Insert at new position, and notify. event.iInt=InsertL(aEvent.iContactId); if (event.iInt != KErrNotFound) { event.iEventType=TContactViewEvent::EItemAdded; event.iContactId=aEvent.iContactId; NotifyObservers(event); } break; } case EContactDbObserverEventContactAdded: case EContactDbObserverEventGroupAdded: #if defined(__VERBOSE_DEBUG__) DebugLogNotification(_L("[CNTMODEL] DatabaseEvent -> Contact/Group Added"), aEvent); #endif event.iInt=InsertL(aEvent.iContactId); if (event.iInt != KErrNotFound) { event.iEventType=TContactViewEvent::EItemAdded; event.iContactId=aEvent.iContactId; NotifyObservers(event); } break; case EContactDbObserverEventContactDeleted: if(aEvent.iContactId == KNullContactId) // KNullContactId indicates a bulk delete. { SetState(EInitializing); // Use initializing state to avoid ESortOrderChanged event being sent to observers. SafeResort(); } else { event.iInt=RemoveL(aEvent.iContactId); if (event.iInt != KErrNotFound) { event.iEventType=TContactViewEvent::EItemRemoved; event.iContactId=aEvent.iContactId; NotifyObservers(event); } } break; case EContactDbObserverEventGroupDeleted: case EContactDbObserverEventOwnCardDeleted: event.iInt=RemoveL(aEvent.iContactId); if (event.iInt != KErrNotFound) { event.iEventType=TContactViewEvent::EItemRemoved; event.iContactId=aEvent.iContactId; NotifyObservers(event); } break; case EContactDbObserverEventUnknownChanges: case EContactDbObserverEventCurrentDatabaseChanged: SetState(EInitializing); // Use initializing state to avoid ESortOrderChanged event being sent to observers. SafeResort(); break; case EContactDbObserverEventSortOrderChanged: // event is not currently used SetState(ENotReady); SafeResort(); break; case EContactDbObserverEventTablesClosed: if (iState == EReady) { SetState(ENotReady); } break; case EContactDbObserverEventTablesOpened: // re-read database and sort SafeResort(); break; case EContactDbObserverEventNull: case EContactDbObserverEventUnused: case EContactDbObserverEventRecover: case EContactDbObserverEventCompress: case EContactDbObserverEventRollback: case EContactDbObserverEventTemplateChanged: case EContactDbObserverEventTemplateDeleted: case EContactDbObserverEventTemplateAdded: case EContactDbObserverEventCurrentItemDeleted: case EContactDbObserverEventCurrentItemChanged: case EContactDbObserverEventPreferredTemplateChanged: case EContactDbObserverEventSpeedDialsChanged: case EContactDbObserverEventRestoreBadDatabase: break; // these events should not come here, but be dealt with at the top of HandleDatabaseEventL case EContactDbObserverEventBackupBeginning: case EContactDbObserverEventRestoreBeginning: case EContactDbObserverEventBackupRestoreCompleted: break; default: ASSERT(EFalse); } } }