|
1 /* |
|
2 * Copyright (c) 2006 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: Implements the buffer timeout logic specific to the speech item |
|
15 * trainer. Is notified about the speech item trainer action requests, |
|
16 * and decides when to actually fire the buffered actions |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "nssvasctrainingactiontracker.h" |
|
22 #include "rubydebug.h" |
|
23 |
|
24 const TInt KDelayInMicroseconds = 500000; |
|
25 |
|
26 |
|
27 CNssTrainingActionTracker* CNssTrainingActionTracker::NewL( MDelayedNotifiable& aNotifiable ) |
|
28 { |
|
29 CNssTrainingActionTracker* self = new (ELeave) CNssTrainingActionTracker( aNotifiable ); |
|
30 CleanupStack::PushL( self ); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop( self ); |
|
33 return self; |
|
34 } |
|
35 |
|
36 CNssTrainingActionTracker::CNssTrainingActionTracker( MDelayedNotifiable& aNotifiable ) : |
|
37 CTimer( EPriorityStandard ), iHost( aNotifiable ) |
|
38 { |
|
39 // empty |
|
40 } |
|
41 |
|
42 CNssTrainingActionTracker::~CNssTrainingActionTracker() |
|
43 { |
|
44 delete iAsyncCallback; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Is called by the client to notify tracker about the request to |
|
49 * perform a potentially bufferable action. It is up to tracker |
|
50 * when to stop recording the action requests and fire the |
|
51 * delayed actions via MDelayedNotifiable::DoBufferedActionsL |
|
52 * |
|
53 * DoBufferedActionsL is always called asynchronously. Even if tracker |
|
54 * decides to fire the delayable actions immediately |
|
55 */ |
|
56 void CNssTrainingActionTracker::ActionRequestedL() |
|
57 { |
|
58 RUBY_DEBUG_BLOCK(""); |
|
59 iUnfiredActions = ETrue; |
|
60 if ( !IsActive() ) |
|
61 { |
|
62 RUBY_DEBUG0( "The first event in a sequence" ); |
|
63 iAsyncCallback->CallBack(); |
|
64 } |
|
65 RestartTimer(); |
|
66 } |
|
67 |
|
68 void CNssTrainingActionTracker::RestartTimer() |
|
69 { |
|
70 if( IsActive() ) |
|
71 { |
|
72 Cancel(); |
|
73 } |
|
74 After( TTimeIntervalMicroSeconds32( KDelayInMicroseconds ) ); |
|
75 } |
|
76 |
|
77 |
|
78 void CNssTrainingActionTracker::ConstructL() |
|
79 { |
|
80 CTimer::ConstructL(); |
|
81 CActiveScheduler::Add( this ); |
|
82 iAsyncCallback = new (ELeave) CAsyncCallBack( TCallBack(FireActionsImmediately, this ), |
|
83 CActive::EPriorityStandard ); |
|
84 } |
|
85 |
|
86 void CNssTrainingActionTracker::RunL() |
|
87 { |
|
88 // timeout happened |
|
89 if( iUnfiredActions ) |
|
90 { |
|
91 RUBY_DEBUG0("Unfired actions in the buffeer"); |
|
92 DoFireActionsL(); |
|
93 } |
|
94 } |
|
95 |
|
96 TInt CNssTrainingActionTracker::FireActionsImmediately( TAny* pX ) |
|
97 { |
|
98 TRAPD( err, static_cast<CNssTrainingActionTracker*>(pX)->DoFireActionsL() ); |
|
99 return err; |
|
100 } |
|
101 |
|
102 |
|
103 void CNssTrainingActionTracker::DoFireActionsL() |
|
104 { |
|
105 RUBY_DEBUG_BLOCK(""); |
|
106 // Whatever is requested after RunBufferedActionsL or *during* RunBufferedActionsL |
|
107 // has to be fired later |
|
108 iUnfiredActions = EFalse; |
|
109 iHost.RunBufferedActionsL(); |
|
110 } |
|
111 |
|
112 // End of file |