|
1 /* |
|
2 * Copyright (c) 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: Haptics generic timer class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "hwrmhapticsgenerictimer.h" |
|
21 #include "hwrmhapticstrace.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CHWRMHapticsGenericTimer::NewL |
|
27 // Two-phased constructor. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CHWRMHapticsGenericTimer* CHWRMHapticsGenericTimer::NewL( |
|
31 MHWRMHapticsGenericTimerCallback* aCallback, |
|
32 const TTimeIntervalMicroSeconds32& aMaxTime, |
|
33 TInt aTimerId ) |
|
34 { |
|
35 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::NewL(0x%x, 0x%x, 0x%x)" ), aCallback, aMaxTime.Int(), aTimerId ) ); |
|
36 |
|
37 CHWRMHapticsGenericTimer* self = new ( ELeave ) CHWRMHapticsGenericTimer( |
|
38 aCallback, |
|
39 aMaxTime, |
|
40 aTimerId ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); //base call |
|
43 CleanupStack::Pop( self ); |
|
44 |
|
45 CActiveScheduler::Add( self ); |
|
46 |
|
47 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::NewL - return 0x%x" ), self ) ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CHWRMHapticsGenericTimer::CHWRMHapticsGenericTimer |
|
53 // Constructor with callback class as a parameter. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CHWRMHapticsGenericTimer::CHWRMHapticsGenericTimer( |
|
57 MHWRMHapticsGenericTimerCallback* aCallback, |
|
58 const TTimeIntervalMicroSeconds32& aMaxTime, |
|
59 TInt aTimerId ) |
|
60 : CTimer( EPriorityHigh ), |
|
61 iCallback( aCallback ), |
|
62 iMaximumTime( aMaxTime ), |
|
63 iCutOff( EFalse ), |
|
64 iTimerId( aTimerId ) |
|
65 { |
|
66 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::CHWRMHapticsGenericTimer(0x%x, 0x%x)" ), aCallback, aMaxTime.Int() ) ); |
|
67 |
|
68 __ASSERT_ALWAYS( aCallback, User::Invariant() ); |
|
69 |
|
70 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::CHWRMHapticsGenericTimer - return" ) ) ); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CHWRMHapticsGenericTimer::~CHWRMHapticsGenericTimer |
|
75 // Destructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CHWRMHapticsGenericTimer::~CHWRMHapticsGenericTimer() |
|
79 { |
|
80 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::~CHWRMHapticsGenericTimer()" ) ) ); |
|
81 |
|
82 iCallback = NULL; |
|
83 |
|
84 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::~CHWRMHapticsGenericTimer - return" ) ) ); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CHWRMHapticsGenericTimer::Set |
|
89 // Start the timer to complete after the specified number of microseconds. |
|
90 // If the duration is zero, then timer is set to predefined maximum value. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CHWRMHapticsGenericTimer::Set(const TTimeIntervalMicroSeconds32& aInterval) |
|
94 { |
|
95 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::Set(%d)" ), aInterval.Int() ) ); |
|
96 |
|
97 __ASSERT_ALWAYS( CActiveScheduler::Current(), User::Invariant() ); |
|
98 |
|
99 if ( IsActive() ) |
|
100 { |
|
101 Cancel(); |
|
102 } |
|
103 |
|
104 // And set the new timer. If timer has specified maximum time, enforce that. |
|
105 TTime now; |
|
106 now.UniversalTime(); |
|
107 |
|
108 if ( iMaximumTime.Int() != 0 && ( 0 == aInterval.Int() || aInterval > iMaximumTime ) ) |
|
109 { |
|
110 // Maximum time has been specified, and interval parameter is such that |
|
111 // it should be enforced |
|
112 iActivationTime = now + iMaximumTime; |
|
113 |
|
114 After( iMaximumTime ); |
|
115 |
|
116 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::Set - Using Maximum time %d" ), iMaximumTime.Int() ) ); |
|
117 iCutOff = ETrue; |
|
118 } |
|
119 else if ( iMaximumTime.Int() == 0 && aInterval.Int() == 0 ) |
|
120 { |
|
121 // No maximum time specified and interval calls for infinite duration. |
|
122 // --> Do not set the timer at all. |
|
123 } |
|
124 else |
|
125 { |
|
126 // Otherwise just set the time to specified interval. |
|
127 iActivationTime = now + aInterval; |
|
128 After( aInterval ); |
|
129 iCutOff = EFalse; |
|
130 } |
|
131 |
|
132 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::Set - return" ) ) ); |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CHWRMHapticsGenericTimer::Freeze |
|
137 // Stop timer and returns the remaining time |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TTimeIntervalMicroSeconds32 CHWRMHapticsGenericTimer::Freeze() |
|
141 { |
|
142 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::Freeze()" ) ) ); |
|
143 |
|
144 // Must use 64 bit version as no way to get TTimeIntervalMicroSeconds32 from TTime. |
|
145 TTimeIntervalMicroSeconds frozenTime = 0LL; |
|
146 |
|
147 if ( IsAdded() && IsActive() ) |
|
148 { |
|
149 Cancel(); |
|
150 |
|
151 TTime now; |
|
152 now.UniversalTime(); |
|
153 frozenTime = iActivationTime.MicroSecondsFrom( now ); |
|
154 if ( frozenTime.Int64() <= 0 ) |
|
155 { |
|
156 // Should have activated by now, set freeze timer to 1 for instant activation |
|
157 // after unfreeze. |
|
158 frozenTime = 1LL; |
|
159 } |
|
160 } |
|
161 |
|
162 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::Freeze - return %d" ), frozenTime.Int64() ) ); |
|
163 |
|
164 // Loss of precision ok, as frozentime never exceeds 32 bits. |
|
165 return frozenTime.Int64(); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CHWRMHapticsGenericTimer::RunL |
|
170 // RunL() function will be run after the specified system time expires, |
|
171 // i.e. time is set by After() method, |
|
172 // ----------------------------------------------------------------------------- |
|
173 void CHWRMHapticsGenericTimer::RunL() |
|
174 { |
|
175 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::RunL()" ) ) ); |
|
176 |
|
177 __ASSERT_ALWAYS( iCallback, User::Invariant() ); |
|
178 |
|
179 iCallback->GenericTimerFired( iTimerId, iCutOff ); |
|
180 |
|
181 COMPONENT_TRACE( ( _L( "HWRMHaptics Server - CHWRMHapticsGenericTimer::RunL - return" ) ) ); |
|
182 } |
|
183 |
|
184 // End of File |