|
1 /* |
|
2 * Copyright (c) 2008 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: Haptic service implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32mem.h> // RDesReadStream |
|
20 #include <hwrmhaptics.h> |
|
21 #include <hwrmhapticsobserver.h> |
|
22 #include <hwrmlogicalactuators.h> |
|
23 #include <hwrmhapticscommands.h> // adaptation interface |
|
24 #include <hwrmhapticspacketizer.h> |
|
25 |
|
26 #include "hwrmhapticsclientserver.h" // panic codes, service ID |
|
27 #include "hwrmhapticsserver.h" // default case in ExecuteMessageL |
|
28 #include "hwrmhapticsservice.h" |
|
29 #include "hwrmhapticspluginmanager.h" |
|
30 #include "hwrmhapticsreservationhandler.h" |
|
31 #include "hwrmhapticscommondata.h" |
|
32 #include "hwrmhapticstrace.h" |
|
33 #include "hwrmhapticspluginrequestdata.h" |
|
34 |
|
35 _LIT( KPanicCategory, "HWRMHapticsSService" ); |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Two-phased constructor. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CHWRMHapticsService* CHWRMHapticsService::NewL( |
|
42 CHWRMHapticsPluginManager* aPluginHandler, |
|
43 CHWRMHapticsReservationHandler* aReservationHandler, |
|
44 CHWRMHapticsCommonData& aHapticsCommonData, |
|
45 const RMessage2& aMessage ) |
|
46 { |
|
47 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::NewL()" ) ) ); |
|
48 |
|
49 CHWRMHapticsService* self = |
|
50 new ( ELeave ) CHWRMHapticsService( aHapticsCommonData, aMessage ); |
|
51 |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL( aPluginHandler, aReservationHandler ); |
|
54 CleanupStack::Pop( self ); |
|
55 |
|
56 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::NewL - return 0x%x" ), self ) ); |
|
57 |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Destructor. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CHWRMHapticsService::~CHWRMHapticsService() |
|
66 { |
|
67 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::~CHWRMHapticsService()" ) ) ); |
|
68 |
|
69 // Cleanup haptics just in case regular cleanup failed |
|
70 CleanupHaptics(); |
|
71 |
|
72 if ( iPacketizer ) |
|
73 { |
|
74 delete iPacketizer; |
|
75 iPacketizer = NULL; |
|
76 } |
|
77 |
|
78 // Complete any pending requests |
|
79 while ( iTransactionList->FirstItem() ) |
|
80 { |
|
81 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::~CHWRMHapticsService() - Deleting request %d" ), iTransactionList->FirstItem()->TransactionId() ) ); |
|
82 CHWRMHapticsPluginRequestData* data = |
|
83 static_cast<CHWRMHapticsPluginRequestData*>( |
|
84 iTransactionList->RemoveFirstItem() ); |
|
85 |
|
86 if ( data->RequestMessage().Handle() ) |
|
87 { |
|
88 // Check that this request is not first one of a split request |
|
89 if ( !data->CommandSplit() || |
|
90 !CheckForMessage(data->RequestMessage().Handle()) ) |
|
91 { |
|
92 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::~CHWRMHapticsService() - Canceling pending message" ) ) ); |
|
93 data->RequestMessage().Complete( KErrCancel ); |
|
94 } |
|
95 else |
|
96 { |
|
97 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::~CHWRMHapticsService() - Split request, not canceling message yet" ) ) ); |
|
98 } |
|
99 } |
|
100 |
|
101 TRAPD ( err, iPluginManager->CancelCommandL( data->TransactionId() ) ); |
|
102 |
|
103 if ( err != KErrNone ) |
|
104 { |
|
105 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::~CHWRMHapticsService() - Cancelling Command (transid: %d) failed: %d" ), data->TransactionId(), err ) ); |
|
106 } |
|
107 |
|
108 delete data; |
|
109 } |
|
110 |
|
111 // Destroy transaction list |
|
112 delete iTransactionList; |
|
113 |
|
114 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::~CHWRMHapticsService() - return" ) ) ); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Handles Haptics requests. |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C TBool CHWRMHapticsService::ExecuteMessageL( |
|
122 const RMessage2& aMessage ) |
|
123 { |
|
124 COMPONENT_TRACE( ( _L( "e_HWRMHAPTICS_SERVICE_EXECUTEMESSAGEL 1" ) ) ); |
|
125 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ExecuteMessageL(0x%x)" ), aMessage.Function() ) ); |
|
126 __ASSERT_ALWAYS( iPluginManager, |
|
127 User::Panic( KPanicCategory, EPanicBadHandle ) ); |
|
128 __ASSERT_ALWAYS( iReservationHandler, |
|
129 User::Panic( KPanicCategory, EPanicBadHandle ) ); |
|
130 |
|
131 if ( aMessage.IsNull() ) |
|
132 { |
|
133 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ExecuteMessageL - NULL message!" ) ) ); |
|
134 User::Leave( KErrBadHandle ); |
|
135 } |
|
136 |
|
137 TBool completeMessage( EFalse ); |
|
138 |
|
139 switch( aMessage.Function() ) |
|
140 { |
|
141 case RMessage2::EDisConnect: |
|
142 { |
|
143 // send command to close actuator, if actuator has |
|
144 // been opened (i.e. packetizer exists) |
|
145 if ( iPacketizer ) |
|
146 { |
|
147 SendMsgToPluginManagerL( aMessage ); |
|
148 } |
|
149 |
|
150 CleanupHaptics(); |
|
151 break; |
|
152 } |
|
153 case EHWRMHaptics: |
|
154 case EHWRMHapticsBridgeCommand: // flow through |
|
155 { |
|
156 // send haptics message |
|
157 SendMsgToPluginManagerL( aMessage ); |
|
158 break; |
|
159 } |
|
160 case EHWRMHapticsPlayEffect: |
|
161 { |
|
162 // check if suspended |
|
163 if ( iSuspended ) |
|
164 { |
|
165 // no effect playing, just complete the message |
|
166 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ExecuteMessageL - Haptics suspended; Play not executed." ) ) ); |
|
167 aMessage.Complete( KErrNone ); |
|
168 } |
|
169 else if ( iReservationHandler->IsReserved( this ) && |
|
170 iReservationHandler->ReservedPriorityHigher( iSid ) ) |
|
171 { |
|
172 // haptics has not been reserved for some other client with |
|
173 // higher (or equal) priority, notify caller with an error code |
|
174 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ExecuteMessageL - Haptics Reserved!" ) ) ); |
|
175 User::Leave( KErrInUse ); |
|
176 } |
|
177 else |
|
178 { |
|
179 // send play effect -command forwards to plugin manager |
|
180 SendMsgToPluginManagerL( aMessage ); |
|
181 } |
|
182 |
|
183 break; |
|
184 } |
|
185 case EHWRMHapticsOpenActuator: |
|
186 { |
|
187 // get actuator type |
|
188 THWRMLogicalActuators actuator = |
|
189 static_cast<THWRMLogicalActuators>( aMessage.Int2() ); |
|
190 |
|
191 // open the plugin to send the message to appropriate actuator; |
|
192 TBool created = iPluginManager->OpenPluginToActuatorL( actuator ); |
|
193 |
|
194 // reset packetizer instance |
|
195 if ( iPacketizer ) |
|
196 { |
|
197 delete iPacketizer; |
|
198 iPacketizer = NULL; |
|
199 } |
|
200 |
|
201 iPacketizer = CHWRMHapticsPacketizer::NewL( actuator ); |
|
202 |
|
203 // if plugin was not created, it already exists. Inform client |
|
204 // about the last status of the plugin. |
|
205 if ( !created ) |
|
206 { |
|
207 iHapticsCommonData.NotifyActuatorEvent( actuator, iSession ); |
|
208 } |
|
209 |
|
210 // send the open device message; |
|
211 SendMsgToPluginManagerL( aMessage ); |
|
212 |
|
213 break; |
|
214 } |
|
215 case EHWRMHapticsCleanup: |
|
216 { |
|
217 CleanupHaptics(); |
|
218 |
|
219 // complete as there is no ProcessResponse for this |
|
220 aMessage.Complete( KErrNone ); |
|
221 break; |
|
222 } |
|
223 case EHWRMHapticsReserve: |
|
224 { |
|
225 COMPONENT_TRACE( ( _L("CHWRMHapticsService::ExecuteMessageL - EHWRMReserveHaptics") ) ); |
|
226 |
|
227 ReserveHapticsL( aMessage ); |
|
228 |
|
229 // Since using dummy messages for freeze state restores, need complete always. |
|
230 completeMessage = ETrue; |
|
231 |
|
232 break; |
|
233 } |
|
234 case EHWRMHapticsRelease: |
|
235 { |
|
236 COMPONENT_TRACE( ( _L("CHWRMHapticsService::ExecuteMessageL - EHWRMReleaseHaptics") ) ); |
|
237 |
|
238 ReleaseHaptics(); |
|
239 |
|
240 // Since using dummy messages for default state restores, need complete always. |
|
241 completeMessage = ETrue; |
|
242 |
|
243 break; |
|
244 } |
|
245 case EHWRMHapticsSuppActuators: |
|
246 { |
|
247 // get the supported logical actuator types from |
|
248 // the plugin manager |
|
249 TUint32 types = iPluginManager->GetSupportedActuatorInfo(); |
|
250 |
|
251 // write the supported types to aMessage |
|
252 TPckg<TUint32> actuatorInfoRetPckg( types ); |
|
253 TInt err = aMessage.Write( 0, actuatorInfoRetPckg, 0 ); |
|
254 |
|
255 // complete the message |
|
256 aMessage.Complete( err ); |
|
257 break; |
|
258 } |
|
259 |
|
260 case EHWRMHapticsSetLicenseProp: |
|
261 { |
|
262 // The license key is set automatically if it is given as empty |
|
263 // string and if LicenseAutoSettingAllowed check succeeds. |
|
264 // The actual license key setting occures in lower layer, |
|
265 // here it is enough to create new command message. |
|
266 |
|
267 // check license key length |
|
268 if ( aMessage.Int1() == 0 ) |
|
269 { |
|
270 // check if automatic license key setting is allowed |
|
271 // for the calling client |
|
272 if ( iPluginManager->LicenseAutoSettingAllowed( aMessage ) && |
|
273 iPacketizer ) |
|
274 { |
|
275 // create buffer for new request data |
|
276 HWRMHapticsCommand::RHWRMHapticsReqData reqData; |
|
277 |
|
278 // client is allowed to get automatic license key setting, |
|
279 // create new command package |
|
280 TInt err = iPacketizer->EncSetPlatformLicenseKeyReq( |
|
281 iPacketizer->DeviceHandle(), |
|
282 reqData ); |
|
283 |
|
284 // write new request data to request message, if creating |
|
285 // it succeeded |
|
286 if ( err == KErrNone ) |
|
287 { |
|
288 aMessage.Write( 0, reqData, 0 ); |
|
289 } |
|
290 |
|
291 reqData.Close(); |
|
292 } |
|
293 } |
|
294 |
|
295 // send message to plugin manager |
|
296 SendMsgToPluginManagerL( aMessage ); |
|
297 break; |
|
298 } |
|
299 case EHWRMHapticsStatusNotification: |
|
300 { |
|
301 // store the message. It will be completed only |
|
302 // when the haptics/actuator status for this client changes |
|
303 // (thus the command should always be asynchronous on the |
|
304 // client side) |
|
305 iHapticsCommonData.AddStatusObserver( aMessage ); |
|
306 |
|
307 break; |
|
308 } |
|
309 case EHWRMHapticsGetStatus: |
|
310 { |
|
311 // get the current status value for this client |
|
312 MHWRMHapticsObserver::THWRMHapticsStatus status = |
|
313 iHapticsCommonData.CurrentStatus( aMessage.Session() ); |
|
314 |
|
315 // write the status to message |
|
316 TPckg<MHWRMHapticsObserver::THWRMHapticsStatus> statusPckg( status ); |
|
317 TInt err = aMessage.Write( 0, statusPckg, 0 ); |
|
318 |
|
319 // complete message |
|
320 aMessage.Complete( err ); |
|
321 |
|
322 break; |
|
323 } |
|
324 default: |
|
325 { |
|
326 // Cannot identify the message, panic the client |
|
327 aMessage.Panic( KPanicCategory, EPanicIllegalFunction ); |
|
328 break; |
|
329 } |
|
330 |
|
331 }//switch |
|
332 |
|
333 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ExecuteMessageL - return 0x%x" ), completeMessage ) ); |
|
334 COMPONENT_TRACE( ( _L( "e_HWRMHAPTICS_SERVICE_EXECUTEMESSAGEL 0" ) ) ); |
|
335 |
|
336 return completeMessage; |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // Handles Haptics requests responses. |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 void CHWRMHapticsService::ProcessResponseL( TInt aCommandId, |
|
344 TUint8 aTransId, |
|
345 const TDesC8& aData ) |
|
346 { |
|
347 COMPONENT_TRACE( ( _L( "e_HWRMHAPTICS_SERVICE_PROCESSRESPONSEL 1" ) ) ); |
|
348 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ProcessResponseL(0x%x, 0x%x, <data>)" ), aCommandId, aTransId ) ); |
|
349 |
|
350 if( aCommandId == HWRMHapticsCommand::EHapticsCmdId ) |
|
351 { |
|
352 TInt contextErr = CompleteRequestL( aTransId, aData ); |
|
353 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ProcessResponseL - CompleteRequestL ret = %d" ), contextErr ) ); |
|
354 |
|
355 // Leave if there is error in context |
|
356 User::LeaveIfError( contextErr ); |
|
357 } |
|
358 |
|
359 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ProcessResponseL - return" ) ) ); |
|
360 COMPONENT_TRACE( ( _L( "e_HWRMHAPTICS_SERVICE_PROCESSRESPONSEL 0" ) ) ); |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Suspends haptics. |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 void CHWRMHapticsService::SuspendResource() |
|
368 { |
|
369 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::SuspendSubResource()" ) ) ); |
|
370 |
|
371 iSuspended = ETrue; |
|
372 |
|
373 // notify client that haptics for it has been suspended |
|
374 iHapticsCommonData.NotifyStatus( |
|
375 MHWRMHapticsObserver::EHWRMHapticsStatusSuspended, iSession ); |
|
376 |
|
377 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::SuspendSubResource - return" ) ) ); |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------------------------- |
|
381 // Resumes haptics. |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 void CHWRMHapticsService::ResumeResource() |
|
385 { |
|
386 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ResumeSubResource()" ) ) ); |
|
387 |
|
388 iSuspended = EFalse; |
|
389 |
|
390 // notify client that haptics for it is now available |
|
391 iHapticsCommonData.NotifyStatus( |
|
392 MHWRMHapticsObserver::EHWRMHapticsStatusAvailable, iSession ); |
|
393 |
|
394 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ResumeSubResource - return" ) ) ); |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // Cancels outstanding request by completing the RMessage2 and removing data |
|
399 // from transaction list. |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 void CHWRMHapticsService::CancelRequest( TUint8 aTransId ) |
|
403 { |
|
404 CHWRMHapticsPluginRequestData* data = |
|
405 static_cast<CHWRMHapticsPluginRequestData*>( |
|
406 iTransactionList->FindTransaction( aTransId, ETrue ) ); |
|
407 |
|
408 if ( data && data->RequestMessage().Handle() ) |
|
409 { |
|
410 data->RequestMessage().Complete( KErrTimedOut ); |
|
411 } |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // Constructor. |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 CHWRMHapticsService::CHWRMHapticsService( |
|
419 CHWRMHapticsCommonData& aHapticsCommonData, |
|
420 const RMessage2& aMessage ) |
|
421 : iHapticsCommonData( aHapticsCommonData ), iSid( aMessage.SecureId() ), |
|
422 iSession( aMessage.Session() ) |
|
423 { |
|
424 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CHWRMHapticsService()" ) ) ); |
|
425 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CHWRMHapticsService - return" ) ) ); |
|
426 } |
|
427 |
|
428 // --------------------------------------------------------------------------- |
|
429 // Symbian 2nd phase constructor. |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 void CHWRMHapticsService::ConstructL( |
|
433 CHWRMHapticsPluginManager* aPluginManager, |
|
434 CHWRMHapticsReservationHandler* aReservationHandler ) |
|
435 { |
|
436 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ConstructL(0x%x)" ), aPluginManager ) ); |
|
437 |
|
438 if ( !aPluginManager ) |
|
439 { |
|
440 User::Leave( KErrBadHandle ); |
|
441 } |
|
442 |
|
443 iPluginManager = aPluginManager; |
|
444 iReservationHandler = aReservationHandler; |
|
445 |
|
446 iTransactionList = new( ELeave ) CHWRMHapticsPluginTransactionList(); |
|
447 |
|
448 // set this session to the common data for storing the client |
|
449 // specific status information |
|
450 iHapticsCommonData.AddSessionL( iSession ); |
|
451 |
|
452 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ConstructL - return " ) ) ); |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------------------------- |
|
456 // Completes request. Subclass calls this from ProcessResponseL |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 TInt CHWRMHapticsService::CompleteRequestL( TUint8 aTransId, |
|
460 const TDesC8& aData ) |
|
461 { |
|
462 // return value |
|
463 TInt contextErr( KErrNone ); |
|
464 |
|
465 // find transaction data |
|
466 CHWRMHapticsPluginRequestData* data = |
|
467 static_cast<CHWRMHapticsPluginRequestData*>( |
|
468 iTransactionList->FindTransaction( aTransId, ETrue ) ); |
|
469 |
|
470 CleanupStack::PushL( data ); |
|
471 |
|
472 if ( data && data->RequestMessage().Handle() ) |
|
473 { |
|
474 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CompleteRequestL - iRequestMessage.Handle() ok." ) ) ); |
|
475 |
|
476 // data storage for the protocol version and error code |
|
477 CHWRMHapticsRespData* respData = |
|
478 CHWRMHapticsRespData::NewLC( KErrNone, KNullDesC8 ); |
|
479 |
|
480 // internalize data using stream reader |
|
481 RDesReadStream reader( aData ); |
|
482 CleanupClosePushL( reader ); |
|
483 reader >> *respData; |
|
484 CleanupStack::PopAndDestroy( &reader ); |
|
485 |
|
486 // status filled in message decoding |
|
487 TInt vibeStatus = KErrNone; |
|
488 |
|
489 // decode data, if no error |
|
490 if ( respData->ErrorCode() == KErrNone ) |
|
491 { |
|
492 if ( data->RequestMessage().Function() == EHWRMHapticsBridgeCommand ) |
|
493 { |
|
494 // bridge command handling |
|
495 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CompleteRequest - inside EHWRMHapticsBridgeCommand case:" ) ) ); |
|
496 DATADUMP_TRACE( _L("CHWRMHapticsService::CompleteRequest - (EHWRMHapticsBridgeCommand case) - data dump "), respData->Data() ); |
|
497 |
|
498 // write error code and response data |
|
499 TPckg<TInt> vibeDummyCodePckg( KErrNone ); |
|
500 data->RequestMessage().Write( 1, vibeDummyCodePckg, 0 ); |
|
501 data->RequestMessage().Write( 2, respData->Data(), 0 ); |
|
502 } |
|
503 else |
|
504 { |
|
505 // decode the message and send it to the callback service |
|
506 CDesC8ArraySeg* decodeArray = NULL; |
|
507 TRAPD( err, decodeArray = iPacketizer->DecodeMessageL( |
|
508 respData->Data(), vibeStatus ) ); |
|
509 |
|
510 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CompleteRequestL - Return msg decoding, err = %d" ), err ) ); |
|
511 |
|
512 for ( TInt i = 0; err == KErrNone && |
|
513 i < decodeArray->MdcaCount(); ++i ) |
|
514 { |
|
515 // write data back to client |
|
516 err = data->RequestMessage().Write( |
|
517 KHapticsMessageResponseArgsOffset + i, |
|
518 decodeArray->MdcaPoint( i ), 0 ); |
|
519 } |
|
520 |
|
521 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CompleteRequestL - Data writing err = %d" ), err ) ); |
|
522 } |
|
523 } |
|
524 |
|
525 CleanupStack::PopAndDestroy( respData ); |
|
526 |
|
527 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CompleteRequestL - calling iRequestMessage.Complete()") ) ) ; |
|
528 data->RequestMessage().Complete( vibeStatus ); |
|
529 } |
|
530 else |
|
531 { |
|
532 // transaction data not found |
|
533 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CompleteRequest - No transaction data found!" ) ) ); |
|
534 contextErr = KErrBadHandle; |
|
535 } |
|
536 |
|
537 // cleanup data |
|
538 CleanupStack::PopAndDestroy( data ); |
|
539 |
|
540 return contextErr; |
|
541 } |
|
542 |
|
543 // --------------------------------------------------------------------------- |
|
544 // Checks transaction list if specified message is in any transaction. |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 TBool CHWRMHapticsService::CheckForMessage( TInt aHandle ) |
|
548 { |
|
549 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CheckForMessage - Checking for message: 0x%x" ), aHandle ) ); |
|
550 |
|
551 CHWRMHapticsPluginRequestData* data = |
|
552 static_cast<CHWRMHapticsPluginRequestData*>( |
|
553 iTransactionList->FirstItem() ); |
|
554 |
|
555 TBool retval( EFalse ); |
|
556 |
|
557 while ( !retval && data ) |
|
558 { |
|
559 if ( data->RequestMessage().Handle() == aHandle ) |
|
560 { |
|
561 retval = ETrue; |
|
562 } |
|
563 |
|
564 data = static_cast<CHWRMHapticsPluginRequestData*>( data->NextItem() ); |
|
565 } |
|
566 |
|
567 return retval; |
|
568 } |
|
569 |
|
570 // --------------------------------------------------------------------------- |
|
571 // Cleans up haptics. |
|
572 // --------------------------------------------------------------------------- |
|
573 // |
|
574 void CHWRMHapticsService::CleanupHaptics() |
|
575 { |
|
576 if ( !iCleanupDone ) |
|
577 { |
|
578 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CleanupHaptics()" ) ) ); |
|
579 |
|
580 // release haptics in case this client has made the reservation |
|
581 ReleaseHaptics(); |
|
582 |
|
583 iSuspended = EFalse; |
|
584 |
|
585 // remove priority of the client from reservation handler |
|
586 iReservationHandler->RemovePriority( iSid ); |
|
587 |
|
588 // remove this session from the common data |
|
589 iHapticsCommonData.RemoveSession( iSession ); |
|
590 |
|
591 iCleanupDone = ETrue; |
|
592 |
|
593 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::CleanupHaptics - return" ) ) ); |
|
594 } |
|
595 } |
|
596 |
|
597 // --------------------------------------------------------------------------- |
|
598 // Handles Haptics requests. |
|
599 // --------------------------------------------------------------------------- |
|
600 // |
|
601 void CHWRMHapticsService::SendMsgToPluginManagerL( const RMessage2& aMessage ) |
|
602 { |
|
603 // Create new data (TransId is updated later, commandId is not important) |
|
604 CHWRMHapticsPluginRequestData* data( NULL ); |
|
605 if ( aMessage.Function() == RMessage2::EDisConnect ) |
|
606 { |
|
607 data = new ( ELeave ) |
|
608 CHWRMHapticsPluginRequestData( RMessage2(), 0, 0, EFalse ); |
|
609 } |
|
610 else |
|
611 { |
|
612 data = new ( ELeave ) |
|
613 CHWRMHapticsPluginRequestData( aMessage, 0, 0, EFalse ); |
|
614 } |
|
615 |
|
616 CleanupStack::PushL( data ); |
|
617 |
|
618 if ( aMessage.Function() == RMessage2::EDisConnect ) |
|
619 { |
|
620 // form from Disconnect message actuator closing request |
|
621 RBuf8 closeBuf; |
|
622 CleanupClosePushL( closeBuf ); |
|
623 |
|
624 User::LeaveIfError( iPacketizer->EncCloseDeviceReq( |
|
625 iPacketizer->DeviceHandle(), closeBuf ) ); |
|
626 |
|
627 HBufC8* reqData = closeBuf.AllocL(); |
|
628 |
|
629 CleanupStack::PopAndDestroy( &closeBuf ); |
|
630 |
|
631 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::SendMsgToPluginManagerL - Disconnect actuator") ) ); |
|
632 |
|
633 // created buffer is deleted in the request data object |
|
634 data->SetRequestData( reqData ); |
|
635 |
|
636 // command to plugin manager |
|
637 TUint8 transId = iPluginManager->ProcessCommandL( |
|
638 HWRMHapticsCommand::EHapticsCmdId, |
|
639 *reqData, this ); |
|
640 data->SetTransactionId( transId ); |
|
641 } |
|
642 else |
|
643 { |
|
644 // read message data into a heap buffer |
|
645 HBufC8* reqData = HBufC8::NewL( aMessage.GetDesLength( 0 ) ); |
|
646 TPtr8 dataPtr = reqData->Des(); |
|
647 TInt err = aMessage.Read( 0, dataPtr, 0 ); |
|
648 |
|
649 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::SendMsgToPluginManagerL - aMessageRead err = %d"), err ) ); |
|
650 |
|
651 // created buffer is deleted in the request data object |
|
652 data->SetRequestData( reqData ); |
|
653 |
|
654 // command to plugin manager |
|
655 TUint8 transId = iPluginManager->ProcessCommandL( |
|
656 HWRMHapticsCommand::EHapticsCmdId, |
|
657 *reqData, this); |
|
658 data->SetTransactionId( transId ); |
|
659 } |
|
660 |
|
661 // data still needed, do not destroy, just pop |
|
662 CleanupStack::Pop( data ); |
|
663 |
|
664 // Add data to list |
|
665 iTransactionList->AddTransaction( data ); |
|
666 } |
|
667 |
|
668 // --------------------------------------------------------------------------- |
|
669 // Reserves haptics. |
|
670 // --------------------------------------------------------------------------- |
|
671 // |
|
672 void CHWRMHapticsService::ReserveHapticsL( const RMessage2& aMessage ) |
|
673 { |
|
674 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ReserveHapticsL()" ) ) ); |
|
675 |
|
676 // Reserve the haptics |
|
677 TBool noCoeEnv = aMessage.Int0(); |
|
678 TBool suspended = iReservationHandler->ReserveL( iSid, noCoeEnv, this ); |
|
679 |
|
680 // if reservation became the affective reservation, inform all other |
|
681 // clients that haptics is reserved |
|
682 if ( !suspended ) |
|
683 { |
|
684 iHapticsCommonData.BroadcastStatus( |
|
685 MHWRMHapticsObserver::EHWRMHapticsStatusReserved, iSession ); |
|
686 } |
|
687 |
|
688 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ReserveHapticsL() return" ) ) ); |
|
689 } |
|
690 |
|
691 // --------------------------------------------------------------------------- |
|
692 // Releases haptics. |
|
693 // --------------------------------------------------------------------------- |
|
694 // |
|
695 void CHWRMHapticsService::ReleaseHaptics() |
|
696 { |
|
697 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ReleaseHaptics()" ) ) ); |
|
698 |
|
699 // get info is haptics currently reserved for this client |
|
700 TBool activeReservation = iReservationHandler->ActiveReservation( this ); |
|
701 |
|
702 // release reservation (removes, if this has a reservation) |
|
703 TBool reserved = iReservationHandler->Release( this ); |
|
704 |
|
705 // if haptics is still reserved for another client, notify client |
|
706 if ( reserved ) |
|
707 { |
|
708 iHapticsCommonData.NotifyStatus( |
|
709 MHWRMHapticsObserver::EHWRMHapticsStatusReserved, iSession ); |
|
710 } |
|
711 else if ( activeReservation ) |
|
712 { |
|
713 // haptics was reserved for this client, but there are no more |
|
714 // reservations --> inform all clients, which have been blocked |
|
715 iHapticsCommonData.BroadcastStatus( |
|
716 MHWRMHapticsObserver::EHWRMHapticsStatusAvailable, iSession ); |
|
717 } |
|
718 |
|
719 COMPONENT_TRACE( ( _L( "CHWRMHapticsService::ReleaseHaptics() return" ) ) ); |
|
720 } |
|
721 |
|
722 |
|
723 // End of File |