|
1 /* |
|
2 * Copyright (c) 2007-2007 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: CCFDelay class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cfdelay.h" |
|
22 #include "cfbasicoptrace.h" |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 //----------------------------------------------------------------------------- |
|
28 // CCFDelay::CCFDelay |
|
29 // Delayed evaluation should be as exact as possible. Set high priority. |
|
30 //----------------------------------------------------------------------------- |
|
31 // |
|
32 CCFDelay::CCFDelay( MCFDelayExpired& aDelayer ) |
|
33 : CTimer( EPriorityHigh ), |
|
34 iDelayer( aDelayer ) |
|
35 { |
|
36 FUNC_LOG; |
|
37 } |
|
38 |
|
39 //----------------------------------------------------------------------------- |
|
40 // CCFDelay::ConstructL |
|
41 //----------------------------------------------------------------------------- |
|
42 // |
|
43 void CCFDelay::ConstructL() |
|
44 { |
|
45 FUNC_LOG; |
|
46 |
|
47 // Construct ctimer |
|
48 CTimer::ConstructL(); |
|
49 |
|
50 // Add into active scheduler if not already added |
|
51 if( !IsAdded() ) |
|
52 { |
|
53 CActiveScheduler::Add( this ); |
|
54 } |
|
55 } |
|
56 |
|
57 //----------------------------------------------------------------------------- |
|
58 // CCFDelay::NewL |
|
59 //----------------------------------------------------------------------------- |
|
60 // |
|
61 CCFDelay* CCFDelay::NewL( MCFDelayExpired& aDelayer ) |
|
62 { |
|
63 FUNC_LOG; |
|
64 |
|
65 CCFDelay* self = CCFDelay::NewLC( aDelayer ); |
|
66 CleanupStack::Pop( self ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 //----------------------------------------------------------------------------- |
|
71 // CCFDelay::NewLC |
|
72 //----------------------------------------------------------------------------- |
|
73 // |
|
74 CCFDelay* CCFDelay::NewLC( MCFDelayExpired& aDelayer ) |
|
75 { |
|
76 FUNC_LOG; |
|
77 |
|
78 CCFDelay* self = new( ELeave ) CCFDelay( aDelayer ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // Destructor |
|
85 CCFDelay::~CCFDelay() |
|
86 { |
|
87 FUNC_LOG; |
|
88 |
|
89 Cancel(); |
|
90 } |
|
91 |
|
92 |
|
93 //----------------------------------------------------------------------------- |
|
94 // CCFDelay::Delay |
|
95 //----------------------------------------------------------------------------- |
|
96 // |
|
97 void CCFDelay::Delay( const TTimeIntervalMicroSeconds32& aDelay ) |
|
98 { |
|
99 FUNC_LOG; |
|
100 |
|
101 TBool startDelay = ETrue; |
|
102 if ( IsActive() ) |
|
103 { |
|
104 TTime currentTime; |
|
105 currentTime.HomeTime(); |
|
106 TInt64 elapsedTime = currentTime.Int64() - iDelayStartTime.Int64(); |
|
107 if ( aDelay.Int() < ( iDelay - elapsedTime ) ) |
|
108 { |
|
109 startDelay = EFalse; // Current delay outlasts the new one |
|
110 } |
|
111 } |
|
112 |
|
113 if ( startDelay ) |
|
114 { |
|
115 Cancel(); // Cancel ongoing timer if any |
|
116 |
|
117 iDelay = aDelay.Int(); |
|
118 iDelayStartTime.HomeTime(); |
|
119 After( aDelay ); // Start delay |
|
120 } |
|
121 } |
|
122 |
|
123 //----------------------------------------------------------------------------- |
|
124 // CCFDelay::RunL |
|
125 //----------------------------------------------------------------------------- |
|
126 // |
|
127 void CCFDelay::RunL() |
|
128 { |
|
129 FUNC_LOG; |
|
130 |
|
131 iDelayer.ExpiredL(); |
|
132 } |
|
133 |
|
134 //----------------------------------------------------------------------------- |
|
135 // CCFDelay::RunError |
|
136 //----------------------------------------------------------------------------- |
|
137 // |
|
138 #ifndef ERROR_TRACE |
|
139 TInt CCFDelay::RunError( TInt /*aError*/ ) |
|
140 #else // ERROR_TRACE defined |
|
141 TInt CCFDelay::RunError( TInt aError ) |
|
142 #endif |
|
143 { |
|
144 FUNC_LOG; |
|
145 |
|
146 ERROR( aError, "Call MCFDelayExpired::ExpiredL() leave code: %d (skipped)" ); |
|
147 |
|
148 return KErrNone; // Ignore errors |
|
149 } |