|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <SyncMLTransportProperties.h> |
|
23 #include <eikenv.h> |
|
24 #include <bautils.h> |
|
25 #include <collate.h> |
|
26 #include <StringLoader.h> |
|
27 #include <avkon.rsg> |
|
28 |
|
29 #include "iaupdatefwsyncutil.h" |
|
30 #include "iaupdatefwdebug.h" |
|
31 #include "iaupdatefwconst.h" |
|
32 |
|
33 /***************************************************************************** |
|
34 * class TUtil |
|
35 *****************************************************************************/ |
|
36 |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // Panic |
|
40 // ---------------------------------------------------------------------------- |
|
41 // |
|
42 void TUtil::Panic(TInt aReason) |
|
43 { |
|
44 _LIT(KPanicCategory,"IAUpdateFWSyncUtil"); |
|
45 |
|
46 User::Panic( KPanicCategory, aReason ); |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // StrCopy |
|
51 // String copy with lenght check. |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 void TUtil::StrCopy( TDes8& aTarget, const TDesC& aSource ) |
|
55 { |
|
56 aTarget.Copy( aSource.Left(aTarget.MaxLength() ) ); |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // StrCopy |
|
61 // String copy with lenght check. |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 void TUtil::StrCopy( TDes& aTarget, const TDesC8& aSource ) |
|
65 { |
|
66 aTarget.Copy( aSource.Left(aTarget.MaxLength() ) ); |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // StrCopy |
|
71 // String copy with lenght check. |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 void TUtil::StrCopy( TDes& aTarget, const TDesC& aSource ) |
|
75 { |
|
76 aTarget.Copy( aSource.Left( aTarget.MaxLength() ) ); |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // StrAppend |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 void TUtil::StrAppend( TDes& aTarget, const TDesC& aSource ) |
|
84 { |
|
85 if ( aSource.Length() == 0 ) |
|
86 { |
|
87 return; |
|
88 } |
|
89 TInt free = aTarget.MaxLength() - aTarget.Length(); |
|
90 if ( aSource.Length() <= free ) |
|
91 { |
|
92 aTarget.Append( aSource ); |
|
93 } |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // StrInsert |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 void TUtil::StrInsert( TDes& aTarget, const TDesC& aSource ) |
|
101 { |
|
102 TInt free = aTarget.MaxLength() - aTarget.Length(); |
|
103 if (aSource.Length() <= free) |
|
104 { |
|
105 aTarget.Insert(0, aSource); |
|
106 } |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // StrToInt |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 TInt TUtil::StrToInt( const TDesC& aText, TInt& aNum ) |
|
114 { |
|
115 TLex lex( aText ); |
|
116 TInt err = lex.Val( aNum ); |
|
117 return err; |
|
118 } |
|
119 |
|
120 // |
|
121 //----------------------------------------------------------------------------- |
|
122 // IsEmpty |
|
123 // Function returns ETrue if string only contains white space |
|
124 // or has no characters. |
|
125 //----------------------------------------------------------------------------- |
|
126 // |
|
127 TBool TUtil::IsEmpty( const TDesC& aText ) |
|
128 { |
|
129 TInt len = aText.Length(); |
|
130 for ( TInt index=0; index < len; index++ ) |
|
131 { |
|
132 TChar character = aText[index]; |
|
133 if ( !character.IsSpace() ) |
|
134 { |
|
135 return EFalse; |
|
136 } |
|
137 } |
|
138 return ETrue; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // SyncTimeLC |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 HBufC* TUtil::SyncTimeLC( TTime aLastSync ) |
|
146 { |
|
147 FLOG( "[OMADM] TUtil::SyncTimeLC" ); |
|
148 |
|
149 TTime homeTime = ConvertUniversalToHomeTime( aLastSync ); |
|
150 |
|
151 HBufC* hBuf = HBufC::NewLC( KBufSize255 ); |
|
152 TPtr ptr = hBuf->Des(); |
|
153 |
|
154 if ( IsToday( homeTime ) ) |
|
155 { |
|
156 FLOG( "[OMADM] TUtil::SyncTimeLC time" ); |
|
157 |
|
158 TBuf<KBufSize> timeFormat; |
|
159 HBufC* buf = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
160 TUtil::StrCopy( timeFormat, *buf ); |
|
161 CleanupStack::PopAndDestroy( buf ); |
|
162 homeTime.FormatL( ptr, timeFormat ); |
|
163 |
|
164 FLOG( "[OMADM] TUtil::SyncTimeLC time done" ); |
|
165 } |
|
166 else |
|
167 { |
|
168 FLOG( "[OMADM] TUtil::SyncTimeLC date" ); |
|
169 |
|
170 TBuf<KBufSize> dateFormat; |
|
171 HBufC* buf = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
172 TUtil::StrCopy( dateFormat, *buf ); |
|
173 CleanupStack::PopAndDestroy( buf ); |
|
174 homeTime.FormatL(ptr, dateFormat); |
|
175 |
|
176 FLOG( "[OMADM] TUtil::SyncTimeLC date done" ); |
|
177 } |
|
178 FLOG( "[OMADM] TUtil::SyncTimeLC Done" ); |
|
179 return hBuf; |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // ConvertUniversalToHomeTime |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TTime TUtil::ConvertUniversalToHomeTime( const TTime& aUniversalTime ) |
|
187 { |
|
188 TTime time( aUniversalTime ); // time stores UTC time. |
|
189 |
|
190 TLocale locale; |
|
191 TTimeIntervalSeconds universalTimeOffset( locale.UniversalTimeOffset() ); |
|
192 |
|
193 // Add locale's universal time offset to universal time. |
|
194 time += universalTimeOffset; // time stores Local Time. |
|
195 |
|
196 // If home daylight saving in effect, add one hour offset. |
|
197 if ( locale.QueryHomeHasDaylightSavingOn() ) |
|
198 { |
|
199 TTimeIntervalHours daylightSaving(1); |
|
200 time += daylightSaving; |
|
201 } |
|
202 |
|
203 return time; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // IsToDay |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 TBool TUtil::IsToday(TTime aTime) |
|
211 { |
|
212 FLOG( "[OMADM] TUtil::IsToday" ); |
|
213 |
|
214 TTime now; |
|
215 now.HomeTime(); |
|
216 TInt day1 = now.DayNoInYear(); |
|
217 TInt day2 = aTime.DayNoInYear(); |
|
218 TTimeIntervalDays daysBetween = now.DaysFrom( aTime ); |
|
219 |
|
220 if ( day1 != day2 ) |
|
221 { |
|
222 FLOG( "[OMADM] TUtil::IsToday False 1" ); |
|
223 return EFalse; |
|
224 } |
|
225 |
|
226 if ( daysBetween.Int() > 0 ) |
|
227 { |
|
228 FLOG( "[OMADM] TUtil::IsToday False 2" ); |
|
229 return EFalse; |
|
230 } |
|
231 |
|
232 FLOG( "[OMADM] TUtil::IsToday True" ); |
|
233 return ETrue; |
|
234 } |
|
235 |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // TUtil::GetDateTextL |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void TUtil::GetDateTextL(TDes& aText, TTime aDateTime) |
|
242 { |
|
243 TTime homeTime = ConvertUniversalToHomeTime( aDateTime ); |
|
244 HBufC* hBuf = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
245 homeTime.FormatL( aText, *hBuf ); |
|
246 CleanupStack::PopAndDestroy( hBuf ); |
|
247 } |
|
248 |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // TUtil::GetTimeTextL |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void TUtil::GetTimeTextL( TDes& aText, TTime aDateTime ) |
|
255 { |
|
256 TTime homeTime = ConvertUniversalToHomeTime( aDateTime ); |
|
257 HBufC* hBuf = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
258 homeTime.FormatL( aText, *hBuf ); |
|
259 CleanupStack::PopAndDestroy( hBuf ); |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // TUtil::GetDateTimeTextL |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void TUtil::GetDateTimeTextL( TDes& aText, TTime aDateTime ) |
|
268 { |
|
269 TDateTime dt = aDateTime.DateTime(); |
|
270 aText.Format(_L("%02d.%02d.%04d %02d:%02d:%02d"), dt.Day()+1, |
|
271 dt.Month()+1, |
|
272 dt.Year(), |
|
273 dt.Hour(), |
|
274 dt.Minute(), |
|
275 dt.Second() ); |
|
276 } |
|
277 |
|
278 |
|
279 /***************************************************************************** |
|
280 * class TURIParser |
|
281 *****************************************************************************/ |
|
282 |
|
283 // ---------------------------------------------------------------------------- |
|
284 // Constructor |
|
285 // ---------------------------------------------------------------------------- |
|
286 // |
|
287 TURIParser::TURIParser( const TDesC& aStr ) : iOriginalStr( aStr ) |
|
288 { |
|
289 SkipHttp(); |
|
290 } |
|
291 |
|
292 // ---------------------------------------------------------------------------- |
|
293 // GetUriWithoutPort |
|
294 // URI format: "http://serveraddress/documentname/" |
|
295 // ---------------------------------------------------------------------------- |
|
296 // |
|
297 void TURIParser::GetUriWithoutPort( TDes& aText ) |
|
298 { |
|
299 aText = KNullDesC; |
|
300 TPtrC http = ParseHttp(); |
|
301 TPtrC address = ParseAddress(); |
|
302 TPtrC document = ParseDocument(); |
|
303 TUtil::StrAppend( aText, http ); |
|
304 TUtil::StrAppend( aText, address ); |
|
305 |
|
306 if (document.Length() > 0) |
|
307 { |
|
308 TUtil::StrAppend( aText, KSlash ); |
|
309 TUtil::StrAppend( aText, document ); |
|
310 } |
|
311 else if ( iSlash ) |
|
312 { |
|
313 TUtil::StrAppend( aText, KSlash ); |
|
314 } |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------------------------------- |
|
318 // GetURI |
|
319 // URI format: "http://serveraddress:port/documentname/" |
|
320 // ---------------------------------------------------------------------------- |
|
321 // |
|
322 void TURIParser::GetUri( TDes& aText, const TInt aPort ) |
|
323 { |
|
324 aText = KNullDesC; |
|
325 TPtrC http = ParseHttp(); |
|
326 TPtrC address = ParseAddress(); |
|
327 TPtrC document = ParseDocument(); |
|
328 TUtil::StrAppend( aText, http ); |
|
329 TUtil::StrAppend( aText, address ); |
|
330 |
|
331 TBuf<KBufSize32> buf; |
|
332 buf.Num( aPort ); |
|
333 TUtil::StrAppend( aText, KColon ); |
|
334 TUtil::StrAppend( aText, buf ); |
|
335 |
|
336 if ( document.Length() > 0 ) |
|
337 { |
|
338 TUtil::StrAppend( aText, KSlash ); |
|
339 TUtil::StrAppend( aText, document ); |
|
340 } |
|
341 else if ( iSlash ) |
|
342 { |
|
343 TUtil::StrAppend( aText, KSlash ); |
|
344 } |
|
345 } |
|
346 |
|
347 // ---------------------------------------------------------------------------- |
|
348 // Port |
|
349 // ---------------------------------------------------------------------------- |
|
350 // |
|
351 TInt TURIParser::Port() |
|
352 { |
|
353 TInt port = KErrNotFound; |
|
354 |
|
355 TInt err = ParsePort( port ); |
|
356 if ( err != KErrNone ) |
|
357 { |
|
358 return KErrNotFound; |
|
359 } |
|
360 return port; |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------- |
|
364 // DefaultPort |
|
365 // |
|
366 // ---------------------------------------------------------------------------- |
|
367 // |
|
368 TInt TURIParser::DefaultPort() |
|
369 { |
|
370 TInt pos = iOriginalStr.FindF( KHttpsHeader ); |
|
371 if ( pos != KErrNotFound ) |
|
372 { |
|
373 return KDefaultHttpsPort; |
|
374 } |
|
375 return KDefaultHttpPort; |
|
376 } |
|
377 |
|
378 // ---------------------------------------------------------------------------- |
|
379 // SkipHttp |
|
380 // Set pointer to the end of "http://". |
|
381 // ---------------------------------------------------------------------------- |
|
382 // |
|
383 void TURIParser::SkipHttp() |
|
384 { |
|
385 TInt start = KErrNotFound; |
|
386 TInt end = KErrNotFound; |
|
387 TStr str(iOriginalStr); |
|
388 |
|
389 GetHttpPos( start, end ); |
|
390 |
|
391 if ( start != KErrNotFound ) |
|
392 { |
|
393 iPtr.Set( str.Right( end + 1 ) ); |
|
394 } |
|
395 else |
|
396 { |
|
397 iPtr.Set( str.Right(0) ); |
|
398 } |
|
399 } |
|
400 |
|
401 // ---------------------------------------------------------------------------- |
|
402 // ParseHttp |
|
403 // |
|
404 // ---------------------------------------------------------------------------- |
|
405 // |
|
406 TPtrC TURIParser::ParseHttp() |
|
407 { |
|
408 TInt start = KErrNotFound; |
|
409 TInt end = KErrNotFound; |
|
410 |
|
411 GetHttpPos(start, end); |
|
412 |
|
413 if (start == KErrNotFound) |
|
414 { |
|
415 return TPtrC(); |
|
416 } |
|
417 |
|
418 TStr str(iOriginalStr); |
|
419 return str.SubStr(start, end); |
|
420 } |
|
421 |
|
422 // ---------------------------------------------------------------------------- |
|
423 // GetHttpPos |
|
424 // ---------------------------------------------------------------------------- |
|
425 // |
|
426 void TURIParser::GetHttpPos( TInt& aStartPos, TInt& aEndPos ) |
|
427 { |
|
428 aEndPos = KErrNotFound; |
|
429 |
|
430 aStartPos = iOriginalStr.FindF( KHttpHeader ); |
|
431 if ( aStartPos != KErrNotFound ) |
|
432 { |
|
433 aEndPos = aStartPos + KHttpHeader().Length() - 1; |
|
434 return; |
|
435 } |
|
436 |
|
437 aStartPos = iOriginalStr.FindF( KHttpsHeader ); |
|
438 if ( aStartPos != KErrNotFound ) |
|
439 { |
|
440 aEndPos = aStartPos + KHttpsHeader().Length() - 1; |
|
441 return; |
|
442 } |
|
443 } |
|
444 |
|
445 // ---------------------------------------------------------------------------- |
|
446 // ParseAddress |
|
447 // ---------------------------------------------------------------------------- |
|
448 TPtrC TURIParser::ParseAddress() |
|
449 { |
|
450 const TChar KSlash('/'); |
|
451 const TChar KColon(':'); |
|
452 TStr str( iPtr ); |
|
453 TInt firstSlash = str.Find( 0, KSlash ); |
|
454 TInt firstcolon = str.Find( 0, KColon ); |
|
455 TBool portFound = EFalse; |
|
456 iSlash = EFalse; |
|
457 if ( firstSlash != KErrNotFound ) |
|
458 { |
|
459 iSlash = ETrue; |
|
460 } |
|
461 if (firstcolon != KErrNotFound) |
|
462 { |
|
463 if ( firstSlash == KErrNotFound ) |
|
464 { |
|
465 portFound = ETrue; |
|
466 } |
|
467 else if ( firstcolon < firstSlash ) |
|
468 { |
|
469 portFound = ETrue; |
|
470 } |
|
471 } |
|
472 |
|
473 if ( portFound ) |
|
474 { |
|
475 // address is text before first colon |
|
476 return str.Left( firstcolon - 1 ); |
|
477 } |
|
478 else if (firstSlash != KErrNotFound) |
|
479 { |
|
480 // address is text before first slash |
|
481 return str.Left( firstSlash - 1 ); |
|
482 } |
|
483 else |
|
484 { |
|
485 // address is all text |
|
486 return str.Right( 0 ); |
|
487 } |
|
488 } |
|
489 |
|
490 // ---------------------------------------------------------------------------- |
|
491 // ParseDocument |
|
492 // ---------------------------------------------------------------------------- |
|
493 TPtrC TURIParser::ParseDocument() |
|
494 { |
|
495 const TChar KSlash('/'); |
|
496 |
|
497 TStr str(iPtr); |
|
498 TInt firstSlash = str.Find( 0, KSlash ); |
|
499 |
|
500 if ( firstSlash != KErrNotFound ) |
|
501 { |
|
502 // document is all text after first slash |
|
503 return str.Right( firstSlash + 1 ); |
|
504 } |
|
505 return TPtrC(); |
|
506 } |
|
507 |
|
508 // ---------------------------------------------------------------------------- |
|
509 // ParsePort |
|
510 // ---------------------------------------------------------------------------- |
|
511 // |
|
512 TInt TURIParser::ParsePort( TInt& aNumber ) |
|
513 { |
|
514 TPtrC port = ParsePort(); |
|
515 if ( port.Length() == 0 ) |
|
516 { |
|
517 return KErrNotFound; |
|
518 } |
|
519 return TUtil::StrToInt( port, aNumber ); |
|
520 } |
|
521 |
|
522 // ---------------------------------------------------------------------------- |
|
523 // ParsePort |
|
524 // ---------------------------------------------------------------------------- |
|
525 // |
|
526 TPtrC TURIParser::ParsePort() |
|
527 { |
|
528 const TChar KSlash('/'); |
|
529 const TChar KColon(':'); |
|
530 |
|
531 TStr str(iPtr); |
|
532 TInt firstSlash = str.Find( 0, KSlash ); |
|
533 TInt firstColon = str.Find( 0, KColon ); |
|
534 |
|
535 if ( firstSlash != KErrNotFound ) |
|
536 { |
|
537 if ( firstColon != KErrNotFound && firstColon < firstSlash ) |
|
538 { |
|
539 // port number is text between colon and slash |
|
540 return str.SubStrEx( firstColon, firstSlash ); |
|
541 } |
|
542 } |
|
543 else |
|
544 { |
|
545 if ( firstColon != KErrNotFound ) |
|
546 { |
|
547 // port number is all text after colon |
|
548 return str.Right(firstColon+1); |
|
549 } |
|
550 } |
|
551 return TPtrC(); |
|
552 } |
|
553 |
|
554 /***************************************************************************** |
|
555 * class TStr |
|
556 *****************************************************************************/ |
|
557 |
|
558 // ---------------------------------------------------------------------------- |
|
559 // TStr::TStr |
|
560 // C++ default constructor can NOT contain any code, that |
|
561 // might leave. |
|
562 // ---------------------------------------------------------------------------- |
|
563 // |
|
564 TStr::TStr( const TDesC& aStr ) : iStr( aStr ) |
|
565 { |
|
566 } |
|
567 |
|
568 // ---------------------------------------------------------------------------- |
|
569 // TStr::Mid |
|
570 // ---------------------------------------------------------------------------- |
|
571 // |
|
572 TPtrC TStr::Mid( TInt aPos ) |
|
573 { |
|
574 if ( ( aPos < 0 ) || ( aPos >= iStr.Length() ) ) |
|
575 { |
|
576 return TPtrC(); // return empty descriptor |
|
577 } |
|
578 return iStr.Mid( aPos ); |
|
579 } |
|
580 |
|
581 // ---------------------------------------------------------------------------- |
|
582 // TStr::Mid |
|
583 // ---------------------------------------------------------------------------- |
|
584 // |
|
585 TPtrC TStr::Mid( TInt aPos, TInt aLen ) |
|
586 { |
|
587 TInt len = iStr.Length(); |
|
588 if ( ( aPos < 0 ) || ( aPos >= len ) ) |
|
589 { |
|
590 return TPtrC(); |
|
591 } |
|
592 if ( ( aLen <= 0 ) || ( aPos + aLen > len ) ) |
|
593 { |
|
594 return TPtrC(); |
|
595 } |
|
596 |
|
597 return iStr.Mid( aPos, aLen ); |
|
598 } |
|
599 |
|
600 // ---------------------------------------------------------------------------- |
|
601 // TStr::Right |
|
602 // ---------------------------------------------------------------------------- |
|
603 // |
|
604 TPtrC TStr::Right( TInt aPos ) |
|
605 { |
|
606 return Mid( aPos ); |
|
607 } |
|
608 |
|
609 // ---------------------------------------------------------------------------- |
|
610 // TStr::Left |
|
611 // ---------------------------------------------------------------------------- |
|
612 // |
|
613 TPtrC TStr::Left( TInt aPos ) |
|
614 { |
|
615 TInt len = iStr.Length(); |
|
616 |
|
617 if ( ( aPos < 0 ) || ( len == 0 ) ) |
|
618 { |
|
619 return TPtrC(); |
|
620 } |
|
621 |
|
622 TInt pos = len; |
|
623 if ( ( aPos + 1 ) < len ) |
|
624 { |
|
625 pos = aPos + 1; |
|
626 } |
|
627 |
|
628 return iStr.Left( pos ); |
|
629 } |
|
630 |
|
631 // ---------------------------------------------------------------------------- |
|
632 // TStr::SubStr |
|
633 // ---------------------------------------------------------------------------- |
|
634 // |
|
635 TPtrC TStr::SubStr( TInt aStartPos, TInt aEndPos ) |
|
636 { |
|
637 return Mid( aStartPos, aEndPos - aStartPos + 1 ); |
|
638 } |
|
639 |
|
640 // ---------------------------------------------------------------------------- |
|
641 // TStr::SubStrEx |
|
642 // ---------------------------------------------------------------------------- |
|
643 // |
|
644 TPtrC TStr::SubStrEx( TInt aStartPos, TInt aEndPos ) |
|
645 { |
|
646 return Mid( aStartPos + 1, aEndPos - aStartPos - 1 ); |
|
647 } |
|
648 |
|
649 // ---------------------------------------------------------------------------- |
|
650 // TStr::LastPos |
|
651 // ---------------------------------------------------------------------------- |
|
652 // |
|
653 TInt TStr::LastPos() |
|
654 { |
|
655 return iStr.Length() - 1; |
|
656 } |
|
657 |
|
658 // ---------------------------------------------------------------------------- |
|
659 // TStr::Len |
|
660 // ---------------------------------------------------------------------------- |
|
661 // |
|
662 TInt TStr::Len() |
|
663 { |
|
664 return iStr.Length(); |
|
665 } |
|
666 |
|
667 // ---------------------------------------------------------------------------- |
|
668 // TStr::Compare |
|
669 // ---------------------------------------------------------------------------- |
|
670 // |
|
671 TBool TStr::Compare( TInt aPos, TChar aChar ) |
|
672 { |
|
673 TInt len = iStr.Length(); |
|
674 if ( ( aPos < 0) || ( aPos >= len ) ) |
|
675 { |
|
676 return EFalse; |
|
677 } |
|
678 TChar ch = iStr[aPos]; |
|
679 if ( ch == aChar ) |
|
680 { |
|
681 return ETrue; |
|
682 } |
|
683 return EFalse; |
|
684 } |
|
685 |
|
686 // ---------------------------------------------------------------------------- |
|
687 // TStr::Find |
|
688 // ---------------------------------------------------------------------------- |
|
689 // |
|
690 TInt TStr::Find(TInt aPos, TChar aChar) |
|
691 { |
|
692 TInt len = iStr.Length(); |
|
693 if ( (aPos < 0) || (aPos >= len) ) |
|
694 { |
|
695 return KErrNotFound; |
|
696 } |
|
697 |
|
698 TPtrC ptr(iStr.Mid(aPos)); // move to possition aPos |
|
699 return ptr.Locate(aChar); |
|
700 } |
|
701 |
|
702 //***************************************************************************** |
|
703 //* class CIAUpdateFWActiveCaller |
|
704 //***************************************************************************** |
|
705 |
|
706 // ---------------------------------------------------------------------------- |
|
707 // CIAUpdateFWActiveCaller::NewL |
|
708 // ---------------------------------------------------------------------------- |
|
709 // |
|
710 CIAUpdateFWActiveCaller* CIAUpdateFWActiveCaller::NewL( |
|
711 MIAUpdateFWActiveCallerObserver* aObserver ) |
|
712 { |
|
713 CIAUpdateFWActiveCaller* self = new(ELeave) CIAUpdateFWActiveCaller( aObserver ); |
|
714 CleanupStack::PushL(self); |
|
715 self->ConstructL(); |
|
716 CleanupStack::Pop(self); |
|
717 |
|
718 return self; |
|
719 } |
|
720 |
|
721 // ---------------------------------------------------------------------------- |
|
722 // Destructor |
|
723 // ---------------------------------------------------------------------------- |
|
724 // |
|
725 CIAUpdateFWActiveCaller::~CIAUpdateFWActiveCaller() |
|
726 { |
|
727 Cancel(); |
|
728 iTimer.Close(); |
|
729 } |
|
730 |
|
731 // ---------------------------------------------------------------------------- |
|
732 // CIAUpdateFWActiveCaller::CIAUpdateFWActiveCaller |
|
733 // ---------------------------------------------------------------------------- |
|
734 // |
|
735 CIAUpdateFWActiveCaller::CIAUpdateFWActiveCaller( |
|
736 MIAUpdateFWActiveCallerObserver* aObserver ) |
|
737 : CActive(CActive::EPriorityStandard ) |
|
738 { |
|
739 iObserver = aObserver; |
|
740 } |
|
741 |
|
742 // ---------------------------------------------------------------------------- |
|
743 // CIAUpdateFWActiveCaller::ConstructL |
|
744 // ---------------------------------------------------------------------------- |
|
745 // |
|
746 void CIAUpdateFWActiveCaller::ConstructL() |
|
747 { |
|
748 User::LeaveIfError(iTimer.CreateLocal()); |
|
749 CActiveScheduler::Add(this); |
|
750 } |
|
751 |
|
752 // ---------------------------------------------------------------------------- |
|
753 // CIAUpdateFWActiveCaller::DoCancel |
|
754 // ---------------------------------------------------------------------------- |
|
755 // |
|
756 void CIAUpdateFWActiveCaller::DoCancel() |
|
757 { |
|
758 iTimer.Cancel(); |
|
759 } |
|
760 |
|
761 // ---------------------------------------------------------------------------- |
|
762 // CIAUpdateFWActiveCaller::RunL |
|
763 // ---------------------------------------------------------------------------- |
|
764 // |
|
765 void CIAUpdateFWActiveCaller::RunL() |
|
766 { |
|
767 iObserver->HandleActiveCallL( ); |
|
768 } |
|
769 |
|
770 // ---------------------------------------------------------------------------- |
|
771 // CIAUpdateFWActiveCaller::RunError |
|
772 // ---------------------------------------------------------------------------- |
|
773 // |
|
774 TInt CIAUpdateFWActiveCaller::RunError( TInt /*aError*/ ) |
|
775 { |
|
776 return KErrNone; |
|
777 } |
|
778 |
|
779 // ---------------------------------------------------------------------------- |
|
780 // CIAUpdateFWActiveCaller::CompleteSelf |
|
781 // |
|
782 // This function calls this class RunL. |
|
783 // ---------------------------------------------------------------------------- |
|
784 // |
|
785 void CIAUpdateFWActiveCaller::CompleteSelf() |
|
786 { |
|
787 SetActive(); |
|
788 TRequestStatus* status = &iStatus; |
|
789 User::RequestComplete( status, KErrNone ); |
|
790 } |
|
791 |
|
792 // ---------------------------------------------------------------------------- |
|
793 // CIAUpdateFWActiveCaller::Start |
|
794 // ---------------------------------------------------------------------------- |
|
795 // |
|
796 void CIAUpdateFWActiveCaller::Start( TInt aCallId, TInt aMilliseconds ) |
|
797 { |
|
798 if (IsActive()) |
|
799 { |
|
800 return; |
|
801 } |
|
802 |
|
803 iCallId = aCallId; |
|
804 |
|
805 if (aMilliseconds <= 0) |
|
806 { |
|
807 CompleteSelf(); // no delay - complete right away |
|
808 } |
|
809 else |
|
810 { |
|
811 iTimer.After( iStatus, aMilliseconds*1000 ); |
|
812 SetActive(); |
|
813 } |
|
814 } |
|
815 |
|
816 // End of File |