|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Email agent base class. common functions and data |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __ALWAYSONLINEEMAILAGENTBASE_H__ |
|
21 #define __ALWAYSONLINEEMAILAGENTBASE_H__ |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <msvapi.h> |
|
25 #include <MuiuMsvSingleOpWatcher.h> |
|
26 #include <miutset.h> |
|
27 #include <AlwaysOnlineManagerCommon.h> |
|
28 #include <MNcnInternalNotification.h> |
|
29 #include <muiuflagger.h> |
|
30 #include <cmconnectionmethod.h> |
|
31 #include <cmmanager.h> |
|
32 |
|
33 #include "AlwaysOnlineEmailLoggingTools.h" |
|
34 const TInt KAOMaxRetries = 3; |
|
35 |
|
36 const TInt KAOMaxRetriesSwitchOff = 5*KAOMaxRetries; |
|
37 |
|
38 const TInt KAOUsernameLength = 50; |
|
39 |
|
40 //reconnect intervals in seconds |
|
41 enum TAgentReconnectIntervals |
|
42 { |
|
43 EEMailAgentReconnectOne = 10, //10 seconds |
|
44 EEMailAgentReconnectTwo = 20, //20 |
|
45 EEMailAgentReconnectThree = 30, //30 |
|
46 EEMailAgentReconnectFour = 40, //40 secs |
|
47 EEMailAgentReconnectFive = 60, //one minute |
|
48 EEMailAgentReconnectSix = 300 //five minutes |
|
49 }; |
|
50 |
|
51 enum TAgentScheduleWaitStates |
|
52 { |
|
53 EWaitForStop = 0, |
|
54 EWaitForStart |
|
55 }; |
|
56 |
|
57 enum TAlwaysOnlineEmailIAPNotes |
|
58 { |
|
59 EEmailAgentCSDIAP, |
|
60 EEmailAgentInvalidInterval, |
|
61 EEmailAgentOutOfDisk, |
|
62 EEmailAgentEMNFatalError, |
|
63 EEmailAgentOtherInvalidity |
|
64 }; |
|
65 |
|
66 enum TMailSettingType |
|
67 { |
|
68 EMailboxSettings = 0, |
|
69 EAlwaysonlineSettings |
|
70 }; |
|
71 |
|
72 // Always Online features |
|
73 enum TAlwaysOnlineLocalFeatures |
|
74 { |
|
75 // KEmailFeatureIdAlwaysOnlineCSD |
|
76 EAOLFAlwaysOnlineCSD = 0, |
|
77 // KEmailFeatureIdEmailVPNAllowed |
|
78 EAOLFAlwaysOnlineVPN |
|
79 }; |
|
80 |
|
81 |
|
82 // Always Online flags |
|
83 enum TAlwaysOnlineBaseFlags |
|
84 { |
|
85 // Flag to indicate when the connection should be made |
|
86 EAOBFConnectNow = 0, |
|
87 // Flag to indicate the protocol of the current mailbox |
|
88 EAOBFIsImap4, |
|
89 // Last Base Flag |
|
90 EAOBFLastFlag |
|
91 }; |
|
92 |
|
93 const TInt KInitWaitSeconds = 5; |
|
94 const TInt KErrAoServerNotFound = -5120; |
|
95 |
|
96 //constants |
|
97 class CClientMtmRegistry; |
|
98 class CMsvSession; |
|
99 class MAlwaysOnlineStatusQueryInterface; |
|
100 class CAlwaysOnlineEmailAgent; |
|
101 class CImumInternalApi; |
|
102 class CImumInSettingsData; |
|
103 |
|
104 /** |
|
105 * CAlwaysOnlineEmailAgentBase |
|
106 * |
|
107 * Base class for IMAP and POP mailbox agents. |
|
108 * Agents contain the logic to keep mailboxes up to date. |
|
109 * One agent per mailbox. |
|
110 */ |
|
111 class CAlwaysOnlineEmailAgentBase : public CBase, public MMsvSingleOpWatcher |
|
112 { |
|
113 public: |
|
114 |
|
115 /** |
|
116 * ~CAlwaysOnlineEmailAgentBase |
|
117 * Destructor |
|
118 */ |
|
119 virtual ~CAlwaysOnlineEmailAgentBase(); |
|
120 |
|
121 /** |
|
122 * StartL |
|
123 */ |
|
124 virtual void StartL() = 0; |
|
125 |
|
126 /** |
|
127 * ConnectL |
|
128 * Calls ConnectAndUpdateHeadersL if mailbox not connected, if already connected then calls UpdateHeadersWhenAlreadyConnectedL |
|
129 */ |
|
130 virtual void ConnectL(); |
|
131 |
|
132 /** |
|
133 * ConnectAndUpdateHeadersL |
|
134 * |
|
135 */ |
|
136 virtual void ConnectAndUpdateHeadersL( ) = 0; |
|
137 |
|
138 |
|
139 /** |
|
140 * DisconnectL |
|
141 * @param TBool, is disconnection automatic or user initiated. |
|
142 */ |
|
143 virtual void DisconnectL( TBool aAutomatic ) = 0; |
|
144 |
|
145 /** |
|
146 * MailboxId |
|
147 * @return TMsvId, mailbox id |
|
148 */ |
|
149 TMsvId MailboxId() const; |
|
150 |
|
151 /** |
|
152 * Mailbox type |
|
153 * @since S60 v3.1 |
|
154 * @return TBool |
|
155 */ |
|
156 inline TBool IsImap4() const; |
|
157 |
|
158 /** |
|
159 * Gets email address |
|
160 * @param aEmailAddress will point to email address after function call |
|
161 * @since S60 v3.1 |
|
162 */ |
|
163 void EmailAddress( TDes& aEmailAddress ); |
|
164 |
|
165 /** |
|
166 * Gets username |
|
167 * @param aUsername will point to username after function call |
|
168 * @since S60 v3.1 |
|
169 */ |
|
170 void Username( TDes8& aUsername ); |
|
171 |
|
172 /** |
|
173 * Gets incoming server |
|
174 * @param aServer will point to incoming server after function call |
|
175 * @since S60 v3.1 |
|
176 */ |
|
177 void ServerAddress( TDes& aServer ); |
|
178 |
|
179 /** |
|
180 * Loads a value of single setting |
|
181 * |
|
182 * @since S60 v3.2 |
|
183 * @param |
|
184 * @leave Any Imum Internal API leave code |
|
185 */ |
|
186 template<class T> |
|
187 inline T LoadSettingL( |
|
188 const TUint aKey, |
|
189 const TBool aConnectionSetting ) const; |
|
190 |
|
191 |
|
192 /** |
|
193 * Is mail agent EMN or not? |
|
194 * @since S60 v3.1 |
|
195 * @return TBool if EMN is in automatic or in home network only states. |
|
196 */ |
|
197 inline TBool IsEmn() const; |
|
198 |
|
199 /** |
|
200 * Suspend |
|
201 * Called when plugin receives offline event ( network operations not allowed ) |
|
202 */ |
|
203 virtual void Suspend(); |
|
204 |
|
205 /** |
|
206 * ResumeL |
|
207 * Called when plugin receives offline event ( network operations allowed ) |
|
208 * @since Series60 2.6 |
|
209 * @param aConnectNow When true, connection is started to mailbox |
|
210 */ |
|
211 virtual void ResumeL( const TBool aConnectNow = EFalse ); |
|
212 |
|
213 /** |
|
214 * HandleHomeNetworkEventL |
|
215 * Called when plugin receives HomeNetwork event |
|
216 */ |
|
217 void HandleHomeNetworkEventL(); |
|
218 |
|
219 /** |
|
220 * HandleRoamingEventL |
|
221 * Called when plugin receives Roaming event |
|
222 */ |
|
223 void HandleRoamingEventL(); |
|
224 |
|
225 /** |
|
226 * HandleOutOfDiskEventL |
|
227 * Called when plugin receives out of disk event |
|
228 */ |
|
229 void HandleOutOfDiskEventL(); |
|
230 |
|
231 /** |
|
232 * SwitchOffL |
|
233 * Will switch off this mailagent |
|
234 */ |
|
235 void SwitchOffL(); |
|
236 |
|
237 public: |
|
238 /** |
|
239 * OpCompleted |
|
240 * From MMsvSingleOpWatcher |
|
241 * @param CMsvSingleOpWatcher&, opwathcer, which just completed |
|
242 * @param TInt, completion code |
|
243 */ |
|
244 virtual void OpCompleted( |
|
245 CMsvSingleOpWatcher& aOpWatcher, |
|
246 TInt aCompletionCode ); |
|
247 |
|
248 protected: |
|
249 |
|
250 /** |
|
251 * CAlwaysOnlineEmailAgentBase |
|
252 * C++ Constructor |
|
253 * @param CMsvSession&, session reference |
|
254 * @param CClientMtmRegistry&, mtm registry reference |
|
255 * @param TMsvId, mailbox id |
|
256 * @param MAlwaysOnlineStatusQueryInterface&, status query interface reference |
|
257 * @param CAlwaysOnlineEmailAgent&, email agent reference |
|
258 */ |
|
259 CAlwaysOnlineEmailAgentBase( CMsvSession& aSession, |
|
260 CClientMtmRegistry& aClientMtmRegistry, |
|
261 MAlwaysOnlineStatusQueryInterface& aAlwaysOnlineManager, |
|
262 CAlwaysOnlineEmailAgent& aEmailAgent ); |
|
263 |
|
264 /** |
|
265 * ConstructL |
|
266 * @param TMsvId, mailbox id |
|
267 */ |
|
268 void ConstructL( TMsvId aMailboxId ); |
|
269 |
|
270 /** |
|
271 * AppendWatcherAndSetOperationL |
|
272 * Appends aWatcher to iOperations array and sets watcher operation to aOperation. |
|
273 * NOTE: Takes ownership of aWatcher and aOperation so those MUST be removed from CleanupStack |
|
274 * immediately after this function call |
|
275 * @param CMsvSingleOpWatcher*, opwatcher to be appended |
|
276 * @param CMsvOperation*, operation to be wathced |
|
277 */ |
|
278 void AppendWatcherAndSetOperationL( |
|
279 CMsvSingleOpWatcher* aWatcher, CMsvOperation* aOperation ); |
|
280 |
|
281 /** |
|
282 * ChangeNextStateL |
|
283 * Called by OpCompleted, need to decide what to do next... |
|
284 * The core of our state machine |
|
285 */ |
|
286 virtual void ChangeNextStateL() = 0; |
|
287 |
|
288 /** |
|
289 * HandleOpErrorL |
|
290 * Called in ChangeNextStateL() if error is detected in OpCompleted() |
|
291 */ |
|
292 virtual void HandleOpErrorL() = 0; |
|
293 |
|
294 /** |
|
295 * StartTimerOperationL |
|
296 * @param TTime&, time reference |
|
297 * @param TMsvOp& reference of operation id which will be set in this function |
|
298 */ |
|
299 virtual void StartTimerOperationL( const TTime& aTime, TMsvOp& aOpId ); |
|
300 |
|
301 /** |
|
302 * DoSyncDisconnectL() |
|
303 * Does sync disconnect. Meant to be called from ResetAll(). |
|
304 * This is needed because this must not have imapact on state machine. |
|
305 */ |
|
306 virtual void DoSyncDisconnectL() = 0; |
|
307 |
|
308 /** |
|
309 * Is agent temporary? |
|
310 * @since S60 3.1 |
|
311 * @return ETrue, if temporary (default is ETrue ) |
|
312 */ |
|
313 virtual TBool IsTemporary() const; |
|
314 |
|
315 /** |
|
316 * CheckAndHandleSchedulingL |
|
317 * Checks schedules and starts timers accordingly |
|
318 */ |
|
319 void CheckAndHandleSchedulingL(); |
|
320 |
|
321 /** |
|
322 * ResetAll |
|
323 * Resets all operations and their saved IDs |
|
324 */ |
|
325 void ResetAll(); |
|
326 |
|
327 /** |
|
328 * StartScheduleWaiterL |
|
329 * Does the actual starting of timers and does the wait calculating |
|
330 * @param TBool, ETrue if we're waiting for stop ( chedule is ok ) |
|
331 */ |
|
332 void StartScheduleWaiterL( const TBool aShouldConnect ); |
|
333 |
|
334 /** |
|
335 * HandleOpCompleted |
|
336 * If completed operation requires special handling, it is taken care of in here |
|
337 * @param TMsvOp, id of the completed operation |
|
338 * @param TInt, completion code |
|
339 */ |
|
340 virtual void HandleOpCompleted( TMsvOp opId, TInt aCompletionCode ) = 0; |
|
341 |
|
342 /** |
|
343 * CreateCompletedOpL |
|
344 * Function to create a completed operation. Needed to switch state when no other operation needs to be created. |
|
345 */ |
|
346 virtual void CreateCompletedOpL() = 0; |
|
347 |
|
348 /** |
|
349 * SetLastSuccessfulUpdate |
|
350 * Function to set last successful update time. |
|
351 */ |
|
352 void SetLastSuccessfulUpdate(); |
|
353 |
|
354 /** |
|
355 * SetLastUpdateFailed |
|
356 * Function to set last update failed. |
|
357 */ |
|
358 void SetLastUpdateFailed(); |
|
359 |
|
360 /** |
|
361 * DisplayGlobalErrorNoteL |
|
362 * Shows global error note in case of an fatal error |
|
363 * @param TAlwaysOnlineEmailIAPNotes, id of fail type |
|
364 */ |
|
365 void DisplayGlobalErrorNoteL( |
|
366 TAlwaysOnlineEmailIAPNotes aInvalidity=EEmailAgentOtherInvalidity ); |
|
367 |
|
368 /** |
|
369 * IsBearerCSDL |
|
370 * Checks if our bearer is CSD or not |
|
371 * @return TBool, ETrue if bearer is circuit switched |
|
372 */ |
|
373 TBool IsBearerCSDL(); |
|
374 |
|
375 |
|
376 /** |
|
377 * Creates SingleOpWatcher operation and places it to cleanup stack |
|
378 */ |
|
379 CMsvSingleOpWatcher* CreateSingleOpWatcherLC(); |
|
380 |
|
381 /** |
|
382 * Handles default errors |
|
383 * @since S60 v3.0 |
|
384 */ |
|
385 |
|
386 void HandleDefaultError(); |
|
387 |
|
388 /** |
|
389 * Handles Email notification connection related errors |
|
390 * @since S60 v3.1 |
|
391 * @return TBool, ETrue if we should reconnect |
|
392 */ |
|
393 TBool IsReconnectAfterError(); |
|
394 |
|
395 |
|
396 /** |
|
397 * Converts TImumDaSettings::TAutoIntervalValues into minutes. |
|
398 * @since S60 3.2 |
|
399 * @param aIntervalIndex TAutoIntervalValues Interval |
|
400 * @return Interval in minutes |
|
401 */ |
|
402 TInt RetrievalIntervalInMinutes( TInt aIntervalIndex ); |
|
403 |
|
404 protected: |
|
405 |
|
406 |
|
407 /** |
|
408 * QueryAndHandleAOServerInfoL |
|
409 * Queries offline and roaming info from AO server |
|
410 * and takes action accordingly |
|
411 * @param TBool&, parameter is set in this function |
|
412 */ |
|
413 void QueryAndHandleAOServerInfoL( TBool& aSuspended ); |
|
414 |
|
415 /** |
|
416 * @since S60 v3.1 |
|
417 * @return ETrue if agent has home network only selected |
|
418 */ |
|
419 TBool CheckIfAgentHomeOnly(); |
|
420 |
|
421 /** |
|
422 * SwitchAutoUpdateOffL() |
|
423 **/ |
|
424 void SwitchAutoUpdateOffL(); |
|
425 |
|
426 /** |
|
427 * IsIAPInvalidL |
|
428 * Checks accesspoint settings. Password prompt and IAP type and other validity |
|
429 * @param TAlwaysOnlineEmailIAPNotes&, id of invalidity. Set in this function |
|
430 * @return TBool, ETrue if AP is invalid |
|
431 */ |
|
432 TBool IsIAPInvalidL( TAlwaysOnlineEmailIAPNotes& aInvalidity ); |
|
433 |
|
434 /** |
|
435 * GetConnectionMethodLC |
|
436 * Leaves the Connection Method into cleanupstack if found |
|
437 * @return RCmConnectionMethod The used connection method |
|
438 * @leave System wide leave codes |
|
439 */ |
|
440 RCmConnectionMethod GetConnectionMethodLC(); |
|
441 |
|
442 /** |
|
443 * RemoveMe |
|
444 * Tells email agent to remove this plugin |
|
445 */ |
|
446 void RemoveMe(); |
|
447 |
|
448 /** |
|
449 * Make an connection check and determine scheduling |
|
450 * @since Series60 2.6 |
|
451 * @param aOperation, Operation that must exist |
|
452 */ |
|
453 void ConnectIfAllowedL( const TMsvOp& aOperation ); |
|
454 |
|
455 /** |
|
456 * Tell to Ncn that there might be new messages to show |
|
457 * @since Series60 3.0 |
|
458 */ |
|
459 void CallNewMessagesL(); |
|
460 |
|
461 /** |
|
462 * |
|
463 * @since Series60 3.0 |
|
464 */ |
|
465 void CleanOperation( TMsvOp& aOpId ); |
|
466 |
|
467 /** |
|
468 * Cancels the ongoing operations. The method should be called in the beginning |
|
469 * of the destructors of the subclasses. No errors returned, because the method |
|
470 * is called at the shutdown phase where no reasonable error handling is possible |
|
471 * anymore. |
|
472 * @since S60 3.0 |
|
473 */ |
|
474 void CloseServices(); |
|
475 |
|
476 /** |
|
477 * Gets the current state of the Always Online |
|
478 * |
|
479 * @since S60 v3.2 |
|
480 * @param Key to be used |
|
481 * @return |
|
482 */ |
|
483 TInt AoState() const; |
|
484 |
|
485 /** |
|
486 * Gets the current state of the Always Online |
|
487 * |
|
488 * @since S60 v3.2 |
|
489 * @param Key to be used |
|
490 * @return |
|
491 */ |
|
492 TInt EmnState() const; |
|
493 |
|
494 private: |
|
495 |
|
496 /** |
|
497 * Try to create completed operation |
|
498 * @since Series60 2.6 |
|
499 * @param aOpId Id of the given operation |
|
500 * @param aOp Actual operation |
|
501 * @param aUid Used MTM Uid |
|
502 */ |
|
503 void HandleCompletingOperation( |
|
504 const TMsvOp& aOpId, |
|
505 CMsvOperation& aOp, |
|
506 const TUid& aUid ); |
|
507 |
|
508 /** |
|
509 * |
|
510 * @since Series60 3.0 |
|
511 */ |
|
512 void LaunchStartTimerL( |
|
513 TTime& aClock, |
|
514 const TTimeIntervalSeconds& aSeconds ); |
|
515 |
|
516 /** |
|
517 * |
|
518 * @since Series60 3.0 |
|
519 */ |
|
520 void LaunchStopTimerL( |
|
521 TTime& aClock, |
|
522 const TTimeIntervalSeconds& aSeconds ); |
|
523 |
|
524 /** |
|
525 * |
|
526 * @since Series60 3.0 |
|
527 */ |
|
528 CMuiuFlags* AlwaysOnlineFlagsL(); |
|
529 |
|
530 //data |
|
531 protected: |
|
532 CClientMtmRegistry& iClientMtmRegistry; |
|
533 CMsvSession& iSession; |
|
534 CMsvEntry* iEntry; // Entry of the mailbox we are polling |
|
535 CMsvSingleOpWatcherArray iOperations; |
|
536 |
|
537 enum TAlwaysOnlineEmailAgentStates |
|
538 { |
|
539 EEmailAgentInitialised = 0, |
|
540 EEmailAgentIdle, //( 1 ) |
|
541 EEmailAgentConnecting, //( 2 ) |
|
542 EEmailAgentDoingFilteredPopulate, //( 3 ) |
|
543 EEmailAgentPlainConnecting, //( 4 ) |
|
544 EEmailAgentConnectingToStayOnline, //( 5 ) |
|
545 EEmailAgentSynchronising, //( 6 ) |
|
546 EEmailAgentFetching, //( 7 ) |
|
547 EEmailAgentAutoDisconnecting, //( 8 ) |
|
548 EEmailAgentUserDisconnecting, //( 9 ) |
|
549 EEmailAgentQueued, //( 10 ) |
|
550 EEmailAgentTimerWaiting, //( 11 ) |
|
551 EEmailAgentTimerWaitingForStart, //( 12 ) |
|
552 EEmailAgentTimerWaitingForStop, //( 13 ) |
|
553 EEmailAgentReconnecting, //( 14 ) |
|
554 EEmailAgentConnectFailed, //( 15 ) |
|
555 EEmailAgentFatalError,//( 16 ) |
|
556 EEmailAgentConnTerminated //( 17 ) |
|
557 }; |
|
558 |
|
559 |
|
560 TAlwaysOnlineEmailAgentStates iState; |
|
561 |
|
562 TInt iRetryCounter; |
|
563 |
|
564 TInt iLoggerFileCounter; // delete logger file time to time so that it does not grow too much... |
|
565 // Owned: Pointer to email API object |
|
566 CImumInternalApi* iMailboxApi; |
|
567 // Owned: Pointer to email settings object |
|
568 CImumInSettingsData* iMailboxSettings; |
|
569 |
|
570 //These ids are needed by our state machine. We need to know which operation is completing |
|
571 //to take appropriate action |
|
572 TMsvOp iIntervalWaitId;//operation id for interval timer |
|
573 TMsvOp iConnectSyncOpId;//operation id for connect and sync operation |
|
574 |
|
575 TMsvOp iConnectOpId;//operation id for plain connection operation |
|
576 TMsvOp iSyncOpId;//operation id for separate header sync |
|
577 TMsvOp iWaitForStartOpId;//operation id for schedule wait timer ( waiting for start ) |
|
578 TMsvOp iWaitForStopOpId;//operation id for schedule wait timer ( waiting for stop ) |
|
579 TMsvOp iStartDelayOpId;//operation id for start delay timer. Once set, never reset. |
|
580 TMsvOp iConnectAndStayOnlineOpId; //operation id for connection after which we stay online. |
|
581 TMsvOp iDisconnectOpId;//operation id for disconnection |
|
582 TMsvOp iFolderUpdateTimerOpId;//operation id for imap folder update timer. |
|
583 TMsvOp iFolderSyncOpId;//op id for folder sync operation |
|
584 TMsvOp iFilteredPopulateOpId;//op id for filtered email population ( partial fetch ) |
|
585 |
|
586 TInt iError; |
|
587 |
|
588 MNcnInternalNotification* iNcnNotification; |
|
589 |
|
590 MAlwaysOnlineStatusQueryInterface& iStatusQueryInterface; |
|
591 |
|
592 CAlwaysOnlineEmailAgent& iEmailAgent; |
|
593 // Object to handle and store the flags |
|
594 CMuiuFlags* iFlags; |
|
595 |
|
596 // For handling access point settings |
|
597 RCmManager iCmManager; |
|
598 }; |
|
599 |
|
600 #include "AlwaysOnlineEmailAgentBase.inl" |
|
601 |
|
602 typedef CArrayPtrFlat<CAlwaysOnlineEmailAgentBase> CAOEmailAgentArray; |
|
603 |
|
604 #endif |
|
605 //EOF |