|
1 /* |
|
2 * Copyright (c) 2008 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 * Contains mailbox specified always online logic |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef IPSSOSAOMBOXLOGIC_CPP_ |
|
20 #define IPSSOSAOMBOXLOGIC_CPP_ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <msvapi.h> |
|
24 |
|
25 //<cmail> removing internal dependency |
|
26 /*#ifdef _DEBUG |
|
27 #include "../../internal/IpsSosAOPluginTester/inc/IpsSosAOPluginTester.hrh" |
|
28 #endif // _DEBUG*/ |
|
29 //</cmail> |
|
30 |
|
31 #include "IpsSosAOBaseAgent.h" |
|
32 #include "IpsSetDataExtension.h" |
|
33 #include "IpsSosAOPluginTimer.h" |
|
34 //<cmail> |
|
35 //</cmail> |
|
36 |
|
37 class CIpsSetDataApi; |
|
38 class CIpsSosAOBaseAgent; |
|
39 class CIpsSetDataExtension; |
|
40 class CIpsSosAOImapPopLogic; |
|
41 |
|
42 /** |
|
43 * class CIpsSosAOImapPopLogic; |
|
44 * |
|
45 */ |
|
46 class CIpsSosAOMBoxLogic : |
|
47 public CBase, |
|
48 public MIpsSosAOPluginTimerCallBack, |
|
49 public MIpsSosAOAgentOperationResponse |
|
50 { |
|
51 |
|
52 public: |
|
53 |
|
54 /** |
|
55 * Two phased constructor |
|
56 * @return self pointer |
|
57 */ |
|
58 static CIpsSosAOMBoxLogic* NewL( |
|
59 CMsvSession& aSession, |
|
60 TMsvId aMailboxId ); |
|
61 |
|
62 /** |
|
63 * Destructor |
|
64 */ |
|
65 virtual ~CIpsSosAOMBoxLogic(); |
|
66 |
|
67 public: |
|
68 |
|
69 // from MIpsSosAOPluginTimerCallBack |
|
70 virtual void TimerFiredL(); |
|
71 |
|
72 // from MIpsSosAOAgentOperationResponse |
|
73 virtual void OperationCompletedL( TInt aError ); |
|
74 |
|
75 public: |
|
76 |
|
77 enum TMboxLogicCommand |
|
78 { |
|
79 // starts timed sync, or set logic to idle |
|
80 // state to wait other commands |
|
81 ECommandStart, |
|
82 // cancel all ongoing operation and switch logic |
|
83 // to error state |
|
84 ECommandStop, |
|
85 // suspends logic to certain period of time |
|
86 ECommandSuspend, |
|
87 // continue suspended logic, does nothing if not |
|
88 // suspended |
|
89 ECommandContinue, |
|
90 // starts sync if connection is allowed, |
|
91 // used if emn is received |
|
92 ECommandStartSync, |
|
93 // inform roaming state. If sync is not allowed |
|
94 // in roaming state, stops logic |
|
95 ECommandStartedRoaming, |
|
96 // inform home network state. Starts logic if it |
|
97 // is stopped |
|
98 ECommandStoppedRoaming, |
|
99 // cancel all ongoing operations and disconnect if mailbox |
|
100 // is connected state |
|
101 ECommandCancelAndDisconnect, |
|
102 // cancel all but not disconnect |
|
103 ECommandCancelDoNotDiconnect, |
|
104 // mailbox is not disconnected if box is connected |
|
105 // non of ongoing operations are cancelled |
|
106 ECommandDoNotDisconnect, |
|
107 // clear do not disconnect flag, it's also |
|
108 // cleared if mailbox is disconnected elsewhere |
|
109 ECommandClearDoNotDisconnect |
|
110 }; |
|
111 |
|
112 enum TMBoxLogicState |
|
113 { |
|
114 // in this state timer is waiting to sync start |
|
115 EStateWaitSyncStart = 0, |
|
116 // |
|
117 EStateSyncOngoing, |
|
118 // |
|
119 EStateFetchOngoing, |
|
120 // |
|
121 EStateSuspended, |
|
122 // |
|
123 EStateIdleAndWaitCommands, |
|
124 // in error state not taking any commands exept start |
|
125 EStateError |
|
126 }; |
|
127 |
|
128 /* |
|
129 * Used by imap pop logic object to send commands to this logic object |
|
130 * @param aCommand TMBoxLogicCommand |
|
131 */ |
|
132 void SendCommandL( TInt aCommand ); |
|
133 |
|
134 /* |
|
135 * Starts fetching messages |
|
136 * NOTE: this is not currently used or tested, function can be |
|
137 * used if IMAP-IDLE supportis needed |
|
138 * @param aArray msv id array of messages to be fetched |
|
139 */ |
|
140 void FetchMessagesL( const RArray<TMsvId> aArray ); |
|
141 |
|
142 /* |
|
143 * Gets mailbox id of logic object |
|
144 * @return msv id of the service |
|
145 */ |
|
146 TMsvId GetMailboxId(); |
|
147 |
|
148 /* |
|
149 * Gets reference to agent object |
|
150 * not currently used |
|
151 * @return reference to agent object |
|
152 */ |
|
153 CIpsSosAOBaseAgent& GetAgent() const; |
|
154 |
|
155 /* |
|
156 * Gets emn state of mailbox settings |
|
157 * @return ETrue if emn is on |
|
158 */ |
|
159 TBool IsEmnOn() const; |
|
160 |
|
161 /* |
|
162 * Gets TMboxLogicState of this logic object |
|
163 * @return TMBoxLogicState |
|
164 */ |
|
165 TInt GetCurrentState() const; |
|
166 |
|
167 /* |
|
168 * Gets current error code |
|
169 * @return iError value |
|
170 */ |
|
171 TInt GetCurrentError() const; |
|
172 |
|
173 /* |
|
174 * Gets email address from settings |
|
175 * @param aEmailAddress mailbox email address |
|
176 */ |
|
177 void GetEmailAddress( |
|
178 TBuf<KIpsSosAOTextBufferSize>& aEmailAddress ) const; |
|
179 |
|
180 /* |
|
181 * Sets new value to emn received but no synced flag in |
|
182 * mailbox settings |
|
183 * @param aNewValue new value of flag |
|
184 */ |
|
185 //<cmail> |
|
186 void SetEmnReceivedFlagL( TBool aNewValue ); |
|
187 //</cmail> |
|
188 |
|
189 /* |
|
190 * Gets mailbox roaming stopped status |
|
191 * @return ETrue if roaming and mailbox logic is stopped during roaming |
|
192 */ |
|
193 //<cmail> |
|
194 TBool IsMailboxRoamingStoppedL(); |
|
195 //</cmail> |
|
196 |
|
197 /** |
|
198 * Has mailbox ever received and OMA EMN |
|
199 */ |
|
200 TBool FirstEMNReceived(); |
|
201 |
|
202 /** |
|
203 * First OMA EMN has been received. |
|
204 * Sets a flag to indicate the reception of fist OMA EMN, |
|
205 * Changes settings to "after notification", which means |
|
206 * turning off alwaysonline and using OMA EMN only. |
|
207 */ |
|
208 void SetFirstEMNReceived(); |
|
209 |
|
210 private: |
|
211 |
|
212 /* |
|
213 * internal events which are generated when timer tricks of whne |
|
214 * command is sent to logic |
|
215 */ |
|
216 enum TMBoxLogicEvent |
|
217 { |
|
218 EEventTimerFired, |
|
219 EEventStartSync, |
|
220 EEventFetchMessages, |
|
221 EEventOperationCompleted, |
|
222 EEventSuspendOperations, |
|
223 EEventContinueOperations, |
|
224 EEventStart, |
|
225 EEventStopAndRemoveOps, |
|
226 EEventNop |
|
227 }; |
|
228 |
|
229 private: |
|
230 |
|
231 /** |
|
232 * Constructor |
|
233 */ |
|
234 CIpsSosAOMBoxLogic( |
|
235 CMsvSession& aSession, |
|
236 TMsvId aMailboxId ); |
|
237 |
|
238 /** |
|
239 * Second phase constructor |
|
240 */ |
|
241 void ConstructL(); |
|
242 |
|
243 /* |
|
244 * Switch state according to event, all state transion |
|
245 * are handled in this function according to event parameter. |
|
246 */ |
|
247 void HandleEventAndSwitchStateL( TInt aEvent ); |
|
248 |
|
249 /* |
|
250 * is called by timer object |
|
251 */ |
|
252 TInt HandleTimerFiredL(); |
|
253 |
|
254 /* |
|
255 * is called when agent have completed its async operation |
|
256 */ |
|
257 TInt HandleOperationCompletionL(); |
|
258 |
|
259 /* |
|
260 * checks is operation completion error fatal and should timed sync swithc off |
|
261 */ |
|
262 //<cmail> |
|
263 TBool IsErrorFatalL( TInt aError ); |
|
264 //</cmail> |
|
265 |
|
266 /* |
|
267 * Suspends ongoing sync (or fetch) and swiths logic to suspend state |
|
268 */ |
|
269 void SuspendOperations(); |
|
270 |
|
271 /* |
|
272 * Checks is it time to start sync or set timer back on |
|
273 * returns event to handle event and switch state loop |
|
274 */ |
|
275 TMBoxLogicEvent CheckSchedulingAndSwitchStateL(); |
|
276 |
|
277 /* |
|
278 * calculates next interval (clock) time |
|
279 */ |
|
280 void CalculateToNextIntervalL(); |
|
281 |
|
282 /* |
|
283 * calculates seconds to next sync |
|
284 */ |
|
285 TTimeIntervalSeconds CalculateScheduledSyncTimeL(); |
|
286 |
|
287 /* |
|
288 * destroys old setting object and loads it again from setttings |
|
289 */ |
|
290 void LoadSettingsL(); |
|
291 |
|
292 /* |
|
293 * saves successfull sync time to mailbox settings |
|
294 */ |
|
295 void SaveSuccessfulSyncTimeL(); |
|
296 |
|
297 /* |
|
298 * checks from settings is connect allowed in roaming state |
|
299 */ |
|
300 TBool CanConnectIfRoamingL(); |
|
301 |
|
302 // <cmail> removing flags |
|
303 /*#ifdef IPSSOSIMAPPOLOGGING_ON |
|
304 void WriteDebugData( TInt aEvent ); |
|
305 #endif*/ |
|
306 //</cmail> |
|
307 |
|
308 private: |
|
309 |
|
310 CMsvSession& iSession; |
|
311 TMsvId iMailboxId; |
|
312 TMBoxLogicState iState; |
|
313 TInt iErrorCounter; |
|
314 TInt iError; |
|
315 CIpsSosAOPluginTimer* iTimer; |
|
316 // message fetch is not currently used |
|
317 RArray<TMsvId> iFetchMsgArray; |
|
318 CIpsSetDataApi* iDataApi; |
|
319 CIpsSosAOBaseAgent* iAgent; |
|
320 CIpsSetDataExtension* iExtendedSettings; |
|
321 TBool iIsRoaming; |
|
322 }; |
|
323 |
|
324 #endif /*IPSSOSAOMBOXLOGIC_CPP_*/ |