|
1 /* |
|
2 * Copyright (c) 2005 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: Manages schedules using Symbian Task scheduler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef ASPAUTOSYNCHANDLER_H |
|
20 #define ASPAUTOSYNCHANDLER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <SyncMLClient.h> // for RSyncMLSession |
|
25 #include <SyncMLObservers.h> |
|
26 #include <schtask.h> |
|
27 |
|
28 #include "AspDefines.h" |
|
29 #include "AspUtil.h" |
|
30 #include "AspSchedule.h" |
|
31 |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * CAspAutoSyncHandler |
|
37 * |
|
38 */ |
|
39 NONSHARABLE_CLASS (CAspAutoSyncHandler) : public CBase, |
|
40 public MSyncMLEventObserver, |
|
41 public MSyncMLProgressObserver |
|
42 { |
|
43 public: |
|
44 enum TAutoSyncError |
|
45 { |
|
46 EOtherSyncRunning = -100, |
|
47 EIncorrectProfile = -101, |
|
48 EIncorrectSchedule = -102 |
|
49 }; |
|
50 |
|
51 public:// Constructors and destructor |
|
52 |
|
53 /** |
|
54 * Two-phased constructor. |
|
55 */ |
|
56 static CAspAutoSyncHandler* NewL(); |
|
57 |
|
58 /** |
|
59 * Destructor. |
|
60 */ |
|
61 virtual ~CAspAutoSyncHandler(); |
|
62 |
|
63 private: |
|
64 |
|
65 /** |
|
66 * C++ default constructor. |
|
67 */ |
|
68 CAspAutoSyncHandler(); |
|
69 |
|
70 /** |
|
71 * By default Symbian OS constructor is private. |
|
72 */ |
|
73 void ConstructL(); |
|
74 |
|
75 |
|
76 public: |
|
77 void SynchronizeL(RFile& aTaskFile); |
|
78 |
|
79 void DoSynchronizeL(); |
|
80 |
|
81 private: |
|
82 void OpenSyncSessionL(); |
|
83 void CloseSyncSession(); |
|
84 TInt CheckMandatoryDataL(TInt aProfileId); |
|
85 TBool IsRoamingL(); |
|
86 TBool IsRoaming(); |
|
87 |
|
88 |
|
89 private: // from MSyncMLEventObserver |
|
90 |
|
91 void OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier, |
|
92 TInt aError, TInt aAdditionalData); |
|
93 |
|
94 private: //from MSyncMLProgressObserver |
|
95 |
|
96 void OnSyncMLSyncProgress(TStatus aStatus, TInt aInfo1, TInt aInfo2); |
|
97 void OnSyncMLDataSyncModifications(TInt aTaskId, |
|
98 const TSyncMLDataSyncModifications& aClientModifications, |
|
99 const TSyncMLDataSyncModifications& aServerModifications); |
|
100 void OnSyncMLSyncError(TErrorLevel aErrorLevel, TInt aError, |
|
101 TInt aTaskId, TInt aInfo1, TInt aInfo2); |
|
102 |
|
103 |
|
104 |
|
105 private: |
|
106 |
|
107 // sync session |
|
108 RSyncMLSession iSyncSession; |
|
109 |
|
110 // sync job |
|
111 RSyncMLDataSyncJob iSyncJob; |
|
112 |
|
113 // is sync currently running |
|
114 TBool iSyncRunning; |
|
115 |
|
116 // sync error code |
|
117 TInt iSyncError; |
|
118 |
|
119 // is sync session open |
|
120 TBool iSyncSessionOpen; |
|
121 |
|
122 // for stopping code until sync is finished |
|
123 CActiveSchedulerWait* iWait; |
|
124 |
|
125 // for reading auto sync settings |
|
126 CAspSchedule* iSchedule; |
|
127 }; |
|
128 |
|
129 |
|
130 /** |
|
131 * CAspSyncSchedule |
|
132 * |
|
133 */ |
|
134 NONSHARABLE_CLASS (CAspSyncSchedule) : public CBase |
|
135 { |
|
136 |
|
137 |
|
138 public:// Constructors and destructor |
|
139 |
|
140 /** |
|
141 * Two-phased constructor. |
|
142 */ |
|
143 static CAspSyncSchedule* NewL(); |
|
144 |
|
145 /** |
|
146 * Two-phased constructor. |
|
147 */ |
|
148 static CAspSyncSchedule* NewLC(); |
|
149 |
|
150 /** |
|
151 * Destructor. |
|
152 */ |
|
153 virtual ~CAspSyncSchedule(); |
|
154 |
|
155 private: |
|
156 |
|
157 /** |
|
158 * C++ default constructor. |
|
159 */ |
|
160 CAspSyncSchedule(); |
|
161 |
|
162 /** |
|
163 * By default Symbian OS constructor is private. |
|
164 */ |
|
165 void ConstructL(); |
|
166 |
|
167 public: |
|
168 |
|
169 /** |
|
170 * Delete existing schedule.Called before creating a new schedule |
|
171 */ |
|
172 void DeleteScheduleL(CAspSchedule* aAspSchedule); |
|
173 void DoDeleteScheduleL(CAspSchedule* aAspSchedule); |
|
174 |
|
175 /** |
|
176 * Create a new schedule based on changed settings |
|
177 */ |
|
178 void CreatePeakScheduleL(CAspSchedule* aAspSchedule); |
|
179 void CreateOffPeakScheduleL(CAspSchedule* aAspSchedule); |
|
180 |
|
181 /** |
|
182 * Edit the schedule to start after 15 min/30 mins.This is needed as task scheduler does not support |
|
183 * schedulling interval less than a hour |
|
184 */ |
|
185 |
|
186 void EditPeakScheduleL(CAspSchedule* aAspSchedule); |
|
187 void EditOffPeakScheduleL(CAspSchedule* aAspSchedule); |
|
188 |
|
189 /** |
|
190 * Post pone the scheduled sync in till next valid time |
|
191 */ |
|
192 |
|
193 void UpdatePeakScheduleL(CAspSchedule* aAspSchedule); |
|
194 void UpdateOffPeakScheduleL(CAspSchedule* aAspSchedule); |
|
195 |
|
196 /** |
|
197 * Enable schedules |
|
198 */ |
|
199 void EnableSchedule(CAspSchedule* aAspSchedule); |
|
200 |
|
201 #ifdef _DEBUG |
|
202 public: |
|
203 void LogScheduleL(CAspSchedule* aAspSchedule); |
|
204 TInt LogSchedule(CAspSchedule* aAspSchedule); |
|
205 static void LogIntervalType(TScheduleEntryInfo2& aInfo, TDes& aText); |
|
206 static void LogInterval(TScheduleEntryInfo2& aInfo, TDes& aText); |
|
207 static void LogTsTime(TTsTime aTsTime, TDes& aText); |
|
208 static void LogTaskInfo(TTaskInfo& aInfo, TDes& aText); |
|
209 #endif |
|
210 |
|
211 public: |
|
212 |
|
213 /** |
|
214 * Get next sync time.Reads due time from task scheduler. |
|
215 */ |
|
216 void GetPeakStartTimeL(CAspSchedule* aAspSchedule, TTime& aTime, TBool aHomeTime); |
|
217 void GetOffPeakStartTimeL(CAspSchedule* aAspSchedule, TTime& aTime, TBool aHomeTime); |
|
218 |
|
219 public: |
|
220 TIntervalType IntervalType(TInt aInterval); |
|
221 TTsTime StartTime(TInt aStartHour, TInt aInterval); |
|
222 TInt Interval(TInt aInterval); |
|
223 |
|
224 |
|
225 private: |
|
226 //task scheduler server session |
|
227 RScheduler iScheduler; |
|
228 |
|
229 |
|
230 // schedule entry list |
|
231 CArrayFixFlat<TScheduleEntryInfo2>* ipeakEntryList; |
|
232 CArrayFixFlat<TScheduleEntryInfo2>* ioffPeakEntryList; |
|
233 |
|
234 // schedule entry list |
|
235 CArrayFixFlat<TTaskInfo>* ipeakTaskList; |
|
236 CArrayFixFlat<TTaskInfo>* ioffPeakTaskList; |
|
237 // long buffer for string handling |
|
238 TBuf<KBufSize255> iBuf; |
|
239 }; |
|
240 |
|
241 |
|
242 |
|
243 #endif // ASPAUTOSYNCHANDLER_H |
|
244 |
|
245 // End of file |