Beispiel #1
0
BOOL PSGame::LoadHistory()
{
	// Get the name of the game.
	CFrameWnd* pFrame = (CFrameWnd*) AfxGetMainWnd();
	CDocument* pDoc = pFrame->GetActiveDocument();
	CString strName = pDoc->GetPathName();
	if (strName == "")
		return FALSE;

	// Open the history file.
	char* path_buffer = strName.GetBuffer(_MAX_PATH);
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	_splitpath( path_buffer, drive, dir, fname, ext );
	strName.Format("%s%s%s%s", drive, dir, fname, ".dph");

	CFile f;
	CFileException fe;
	f.Open(strName, CFile::modeRead, &fe);
	if (fe.m_cause)
		return FALSE;

	// Load the history.
	PSHistory* pHist = new PSHistory;
	CArchive arh(&f, CArchive::load);
	pHist->Serialize(arh);
	arh.Close();
	f.Close();

	// If the data in the last step of the history is the same as the game's data, copy the history
	// into the game's history. If not, disregard the loaded history.
	PSStep* pLastStep = pHist->GetLastStep();
	PSData* pLastData = pLastStep->GetData();
	if (!(*pLastData == m_Data))// Operator != not defined.
	{
		AfxMessageBox(IDS_BAD_HISTORY);
		delete pHist;
		return FALSE;
	}

	SetHistory(pHist);
	SetCurrentStep(pLastStep);
	return TRUE;
}
/**
Handles the compound operation state machine

@return ETrue if compound operation is completed, 
		EFalse otherwise (will be called again, unless active)
*/
TBool CImapCompoundDelete::DoRunLoopL()
	{
	SetCurrentStep();
	switch (iCurrentStep)
		{
		case ESelectSourceMailboxRW: // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDelete1); // select source folder
			// Anything to do?
			if (iSourceSel->Count()==0)
				{
				iNextStep = EFinished;
				return EFalse;
				}
			
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundDelete::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = ESelectSourceMailboxRW;
				Complete(KErrNone);
				return ETrue;
				}
			
			// Find the parent folder for the first entry in the array
			iParentFolderId = FindFolderL((*iSourceSel)[0]);
			iParentFolder = iSyncManager.GetFolderL(iParentFolderId);
			if (iParentFolder==NULL)
				{
				// Try again with the next message
				// Delete the first entry in the source selection
				iSourceSel->Delete(0, 1);
				// increment progress counter
				++iProgressMsgsDone;
				return EFalse;
				}
			
			// reset the message UID list
			iMessageUids.Reset();

			__LOG_FORMAT((iSession->LogId(), "Deleting message %x in folder %x", (*iSourceSel)[0], iParentFolderId));

			iParentFolder->SelectL(iStatus, *iSession);
			iProgressState = TImap4GenericProgress::ESelecting;
			iNextStep = EDeleteMessage;
			SetActive();
			break;
			}

		case EDeleteMessage: // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDelete2); // issue the STORE /deleted command
			// build an array of the UIDs to delete,
			// mark local IMAP \deleted flag.
			TInt  i = 0;
			TInt  count = iSourceSel->Count();
			TBool sameParent = ETrue;
			while (i<count && sameParent)
				{
				SetEntryL((*iSourceSel)[i]);
				TMsvEmailEntry entry = iServerEntry.Entry();
				if (entry.Parent()==iParentFolderId)
					{
					TUint id = entry.UID();
					iMessageUids.AppendL(id);

					// Set deleted flag on local entry
					entry.SetDeletedIMAP4Flag(ETrue);
					User::LeaveIfError(iServerEntry.ChangeEntry(entry));
					++iSelectionToDelete;
					}
				else
					{
					sameParent=EFalse;
					}
				++i;
				}

			HBufC8* uidSeq = CImapSession::CreateSequenceSetLC(iMessageUids);

			// issue the store command
			iSession->StoreL(iStatus, uidSeq->Des(), KImapAddFlags, KImapFlagDeleted, ETrue, iFlagInfoResponseArray);
			iProgressState = TImap4GenericProgress::EDeleting;
			CleanupStack::PopAndDestroy(uidSeq);
			if (iImapSettings.UseExpunge())
				{
				iNextStep=EExpunge;
				}
			else
				{
				iNextStep=ECloseFolder;
				}
			SetActive();
			break;
			}

		case EExpunge: // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDelete3); // issue the EXPUNGE command
			// Messages have been marked for delete on the remote server
			// issue the expunge command to remove them completely
			iSession->ExpungeL(iStatus);
			// no change in progress state
			iNextStep = EDeleteLocalMessage;
			SetActive();
			break;
			}

		case ECloseFolder:
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDelete4); // CLOSE FOLDER
			//Permanently removes all messages that have the deleted flag set
			//from the currently selected mailbox
			iSession->CloseL(iStatus);
			iNextStep=ESelectFolderAfterClose;
			SetActive();
			break;
			}

		case ESelectFolderAfterClose:
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDelete5); // SELECT FOLDER
			//Selecting a mailbox so that messages in the mailbox can be accessed. 
			iParentFolder->SelectL(iStatus, *iSession);
			iNextStep=EDeleteLocalMessage;
			SetActive();
			break;
			}

		case EDeleteLocalMessage: // synchronous
			{
			DeleteLocalMessagesL();
			// test for remaining messages to delete performed in state ESelectSourceMailboxRW;
			iNextStep=ESelectSourceMailboxRW;
			// no async request made.
			return EFalse;
			}
				
		case EFinished:	// finished
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundDelete::Completing OK");
			iProgressState = TImap4GenericProgress::EIdle;
			Complete(KErrNone);
			return ETrue;
			}
			
		default:
			{
			__ASSERT_DEBUG(EFalse, 
				TImapServerPanic::ImapPanic(TImapServerPanic::EDeleteCompoundUnexpectedState));
			// unexpected state - complete the request
			iProgressState = TImap4GenericProgress::EIdle;
			return ETrue;
			}
		}
	return EFalse;
	}
/**
Handles the compound operation state machine

@return ETrue if compound operation is completed, 
		EFalse otherwise (will be called again, unless active)
*/
TBool CImapCompoundSyncService::DoRunLoopL()
	{
	SetCurrentStep();
	switch (iCurrentStep)
		{
		case ESyncService:  // synchronous
			{
			// Starts the full sync process by synching the inbox
			iNextFolderSync = 0;
					
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Starting the full Sync steps.");
			CImapFolder* inbox = iSyncManager.Inbox();
			
			if(inbox != NULL)
				{
				iNextStep = EInboxSync;
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Processing offline for the inbox.");
					// Deal with operations in the array
				if (RefreshOutstandingOpsL(inbox->MailboxId()))
					{
					iNextStep = EInboxCheckPendingOps;
					}
				}
			else
				{
				iNextStep = ESyncTree;
				}
			
			CompleteSelf();
			}
			break;
		case EInboxDoneOps: // synchronous
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Performing the current offline op for the inbox.");

			iNextStep = EInboxCheckPendingOps;
			DonePendingOpL();
			CompleteSelf();
			}
			break;
		case EInboxCheckPendingOps: // synchronous
			{
			iSyncProgressState=TImap4SyncProgress::EProcessingPendingOps;
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Find the next offline op for the inbox.");
			if (NextPendingOpL())
				{
				iNextStep = EInboxSync;
				DonePendingOpL();
				CompleteSelf();
				}
			else
				{
				iNextStep = EInboxDoneOps;

				// As there is a next pending op, we should be active so that the
				// operation can go ahead. However under some circumstances (such
				// as a missing shadow ID), the operation will not happen so we need
				// to ensure the state machine does not lock up.
				if (!IsActive())
					{
					CompleteSelf();
					}
				}
			}
			break;
		case EInboxEarlyDeletes: // async, SELECTing the inbox prior to EXPUNGE. 
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Performing early deletes for the inbox.");

			iSyncProgressState=TImap4SyncProgress::EDeleting;
			// get rid of the FromLocal message sources
			CImapFolder* inbox = iSyncManager.Inbox();
			
			if(inbox)
				{
				for (TInt i = 0; i < iOutstandingLocalDeletes->Count(); ++i)
					{
					TMsvId id = (*iOutstandingLocalDeletes)[i];
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Removing message %d.", id));
					inbox->DeleteMessageL(id);
					}

				iOutstandingLocalDeletes->Reset();

				// then do the inbox deletes
				if (ProcessPendingDeleteOpsL(inbox->MailboxId(), !iPerformDeletes))
					{
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEInboxEarlyDeletes);
					iNextStep = EInboxEarlyExpunge;
					inbox->SelectL(iStatus, *iSession);
					SetActive();
					return EFalse;
					}
				}
			else
				{
				iOutstandingLocalDeletes->Reset();
				}

			iNextStep = ESyncTree;
			CompleteSelf();
			}
	  		break;
		case EInboxEarlyExpunge: // async - sync deletes performed by the folder object, STORE /deleted and EXPUNGE
			{
			iSyncProgressState=TImap4SyncProgress::EDeleting;

			iNextStep = ESyncTree;

			if (iStatus.Int() == KErrImapNo)
				{
				iFoldersNotFound++;
				}
			else
				{
				// expunge the folder
				iFolder = iSyncManager.Inbox();
				
				if(iFolder)
					{
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEInboxEarlyExpunge);
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Expunge the folder %S.", &(iFolder->FullFolderPathL())));
					iFolder->SyncDeletesL(iStatus, *iSession);
					SetActive();
					return EFalse;
					}
				}

			CompleteSelf();
			}
			break;
		case EInboxSync: // async
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Calling the Syncmanger step for synching the inbox.");

			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = EInboxSync;
				Complete(KErrNone);
				return ETrue;
				}

			// Call the SyncManager inbox sync
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEInboxSync);			
			iSyncProgressState=TImap4SyncProgress::ESyncInbox;
			iSyncManager.SynchroniseInboxL(iStatus, *iSession);
			iNextStep = EInboxEarlyDeletes;
			}
			break;
		case ESyncTree:  // async
			{
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = ESyncTree;
				Complete(KErrNone);
				return ETrue;
				}

			iNextStep = ESyncSubscriptions;

			// skip folder tree sync if disabled.
			if (iImapSettings.FolderSyncDisabled())
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Folder Tree Sync Disabled....");
				return EFalse;
				}

			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Calling the Syncmanger step to sync the folder tree.");

			// Synching the remote folders tree to local
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncESyncTree);			
			iSyncProgressState=TImap4SyncProgress::ESyncFolderTree;
			iSyncManager.SynchroniseFolderTreeL(iStatus, *iSession);
			}
			break;
		case ESyncSubscriptions:  // async
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Calling the Syncmanger step to sync the folders subscriptions.");
			// Synching the remote folders tree to local
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncESyncSubscriptions);
			iSyncProgressState=TImap4SyncProgress::ECheckRemoteSubscription;
			iSyncManager.SynchroniseFolderSubscriptionsL(iStatus, *iSession);
			iNextStep = ESelectSyncFolder;
			}
			break;	
		case EFolderDoneOps:  // synchronous
			{
			if(iNextFolderSync > 0)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Calling DonePendingOp.");
				iNextStep = EFolderCheckPendingOPs;
				DonePendingOpL();
				}
			else
				{
				// All folders are done.
				iNextStep = ESyncInboxAutoFetch;
				}
			
			CompleteSelf();
			}
			break;
		case EFolderCheckPendingOPs: // synchronous
			{
			iSyncProgressState=TImap4SyncProgress::EProcessingPendingOps;

			if(NextPendingOpL())
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : All offline ops are done, calling folder sync.");
				iNextStep = ESyncFolder;
				DonePendingOpL();
				CompleteSelf();
				}
			else
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Got a pending offline op, now do it.");
				iNextStep = EFolderDoneOps;

				// As there is a next pending op, we should be active so that the
				// operation can go ahead. However under some circumstances (such
				// as a missing shadow ID), the operation will not happen so we need
				// to ensure the state machine does not lock up.
				if (!IsActive())
					{
					CompleteSelf();
					}
				}
			}
			break;
		case EFolderEarlyDeletes: // asynchronous
			{
			iSyncProgressState=TImap4SyncProgress::EDeleting;

			CImapFolder* currentFolder = iSyncManager.GetFolderL(iNextFolderSync);

			if (currentFolder)
				{
				for (TInt i = 0; i < iOutstandingLocalDeletes->Count(); ++i)
					{
					TMsvId id = (*iOutstandingLocalDeletes)[i];
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Removing message %d.", id));
					currentFolder->DeleteMessageL(id);
					}

				iOutstandingLocalDeletes->Reset();

				// if we are doing deletes on connection then all deletes will
				// be marked Delete
				if (ProcessPendingDeleteOpsListL(!iPerformDeletes))
					{
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Selecting the folder %S for expunge.", &(currentFolder->FullFolderPathL())));
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEFolderEarlyDeletes);
					currentFolder->SelectL(iStatus, *iSession);
					iNextStep = EFolderEarlyExpunge;
					SetActive();
					return EFalse;
					}
				}
			else
				{
				iOutstandingLocalDeletes->Reset();
				}

			iNextStep = ESelectSyncFolder;
			CompleteSelf();
			}
			break;
		case EFolderEarlyExpunge: // asynchronous
			{
			iSyncProgressState=TImap4SyncProgress::EDeleting;

			iNextStep = ESelectSyncFolder;

			if (iStatus.Int() == KErrImapNo)
				{
				++iFoldersNotFound;
				}
			else
				{
				iFolder = iSyncManager.GetFolderL(iNextFolderSync);
				if(iFolder)
					{
					// expunge the folder
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Expunge the folder %S.", &(iFolder->FullFolderPathL())));
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEFolderEarlyExpunge);
					iFolder->SyncDeletesL(iStatus, *iSession);
					SetActive();
					return EFalse;
					}
				}

			CompleteSelf();
			}
			break;
		case ESelectSyncFolder: // synchronous
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::ESelectSyncFolder()");
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = ESelectSyncFolder;
				Complete(KErrNone);
				return ETrue;
				}
				
			// Call for the first time will not be active
			iSyncManager.NextSubscribedFoldersL(iNextFolderSync);
			iSyncProgressState=TImap4SyncProgress::ESyncOther;

			if(iNextFolderSync > 0)
				{
				// Perform the pending offline operations first
				iNextStep = ESyncFolder;
				if(RefreshOutstandingOpsL(iNextFolderSync))
					{
					iNextStep = EFolderCheckPendingOPs;	
					}
				}
			else
				{
				// All folders are done.
				iNextStep = ESyncInboxAutoFetch;
				}
			CompleteSelf();
			}
			break;
		case ESyncFolder: // async
			{
			if(iNextFolderSync > 0)
				{
				// Now sync the folder
				MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncESyncFolder);
				iSyncManager.SynchroniseSubscribedFoldersL(iStatus, *iSession, iNextFolderSync);
				iNextStep = EFolderEarlyDeletes;
				}
			else
				{
				// All folders are done.
				iNextStep = ESyncInboxAutoFetch;
				CompleteSelf();
				}
			}
			break;	
		case EInboxLateDeletes: // async
			{
			iNextFolderSync = 0;
			iSyncProgressState=TImap4SyncProgress::EDeleting;
			CImapFolder* inbox = iSyncManager.Inbox();

			if (inbox)
				{
				if (ProcessPendingDeleteOpsL( inbox->MailboxId(), EFalse ))
					{
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapEInboxLateDeletes);
					inbox->SelectL(iStatus, *iSession);
					iNextStep = EInboxLateExpunge;
					SetActive();
					return EFalse;
					}
				}

			iNextStep = EFolderLateDeletes;
			CompleteSelf();
			}
			break;	
		case EInboxLateExpunge: // async
			{
			iNextStep = EFolderLateDeletes;

			if (iStatus.Int() == KErrImapNo)
				{
				iFoldersNotFound++;
				}
			else
				{
				// expunge the folder
				iFolder = iSyncManager.Inbox();
				
				if(iFolder)
					{
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncESyncFolder);
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Late Expunge the folder %S.", &(iFolder->FullFolderPathL())));
					iFolder->SyncDeletesL(iStatus, *iSession);
					SetActive();
					return EFalse;
					}
				}

			CompleteSelf();
			}
			break;
		case EFolderLateDeletes: // async
			{
			iSyncProgressState=TImap4SyncProgress::EDeleting;

			// Call for the first time will not be active
			iSyncManager.NextSubscribedFoldersL(iNextFolderSync);

			if(iNextFolderSync > 0)
				{
				if (ProcessPendingDeleteOpsListL( EFalse ) )
					{
					iNextStep = EFolderLateExpunge;
					}		
				else
					{
					CImapFolder* currentFolder = iSyncManager.GetFolderL(iNextFolderSync);
					if(currentFolder)
						{
						__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Selecting the folder %S for expunge.", &(currentFolder->FullFolderPathL())));
						MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEFolderLateDeletes);
						iNextStep = EFolderLateExpunge;
						currentFolder->SelectL(iStatus, *iSession);
						SetActive();
						return EFalse;
						}

					// back to select next folder
					iNextStep = EFolderLateDeletes;
					}
				}
			else
				{
				// No more subscribed folder was found
				iNextStep = EFinished;
				}

			CompleteSelf();
			}
			break;
		case EFolderLateExpunge: // async
			{
			iNextStep = EFolderLateDeletes;

			if (iStatus.Int() == KErrImapNo)
				{
				iFoldersNotFound++;
				}
			else
				{
				iFolder = iSyncManager.GetFolderL(iNextFolderSync);
				if(iFolder)
					{
					__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::DoRunLoopL : Late Expunge the folder %S.", &(iFolder->FullFolderPathL())));
					// expunge the folder
					MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmImapSyncEFolderLateExpunge);
					iFolder->SyncDeletesL(iStatus, *iSession);
					SetActive();
					return EFalse;
					}
				}

			CompleteSelf();
			}
			break;
		case ESyncInboxAutoFetch:
			{
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = ESyncInboxAutoFetch;
				Complete(KErrNone);
				return ETrue;
				}
				
			iSyncProgressState=TImap4SyncProgress::ESyncOther;
			if (!iImapSettings.UseSyncDownloadRules())
				{
				// not using sync rules, loop to EFinished.
				iNextStep = EFinished;
				return EFalse;
				}

			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Starting Second Phase Synchronisation");

			// set the next step to perform
			iNextStep = ESyncFolderAutoFetchCheck;
			
			if (KErrNotFound == iImapSettings.GetSyncDownloadRuleL(CImapSyncDownloadRules::EInboxRulesType, iMailInfo))
				{
				// No download rules for the inbox, check other folders
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::No download rules for inbox on this bearer");
				return EFalse;
				}
			
			CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
			CleanupStack::PushL(selection);
			
			TInt msgsToFetch = iSyncManager.Inbox()->GetFetchMessageChildrenL(*selection);
			__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::Fetching %d INBOX messages.", msgsToFetch));
			if (msgsToFetch>0)
				{
				delete iImapCompound;
				iImapCompound = NULL;
				// Create the compound operation object
				iImapCompound = CImapCompoundCopyToLocal::NewL(iSyncManager, 
				                    			               iServerEntry, 
				                                			   iImapSettings,
				                                			   iImapMailStore, 
				                                               EFalse,
				                                               *selection,
				                                               KMsvNullIndexEntryId,
				                                               iMailInfo);
				iImapCompound->StartOperation(iStatus, *iSession);
				if (iDoNotFetchSel)
					{
					((CImapCompoundCopyToLocal*)iImapCompound)->RemoveFromSelection(*iDoNotFetchSel);
					}
				SetActive();
				}
			CleanupStack::PopAndDestroy(selection);
			return EFalse; // if not active, will re-enter this function and perform next step...
			}
			
		case ESyncFolderAutoFetchCheck:
			{
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				// fetching of inbox contents may have been stopped prematurely,
				// on resume, go back to check if any inbox messages still to fetch.
				iNextStep = ESyncInboxAutoFetch;
				Complete(KErrNone);
				return ETrue;
				}

			// reset folder sync counter
			iFolderSyncCount = 0;
			// can only get here if download rules being used, so no need to check that.
			// No point in continuing if no download rules defined for non-inbox folders:
			if (KErrNotFound == iImapSettings.GetSyncDownloadRuleL(CImapSyncDownloadRules::EFolderRulesType, iMailInfo))
				{
				// No download rules for non-inbox folders.
				iNextStep = EFinished;
				return EFalse;
				}
			// else continue to next step...
			}
		case ESyncFolderAutoFetch:
			{
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = ESyncFolderAutoFetchCheck;
				// delete the compound fetch operation - we will create a new one on resume,
				// using the download rules for the new bearer.
				delete iImapCompound;
				iImapCompound = NULL;
				Complete(KErrNone);
				return ETrue;
				}

			TInt32 numSubscribedFolders;
			CImapFolder* folder = iSyncManager.GetSubscribedFolder(iFolderSyncCount, numSubscribedFolders);
			if (folder)
				{
				CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
				CleanupStack::PushL(selection);
				TInt msgsToFetch = folder->GetFetchMessageChildrenL(*selection);
				__LOG_FORMAT((iSession->LogId(), "CImapCompoundSyncService::Fetching %d messages in folder %d.", msgsToFetch, folder->MailboxId()));
				if (msgsToFetch>0)
					{
					delete iImapCompound;
					iImapCompound = NULL;
					// Create the compound operation object
					iImapCompound = CImapCompoundCopyToLocal::NewL(iSyncManager, 
					                    			               iServerEntry, 
					                                			   iImapSettings,
					                                			   iImapMailStore, 
					                                               EFalse,
					                                               *selection,
					                                               KMsvNullIndexEntryId,
					                                               iMailInfo);
					iImapCompound->StartOperation(iStatus, *iSession);
					if (iDoNotFetchSel)
						{
						((CImapCompoundCopyToLocal*)iImapCompound)->RemoveFromSelection(*iDoNotFetchSel);
						}
					SetActive();
					}
				CleanupStack::PopAndDestroy(selection);
				// when complete, check the next folder...
				++iFolderSyncCount;
				iNextStep = ESyncFolderAutoFetch;
				}
			else
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Download Rules Auto Fetch Completed.");
				iNextStep = EFinished;
				}
			return EFalse; // not finished yet...
			}
			
		case EFinished:
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundSyncService::Completing OK");
			iSyncProgressState=TImap4SyncProgress::EIdle;
			iProgressState = TImap4GenericProgress::EIdle;
			Complete(KErrNone);
			return ETrue;
			}
		default:
			{
			__ASSERT_DEBUG(EFalse, TImapServerPanic::ImapPanic(TImapServerPanic::ESyncServiceCompoundUnexpectedState));
			// unexpected state - complete the request
			iSyncProgressState=TImap4SyncProgress::EIdle;
			iProgressState = TImap4GenericProgress::EIdle;
			return ETrue;
			}
		} // end of switch (iCurrentStep)

	if (!IsActive())
		{
		SetActive();
		}
	return EFalse;
	}
/**
Handles the compound operation state machine

@return ETrue if compound operation is completed, 
		EFalse otherwise (will be called again, unless active)
*/
TBool CImapCompoundDeleteFolder::DoRunLoopL()
	{
	SetCurrentStep();
	switch (iCurrentStep)
		{
		case ESelectSourceMailboxRW:  // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDeleteFolder1); // selecting folder
			// anything to do?
			if (iDeleteSel->Count() <= 0)
				{
				iNextStep = EFinished;
				return EFalse;
				}
				
			// suspend operation if stop for migrate has been requested
			if (iStopForMigrate)
				{
				__LOG_TEXT(iSession->LogId(), "CImapCompoundDeleteFolder::Stopped for migrate");
				iCurrentStep = ESuspendedForMigrate;
				iNextStep = ESelectSourceMailboxRW;
				Complete(KErrNone);
				return ETrue;
				}
			
			// Note that SelectSourceMailboxL() calls SetActive();	
			SelectSourceMailboxL();
			break;
			}

		case EDeleteAllMessages:  // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDeleteFolder2); // deleting all messages
			// mark all messages in the selected folder /deleted
			DeleteAllMessagesL(); // note this method calls SetActive();
			break;
			}
			
		case ECloseFolder:  // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDeleteFolder3); // closing the folder
			// closing the folder causes messages 
			// marked /Deleted to be expunged
			iSession->CloseL(iStatus);
			iNextStep=EDeleteFolder;
			SetActive();
			break;
			}
			
		case EDeleteFolder:  // asynchronous
			{
			MOBILITY_TEST_MTM_STATE(iImapSettings.ServiceId(), KMobilityTestMtmStateImapDeleteFolder4); // issued delete command
			iSession->DeleteL(iStatus, iFolder->FullFolderPathL());
			iNextStep=EDeleteLocalFolder;
			SetActive();
			break;
			}
		
		case EDeleteLocalFolder:  // synchronous
			{
			DeleteLocalFolderL();
			// No async request issued, loop.
			return EFalse;
			}
			
		case EFinished:  // finished
			{
			__LOG_TEXT(iSession->LogId(), "CImapCompoundDeleteFolder::Completing OK");
			iProgressState = TImap4GenericProgress::EIdle;
			Complete(KErrNone);
			return ETrue;
			}
			
		default:
			{
			__ASSERT_DEBUG(EFalse, TImapServerPanic::ImapPanic(TImapServerPanic::EDeleteFolderCompoundUnexpectedState));
			// unexpected state - complete the request
			iProgressState = TImap4GenericProgress::EIdle;
			return ETrue;
			}
		} // end switch (iCurrentStep)
	return EFalse;
	}
Beispiel #5
0
BOOL CElemCycle::bExecute(CElemInt8 *pCmdRun,CElemInt8 *pCmdStopEndCycle,CElemInt8 *pCmdPause,CElemInt16 *pCmdJumpStep,CElemInt16 *pStatusRealTime,CElemInt16 *pTimeCycle,CEnumInterface &EnumInterface, CStream* argpStream, CElemInt8* argNumCurrentStream)
{
	BOOL bReturn = TRUE;
	CElemCycleStep *pStep = NULL;
	int i;
	int iSize;
		
	iSize = iGetCount();
	pTimeCycle->bSetVal((short)0);
	CElemCycle::m_CurrentStep.m_Step.bSetVal(0);
	CElemCycle::m_CurrentStep.SetLabel(_T(" "));

	for (i = 0;(pCmdRun->ucGetVal() != 0) && bReturn && (i < iSize) && (m_Duration.nGetVal()/**60*/ > pTimeCycle->nGetVal());i++)
	{
		//Entre qu'en cas de saut de pas
		if (pStep = (CElemCycleStep *)pGetAt(i)) 
		{
			if (pCmdJumpStep->nGetVal() > pStep->m_Step.nGetVal())
			{
				// recherche du pas le plus près inférieur
				for (i; (pCmdRun->ucGetVal() != 0) && bReturn && (i < iSize);i++)
				{
					if (pStep = (CElemCycleStep *)pGetAt(i))
					{
						pTimeCycle->bSetVal(pStep->m_Step.nGetVal());
						if (pCmdJumpStep->nGetVal() <= pStep->m_Step.nGetVal())
						{
							SetCurrentStep(pStep);
							break;
						}
						else pStep = NULL;
					}
				}
				// Arret de tous les organes
				if (!m_ElemCycleStepStop.bExecute(pCmdRun,pStatusRealTime,pTimeCycle,EnumInterface))
				{
					TRACE_DEBUG(eDebug,eCycle,_T(__FILE__),_T(__FUNCTION__),__LINE__,_T("Error: m_ElemCycleStepStop"));
					bReturn = FALSE;
				}
			}
		}
		if (pStep)
		{
			if (bWaitForNextStep(pStep->m_Step.nGetVal(), pCmdRun,pCmdPause,pCmdJumpStep,pTimeCycle)) 
			{
				SetCurrentStep(pStep);
				bReturn = pStep->bExecute(pCmdRun,pStatusRealTime,pTimeCycle,EnumInterface);

				//Log en cas d'erreur sur un programme de la carte mesure
				for(int j=0; j<argpStream->iGetNbrMesure(); j++)
				{
					if(argpStream->pGetAt(j)->m_StatusFailure.ucGetVal() != 0)
					{
						TRACE_LOG_ERROR_PRG(argpStream, argNumCurrentStream, j, CElemCycle::m_CurrentStep.m_Step.nGetVal());
						argpStream->m_StatusFailure.bSetVal(1);	
						argpStream->pGetAt(j)->m_StatusFailure.bSetVal(0);
					}
				}
			}
		}
	}

	//Si le cmdRun est a 0 c'est qu'une fin de cycle IMMEDIATE a été demandé : executer le pas stop
 	if(!pCmdRun->ucGetVal())
	{
		//Ce pas ne peut être arrêté
		CElemInt8 m_CmdRunStopStep;
		m_CmdRunStopStep.bSetVal((BYTE)1);
		m_ElemCycleStepStop.bExecute(&m_CmdRunStopStep,pStatusRealTime,pTimeCycle,EnumInterface);
	}

	// attente durée max du cycle
	bWaitForNextTime(m_Duration.nGetVal(), pCmdRun,pCmdPause,pCmdJumpStep,pTimeCycle);
	
	//Aprés attante si il y a une arrêt fiin de cycle, on éxecute la pas stop
	if(pCmdStopEndCycle->ucGetVal())
	{
		//Ce pas ne peut être arrêté
		CElemInt8 m_CmdRunStopStep;
		m_CmdRunStopStep.bSetVal((BYTE)1);
		m_ElemCycleStepStop.bExecute(&m_CmdRunStopStep,pStatusRealTime,pTimeCycle,EnumInterface);
	}

	if (!bReturn)
	{
		TRACE_DEBUG(eDebug,eCycle,_T(__FILE__),_T(__FUNCTION__),__LINE__,_T("Error: %s"),szGetLabel());
		TRACE_DEBUG_IHM(eError,eCycle,eErrorCycleExecute);
	}
	return bReturn;
}