|
1 /* |
|
2 * Copyright (c) 2007-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: Communication with server side implementation of |
|
15 * Area Registry. |
|
16 * Part of: Tactile Feedback. |
|
17 * |
|
18 */ |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <eikenv.h> |
|
22 |
|
23 #include <tactileinternaldatatypes.h> |
|
24 #include <tactilefeedbacktrace.h> |
|
25 |
|
26 #include "touchfeedbackclient.h" |
|
27 #include "touchfeedbackimpl.h" |
|
28 #include "touchfeedbackregistry.h" |
|
29 #include "OstTraceDefinitions.h" |
|
30 #ifdef OST_TRACE_COMPILER_IN_USE |
|
31 #include "touchfeedbackclientTraces.h" |
|
32 #endif |
|
33 |
|
34 // Minimun and maximum sized of one shared memory chunk. |
|
35 const TInt KTactileChunkInitialSize = 4096; // 4kB |
|
36 const TInt KTactileChunkMaxSize = 262144; // 256kB |
|
37 const TUid KTactileClickPluginUid = { 0x2000B493 }; |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CTouchFeedbackClient::CTouchFeedbackClient( CTouchFeedbackImpl& aFeedback ): |
|
45 iClickPlugin ( CEikonEnv::Static()->WsSession()), |
|
46 iFeedback( aFeedback ) |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // We do all the initializations in the construction phase. Other option |
|
52 // would be to postpone these until the first registry entry has been added. |
|
53 // |
|
54 // #1 Connect to our ClickPlugin |
|
55 // #2 Create a shared chunk, which is used for storing this application |
|
56 // process' area registry, so that it can be accessed by the window |
|
57 // server. |
|
58 // #3 Set window count to zero in the new chunk |
|
59 // #4 Try to create a global semaphore to have mutual exclusion on chunks |
|
60 // If semaphore already exists, then try to open it. |
|
61 // #5 Put our chunk name to package buffer, and send it to click plugin |
|
62 // so that it can open a handle to our chunk and thus access the shared |
|
63 // memory. |
|
64 // #6 Create a CIdle object that is used for updating the registry in shared |
|
65 // memory. |
|
66 // |
|
67 // Notice that we will leave in case anything fails. This has to be handled |
|
68 // on higher level, so that whole application launch will not fail in case |
|
69 // touch feedback does not work. |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CTouchFeedbackClient::ConstructL() |
|
73 { |
|
74 TRACE("CTouchFeedbackClient::ConstructL - Begin"); |
|
75 |
|
76 // #1 Connect to click plugin |
|
77 User::LeaveIfError( iClickPlugin.Construct( KTactileClickPluginUid ) ); |
|
78 |
|
79 TBool changable = EFalse; |
|
80 |
|
81 TBool loaded = iClickPlugin.IsLoaded( changable ); |
|
82 |
|
83 if ( !loaded ) |
|
84 { |
|
85 User::Leave( KErrNotSupported ); |
|
86 } |
|
87 |
|
88 // #2 Create shared chunk |
|
89 RThread me; |
|
90 |
|
91 TTactileFeedbackConnectData data; |
|
92 |
|
93 // Set window group identifier |
|
94 data.iWindowGroupId = CCoeEnv::Static()->RootWin().Identifier(); |
|
95 |
|
96 // We use our own thread name as name for the chunk |
|
97 data.iChunkName.Copy( me.Name().Right( KMaxKernelName ) ); |
|
98 |
|
99 // Now create the chunk |
|
100 TInt err = iChunk.CreateGlobal( data.iChunkName, |
|
101 KTactileChunkInitialSize, |
|
102 KTactileChunkMaxSize ); |
|
103 |
|
104 // We have to take into account, that the chunk may already exist. |
|
105 // This may happen in case we have been started (and crashed) |
|
106 // once already. |
|
107 if ( err == KErrAlreadyExists ) |
|
108 { |
|
109 User::LeaveIfError( iChunk.OpenGlobal( data.iChunkName, EFalse ) ); |
|
110 } |
|
111 |
|
112 // #3 Set window count to zero |
|
113 TInt* chunkPtr = reinterpret_cast<TInt*>( iChunk.Base() ); |
|
114 |
|
115 *chunkPtr = 0; // No entries in the chunk in the beginning |
|
116 |
|
117 // #4 Try to create/open global semaphore |
|
118 err = iSemaphore.CreateGlobal( KTouchFeedbackSemaphore, 1 ); |
|
119 |
|
120 if ( err == KErrAlreadyExists ) |
|
121 { |
|
122 User::LeaveIfError( iSemaphore.OpenGlobal( KTouchFeedbackSemaphore ) ); |
|
123 } |
|
124 |
|
125 // #5 Send chunk name to window server |
|
126 TPckgC<TTactileFeedbackConnectData> dataPkg ( data ); |
|
127 |
|
128 User::LeaveIfError( iClickPlugin.CommandReply( ETactileOpCodeConnect, |
|
129 dataPkg ) ); |
|
130 iConnected = ETrue; |
|
131 |
|
132 iFeedbackTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
133 |
|
134 User::LeaveIfError( iFbClient.Connect() ); |
|
135 |
|
136 // #6 We use Standard priority so that we won't disturb the normal |
|
137 // functionality of the application, but can get registry updated |
|
138 // fastly enough in case the application does very plenty of |
|
139 // background prosessing with active objects. |
|
140 iIdle = CIdle::NewL( CActive::EPriorityStandard ); |
|
141 |
|
142 TRACE("CTouchFeedbackClient::ConstructL - End"); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 CTouchFeedbackClient* CTouchFeedbackClient::NewL( CTouchFeedbackImpl& aFeedback ) |
|
150 { |
|
151 CTouchFeedbackClient* self = |
|
152 new( ELeave ) CTouchFeedbackClient ( aFeedback ); |
|
153 CleanupStack::PushL( self ); |
|
154 self->ConstructL(); |
|
155 CleanupStack::Pop( self ); |
|
156 return self; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 CTouchFeedbackClient::~CTouchFeedbackClient() |
|
164 { |
|
165 iChunk.Close(); |
|
166 iSemaphore.Close(); |
|
167 |
|
168 if ( iFeedbackTimer ) |
|
169 { |
|
170 iFeedbackTimer->Cancel(); |
|
171 delete iFeedbackTimer; |
|
172 } |
|
173 |
|
174 iFbClient.Close(); |
|
175 |
|
176 if ( iConnected ) |
|
177 { |
|
178 TTactileFeedbackDisconnectData data; |
|
179 |
|
180 data.iWindowGroupId = CCoeEnv::Static()->RootWin().Identifier(); |
|
181 |
|
182 TPckgC<TTactileFeedbackDisconnectData> dataPkg ( data ); |
|
183 |
|
184 iClickPlugin.CommandReply( ETactileOpCodeDisconnect, dataPkg ); |
|
185 } |
|
186 |
|
187 iClickPlugin.Close(); |
|
188 |
|
189 delete iIdle; |
|
190 } |
|
191 |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // In this function we just activate CIdle. The motivation is that this |
|
195 // way we avoid updating the registry multiple times. For e.g. Calculator |
|
196 // application launch would cause around 20 registry updates in case we would |
|
197 // always make changes to shared memory immediately after registry update. |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CTouchFeedbackClient::RegistryChanged( ) |
|
201 { |
|
202 if ( iIdle && !iIdle->IsActive() ) |
|
203 { |
|
204 iIdle->Start( TCallBack( IdleCallbackL, this ) ); |
|
205 } |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Callback for CIdle. |
|
210 // |
|
211 // We check the current enabled/disabled status of tactile feedback for |
|
212 // this application, and either UpdateRegistryToChunkL for updating whole |
|
213 // registry to shared chunk, or ClearWholeChunkL for clearing all feedback |
|
214 // areas from the shared chunk. |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CTouchFeedbackClient::IdleCallbackL( TAny* aPtr ) |
|
218 { |
|
219 if ( aPtr ) |
|
220 { |
|
221 CTouchFeedbackClient* self = |
|
222 static_cast<CTouchFeedbackClient*> ( aPtr ); |
|
223 |
|
224 if ( self->iFeedback.FeedbackEnabledForThisApp() ) |
|
225 { |
|
226 self->UpdateRegistryToChunkL(); |
|
227 } |
|
228 else |
|
229 { |
|
230 self->ClearWholeChunkL(); |
|
231 } |
|
232 } |
|
233 |
|
234 return KErrNone; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // Area registry is written to shared memory in following format |
|
239 // |
|
240 // + Header (four bytes) = Number of windows as TInt |
|
241 // + Window entries |
|
242 // + Area registry entries |
|
243 // |
|
244 // Window entries: For each window: |
|
245 // [four bytes] = Window handle |
|
246 // [four bytes] = Number of registry entries in this window |
|
247 // [four bytes] = Offset of registry data from beginning of chunk |
|
248 // Area registry entries: |
|
249 // - Each entry written as TFeedbackChunkAreaEntry straight into memory |
|
250 // |
|
251 // |
|
252 // Steps taken in this function: |
|
253 // |
|
254 // #1 Calculate the size needed for area registry data |
|
255 // #2 Mutual exclusion with global semaphore |
|
256 // #3 Increase Chunk size in case necessary |
|
257 // #4 Update Chunk contents. This is now done simply by writing the whole |
|
258 // area registry into the shared memory. |
|
259 // #5 Release semaphore |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 void CTouchFeedbackClient::UpdateRegistryToChunkL() |
|
263 { |
|
264 TRACE( "CTouchFeedbackClient::UpdateRegistryToChunkL - Begin" ); |
|
265 |
|
266 RPointerArray<CTouchFeedbackRegistry>* registry = |
|
267 iFeedback.RegistryArray(); |
|
268 |
|
269 // Do cleanup so that empty registry instances are not hanging anymore |
|
270 TInt windowIndex = 0; |
|
271 TInt cleanupAreaCount = 0; |
|
272 TInt cleanupWindowCount = 0; |
|
273 // value is returned in parameter variable |
|
274 iFeedback.GetAreaCount( cleanupAreaCount, cleanupWindowCount ); |
|
275 |
|
276 while ( windowIndex < cleanupWindowCount ) |
|
277 { |
|
278 TBool emptyWindow = ( (*registry)[windowIndex]->AreaCount() == 0 ); |
|
279 if ( emptyWindow ) |
|
280 { |
|
281 // Remove empty/possibly destroyed registry instance that possibly |
|
282 // may refer to destroyed control/window. |
|
283 CTouchFeedbackRegistry* feedbackRegistry = (*registry)[windowIndex]; |
|
284 registry->Remove( windowIndex ); |
|
285 delete feedbackRegistry; |
|
286 cleanupWindowCount--; |
|
287 } |
|
288 else |
|
289 { |
|
290 windowIndex++; // to next window |
|
291 } |
|
292 } |
|
293 |
|
294 // #1 Calculate the size needed |
|
295 TInt windowCount(0); |
|
296 TInt areaCount(0); |
|
297 iFeedback.GetAreaCount( areaCount, windowCount ); |
|
298 |
|
299 // Header contains only number of windows in this registry |
|
300 TInt headerSize = sizeof( TInt ); |
|
301 |
|
302 // There is a list of windows in this registry in the beginning, with |
|
303 // data offsets in the chunk |
|
304 TInt windowItemSize = |
|
305 sizeof( TInt ) + // Window handle |
|
306 sizeof( TInt ) + // Area count |
|
307 sizeof( TInt ); // Offset to area registry entries |
|
308 |
|
309 // Size of one area registry entry |
|
310 TInt areaItemSize = sizeof( TFeedbackChunkAreaEntry ); |
|
311 |
|
312 TInt sizeNeeded = |
|
313 headerSize + |
|
314 windowCount * windowItemSize + |
|
315 areaCount * areaItemSize; |
|
316 |
|
317 // #2 Mutual exclusion |
|
318 iSemaphore.Wait(); |
|
319 |
|
320 // We use cleanup item for making sure that semaphore will not stay |
|
321 // reserved in case there is a leave. |
|
322 CleanupStack::PushL( TCleanupItem( CleanupSemaphore, &iSemaphore ) ); |
|
323 |
|
324 // #3 Increase chunk (committed) size in case needed |
|
325 if ( iChunk.Size() < sizeNeeded ) |
|
326 { |
|
327 TInt err = iChunk.Adjust( sizeNeeded ); |
|
328 |
|
329 if ( err != KErrNone ) |
|
330 { |
|
331 // In case the current registry does not fit to the chunk, then |
|
332 // we'll set window count to zero, in case that is possible |
|
333 // (it is not possible if chunk size is zero). |
|
334 // This means that there won't be any area registry based |
|
335 // feedback for this application on the moment. |
|
336 if ( iChunk.Size() > 0 ) |
|
337 { |
|
338 TInt* chunkPtr = reinterpret_cast<TInt*>( iChunk.Base() ); |
|
339 |
|
340 // Set window count to zero |
|
341 *chunkPtr = 0; |
|
342 } |
|
343 |
|
344 // We will leave anyway |
|
345 User::Leave( err ); |
|
346 } |
|
347 } |
|
348 |
|
349 |
|
350 // #4 Update chunk contents |
|
351 TInt* chunkPtr = reinterpret_cast<TInt*>( iChunk.Base() ); |
|
352 |
|
353 // Set window count in the beginning of chunk |
|
354 *chunkPtr = windowCount; |
|
355 chunkPtr++; |
|
356 |
|
357 TInt areaOffset = headerSize + windowCount * windowItemSize; |
|
358 |
|
359 // This is pointer to the first area registry entry in the chunk |
|
360 TFeedbackChunkAreaEntry* chunkEntryPtr |
|
361 = reinterpret_cast<TFeedbackChunkAreaEntry*> ( iChunk.Base() + areaOffset ); |
|
362 |
|
363 // Check if audio or vibra is disabled for this application. |
|
364 TBool audioEnabled = iFeedback.FeedbackEnabledForThisApp( ETouchFeedbackAudio ); |
|
365 TBool vibraEnabled = iFeedback.FeedbackEnabledForThisApp( ETouchFeedbackVibra ); |
|
366 |
|
367 // One loop round for each window where we have area registry entries. |
|
368 for ( TInt windowIndex = 0; windowIndex < windowCount; windowIndex++ ) |
|
369 { |
|
370 RArray<TFeedbackEntry>* windowRegistry = |
|
371 (*registry)[windowIndex]->WindowRegistry(); |
|
372 |
|
373 // Write handle of this window |
|
374 *chunkPtr = (*registry)[windowIndex]->WindowHandle(); |
|
375 chunkPtr++; |
|
376 // Store the address where we shall write count later |
|
377 // (We don't know the amount of areas yet, as we shall |
|
378 // only add areas of visible controls). |
|
379 TInt* countPointer = chunkPtr; |
|
380 chunkPtr++; |
|
381 // Write offset of the area registry entries of this window |
|
382 *chunkPtr = ((TInt)chunkEntryPtr-(TInt)iChunk.Base()); |
|
383 chunkPtr++; |
|
384 |
|
385 // Write all areas of visible controls in this window |
|
386 // to the shared memory. Invisible controls' areas are left out so |
|
387 // that they won't mess up the feedback for overlapping visible |
|
388 // controls. |
|
389 TInt visibleAreaCount = 0; |
|
390 for ( TInt areaIndex = windowRegistry->Count()-1; areaIndex >= 0; areaIndex-- ) |
|
391 { |
|
392 TFeedbackEntry entry = (*windowRegistry)[areaIndex]; |
|
393 |
|
394 if ( entry.iVisible ) |
|
395 { |
|
396 chunkEntryPtr->iRect = entry.iRect; |
|
397 |
|
398 TInt feedback = ( entry.iFeedbackTypeUp << 10 ); |
|
399 feedback |= entry.iFeedbackTypeDown; |
|
400 |
|
401 // Add audio and vibra information to feedback type |
|
402 if ( entry.iVibraEnabled && vibraEnabled ) |
|
403 { |
|
404 //feedback |= KTactileVibraBit; |
|
405 if ( entry.iFeedbackDown & ETouchFeedbackVibra ) |
|
406 { |
|
407 feedback |= KTactileVibraBitDown; |
|
408 } |
|
409 if ( entry.iFeedbackUp & ETouchFeedbackVibra ) |
|
410 { |
|
411 feedback |= KTactileVibraBitUp; |
|
412 } |
|
413 |
|
414 } |
|
415 if ( entry.iAudioEnabled && audioEnabled ) |
|
416 { |
|
417 //feedback |= KTactileAudioBit; |
|
418 if ( entry.iFeedbackDown & ETouchFeedbackAudio ) |
|
419 { |
|
420 feedback |= KTactileAudioBitDown; |
|
421 } |
|
422 if ( entry.iFeedbackUp & ETouchFeedbackAudio ) |
|
423 { |
|
424 feedback |= KTactileAudioBitUp; |
|
425 } |
|
426 } |
|
427 |
|
428 chunkEntryPtr->iFeedbackType = static_cast<TTouchLogicalFeedback>( feedback ); |
|
429 |
|
430 chunkEntryPtr->iEventType = entry.iEventType; |
|
431 |
|
432 chunkEntryPtr++; |
|
433 visibleAreaCount++; |
|
434 } |
|
435 } |
|
436 // Now store area count as we know the amount of visible areas |
|
437 // for this window. |
|
438 *countPointer = visibleAreaCount; |
|
439 } |
|
440 |
|
441 // #5 Release semaphore so that other processes can access the chunks again |
|
442 // This calls "Signal" on the semaphore |
|
443 CleanupStack::PopAndDestroy(&iSemaphore); |
|
444 |
|
445 TRACE( "CTouchFeedbackClient::UpdateRegistryToChunkL - End" ); |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------------------------- |
|
449 // Despite the function name, we don't actually clear whole chunk here |
|
450 // as that is not necessary. It is enough to set the window count to zero |
|
451 // at beginning of chunk, as then server will consider this chunk empty. |
|
452 // |
|
453 // #1 Mutual exclusion |
|
454 // #2 Make sure chunk is not of zero -size |
|
455 // #3 Set window count to zero at beginning of chunk |
|
456 // #4 Release mutual exclusion |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CTouchFeedbackClient::ClearWholeChunkL() |
|
460 { |
|
461 TRACE( "CTouchFeedbackClient::ClearWholeChunkL - Begin" ); |
|
462 |
|
463 // #1 Mutual exclusion |
|
464 iSemaphore.Wait(); |
|
465 |
|
466 // We use cleanup item for making sure that semaphore will not stay |
|
467 // reserved in case there is a leave. |
|
468 CleanupStack::PushL( TCleanupItem( CleanupSemaphore, &iSemaphore ) ); |
|
469 |
|
470 // We only need four bytes for the data, as we are only going to store |
|
471 // one number to the chunk. But we count the space just in case anyway, |
|
472 // because at some point chunks initial size may be change so that it is |
|
473 // zero. |
|
474 TInt sizeNeeded = sizeof( TInt ); |
|
475 |
|
476 // #2 Increase chunk (committed) size in case needed |
|
477 if ( iChunk.Size() < sizeNeeded ) |
|
478 { |
|
479 User::LeaveIfError( iChunk.Adjust( sizeNeeded ) ); |
|
480 } |
|
481 |
|
482 // #3 Update chunk contents |
|
483 TInt* chunkPtr = reinterpret_cast<TInt*>( iChunk.Base() ); |
|
484 |
|
485 // Set window count to zero (this is enough for the server to think |
|
486 // that there are no feedback areas at all). |
|
487 *chunkPtr = 0; |
|
488 |
|
489 // #4 Release semaphore |
|
490 CleanupStack::PopAndDestroy(&iSemaphore); |
|
491 |
|
492 TRACE( "CTouchFeedbackClient::ClearWholeChunkL - End" ); |
|
493 } |
|
494 |
|
495 // --------------------------------------------------------------------------- |
|
496 // This is a cleanup function for releasing a semaphore in case there will |
|
497 // be a leave after calling RSemaphore::Wait (otherwise there could easily |
|
498 // be a deadlock in the system). |
|
499 // --------------------------------------------------------------------------- |
|
500 // |
|
501 void CTouchFeedbackClient::CleanupSemaphore( TAny* aPtr ) |
|
502 { |
|
503 TRACE( "CTouchFeedbackClient::CleanupSemaphore" ); |
|
504 |
|
505 if ( aPtr ) |
|
506 { |
|
507 RSemaphore* sem = static_cast<RSemaphore*> ( aPtr ); |
|
508 |
|
509 sem->Signal(); |
|
510 } |
|
511 } |
|
512 |
|
513 // --------------------------------------------------------------------------- |
|
514 // Here we just send the logical feedback type to server. |
|
515 // --------------------------------------------------------------------------- |
|
516 // |
|
517 void CTouchFeedbackClient::ImmediateFeedback( TTouchLogicalFeedback aType, |
|
518 TBool aVibraOn, TBool aAudioOn ) |
|
519 { |
|
520 OstTrace0( TACTILE_PERFORMANCE, TACTILE_CLIENT_INSTANT_FEEDBACK_1, "e_TACTILE_CLIENT_INSTANT_FEEDBACK 1"); |
|
521 |
|
522 if ( aVibraOn || aAudioOn ) |
|
523 { |
|
524 iFbClient.PlayFeedback( aType, aVibraOn, aAudioOn ); |
|
525 } |
|
526 |
|
527 OstTrace0( TACTILE_PERFORMANCE, TACTILE_CLIENT_INSTANT_FEEDBACK_0, "e_TACTILE_CLIENT_INSTANT_FEEDBACK 0"); |
|
528 } |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // Check that we really have something to update, and then do the update. |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CTouchFeedbackClient::FlushUpdates() |
|
535 { |
|
536 if ( iIdle && iIdle->IsActive() ) |
|
537 { |
|
538 // Do the updates |
|
539 TRAP_IGNORE( IdleCallbackL( this ) ); |
|
540 |
|
541 // Cancel pending update request (no need to keep it active since |
|
542 // registry is now up-to-date). |
|
543 iIdle->Cancel(); |
|
544 } |
|
545 } |
|
546 |
|
547 // ---------------------------------------------------------------------------- |
|
548 // |
|
549 // ---------------------------------------------------------------------------- |
|
550 // |
|
551 void CTouchFeedbackClient::StartFeedback( TUint32 aClientHandle, |
|
552 TTouchContinuousFeedback aType, |
|
553 TInt aIntensity, |
|
554 TTimeIntervalMicroSeconds32 aTimeout ) |
|
555 { |
|
556 TRACE("CTouchFeedbackClient::StartFeedback - Begin"); |
|
557 |
|
558 if ( !iFeedbackTimer->IsActive() ) |
|
559 { |
|
560 iPreviousIntensity = aIntensity; |
|
561 iFbClient.StartFeedback( aType, aIntensity ); |
|
562 iClientHandle = aClientHandle; // Control, which started the feedback. |
|
563 } |
|
564 if ( aTimeout != TTimeIntervalMicroSeconds32(0) ) |
|
565 { |
|
566 StartFeedbackTimer( aTimeout ); |
|
567 |
|
568 if ( aIntensity != iPreviousIntensity ) |
|
569 { |
|
570 ModifyFeedback( aClientHandle, aIntensity ); |
|
571 } |
|
572 } |
|
573 |
|
574 TRACE("CTouchFeedbackClient::StartFeedback - End"); |
|
575 } |
|
576 |
|
577 // ---------------------------------------------------------------------------- |
|
578 // |
|
579 // ---------------------------------------------------------------------------- |
|
580 // |
|
581 void CTouchFeedbackClient::ModifyFeedback( TUint32 aClientHandle, |
|
582 TInt aIntensity ) |
|
583 { |
|
584 // Modification is allowed only for the same control, which started |
|
585 // the feedback. |
|
586 if ( aClientHandle == iClientHandle && |
|
587 aIntensity != iPreviousIntensity ) |
|
588 { |
|
589 iPreviousIntensity = aIntensity; |
|
590 iFbClient.ModifyFeedback( aIntensity ); |
|
591 } |
|
592 } |
|
593 |
|
594 // ---------------------------------------------------------------------------- |
|
595 // |
|
596 // ---------------------------------------------------------------------------- |
|
597 // |
|
598 void CTouchFeedbackClient::StopFeedback( const TUint32 aClientHandle ) |
|
599 { |
|
600 TRACE("CTouchFeedbackClient::StopFeedback - Begin"); |
|
601 if ( aClientHandle == iClientHandle ) |
|
602 { |
|
603 iFbClient.StopFeedback(); |
|
604 iFeedbackTimer->Cancel(); |
|
605 // Clear also client handle to indicate there's no ongoing feedback. |
|
606 iClientHandle = 0; |
|
607 } |
|
608 TRACE("CTouchFeedbackClient::StopFeedback - End"); |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------------------------- |
|
612 // |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 TInt CTouchFeedbackClient::SetFeedbackEnabledForDevice( TTouchFeedbackType aFeedbackType ) |
|
616 { |
|
617 return iFbClient.SetFeedbackEnabledForDevice( aFeedbackType ); |
|
618 } |
|
619 |
|
620 // ---------------------------------------------------------------------------- |
|
621 // |
|
622 // ---------------------------------------------------------------------------- |
|
623 // |
|
624 TTouchFeedbackType CTouchFeedbackClient::FeedbackEnabledForDevice() |
|
625 { |
|
626 TTouchFeedbackType feedbackEnabled; |
|
627 iFbClient.FeedbackEnabledForDevice( feedbackEnabled ); |
|
628 return feedbackEnabled; |
|
629 } |
|
630 |
|
631 // ---------------------------------------------------------------------------- |
|
632 // |
|
633 // ---------------------------------------------------------------------------- |
|
634 // |
|
635 void CTouchFeedbackClient::StartFeedbackTimer( TTimeIntervalMicroSeconds32 aTimeout ) |
|
636 { |
|
637 iFeedbackTimer->Cancel(); |
|
638 TCallBack callback( StopFeedbackCallback, this ); |
|
639 iFeedbackTimer->Start( aTimeout, 0, callback ); |
|
640 } |
|
641 |
|
642 // ---------------------------------------------------------------------------- |
|
643 // |
|
644 // ---------------------------------------------------------------------------- |
|
645 // |
|
646 void CTouchFeedbackClient::StopFeedbackByTimeout() |
|
647 { |
|
648 iFeedbackTimer->Cancel(); |
|
649 iFbClient.StopFeedback(); |
|
650 iClientHandle = 0; |
|
651 } |
|
652 |
|
653 // ---------------------------------------------------------------------------- |
|
654 // CAknSlider::StopFeedbackCallback |
|
655 // ---------------------------------------------------------------------------- |
|
656 // |
|
657 TInt CTouchFeedbackClient::StopFeedbackCallback( TAny* aThis ) |
|
658 { |
|
659 TRACE("CTouchFeedbackClient::StopFeedbackCallback - Begin"); |
|
660 static_cast<CTouchFeedbackClient*>( aThis )->StopFeedbackByTimeout(); |
|
661 TRACE("CTouchFeedbackClient::StopFeedbackCallback - End"); |
|
662 return KErrNone; |
|
663 } |
|
664 |
|
665 // End of File |