|
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 __CIMAPPROTOCOLCONTROLLER_H__ |
|
17 #define __CIMAPPROTOCOLCONTROLLER_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <imapset.h> |
|
21 #include <msvstd.h> |
|
22 |
|
23 #include "cimapidlecontroller.h" |
|
24 #include "mimapopbackgroundsyncobserver.h" |
|
25 #include "mimmobileserver.h" |
|
26 #include "cimmobilitymanager.h" |
|
27 |
|
28 /** |
|
29 package buffer for progress info. |
|
30 @internalComponent |
|
31 @prototype |
|
32 */ |
|
33 typedef TPckgBuf<TImap4CompoundProgress> TImap4ProgressBuf; |
|
34 |
|
35 // Forward Declarations |
|
36 class CImapCompoundBase; |
|
37 class CImapSessionManager; |
|
38 class CImapSession; |
|
39 class CImapSettings; |
|
40 class CImapMailStore; |
|
41 class CImapSyncManager; |
|
42 class CMsgActive; |
|
43 class TImImap4GetPartialMailInfo; |
|
44 class CImapOpBackgroundSync; |
|
45 class CImapOfflineControl; |
|
46 |
|
47 /** |
|
48 Provides an API for connecting/disconnecting to a remote IMAP server and for |
|
49 connected IMAP operations. |
|
50 Manages background online activities: synchronisation after connection |
|
51 and the usage of IMAP idle between requested operations. |
|
52 Uses instance of class CImapSyncManager to manage synchronisation of folders |
|
53 on the remote IMAP server and the headers contained within subscribed folders. |
|
54 Uses instances of CImapCompoundBase derived classes to perform requested |
|
55 operations. |
|
56 @internalTechnology |
|
57 @prototype |
|
58 */ |
|
59 class CImapProtocolController : public CMsgActive, |
|
60 public MImapOpBackgroundSyncObserver, |
|
61 public MImapIdleControllerObserver, |
|
62 public MImMobileServer |
|
63 { |
|
64 public: |
|
65 |
|
66 typedef RPointerArray<CImapSession> RImapSessionArray; |
|
67 |
|
68 virtual ~CImapProtocolController(); |
|
69 IMPORT_C static CImapProtocolController* NewL(CMsvServerEntry& aEntry,CImapOfflineControl& aImapOfflineControl); |
|
70 |
|
71 // Connection APIs |
|
72 IMPORT_C TBool Connected() const; |
|
73 IMPORT_C void ConnectL( TRequestStatus& aStatus, |
|
74 CMsvEntrySelection& aSelection ); |
|
75 IMPORT_C void ConnectAndSynchroniseL( TRequestStatus& aStatus, |
|
76 CMsvEntrySelection& aSelection ); |
|
77 |
|
78 IMPORT_C void DisconnectL(TRequestStatus& aStatus); |
|
79 IMPORT_C TBool Busy() const; |
|
80 IMPORT_C TInt GetAccessPointIdForConnection(TUint32& aAccessPointId) const; |
|
81 |
|
82 // Account Synchronisation APIs |
|
83 IMPORT_C TBool BackgroundSyncInProgress() const; |
|
84 IMPORT_C void CancelBackgroundSync(TRequestStatus& aStatus); |
|
85 IMPORT_C void WaitForBackground(TRequestStatus& aStatus); |
|
86 IMPORT_C void SynchroniseTreeL(TRequestStatus& aStatus); |
|
87 IMPORT_C void SynchroniseAllL(TRequestStatus& aStatus); |
|
88 |
|
89 // from MImapOpBackgroundSyncObserver |
|
90 void BackgroundSyncComplete(TInt aError); |
|
91 |
|
92 // from MImapIdleControllerObserver |
|
93 void OnIdleError(TInt aError); |
|
94 |
|
95 // Message/Folder APIs |
|
96 IMPORT_C void CopyToLocalL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, const TMsvId aDestination); |
|
97 IMPORT_C void PopulateL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, TImImap4GetPartialMailInfo aGetPartialMailInfo); |
|
98 IMPORT_C void MoveToLocalL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, const TMsvId aDestination); |
|
99 IMPORT_C void CopyWithinServiceL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, const TMsvId aDestination); |
|
100 IMPORT_C void MoveWithinServiceL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, const TMsvId aDestination); |
|
101 IMPORT_C void CopyFromLocalL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, const TMsvId aDestination); |
|
102 IMPORT_C void MoveFromLocalL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel, const TMsvId aDestination); |
|
103 IMPORT_C void DeleteL(TRequestStatus& aStatus, const CMsvEntrySelection& aSourceSel); |
|
104 IMPORT_C void DeleteFolderL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection); |
|
105 IMPORT_C void NewOnlySyncFolderL(TRequestStatus& aStatus); |
|
106 IMPORT_C void FullSyncFolderL(TRequestStatus& aStatus, const TMsvId aFolder); |
|
107 IMPORT_C void SelectL(TRequestStatus& aStatus, const TMsvId aFolder); |
|
108 IMPORT_C void FullSyncSelectedFolderL(TRequestStatus& aStatus); |
|
109 IMPORT_C void CreateL(TRequestStatus& aStatus, const TMsvId aParent, const TDesC& aLeafName, const TBool aFolder ); |
|
110 IMPORT_C void RenameL(TRequestStatus& aStatus, const TMsvId aTarget, const TDesC& aNewName); |
|
111 |
|
112 IMPORT_C TInt SetLocalSubscription(const TMsvId aFolder, TBool aSubscribed); |
|
113 |
|
114 // Progress and Cancel APIs |
|
115 IMPORT_C TImap4CompoundProgress Progress(); |
|
116 IMPORT_C void CancelAndCleanup(); |
|
117 IMPORT_C void UpdateFlagL(TRequestStatus& aStatus); |
|
118 IMPORT_C void UpdateEntriesFlagL(TRequestStatus& aStatus,const CMsvEntrySelection& aSourceSel, TBool aFlagChanged); |
|
119 |
|
120 // mobility API from MImMobileServer |
|
121 void PrepareForNewCarrier(TImMobilityAction aAction, TBool aIsSeamless); |
|
122 void CarrierLost(); |
|
123 void NewCarrierActive(TAccessPointInfo aNewAp, TBool aIsSeamless); |
|
124 void MobilityError(TUint aError); |
|
125 const TDesC8& MobilityProgress(); |
|
126 |
|
127 |
|
128 private: |
|
129 CImapProtocolController(CMsvServerEntry& aEntry,CImapOfflineControl& aImapOfflineControl); |
|
130 |
|
131 void ConstructL(); |
|
132 // from CMsgActive |
|
133 virtual void DoRunL(); |
|
134 void DoComplete(TInt& aErr); |
|
135 virtual void DoCancel(); |
|
136 void DoCancelClientOp(); |
|
137 |
|
138 void DoDisconnectL(TRequestStatus& aStatus); |
|
139 void DropSession(TInt aSessionId); |
|
140 void DisconnectAll(); |
|
141 TBool CompleteIfBackgroundOpInProgress(TRequestStatus& aStatus); |
|
142 TBool SelectSessionL(TInt& aIndexToUse); |
|
143 void StartPrimaryOperation(); |
|
144 void StartIdle(); |
|
145 |
|
146 void MarkOnOrOfflineL(const TBool aOnline); |
|
147 void ChangeVisibilityL(TMsvId aParent, TBool aInvisible); |
|
148 void ChangeVisibilityL(TMsvId aParent, TBool aInvisible, TBool aRecurse, TUid aType); |
|
149 void PropagateInvisibleFlagL(TMsvId aId); |
|
150 void PropagateUnsubscribeL(const TMsvId aFolder); |
|
151 |
|
152 TBool IdIsLocalL(TMsvId aId); |
|
153 TMsvId ServiceOfL(TMsvId aId); |
|
154 |
|
155 TBool ProcessError(TInt aError); |
|
156 void ThranslateSessionError(TInt& errCode); |
|
157 void ResetProgress(); |
|
158 |
|
159 // Migration methods |
|
160 void DoMigrateRunL(); |
|
161 void CompleteCurrentForMigrate(); |
|
162 void StopCurrentForMigrate(); |
|
163 void CancelForMigrate(); |
|
164 void DoCancelForMigrate(); |
|
165 void ProcessOpCompleteForMigrate(); |
|
166 void DisconnectForMigrateL(); |
|
167 void NewPrimarySessionL(); |
|
168 void RestartAfterMigrateL(); |
|
169 |
|
170 private: |
|
171 |
|
172 enum TImapProtocolOp |
|
173 { |
|
174 /** Idle. The default connected state. */ |
|
175 EIdle, |
|
176 /** Connect operation. */ |
|
177 EConnect, |
|
178 /** Disconnect operation. */ |
|
179 EDisconnect, |
|
180 /** Sync operation. */ |
|
181 ESync, |
|
182 /** Select operation. */ |
|
183 ESelect, |
|
184 /** Copy messages to local operation. */ |
|
185 ECopyToLocal, |
|
186 /** Copy messages within remote server operation. */ |
|
187 ECopyWithinService, |
|
188 /** Copy messages from local operation. */ |
|
189 ECopyFromLocal, |
|
190 /** Move messages to local operation. */ |
|
191 EMoveToLocal, |
|
192 /** Move messages within remote server operation. */ |
|
193 EMoveWithinService, |
|
194 /** Move messages from local operation. */ |
|
195 EMoveFromLocal, |
|
196 /** Message population operation. */ |
|
197 EPopulate, |
|
198 /** Delete operation. (messages) */ |
|
199 EDelete, |
|
200 /** Delete operation. (folders) */ |
|
201 EDeleteFolder, |
|
202 /** Create operation. (folders) */ |
|
203 ECreate, |
|
204 /** Rename operation. (folders) */ |
|
205 ERename, |
|
206 /** Stop idle operation. */ |
|
207 EStopIdle, |
|
208 /** Connect a secondary session. */ |
|
209 EConnectSecondary, |
|
210 /** Recovering primary session following a cancel. */ |
|
211 ECancelRecoverPrimary, |
|
212 /** Update read/unread message flags */ |
|
213 EUpdateFlag, |
|
214 }; |
|
215 |
|
216 // protocol controller migration states |
|
217 enum TImapPcMigrateState |
|
218 { |
|
219 ENotMigrating, // normal state |
|
220 ESuspendingForMigrate, // intermediate state |
|
221 EWaitingForOpToComplete, // async wait on compound op/bground op/idle controller |
|
222 EWaitingForOpToStop, // async wait on compound op/bground op/idle controller |
|
223 EDisconnectingForMigrate, // async wait on compound op |
|
224 EWaitingForNewCarrier, // async wait state on mobility engine |
|
225 EStartingReconnect, // intermediate state |
|
226 EConnectingAfterMigrate, // async wait on session manager |
|
227 EWaitingInitialCarrierRejected, // async wait state on mobility engine |
|
228 EHandlingConnectError // Handling Initial connect error |
|
229 }; |
|
230 |
|
231 CMsvServerEntry& iEntry; |
|
232 |
|
233 // objects the Protocol Controller owns |
|
234 CImapSettings* iImapSettings; |
|
235 CImapMailStore* iImapMailStore; |
|
236 CImapSessionManager* iImapSessionManager; |
|
237 RImapSessionArray iImapSessionArray; |
|
238 CImapCompoundBase* iImapCompound; |
|
239 CImapCompoundBase* iMigrateCompound; |
|
240 |
|
241 // CImapOfflineControl object is owned by the CImap4ServerMtm |
|
242 CImapOfflineControl& iImapOfflineControl; |
|
243 CImapSyncManager* iImapSyncManager; |
|
244 CImapOpBackgroundSync* iBackgroundSyncOp; |
|
245 CImapIdleController* iImapIdleController; |
|
246 CImMobilityManager* iMobilityManager; |
|
247 |
|
248 // Service ID |
|
249 TMsvId iServiceId; |
|
250 |
|
251 // Progress |
|
252 TImap4CompoundProgress iProgress; |
|
253 |
|
254 // Current operational state |
|
255 // Requested and current foreground operation |
|
256 TImapProtocolOp iRequestedOp; |
|
257 TImapProtocolOp iCurrentOp; |
|
258 TInt iForegroundSession; |
|
259 |
|
260 TBool iWaitForBackgroundSync; |
|
261 TBool iFlushPrimary; |
|
262 TBool iCancelInProgress; |
|
263 TImapPcMigrateState iMigrateState; |
|
264 TImap4ProgressBuf iProgressBuffer; |
|
265 }; |
|
266 |
|
267 #endif //__CIMAPPROTOCOLCONTROLLER_H__ |