|
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: Monitors the network for availability and starts any pending |
|
15 * data sync sessions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef C_NETMON_H |
|
21 #define C_NETMON_H |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <e32base.h> |
|
25 #include <rconnmon.h> |
|
26 #include <SyncMLClient.h> |
|
27 #include <SyncMLClientDS.h> |
|
28 #include <SyncMLObservers.h> |
|
29 #include <e32property.h> |
|
30 #include <centralrepository.h> |
|
31 #include <DataSyncInternalPSKeys.h> |
|
32 |
|
33 // USER INCLUDES |
|
34 #include "nsmldebug.h" |
|
35 #include "NsmlProfileUtil.h" |
|
36 |
|
37 // NetMon states |
|
38 enum TNetMonStates { ERegister = 0, |
|
39 EMonitor, |
|
40 ENetworkUp1, |
|
41 ENetworkUp2, |
|
42 ESyncOk, |
|
43 EInitSync, |
|
44 EComplete }; |
|
45 |
|
46 /** |
|
47 * Monitors the network for availability and starts any pending |
|
48 * data sync sessions. |
|
49 */ |
|
50 class CNetMon : public CActive, |
|
51 public MConnectionMonitorObserver, |
|
52 public MSyncMLEventObserver, |
|
53 public MSyncMLProgressObserver |
|
54 { |
|
55 public: |
|
56 |
|
57 /** |
|
58 * Two phase construction |
|
59 */ |
|
60 static CNetMon* NewL(); |
|
61 |
|
62 /** |
|
63 * Destructor |
|
64 */ |
|
65 ~CNetMon(); |
|
66 |
|
67 protected: |
|
68 |
|
69 // From base class CActive |
|
70 |
|
71 /** |
|
72 * Implements cancellation of an outstanding request |
|
73 */ |
|
74 void DoCancel(); |
|
75 |
|
76 /** |
|
77 * Handles an active objects request completion event. |
|
78 */ |
|
79 void RunL(); |
|
80 |
|
81 /** |
|
82 * If the RunL function leaves, then the active scheduler call |
|
83 * RunError() to handle the leave. |
|
84 * @param aError - The error code |
|
85 */ |
|
86 TInt RunError ( TInt aError ); |
|
87 |
|
88 private: |
|
89 |
|
90 /** |
|
91 * Constructor |
|
92 */ |
|
93 CNetMon(); |
|
94 |
|
95 /** |
|
96 * Second phase constructor |
|
97 */ |
|
98 void ConstructL(); |
|
99 |
|
100 /** |
|
101 * Resgiter for events |
|
102 */ |
|
103 void RegisterL(); |
|
104 |
|
105 /** |
|
106 * Trigger sync |
|
107 */ |
|
108 void StartSyncL(); |
|
109 |
|
110 /** |
|
111 * Close the server |
|
112 */ |
|
113 void Complete(); |
|
114 |
|
115 /** |
|
116 * Set active |
|
117 */ |
|
118 void IssueRequest(); |
|
119 |
|
120 /** |
|
121 * Initiates stability check timer |
|
122 */ |
|
123 //void InitTimerL(); |
|
124 |
|
125 /** |
|
126 * Cancels stability check timer |
|
127 */ |
|
128 //void CancelTimer(); |
|
129 |
|
130 /** |
|
131 * Cancels global auto restart timer |
|
132 */ |
|
133 void CancelGlobalTimer(); |
|
134 |
|
135 /** |
|
136 * Checks if packet data is available using conmon |
|
137 */ |
|
138 TBool PacketDataAvailable(); |
|
139 |
|
140 /** |
|
141 * Moves the state to NetworkUp2 since it is stable |
|
142 */ |
|
143 void NetworkStable(); |
|
144 |
|
145 /** |
|
146 * Check if network is already up |
|
147 */ |
|
148 void NetworkUp1(); |
|
149 |
|
150 /** |
|
151 * Check if network is really up. Callback method |
|
152 */ |
|
153 static TInt NetworkUp2(TAny* arg); |
|
154 |
|
155 /** |
|
156 * Check if any other sync is in progress |
|
157 */ |
|
158 void OtherSyncStatus(); |
|
159 |
|
160 /** |
|
161 * This functions checks if all auto restart policies are ok |
|
162 */ |
|
163 TBool AutoStartPolicyOkL(); |
|
164 |
|
165 /** |
|
166 * Global timeout for auto restart has expired. |
|
167 */ |
|
168 static TInt Timeout(TAny* arg); |
|
169 |
|
170 /** |
|
171 * Read the Global timeout from cenrep. |
|
172 */ |
|
173 TInt ReadTimeoutFromCenrepL(); |
|
174 |
|
175 /** |
|
176 * Create the Sync Job. |
|
177 */ |
|
178 void CreateSyncJobL(); |
|
179 |
|
180 /** |
|
181 * From base class MConnectionMonitorObserver |
|
182 */ |
|
183 void EventL ( const CConnMonEventBase& aConnMonEvent ); |
|
184 |
|
185 /** |
|
186 * From base class MSyncMLEventObserver |
|
187 */ |
|
188 void OnSyncMLSessionEvent(TEvent aEvent, |
|
189 TInt aIdentifier, |
|
190 TInt aError, |
|
191 TInt aAdditionalData); |
|
192 |
|
193 //from MSyncMLProgressObserver |
|
194 |
|
195 /** |
|
196 * Receives notification of a synchronisation error. |
|
197 * @param aErrorLevel The error level. |
|
198 * @param aError The type of error. This is one of the SyncMLError error values. |
|
199 * @param aTaskId The ID of the task for which the error occurred. |
|
200 * @param aInfo1 An integer that can contain additional information about the error. Normally 0. |
|
201 * @param aInfo2 An integer that can contain additional information about the error. Normally 0. |
|
202 * @return None. |
|
203 */ |
|
204 void OnSyncMLSyncError(TErrorLevel aErrorLevel, TInt aError, TInt aTaskId, TInt aInfo1, TInt aInfo2); |
|
205 |
|
206 /** |
|
207 * Receives notification of synchronisation progress. |
|
208 * @param aStatus The current status, e.g. 'Connecting'. |
|
209 * @param aInfo1 An integer that can contain additional information about the progress. |
|
210 * @param aInfo2 An integer that can contain additional information about the progress. |
|
211 */ |
|
212 void OnSyncMLSyncProgress(TStatus aStatus, TInt aInfo1, TInt aInfo2); |
|
213 |
|
214 /** |
|
215 * Receives notification of modifications to synchronisation tasks. |
|
216 * @param aTaskId The ID of the task. |
|
217 * @param aClientModifications Modifications made on the clients Data Store. |
|
218 * @param aServerModifications Modifications made on the server Data Store. |
|
219 */ |
|
220 void OnSyncMLDataSyncModifications(TInt aTaskId, const TSyncMLDataSyncModifications& aClientModifications, const TSyncMLDataSyncModifications& aServerModifications); |
|
221 |
|
222 |
|
223 /** |
|
224 * Set/Reset the interrupt flag in the CenRep |
|
225 */ |
|
226 void UpdateInterruptFlagL(TInt aValue); |
|
227 void OpenSyncSessionL(); |
|
228 |
|
229 void CloseSyncSession(); |
|
230 |
|
231 private: |
|
232 |
|
233 /** |
|
234 * Connection Monitor Server Instance |
|
235 */ |
|
236 RConnectionMonitor iConnectionMonitor; |
|
237 |
|
238 /** |
|
239 * States |
|
240 */ |
|
241 TNetMonStates iState; |
|
242 |
|
243 /** |
|
244 * SyncML session |
|
245 */ |
|
246 RSyncMLSession iSyncSession; |
|
247 |
|
248 /** |
|
249 * Data sync job |
|
250 */ |
|
251 RSyncMLDataSyncJob iSyncJob; |
|
252 |
|
253 /** |
|
254 * Stability Timer |
|
255 */ |
|
256 CPeriodic* iStabilityTimer; |
|
257 |
|
258 /** |
|
259 * Global Timer |
|
260 */ |
|
261 CPeriodic* iGlobalTimer; |
|
262 |
|
263 /** |
|
264 * Profile id to be used |
|
265 */ |
|
266 TSmlProfileId iLastUsedProfileId; |
|
267 |
|
268 /** |
|
269 * Sync status P&S keys |
|
270 */ |
|
271 RProperty iProperty; |
|
272 |
|
273 /** |
|
274 * Connection Id used for the Sync Session |
|
275 */ |
|
276 TConnMonBearerId iConMonBearerId; |
|
277 /** |
|
278 * Global timeout from cenrep. |
|
279 */ |
|
280 TInt iGlobalTimeout; |
|
281 |
|
282 /** |
|
283 * Timer count |
|
284 */ |
|
285 TInt iTimerCount; |
|
286 |
|
287 TBool iSyncSessionOpen; |
|
288 |
|
289 TStatus iPrgPrevStatus; |
|
290 |
|
291 TStatus iPrgCurStatus; |
|
292 }; |
|
293 |
|
294 #endif // End of file |