|
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: Utility classes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NSMLDMSYNCUTIL_H |
|
20 #define NSMLDMSYNCUTIL_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 |
|
25 // CLASS DECLARATION |
|
26 |
|
27 /** |
|
28 * TUtil |
|
29 * |
|
30 * This class contains general utility functions. |
|
31 */ |
|
32 NONSHARABLE_CLASS (TUtil) |
|
33 { |
|
34 public: |
|
35 |
|
36 /** |
|
37 * Panic |
|
38 * @param aReason. |
|
39 * @return None |
|
40 */ |
|
41 static void Panic( TInt aReason ); |
|
42 |
|
43 /** |
|
44 * String copy tool |
|
45 * @param aTarget. |
|
46 * @param aSource. |
|
47 * @return None |
|
48 */ |
|
49 static void StrCopy( TDes& aTarget, const TDesC& aSource ); |
|
50 /** |
|
51 * String copy tool |
|
52 * @param aTarget. |
|
53 * @param aSource. |
|
54 * @return None |
|
55 */ |
|
56 static void StrCopy( TDes& aTarget, const TDesC8& aSource ); |
|
57 |
|
58 /** |
|
59 * String copy tool |
|
60 * @param aTarget. |
|
61 * @param aSource. |
|
62 * @return None |
|
63 */ |
|
64 static void StrCopy( TDes8& aTarget, const TDesC& aSource ); |
|
65 |
|
66 /** |
|
67 * String append tool |
|
68 * @param aTarget. |
|
69 * @param aSource. |
|
70 * @return None |
|
71 */ |
|
72 static void StrAppend( TDes& aTarget, const TDesC& aSource ); |
|
73 |
|
74 /** |
|
75 * String insert tool |
|
76 * @param aTarget. |
|
77 * @param aSource. |
|
78 * @return None |
|
79 */ |
|
80 static void StrInsert( TDes& aTarget, const TDesC& aSource ); |
|
81 |
|
82 /** |
|
83 * Convert string to int |
|
84 * @param aText. |
|
85 * @param aNum. |
|
86 * @return None |
|
87 */ |
|
88 static TInt StrToInt( const TDesC& aText, TInt& aNum ); |
|
89 |
|
90 /** |
|
91 * Check whether textline is empty |
|
92 * @param aText. |
|
93 * @return ETrue if empty |
|
94 */ |
|
95 static TBool IsEmpty( const TDesC& aText ); |
|
96 |
|
97 /** |
|
98 * URI Parser |
|
99 * @param aURI |
|
100 * @param aAddress |
|
101 * @param aPort |
|
102 * @param aDocName |
|
103 * @return None |
|
104 */ |
|
105 static void ParseURIL( const TDesC& aURI, |
|
106 TDes& aAddress, |
|
107 TDes& aPort, |
|
108 TDes& aDocName ); |
|
109 |
|
110 /** |
|
111 * Returns formatted sync time |
|
112 * @param aLastSync |
|
113 * @return Sync time |
|
114 */ |
|
115 static HBufC* SyncTimeLC( TTime aLastSync ); |
|
116 |
|
117 /** |
|
118 * Get data as text |
|
119 * @param |
|
120 * @return |
|
121 */ |
|
122 static void GetDateTextL( TDes& aText, TTime aDateTime ); |
|
123 |
|
124 /** |
|
125 * Get time as text |
|
126 * @param |
|
127 * @return |
|
128 */ |
|
129 static void GetTimeTextL( TDes& aText, TTime aDateTime ); |
|
130 |
|
131 /** |
|
132 * Get data and time as text |
|
133 * @param |
|
134 * @return |
|
135 */ |
|
136 static void GetDateTimeTextL( TDes& aText, TTime aDateTime ); |
|
137 |
|
138 /** |
|
139 * Check if SettingEnforcement is set |
|
140 * @param |
|
141 * @return Boolean |
|
142 */ |
|
143 static TBool SettingEnforcementStateL(); |
|
144 |
|
145 /** |
|
146 * Check if SettingEnforcement is set (non-leaving) |
|
147 * @param |
|
148 * @return Boolean |
|
149 */ |
|
150 static TBool SettingEnforcementState(); |
|
151 |
|
152 private: |
|
153 |
|
154 /** |
|
155 * Check if sync has happened today |
|
156 * @param atime |
|
157 * @return Boolean |
|
158 */ |
|
159 static TBool IsToday( TTime aTime ); |
|
160 |
|
161 /** |
|
162 * Convert time to hometime |
|
163 * @param aUniversalTime |
|
164 * @return TTIme |
|
165 */ |
|
166 static TTime ConvertUniversalToHomeTime( const TTime& aUniversalTime ); |
|
167 |
|
168 }; |
|
169 |
|
170 /** |
|
171 * TStr contains descriptor operations with range checking. |
|
172 */ |
|
173 NONSHARABLE_CLASS (TStr) |
|
174 { |
|
175 public: |
|
176 /** |
|
177 * C++ default constructor. |
|
178 */ |
|
179 TStr(const TDesC& aStr); |
|
180 |
|
181 public: |
|
182 /** |
|
183 * String manipulating tools |
|
184 * @param aPos |
|
185 * @param aLen |
|
186 * @return TPtrC |
|
187 */ |
|
188 TPtrC Mid( TInt aPos, TInt aLen ); |
|
189 |
|
190 /** |
|
191 * String manipulating tools |
|
192 * @param aPos |
|
193 * @return TPtrC |
|
194 */ |
|
195 TPtrC Mid( TInt aPos ); |
|
196 |
|
197 /** |
|
198 * String manipulating tools |
|
199 * @param aPos |
|
200 * @return TPtrC |
|
201 */ |
|
202 TPtrC Left( TInt aPos ); |
|
203 |
|
204 /** |
|
205 * String manipulating tools |
|
206 * @param aPos |
|
207 * @return TPtrC |
|
208 */ |
|
209 TPtrC Right( TInt aPos ); |
|
210 |
|
211 /** |
|
212 * String manipulating tools |
|
213 * @param aStartPos |
|
214 * @param aEndPos |
|
215 * @return TPtrC |
|
216 */ |
|
217 TPtrC SubStr( TInt aStartPos, TInt aEndPos ); |
|
218 |
|
219 /** |
|
220 * String manipulating tools |
|
221 * @param aStartPos |
|
222 * @param aEndPos |
|
223 * @return TPtrC |
|
224 */ |
|
225 TPtrC SubStrEx( TInt aStartPos, TInt aEndPos ); |
|
226 |
|
227 /** |
|
228 * String manipulating tools |
|
229 * @return TInt |
|
230 */ |
|
231 TInt LastPos(); |
|
232 |
|
233 /** |
|
234 * String manipulating tools |
|
235 * @return TInt |
|
236 */ |
|
237 TInt Len(); |
|
238 |
|
239 /** |
|
240 * String manipulating tools |
|
241 * @param aPos |
|
242 * @param aChar |
|
243 * @return TBool |
|
244 */ |
|
245 TBool Compare( TInt aPos, TChar aChar ); |
|
246 |
|
247 /** |
|
248 * String manipulating tools |
|
249 * @param aStartPos |
|
250 * @param aChar |
|
251 * @return TInt |
|
252 */ |
|
253 TInt Find( TInt aPos, TChar aChar ); |
|
254 |
|
255 private: |
|
256 // reference to descriptor |
|
257 const TDesC& iStr; |
|
258 }; |
|
259 |
|
260 /** |
|
261 * TURIParser is used for parsing URI. |
|
262 */ |
|
263 NONSHARABLE_CLASS (TURIParser) |
|
264 { |
|
265 public: |
|
266 /** |
|
267 * C++ default constructor. |
|
268 */ |
|
269 TURIParser( const TDesC& aStr ); |
|
270 |
|
271 public: |
|
272 /** |
|
273 * URI manipulating tools |
|
274 * @param aText |
|
275 * @return None |
|
276 */ |
|
277 void GetUriWithoutPort( TDes& aText ); |
|
278 |
|
279 /** |
|
280 * URI manipulating tools |
|
281 * @param aText |
|
282 * @param aPort |
|
283 * @return None |
|
284 */ |
|
285 void GetUri( TDes& aText, const TInt aPort ); |
|
286 |
|
287 /** |
|
288 * URI manipulating tools |
|
289 * @return TInt |
|
290 */ |
|
291 TInt Port(); |
|
292 |
|
293 /** |
|
294 * URI manipulating tools |
|
295 * @return TInt |
|
296 */ |
|
297 TInt DefaultPort(); |
|
298 |
|
299 private: |
|
300 /** |
|
301 * URI manipulating tools |
|
302 * @return TPtrC |
|
303 */ |
|
304 TPtrC ParseHttp(); |
|
305 |
|
306 /** |
|
307 * URI manipulating tools |
|
308 * @return TPtrC |
|
309 */ |
|
310 TPtrC ParseAddress(); |
|
311 |
|
312 /** |
|
313 * URI manipulating tools |
|
314 * @return TPtrC |
|
315 */ |
|
316 TPtrC ParseDocument(); |
|
317 |
|
318 /** |
|
319 * URI manipulating tools |
|
320 * @param aPortNumber |
|
321 * @return TInt |
|
322 */ |
|
323 TInt ParsePort(TInt& aPortNumber); |
|
324 |
|
325 /** |
|
326 * URI manipulating tools |
|
327 * @return TPtrC |
|
328 */ |
|
329 TPtrC ParsePort(); |
|
330 |
|
331 private: |
|
332 |
|
333 /** |
|
334 * URI manipulating tools |
|
335 * @param aStartPos |
|
336 * @param aEndPos |
|
337 * @return None |
|
338 */ |
|
339 void GetHttpPos(TInt& aStartPos, TInt& aEndPos); |
|
340 |
|
341 /** |
|
342 * URI manipulating tools |
|
343 * @return NOne |
|
344 */ |
|
345 void SkipHttp(); |
|
346 |
|
347 private: |
|
348 // reference to original URI text |
|
349 const TDesC& iOriginalStr; |
|
350 |
|
351 // pointer to original URI text |
|
352 TPtrC iPtr; |
|
353 |
|
354 //reference to Boolean variable which tells about Slash in URI |
|
355 TBool iSlash; |
|
356 }; |
|
357 |
|
358 /** |
|
359 * MNSmlDMActiveCallerObserver |
|
360 * |
|
361 * MNSmlDMActiveCallerObserver is for observing CNSmlDMActiveCaller. |
|
362 */ |
|
363 class MNSmlDMActiveCallerObserver |
|
364 { |
|
365 public: |
|
366 virtual void HandleActiveCallL() = 0; |
|
367 }; |
|
368 |
|
369 /** |
|
370 * CNSmlDMActiveCaller |
|
371 * |
|
372 * CNSmlDMActiveCaller is used for generating a call from active scheduler. |
|
373 */ |
|
374 NONSHARABLE_CLASS (CNSmlDMActiveCaller) : public CActive |
|
375 { |
|
376 public: |
|
377 /** |
|
378 * Two-phased constructor. |
|
379 */ |
|
380 static CNSmlDMActiveCaller* NewL(MNSmlDMActiveCallerObserver* aObserver); |
|
381 |
|
382 /** |
|
383 * Destructor. |
|
384 */ |
|
385 virtual ~CNSmlDMActiveCaller(); |
|
386 |
|
387 private: |
|
388 /** |
|
389 * C++ default constructor. |
|
390 */ |
|
391 CNSmlDMActiveCaller(MNSmlDMActiveCallerObserver* aObserver); |
|
392 |
|
393 /** |
|
394 * By default Symbian 2nd phase constructor is private. |
|
395 */ |
|
396 void ConstructL(); |
|
397 |
|
398 public: |
|
399 /** |
|
400 * Calls observer using active object framework. |
|
401 * @param aCallId. |
|
402 * @param aMilliseconds Delay before observer is called. |
|
403 * @return None |
|
404 */ |
|
405 void Start( TInt aCallId, TInt aMilliseconds = 0 ); |
|
406 |
|
407 private: |
|
408 /** |
|
409 * From CActive. Called when asynchronous request completes. |
|
410 * @param None |
|
411 * @return None |
|
412 */ |
|
413 void RunL(); |
|
414 |
|
415 /** |
|
416 * From CActive. Called when RunL Leaves. |
|
417 * @param None |
|
418 * @return error |
|
419 */ |
|
420 TInt RunError( TInt aError ); |
|
421 |
|
422 /** |
|
423 * From CActive. Cancels asynchronous request. |
|
424 * @param None |
|
425 * @return None |
|
426 */ |
|
427 void DoCancel(); |
|
428 |
|
429 /** |
|
430 * Make active scheduler call RunL. |
|
431 * @param None |
|
432 * @return None |
|
433 */ |
|
434 void CompleteSelf(); |
|
435 |
|
436 private: |
|
437 // call that is passed to observer |
|
438 TInt iCallId; |
|
439 |
|
440 // timer |
|
441 RTimer iTimer; |
|
442 |
|
443 // observer that gets called |
|
444 MNSmlDMActiveCallerObserver* iObserver; |
|
445 }; |
|
446 |
|
447 #endif // NSMLDMSYNCUTIL_H |
|
448 |
|
449 // End of File |