email/imap4mtm/imapprotocolcontroller/inc/cimapidlecontroller.h
changeset 31 ebfee66fde93
parent 0 72b543305e3a
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CIMAPIDLECONTROLLER_H__
       
    17 #define __CIMAPIDLECONTROLLER_H__
       
    18 
       
    19 #include <mentact.h>
       
    20 #include <msvstd.h>
       
    21 #include <imapset.h>
       
    22 #include "cimapobservabletimer.h"
       
    23 
       
    24 
       
    25 class CImapSyncManager;
       
    26 class CImapFolder;
       
    27 class CImapSettings;
       
    28 class CMsvServerEntry;
       
    29 class CImapSession;
       
    30 class CImapCompoundCopyToLocal;
       
    31 class CImapMailStore;
       
    32 
       
    33 /**
       
    34 Implemented by anything that wants to use a CImapIdleController.
       
    35 Provides an interface that can be called if an unexpected error
       
    36 occurs while in IDLE.
       
    37 
       
    38 @internalTechnology
       
    39 @prototype
       
    40 */
       
    41 class MImapIdleControllerObserver
       
    42 	{
       
    43 public:
       
    44 	virtual void OnIdleError(TInt aError) = 0;
       
    45 	};
       
    46 
       
    47 
       
    48 /**
       
    49 Provides management of IMAP IDLE as a background task.
       
    50 The Protocol Controller is free to complete a client requested operation
       
    51 immediately after calling StartIdle().
       
    52 
       
    53 @internalTechnology
       
    54 @prototype
       
    55 */
       
    56 class CImapIdleController : public CActive, public MImapTimerObserver
       
    57 	{
       
    58 public:
       
    59 	~CImapIdleController();
       
    60 	
       
    61 	static CImapIdleController* NewL(MImapIdleControllerObserver& aObserver, CImapSession*& aSession, CImapSyncManager& aSyncManager, CMsvServerEntry& aServerEntry, CImapSettings& aImapSettings, CImapMailStore& aImapMailStore);
       
    62 
       
    63 	void StartIdle();
       
    64 	void StopIdle(TRequestStatus& aStatus);
       
    65 	
       
    66 	void Progress(TImap4CompoundProgress& aCompoundProgress);
       
    67 
       
    68 private:
       
    69 	enum TIdleControllerState
       
    70 		{
       
    71 		EFinished,					// 00 No Command Issued,     NOT active in this state
       
    72 		EStartingIdle,				// 01 StartIdle() requested, Active in this state
       
    73 		ESelectingInbox,			// 02 SELECT command issued. Active in this state
       
    74 		EWaitingForContinuation,	// 03 IDLE command issued.   Active in this state
       
    75 		EIdling,					// 04 wait-for-event issued  Active in this state
       
    76 		EWaitingForDone,			// 05 DONE command issued    Active in this state
       
    77 		EWaitingForServerEvent,		// 06 Dummy read issued	  Active in this state 
       
    78 		EWaitingForFlush,			// 07 read cancelled and flushed Active in this state
       
    79 		ESynchronising,			    // 08 CImapFolder::Synchronise issued Active in this state.
       
    80 		ESyncFetching				// 09 CImapCompoundCopyToLocal Active in this state...
       
    81 		};
       
    82 
       
    83 	CImapIdleController(MImapIdleControllerObserver& aObserver, CImapSession*& aSession, CImapSyncManager& aSyncManager, CMsvServerEntry& aServerEntry, CImapSettings& aImapSettings, CImapMailStore& aImapMailStore);
       
    84 	void ConstructL();
       
    85 
       
    86 	void RunContinueL();
       
    87 	void RunStopL();
       
    88 	void GoIdleL();
       
    89 	TBool DoBodyDownloadL();
       
    90 	TBool SyncRequired();
       
    91 
       
    92 	// From CActive
       
    93 	virtual void RunL();
       
    94 	
       
    95 	// mimic CMsgActive	
       
    96 	void Queue(TRequestStatus& aStatus);
       
    97 	virtual void DoRunL();
       
    98 	virtual void DoCancel();
       
    99 	virtual void Complete(TInt aErr);
       
   100 	virtual void DoComplete(TInt& aErr);
       
   101 	
       
   102 	// From MImapTimerObserver
       
   103 	virtual void OnTimerL(const CImapObservableTimer& aSourceTimer);
       
   104 
       
   105 	void EnterIdlingState();
       
   106 	void InternalCancelAndSetState(TIdleControllerState aNextState);
       
   107 
       
   108 private:
       
   109 	MImapIdleControllerObserver& iObserver;
       
   110 	CImapSession*& iSession;
       
   111 	CImapSyncManager& iSyncManager;
       
   112 	CMsvServerEntry& iServerEntry;
       
   113 	CImapSettings& iImapSettings;
       
   114 	CImapMailStore& iImapMailStore;
       
   115 	CImapCompoundCopyToLocal* iCopyToLocal;
       
   116 	
       
   117 	// report request status
       
   118 	TRequestStatus* iReport;
       
   119 	
       
   120 	// State Information
       
   121 	TBool iUsingIdle;
       
   122 	TIdleControllerState iState;
       
   123 	TBool iStoppingIdle;
       
   124 	TBool iInternalCancel;
       
   125 
       
   126 	CImapObservableTimer* iReissueTimer;
       
   127 	};
       
   128 
       
   129 #endif	// __CIMAPIDLECONTROLLER_H__