|
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 |
|
119 // mobility API from MImMobileServer |
|
120 void PrepareForNewCarrier(TImMobilityAction aAction, TBool aIsSeamless); |
|
121 void CarrierLost(); |
|
122 void NewCarrierActive(TAccessPointInfo aNewAp, TBool aIsSeamless); |
|
123 void MobilityError(TUint aError); |
|
124 const TDesC8& MobilityProgress(); |
|
125 |
|
126 |
|
127 private: |
|
128 CImapProtocolController(CMsvServerEntry& aEntry,CImapOfflineControl& aImapOfflineControl); |
|
129 |
|
130 void ConstructL(); |
|
131 // from CMsgActive |
|
132 virtual void DoRunL(); |
|
133 void DoComplete(TInt& aErr); |
|
134 virtual void DoCancel(); |
|
135 void DoCancelClientOp(); |
|
136 |
|
137 void DoDisconnectL(TRequestStatus& aStatus); |
|
138 void DropSession(TInt aSessionId); |
|
139 void DisconnectAll(); |
|
140 TBool CompleteIfBackgroundOpInProgress(TRequestStatus& aStatus); |
|
141 TBool SelectSessionL(TInt& aIndexToUse); |
|
142 void StartPrimaryOperation(); |
|
143 void StartIdle(); |
|
144 |
|
145 void MarkOnOrOfflineL(const TBool aOnline); |
|
146 void ChangeVisibilityL(TMsvId aParent, TBool aInvisible); |
|
147 void ChangeVisibilityL(TMsvId aParent, TBool aInvisible, TBool aRecurse, TUid aType); |
|
148 void PropagateInvisibleFlagL(TMsvId aId); |
|
149 void PropagateUnsubscribeL(const TMsvId aFolder); |
|
150 |
|
151 TBool IdIsLocalL(TMsvId aId); |
|
152 TMsvId ServiceOfL(TMsvId aId); |
|
153 |
|
154 TBool ProcessError(TInt aError); |
|
155 void ThranslateSessionError(TInt& errCode); |
|
156 void ResetProgress(); |
|
157 |
|
158 // Migration methods |
|
159 void DoMigrateRunL(); |
|
160 void CompleteCurrentForMigrate(); |
|
161 void StopCurrentForMigrate(); |
|
162 void CancelForMigrate(); |
|
163 void DoCancelForMigrate(); |
|
164 void ProcessOpCompleteForMigrate(); |
|
165 void DisconnectForMigrateL(); |
|
166 void NewPrimarySessionL(); |
|
167 void RestartAfterMigrateL(); |
|
168 |
|
169 private: |
|
170 |
|
171 enum TImapProtocolOp |
|
172 { |
|
173 /** Idle. The default connected state. */ |
|
174 EIdle, |
|
175 /** Connect operation. */ |
|
176 EConnect, |
|
177 /** Disconnect operation. */ |
|
178 EDisconnect, |
|
179 /** Sync operation. */ |
|
180 ESync, |
|
181 /** Select operation. */ |
|
182 ESelect, |
|
183 /** Copy messages to local operation. */ |
|
184 ECopyToLocal, |
|
185 /** Copy messages within remote server operation. */ |
|
186 ECopyWithinService, |
|
187 /** Copy messages from local operation. */ |
|
188 ECopyFromLocal, |
|
189 /** Move messages to local operation. */ |
|
190 EMoveToLocal, |
|
191 /** Move messages within remote server operation. */ |
|
192 EMoveWithinService, |
|
193 /** Move messages from local operation. */ |
|
194 EMoveFromLocal, |
|
195 /** Message population operation. */ |
|
196 EPopulate, |
|
197 /** Delete operation. (messages) */ |
|
198 EDelete, |
|
199 /** Delete operation. (folders) */ |
|
200 EDeleteFolder, |
|
201 /** Create operation. (folders) */ |
|
202 ECreate, |
|
203 /** Rename operation. (folders) */ |
|
204 ERename, |
|
205 /** Stop idle operation. */ |
|
206 EStopIdle, |
|
207 /** Connect a secondary session. */ |
|
208 EConnectSecondary, |
|
209 /** Recovering primary session following a cancel. */ |
|
210 ECancelRecoverPrimary, |
|
211 /** Update read/unread message flags */ |
|
212 EUpdateFlag, |
|
213 }; |
|
214 |
|
215 // protocol controller migration states |
|
216 enum TImapPcMigrateState |
|
217 { |
|
218 ENotMigrating, // normal state |
|
219 ESuspendingForMigrate, // intermediate state |
|
220 EWaitingForOpToComplete, // async wait on compound op/bground op/idle controller |
|
221 EWaitingForOpToStop, // async wait on compound op/bground op/idle controller |
|
222 EDisconnectingForMigrate, // async wait on compound op |
|
223 EWaitingForNewCarrier, // async wait state on mobility engine |
|
224 EStartingReconnect, // intermediate state |
|
225 EConnectingAfterMigrate, // async wait on session manager |
|
226 EWaitingInitialCarrierRejected, // async wait state on mobility engine |
|
227 EHandlingConnectError // Handling Initial connect error |
|
228 }; |
|
229 |
|
230 CMsvServerEntry& iEntry; |
|
231 |
|
232 // objects the Protocol Controller owns |
|
233 CImapSettings* iImapSettings; |
|
234 CImapMailStore* iImapMailStore; |
|
235 CImapSessionManager* iImapSessionManager; |
|
236 RImapSessionArray iImapSessionArray; |
|
237 CImapCompoundBase* iImapCompound; |
|
238 CImapCompoundBase* iMigrateCompound; |
|
239 |
|
240 // CImapOfflineControl object is owned by the CImap4ServerMtm |
|
241 CImapOfflineControl& iImapOfflineControl; |
|
242 CImapSyncManager* iImapSyncManager; |
|
243 CImapOpBackgroundSync* iBackgroundSyncOp; |
|
244 CImapIdleController* iImapIdleController; |
|
245 CImMobilityManager* iMobilityManager; |
|
246 |
|
247 // Service ID |
|
248 TMsvId iServiceId; |
|
249 |
|
250 // Progress |
|
251 TImap4CompoundProgress iProgress; |
|
252 |
|
253 // Current operational state |
|
254 // Requested and current foreground operation |
|
255 TImapProtocolOp iRequestedOp; |
|
256 TImapProtocolOp iCurrentOp; |
|
257 TInt iForegroundSession; |
|
258 |
|
259 TBool iWaitForBackgroundSync; |
|
260 TBool iFlushPrimary; |
|
261 TBool iCancelInProgress; |
|
262 TImapPcMigrateState iMigrateState; |
|
263 TImap4ProgressBuf iProgressBuffer; |
|
264 }; |
|
265 |
|
266 #endif //__CIMAPPROTOCOLCONTROLLER_H__ |