|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Expire Timer class definition file |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file ExpireTimer.cpp |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #include "ExpireTimer.h" |
|
24 |
|
25 CExpireTimer* CExpireTimer::NewL() |
|
26 /** |
|
27 * Create an instance of the timer |
|
28 * |
|
29 * @internalTechnology |
|
30 */ |
|
31 { |
|
32 CExpireTimer* timer = new(ELeave)CExpireTimer(); |
|
33 CleanupStack::PushL(timer); |
|
34 timer->ConstructL(); |
|
35 CleanupStack::Pop(timer); |
|
36 return timer; |
|
37 } |
|
38 |
|
39 void CExpireTimer::After(TTimeIntervalMicroSeconds32 aSeconds,MExpireTimer& aExpireTimer) |
|
40 { |
|
41 ASSERT(!IsAdded()); |
|
42 CActiveScheduler::Add(this); |
|
43 iExpireTimer = &aExpireTimer; |
|
44 iExpirationTime.HomeTime(); |
|
45 iExpirationTime += aSeconds; |
|
46 CTimer::After( aSeconds ); |
|
47 } |
|
48 |
|
49 void CExpireTimer::After(TTimeIntervalSeconds aSeconds, MExpireTimer& aExpireTimer) |
|
50 { |
|
51 ASSERT(!IsAdded()); |
|
52 CActiveScheduler::Add(this); |
|
53 iExpireTimer = &aExpireTimer; |
|
54 TTime time; |
|
55 time.HomeTime(); |
|
56 time+=aSeconds; |
|
57 iExpirationTime = time; |
|
58 CTimer::At(time); |
|
59 } |
|
60 |
|
61 void CExpireTimer::At(TTime aTime, MExpireTimer& aExpireTimer) |
|
62 { |
|
63 ASSERT(!IsAdded()); |
|
64 CActiveScheduler::Add(this); |
|
65 iExpireTimer = &aExpireTimer; |
|
66 TTime now; |
|
67 now.HomeTime(); |
|
68 if (now > aTime) |
|
69 aTime = now + static_cast<TTimeIntervalSeconds>(5); |
|
70 iExpirationTime = aTime; |
|
71 CTimer::At(aTime); |
|
72 } |
|
73 |
|
74 |
|
75 void CExpireTimer::Cancel() |
|
76 /** |
|
77 * Cancel the timer |
|
78 * |
|
79 * @internalTechnology |
|
80 */ |
|
81 { |
|
82 CTimer::DoCancel(); |
|
83 if (IsAdded()) |
|
84 { |
|
85 Deque(); |
|
86 } |
|
87 } |
|
88 |
|
89 CExpireTimer::~CExpireTimer() |
|
90 /** |
|
91 * Timer destructor |
|
92 * |
|
93 * @internalTechnology |
|
94 */ |
|
95 { |
|
96 Cancel(); |
|
97 } |
|
98 |
|
99 void CExpireTimer::RunL() |
|
100 /** |
|
101 * RunL function alerts the notification |
|
102 * object by calling its TimerExpired interface function |
|
103 * |
|
104 * @internalTechnology |
|
105 */ |
|
106 { |
|
107 ASSERT(iExpireTimer); |
|
108 if (iStatus == KErrAbort) |
|
109 { |
|
110 //Deal with system time change. |
|
111 TTime now; |
|
112 now.HomeTime(); |
|
113 |
|
114 //If its not going to expire in the next five seconds reset it |
|
115 if (now < iExpirationTime + static_cast<TTimeIntervalSeconds>(5)) |
|
116 { |
|
117 CTimer::At(iExpirationTime); |
|
118 return; |
|
119 } |
|
120 } |
|
121 |
|
122 Deque(); |
|
123 iExpireTimer->TimerExpired(); |
|
124 } |
|
125 |
|
126 |