|
1 /* |
|
2 * Copyright (c) 2006-2009 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 /** |
|
22 @file |
|
23 @internalTechnology |
|
24 */ |
|
25 |
|
26 #ifndef HWRMVIBRASERVICE_H |
|
27 #define HWRMVIBRASERVICE_H |
|
28 |
|
29 // INCLUDES |
|
30 #include <e32base.h> |
|
31 #include "HWRMGenericTimer.h" |
|
32 #include "HWRMVibraCommands.h" |
|
33 #include "HWRMVibra.h" |
|
34 #include "HWRMService.h" |
|
35 #include "HWRMVibraCommonService.h" |
|
36 #include "HWRMVibraCommonData.h" |
|
37 // CONSTANTS |
|
38 // None |
|
39 |
|
40 // MACROS |
|
41 // None |
|
42 |
|
43 // DATA TYPES |
|
44 // None |
|
45 |
|
46 // FUNCTION PROTOTYPES |
|
47 // None |
|
48 |
|
49 // FORWARD DECLARATIONS |
|
50 class CHWRMVibraCommonData; |
|
51 class CHWRMPluginHandler; |
|
52 class CHWRMReservationHandler; |
|
53 |
|
54 // CLASS DECLARATION |
|
55 |
|
56 /** |
|
57 * Hardware Resource Manager server side service object for Vibra sessions. |
|
58 * |
|
59 */ |
|
60 class CHWRMVibraService : public CHWRMService, |
|
61 public MHWRMGenericTimerCallback |
|
62 { |
|
63 public: // Constructors and Destructor |
|
64 |
|
65 /** |
|
66 * Two-phased constructor. |
|
67 * |
|
68 * @param aPluginHandler The plugin handler to use with this service. |
|
69 * @param aReservationHandler The reservation handler to use with this service. |
|
70 * @param aVibraCommonData Reference to vibra common data |
|
71 * @param aPrivilegedClient If ETrue the client of this service is privileged |
|
72 * i.e. ignores vibra profile setting checks |
|
73 */ |
|
74 static CHWRMVibraService* NewL(CHWRMPluginHandler* aPluginHandler, |
|
75 CHWRMReservationHandler* aReservationHandler, |
|
76 CHWRMVibraCommonService& aCommonService, |
|
77 CHWRMVibraCommonData& aVibraCommonData, |
|
78 TBool aPrivilegedClient); |
|
79 |
|
80 /** |
|
81 * Destructor. |
|
82 */ |
|
83 virtual ~CHWRMVibraService(); |
|
84 |
|
85 /** |
|
86 * Forces vibra to stop immediately, regardless of reservations. |
|
87 */ |
|
88 void ForceVibraStop(); |
|
89 |
|
90 /** |
|
91 * Checks if it is ok to stop vibra from another session based on what this |
|
92 * session desires for the state to be. |
|
93 * |
|
94 * @return ETrue if ok to stop vibra |
|
95 */ |
|
96 TBool OkToStopVibra(); |
|
97 |
|
98 public: // Base class methods |
|
99 |
|
100 // From CHWRMService |
|
101 virtual TBool ExecuteMessageL(const RMessage2& aMessage); |
|
102 virtual void ProcessResponseL( TInt aCommandId, TUint8 aTransId, TDesC8& aData, TBool aTimeout ); |
|
103 virtual void SuspendSubResource(TInt aSubResource); |
|
104 virtual void ResumeSubResource(TInt aSubResource); |
|
105 virtual void ActivateSubResource(TInt aSubResource, TBool aActivate); |
|
106 |
|
107 // From MHWRMGenericTimerCallback |
|
108 virtual void GenericTimerFired(TInt aTimerId, TBool aCutOff); |
|
109 |
|
110 private: |
|
111 |
|
112 /** |
|
113 * C++ default constructor. |
|
114 */ |
|
115 CHWRMVibraService(CHWRMVibraCommonService& aCommonService, |
|
116 CHWRMVibraCommonData& aVibraCommonData, TBool aPrivilegedClient); |
|
117 |
|
118 |
|
119 /** |
|
120 * By default Symbian 2nd phase constructor is private. |
|
121 */ |
|
122 void ConstructL(CHWRMPluginHandler* aPluginHandler, |
|
123 CHWRMReservationHandler* aReservationHandler); |
|
124 |
|
125 /** |
|
126 * Instructs plugin API to start vibra with specified intensity |
|
127 * |
|
128 * @param aDuration Duration for which the vibra is to be turned on. |
|
129 * @param aIntensity Intensity of the vibra in decimal is -100 to 100, |
|
130 * which shows the percentage of the vibra motor full |
|
131 * rotation speed. When intensity is negative, |
|
132 * the vibra motor rotates in the negative direction. |
|
133 * When intensity is positive, the vibra motor rotates |
|
134 * in the positive direction. Value 0 stops the vibra. |
|
135 * NOTE: The device might have hardware imposed limits |
|
136 * on supported vibra intensity values, so actual |
|
137 * effect might vary between different hardware. |
|
138 * NOTE2: Special value KUseDefaultIntensity (defined |
|
139 * in HWRMVibraService.cpp) can be used to |
|
140 * indicate that default intensity is to be used. |
|
141 * @param aMessage Message related to request. Can have NULL handle for |
|
142 * restore/release/cleanup related requests. |
|
143 * @param aSetTimer If ETrue, call needs to set the timer. Some types of |
|
144 * calls such as restoring last state should not reset |
|
145 * timer should use EFalse. |
|
146 * @param aPulse If ETrue, vibra pulse is requested and new timer for |
|
147 * stopping this request must be created. Original vibra |
|
148 * timer is left always intact, when this parameter ETrue. |
|
149 */ |
|
150 void StartVibraL(const TTimeIntervalMicroSeconds32& aDuration, |
|
151 TInt aIntensity, |
|
152 const RMessage2& aMessage, |
|
153 TBool aSetTimer = ETrue, |
|
154 TBool aPulse = EFalse); |
|
155 |
|
156 /** |
|
157 * Instructs plugin API to pulse vibra with specified intensity and duration |
|
158 * |
|
159 * @param aDuration Duration for which the vibra is to be turned on. |
|
160 * @param aIntensity Intensity of the vibra in decimal is -100 to 100, |
|
161 * which shows the percentage of the vibra motor full |
|
162 * rotation speed. When intensity is negative, |
|
163 * the vibra motor rotates in the negative direction. |
|
164 * When intensity is positive, the vibra motor rotates |
|
165 * in the positive direction. Value 0 stops the vibra. |
|
166 * NOTE: The device might have hardware imposed limits |
|
167 * on supported vibra intensity values, so actual |
|
168 * effect might vary between different hardware. |
|
169 * NOTE2: Special value KUseDefaultIntensity (defined |
|
170 * in HWRMVibraService.cpp) can be used to |
|
171 * indicate that default intensity is to be used. |
|
172 * @param aMessage Message related to request. Can have NULL handle for |
|
173 * restore/release/cleanup related requests. |
|
174 * @param aSetTimer If ETrue, call needs to set the timer. Some types of |
|
175 * calls such as restoring last state should not reset |
|
176 * timer should use EFalse. |
|
177 */ |
|
178 void PulseVibraL(const TTimeIntervalMicroSeconds32& aDuration, |
|
179 TInt aIntensity, |
|
180 const RMessage2& aMessage, |
|
181 TBool aSetTimer = EFalse); |
|
182 |
|
183 |
|
184 |
|
185 /** |
|
186 * Interrupts the device vibration that is started with the StartVibra |
|
187 * method immediately. |
|
188 * @param aMessage Message related to request. Can have NULL handle for |
|
189 * timer initiated requests |
|
190 * @param aForceStop If ETrue, stop is forced regardless of reservation |
|
191 * status. |
|
192 * @param aFinalStop If ETrue, indicates that this is final stop by |
|
193 * destructor and it doesn't require callback. |
|
194 */ |
|
195 void StopVibraL(const RMessage2& aMessage, |
|
196 TBool aForceStop=EFalse, |
|
197 TBool aFinalStop=EFalse); |
|
198 |
|
199 /** |
|
200 * Changes the device vibration intensity to previous active intensity |
|
201 */ |
|
202 void ChangeVibraIntensityL(); |
|
203 |
|
204 /** |
|
205 * Cleans up the vibra state |
|
206 */ |
|
207 void CleanupVibra(); |
|
208 |
|
209 /** |
|
210 * Cleans up buffered vibra pulse data objects |
|
211 */ |
|
212 void ReleasePulseData(); |
|
213 |
|
214 /** |
|
215 * Checks whether vibra pulse should be blocked |
|
216 */ |
|
217 TBool VibraPulseBlocked(); |
|
218 |
|
219 private: // class |
|
220 |
|
221 /** |
|
222 * Embedded class to contain pulse timer objects |
|
223 * and associated intensities for timer period. |
|
224 */ |
|
225 class CPulseData : public CBase |
|
226 { |
|
227 public: // Constructors and destructor |
|
228 |
|
229 /** |
|
230 * Two-phased constructor. |
|
231 * |
|
232 * @param aVibraTimer Vibra pulse timer |
|
233 * @param aLastIntensity Last "suspended" intensity |
|
234 * @param aIntensity Intensity of this pulse request |
|
235 * @param aLastTimerId Last activated timer id |
|
236 */ |
|
237 static CPulseData* NewL( CHWRMGenericTimer& aVibraTimer, |
|
238 const TInt aLastIntensity, |
|
239 const TInt aIntensity, |
|
240 const TInt aLastTimerId ); |
|
241 |
|
242 /** |
|
243 * Destructor. |
|
244 */ |
|
245 virtual ~CPulseData(); |
|
246 |
|
247 public: // New functions |
|
248 |
|
249 /** |
|
250 * Method to return the last intensity |
|
251 * |
|
252 * @return Last intensity |
|
253 */ |
|
254 CHWRMGenericTimer& Timer() const; |
|
255 |
|
256 /** |
|
257 * Method to return the last intensity |
|
258 * |
|
259 * @return Last intensity |
|
260 */ |
|
261 TInt LastIntensity() const; |
|
262 |
|
263 /** |
|
264 * Method to return this requests's intensity |
|
265 * |
|
266 * @return Intensity |
|
267 */ |
|
268 TInt Intensity() const; |
|
269 |
|
270 /** |
|
271 * Method to set last intensity |
|
272 * |
|
273 */ |
|
274 void SetLastIntensity(TInt aIntensity); |
|
275 |
|
276 /** |
|
277 * Method to return last timer id |
|
278 * |
|
279 * @return Timer id |
|
280 */ |
|
281 TInt LastTimerId() const; |
|
282 |
|
283 /** |
|
284 * Method to set last timer id |
|
285 * |
|
286 */ |
|
287 void SetLastTimerId(TInt aTimerId); |
|
288 |
|
289 private: // New functions |
|
290 |
|
291 /** |
|
292 * C++ constructor. |
|
293 */ |
|
294 CPulseData( CHWRMGenericTimer& aVibraTimer, |
|
295 const TInt aLastIntensity, |
|
296 const TInt aIntensity, |
|
297 const TInt aLastTimerId ); |
|
298 |
|
299 private: // Data |
|
300 |
|
301 CHWRMGenericTimer& iVibraTimer; // Timer |
|
302 TInt iLastIntensity; // Vibra intensity, when this pulse timer started |
|
303 TInt iIntensity; // Vibra intensity of this pulse request |
|
304 TInt iLastTimerId; // Timer id, which was active when pulse requested |
|
305 }; |
|
306 |
|
307 |
|
308 /** |
|
309 * Cleans up the vibra state |
|
310 */ |
|
311 //void CleanupVibra(); |
|
312 |
|
313 private: // data |
|
314 |
|
315 CHWRMVibraCommonData& iVibraCommonData; // Pointer to vibra data object common to all sessions. Not owned. |
|
316 CHWRMGenericTimer* iVibraTimer; // Cutoff timer. Owned. |
|
317 |
|
318 TBool iSuspended; // Flag to indicate if this session is suspended. |
|
319 CHWRMVibra::TVibraStatus iLastStatus; // Indicates what state vibra should be on. |
|
320 TInt iLastIntensity; // Indicates what intensity vibra should have (if status is on) |
|
321 |
|
322 CHWRMVibra::TVibraStatus iFrozenStatus; // Vibra status frozen at last release. |
|
323 TInt iFrozenIntensity; // Vibra intensity frozen at last release. |
|
324 TTimeIntervalMicroSeconds32 iFrozenTime; // Remaining vibra timer duration at last release. |
|
325 |
|
326 TBool iReserved; // Flag to indicate if this session is reserved. |
|
327 TBool iPrivilegedClient; // Flag to indicate if this session client is privileged |
|
328 |
|
329 TBool iCleanupDone; // Flag to indicate if cleanup has been done. |
|
330 TBool iStateSetAfterReservation; // Flag to indicate that state has changed after reservation. |
|
331 // This is set to EFalse when reservation is activated. |
|
332 CHWRMVibraCommonService& iCommonService; // Common vibra service for all sessions |
|
333 RPointerArray<CPulseData> iPulseData; // Pulse objects holding timers and associated intensities |
|
334 TSecureId iSid; // SID of vibra using client. |
|
335 TInt iActiveTimerId; // Id of active timer |
|
336 |
|
337 }; |
|
338 |
|
339 #endif // HWRMVIBRASERVICE_H |
|
340 |
|
341 // End of File |