|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "HWRMServer.h" |
|
21 #include "HWRMVibraClientServer.h" |
|
22 #include "HWRMService.h" |
|
23 #include "HWRMVibraCommonService.h" |
|
24 #include "HWRMVibraCommands.h" |
|
25 #include "HWRMPluginHandler.h" |
|
26 #include "HWRMtrace.h" |
|
27 #include "HWRMVibraCommonData.h" |
|
28 #include "HWRMVibra.h" |
|
29 #include "HWRMReservationHandler.h" |
|
30 #include "HWRMPrivateCRKeys.h" |
|
31 #include "HWRMDomainPSKeys.h" |
|
32 #include "HWRMPrivatePSKeys.h" |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 _LIT( KPanicCategory, "HWRMVibraCommonService" ); |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CHWRMVibraCommonService::CHWRMVibraCommonService |
|
41 // C++ constructor |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CHWRMVibraCommonService::CHWRMVibraCommonService() |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CHWRMVibraCommonService::ConstructL |
|
50 // Symbian 2nd phase constructor can leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CHWRMVibraCommonService::ConstructL(CHWRMPluginHandler* aPluginHandler, |
|
54 CHWRMReservationHandler* aReservationHandler) |
|
55 { |
|
56 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ConstructL(0x%x)" ), aPluginHandler); |
|
57 |
|
58 BaseConstructL(aPluginHandler, aReservationHandler); |
|
59 |
|
60 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::ConstructL - return " )); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CHWRMVibraCommonService::NewL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CHWRMVibraCommonService* CHWRMVibraCommonService::NewL(CHWRMPluginHandler* aPluginHandler, |
|
69 CHWRMReservationHandler* aReservationHandler) |
|
70 { |
|
71 COMPONENT_TRACE3(_L( "HWRM Server - CHWRMVibraCommonService::NewL(0x%x, 0x%x)" ), aPluginHandler, aReservationHandler ); |
|
72 |
|
73 CHWRMVibraCommonService* self = new( ELeave ) CHWRMVibraCommonService(); |
|
74 |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(aPluginHandler, aReservationHandler); |
|
77 CleanupStack::Pop(); |
|
78 |
|
79 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::NewL - return 0x%x" ), self); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // Destructor |
|
86 // --------------------------------------------------------- |
|
87 // |
|
88 CHWRMVibraCommonService::~CHWRMVibraCommonService() |
|
89 { |
|
90 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::~CHWRMVibraCommonService()" )); |
|
91 |
|
92 // Base class cleanup |
|
93 BaseDestruct(); |
|
94 |
|
95 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::~CHWRMVibraCommonService - return" ) ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CHWRMVibraCommonService::ExecuteMessageL |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 #if defined(COMPONENT_TRACE_FLAG) && defined(_DEBUG) |
|
103 TBool CHWRMVibraCommonService::ExecuteMessageL( const RMessage2& aMessage ) |
|
104 #else |
|
105 TBool CHWRMVibraCommonService::ExecuteMessageL( const RMessage2& /* aMessage */ ) |
|
106 #endif |
|
107 { |
|
108 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ExecuteMessageL(0x%x)" ), aMessage.Function() ); |
|
109 |
|
110 // This common service is never supposed to get messages for execution |
|
111 __ASSERT_ALWAYS(EFalse, User::Panic(KPanicCategory, EPanicBadHandle)); |
|
112 |
|
113 return EFalse; |
|
114 } |
|
115 |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CHWRMVibraCommonService::ProcessResponseL |
|
119 // Handles Vibra requests responses. |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 #if defined(COMPONENT_TRACE_FLAG) && defined(_DEBUG) |
|
123 void CHWRMVibraCommonService::ProcessResponseL( TInt aCommandId, TUint8 aTransId, TDesC8& aData, TBool aTimeout) |
|
124 #else |
|
125 void CHWRMVibraCommonService::ProcessResponseL( TInt /* aCommandId */, TUint8 aTransId, TDesC8& aData, TBool aTimeout) |
|
126 #endif |
|
127 { |
|
128 COMPONENT_TRACE4(_L( "HWRM Server - CHWRMVibraCommonService::ProcessResponseL(0x%x, 0x%x, <data>, 0x%x)" ), aCommandId, aTransId, aTimeout ); |
|
129 |
|
130 TInt pluginErr(KErrNone); // Error came from plugin as data (or timeout). Used to complete RMessage. |
|
131 TInt contextErr(KErrNone); // Error in context, i.e. bad handle or descriptor. Used to leave. |
|
132 |
|
133 // Unpack the package. All vibra messages contain only possible error code |
|
134 // in return package. |
|
135 if ( !aTimeout && aData.Size() != sizeof(TInt) ) |
|
136 { |
|
137 COMPONENT_TRACE3(_L( "HWRM Server - CHWRMVibraCommonService::ProcessResponseL - Data size mismatch, expected: 0x%x, got 0x%x" ), sizeof(TInt), aData.Size() ); |
|
138 contextErr = KErrBadDescriptor; |
|
139 pluginErr = KErrBadDescriptor; |
|
140 } |
|
141 else |
|
142 { |
|
143 // If response was caused by timeout, set that as the error. |
|
144 // Timeout handled this way instead of just returning KErrTimeout in aData because |
|
145 // aData format is not known in plugin handler and in theoretically some new commands |
|
146 // may also return different response than just error code in future. |
|
147 if ( aTimeout ) |
|
148 { |
|
149 pluginErr = KErrTimedOut; |
|
150 } |
|
151 else |
|
152 { |
|
153 HWRMVibraCommand::TErrorCodeResponsePackage errPckg; |
|
154 errPckg.Copy(aData); |
|
155 pluginErr = errPckg(); |
|
156 } |
|
157 |
|
158 if ( pluginErr != KErrNone ) |
|
159 { |
|
160 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ProcessResponseL - Error: %d" ), pluginErr ); |
|
161 } |
|
162 |
|
163 // It is on each service's responsibility to update vibra status p&s keys |
|
164 } |
|
165 |
|
166 // Complete request and remove delete transaction |
|
167 contextErr = CompleteRequest(aTransId, pluginErr); |
|
168 |
|
169 // Leave if there is error in context |
|
170 User::LeaveIfError(contextErr); |
|
171 |
|
172 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::ProcessResponseL - return" ) ); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CHWRMVibraCommonService::SuspendSubResource |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CHWRMVibraCommonService::SuspendSubResource(TInt /*aSubResource*/) |
|
180 { |
|
181 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::SuspendSubResource" ) ); |
|
182 |
|
183 // This common service is never supposed to get messages for execution |
|
184 __ASSERT_ALWAYS(EFalse, User::Panic(KPanicCategory, EPanicBadHandle)); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CHWRMVibraCommonService::ResumeSubResource |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CHWRMVibraCommonService::ResumeSubResource(TInt /*aSubResource*/) |
|
192 { |
|
193 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::ResumeSubResource" ) ); |
|
194 |
|
195 // This common service is never supposed to get messages for execution |
|
196 __ASSERT_ALWAYS(EFalse, User::Panic(KPanicCategory, EPanicBadHandle)); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CHWRMVibraCommonService::ActivateSubResource |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CHWRMVibraCommonService::ActivateSubResource(TInt /*aSubResource*/, TBool /*aActivate*/) |
|
204 { |
|
205 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::ActivateSubResource" ) ); |
|
206 |
|
207 // This common service is never supposed to get messages for execution |
|
208 __ASSERT_ALWAYS(EFalse, User::Panic(KPanicCategory, EPanicBadHandle)); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CHWRMVibraCommonService::SetClientData |
|
213 // Sets client's parameters. |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CHWRMVibraCommonService::SetClientData( TVibraClientData aData ) |
|
217 { |
|
218 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::SetClientData" ) ); |
|
219 |
|
220 // We cannot do anything if insertion of data fails. That is not dealt as ciritical |
|
221 // problem anyway, because this request just won't get continued. |
|
222 TInt err = iVibraClients.Insert( aData, 0 ); |
|
223 |
|
224 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::SetClientData err %d" ), err ); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CHWRMVibraCommonService::HasData |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 TBool CHWRMVibraCommonService::HasData( CHWRMService* aClient ) |
|
232 { |
|
233 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::HasData" ) ); |
|
234 |
|
235 TBool hasData( EFalse ); |
|
236 TInt count( iVibraClients.Count() ); |
|
237 |
|
238 for ( TInt i = 0; i < count; i++ ) |
|
239 { |
|
240 if( iVibraClients[i].iClient == aClient ) |
|
241 { |
|
242 hasData = ETrue; |
|
243 break; |
|
244 } |
|
245 } |
|
246 |
|
247 return hasData; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CHWRMVibraCommonService::ResetClientData |
|
252 // Resets client's data. |
|
253 // If one service has finished with (all) vibrations, it calls this method. |
|
254 // At this point all entries of service are removed and other service's |
|
255 // vibration is continued if any available. |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CHWRMVibraCommonService::ResetClientData( CHWRMService* aClient ) |
|
259 { |
|
260 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::ResetClientData" ) ); |
|
261 |
|
262 // Remove service's items from list |
|
263 TInt count( iVibraClients.Count() ); |
|
264 |
|
265 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ResetClientData - count %d" ), count ); |
|
266 |
|
267 for ( TInt i=count-1; count > 0 && i >= 0; i-- ) |
|
268 { |
|
269 if( iVibraClients[i].iClient == aClient ) |
|
270 { |
|
271 iVibraClients.Remove( i ); |
|
272 } |
|
273 } |
|
274 |
|
275 // Restart next available "suspended" request. It is ok if original request's |
|
276 // timer fires just after vibration has been restarted, because we are |
|
277 // still running start/stop requests in context of same thread. |
|
278 count = iVibraClients.Count(); |
|
279 |
|
280 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ResetClientData - count %d" ), count ); |
|
281 |
|
282 if( count > 0 ) |
|
283 { |
|
284 // Start vibration with last suspended intensity. If restart fails, we |
|
285 // cannot do anything about that and should not leave calling service. |
|
286 TRAPD( err, RestartVibraL() ); |
|
287 if( err != KErrNone ) |
|
288 { |
|
289 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ResetClientData - err %d" ), err ); |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CHWRMVibraCommonService::RestartVibraL |
|
296 // Restarts vibration with last suspended intensity |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CHWRMVibraCommonService::RestartVibraL() |
|
300 { |
|
301 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::RestartVibraL" ) ); |
|
302 |
|
303 // Ignore Coverity false positive as uninitialized variable. |
|
304 // Since no response is sent back to the client, only a empty message is created here. |
|
305 // Message handle of this will be initialized to NULL in the default constructor. |
|
306 // coverity[var_decl] |
|
307 RMessage2 dummy; |
|
308 |
|
309 THWRMPluginRequestData* data = new (ELeave) THWRMPluginRequestData(dummy, 0, 0, EFalse); |
|
310 CleanupStack::PushL( data ); |
|
311 |
|
312 if( iVibraClients[0].iIntensity == KMaxTInt ) |
|
313 { |
|
314 TBuf8<1> emptyDes; |
|
315 data->iTransId = iPluginHandler->ProcessCommandL( |
|
316 HWRMVibraCommand::EStartVibraWithDefaultSettingsCmdId, emptyDes, this ); |
|
317 } |
|
318 else |
|
319 { |
|
320 HWRMVibraCommand::TStartVibraCmdDataPackage dataPckg(iVibraClients[0].iIntensity); |
|
321 data->iTransId = iPluginHandler->ProcessCommandL( |
|
322 HWRMVibraCommand::EStartVibraCmdId, dataPckg, this ); |
|
323 } |
|
324 |
|
325 // data still needed, do not destroy, just pop |
|
326 CleanupStack::Pop( data ); |
|
327 |
|
328 // Add data to list |
|
329 iTransactionList->AddTransaction( data ); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CHWRMVibraCommonService::ExecutingPriorityHigher |
|
334 // Checks whether vibrating client's priority higher than new request making |
|
335 // client's priority |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 TBool CHWRMVibraCommonService::ExecutingPriorityHigher(TSecureId aSid) |
|
339 { |
|
340 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::ExecutingPriorityHigher" ) ); |
|
341 |
|
342 TBool ret( EFalse ); |
|
343 |
|
344 TInt count = iVibraClients.Count(); |
|
345 |
|
346 if( count > 0 ) |
|
347 { |
|
348 TBool trusted( EFalse ); |
|
349 // Last client requested vibration always the first one in list |
|
350 TInt activePriority = iReservationHandler->GetPolicy()->GetPriority( iVibraClients[0].iSid, trusted ); |
|
351 TInt reqPriority = iReservationHandler->GetPolicy()->GetPriority( aSid, trusted ); |
|
352 |
|
353 if( activePriority < reqPriority ) |
|
354 { |
|
355 ret = ETrue; |
|
356 } |
|
357 } |
|
358 |
|
359 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::ExecutingPriorityHigher - ret %d" ), ret); |
|
360 |
|
361 return ret; |
|
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // CHWRMVibraCommonService::VibraPulseAllowed |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 TBool CHWRMVibraCommonService::VibraPulseAllowed(TSecureId aSid) |
|
369 { |
|
370 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMVibraCommonService::VibraPulseAllowed" ) ); |
|
371 |
|
372 TBool ret = iReservationHandler->GetPolicy()->FeedbackClient( aSid ); |
|
373 |
|
374 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMVibraCommonService::VibraPulseAllowed - ret %d" ), ret ); |
|
375 |
|
376 return ret; |
|
377 } |
|
378 |
|
379 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
380 |
|
381 // End of File |