|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of DTMF buffer class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <coemain.h> |
|
20 #include <cvtlogger.h> |
|
21 #include "cvtuidtmfbuffer.h" |
|
22 #include "tvtuiwsevent.h" |
|
23 #include "VtUiUtility.h" |
|
24 |
|
25 // Time after which buffer will be automatically reset (4 seconds). |
|
26 const TInt KBufferResetInterval = 4 * 1000000; |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CVtUiDTMFBuffer::NewL |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CVtUiDTMFBuffer* CVtUiDTMFBuffer::NewL( const CCoeEnv& aCoeEnv ) |
|
33 { |
|
34 __VTPRINTENTER( "CVtUiDTMFBuffer.NewL" ) |
|
35 CVtUiDTMFBuffer* self = new ( ELeave ) CVtUiDTMFBuffer( aCoeEnv ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); // self |
|
39 __VTPRINTEXIT( "CVtUiDTMFBuffer.NewL" ) |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CVtUiDTMFBuffer::~CVtUiDTMFBuffer |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CVtUiDTMFBuffer::~CVtUiDTMFBuffer() |
|
48 { |
|
49 __VTPRINTENTER( "CVtUiDTMFBuffer.~" ) |
|
50 Cancel(); |
|
51 iTimer.Close(); |
|
52 __VTPRINTEXIT( "CVtUiDTMFBuffer.~" ) |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CVtUiDTMFBuffer::Append |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 TBool CVtUiDTMFBuffer::Append( TChar aChar ) |
|
60 { |
|
61 __VTPRINTENTER( "CVtUiDTMFBuffer.Append" ) |
|
62 TBool result( EFalse ); |
|
63 if ( VtUiUtility::IsDTMFCharacter( aChar ) ) |
|
64 { |
|
65 if ( iBuffer.Length() == iBuffer.MaxLength() ) |
|
66 { |
|
67 iBuffer = iBuffer.Right( 1 ); |
|
68 } |
|
69 iBuffer.Append( aChar ); |
|
70 StartTimer(); |
|
71 result = ETrue; |
|
72 } |
|
73 __VTPRINTEXITR( "CVtUiDTMFBuffer.Append %d", result ) |
|
74 return result; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CVtUiDTMFBuffer::Reset |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CVtUiDTMFBuffer::Reset() |
|
82 { |
|
83 __VTPRINTENTER( "CVtUiDTMFBuffer.Reset" ) |
|
84 Cancel(); |
|
85 ResetBuffer(); |
|
86 __VTPRINTEXIT( "CVtUiDTMFBuffer.Reset" ) |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CVtUiDTMFBuffer::Activate |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CVtUiDTMFBuffer::Activate() |
|
94 { |
|
95 __VTPRINTENTER( "CVtUiDTMFBuffer.Activate" ) |
|
96 TVtUiWsEvent< MVtUiNumberSource > event( |
|
97 EVtUiWsEventNumberSourceActivate, this ); |
|
98 iCoeEnv.WsSession().SendEventToWindowGroup( |
|
99 iCoeEnv.RootWin().WindowGroupId(), event ); |
|
100 __VTPRINTEXIT( "CVtUiDTMFBuffer.Activate" ) |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CVtUiDTMFBuffer::Deactivate |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CVtUiDTMFBuffer::Deactivate() |
|
108 { |
|
109 __VTPRINTENTER( "CVtUiDTMFBuffer.Deactivate" ) |
|
110 TVtUiWsEvent< MVtUiNumberSource > event( |
|
111 EVtUiWsEventNumberSourceDeactivate, this ); |
|
112 iCoeEnv.WsSession().SendEventToWindowGroup( |
|
113 iCoeEnv.RootWin().WindowGroupId(), event ); |
|
114 __VTPRINTEXIT( "CVtUiDTMFBuffer.Deactivate" ) |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CVtUiDTMFBuffer::GetContents |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CVtUiDTMFBuffer::GetContents( TDes& aContents ) const |
|
122 { |
|
123 __VTPRINTENTER( "CVtUiDTMFBuffer.GetContents" ) |
|
124 const TInt length( aContents.MaxLength() < iBuffer.Length() ? |
|
125 aContents.MaxLength() : iBuffer.Length() ); |
|
126 if ( length ) |
|
127 { |
|
128 aContents = iBuffer.Mid( 0, length ); |
|
129 } |
|
130 else |
|
131 { |
|
132 aContents.Zero(); |
|
133 } |
|
134 __VTPRINTEXIT( "CVtUiDTMFBuffer.GetContents" ) |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CVtUiDTMFBuffer::DoCancel |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CVtUiDTMFBuffer::DoCancel() |
|
142 { |
|
143 __VTPRINTENTER( "CVtUiDTMFBuffer.DoCancel" ) |
|
144 iTimer.Cancel(); |
|
145 __VTPRINTEXIT( "CVtUiDTMFBuffer.DoCancel" ) |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // CVtUiDTMFBuffer::RunL |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CVtUiDTMFBuffer::RunL() |
|
153 { |
|
154 __VTPRINTENTER( "CVtUiDTMFBuffer.RunL" ) |
|
155 TimerExpired( iStatus.Int() ); |
|
156 __VTPRINTEXIT( "CVtUiDTMFBuffer.RunL" ) |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CVtUiDTMFBuffer::CVtUiDTMFBuffer |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 CVtUiDTMFBuffer::CVtUiDTMFBuffer( const CCoeEnv& aCoeEnv ) : |
|
164 CActive( EPriorityStandard ), iCoeEnv( aCoeEnv ) |
|
165 { |
|
166 __VTPRINTENTER( "CVtUiDTMFBuffer.ctor" ) |
|
167 CActiveScheduler::Add( this ); |
|
168 __VTPRINTEXIT( "CVtUiDTMFBuffer.ctor" ) |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // CVtUiDTMFBuffer::ConstructL |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CVtUiDTMFBuffer::ConstructL() |
|
176 { |
|
177 __VTPRINTENTER( "CVtUiDTMFBuffer.ConstructL" ) |
|
178 User::LeaveIfError( iTimer.CreateLocal() ); |
|
179 __VTPRINTEXIT( "CVtUiDTMFBuffer.ConstructL" ) |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CVtUiDTMFBuffer::StartTimer |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CVtUiDTMFBuffer::StartTimer() |
|
187 { |
|
188 __VTPRINTENTER( "CVtUiDTMFBuffer.StartTimer" ) |
|
189 Cancel(); |
|
190 SetActive(); |
|
191 iTimer.After( iStatus, KBufferResetInterval ); |
|
192 __VTPRINTEXIT( "CVtUiDTMFBuffer.StartTimer" ) |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CVtUiDTMFBuffer::TimerExpired |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CVtUiDTMFBuffer::TimerExpired( TInt aError ) |
|
200 { |
|
201 __VTPRINTENTER( "CVtUiDTMFBuffer.TimerExpired" ) |
|
202 if ( aError != KErrCancel ) |
|
203 { |
|
204 ResetBuffer(); |
|
205 } |
|
206 __VTPRINTEXIT( "CVtUiDTMFBuffer.TimerExpired" ) |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CVtUiDTMFBuffer::ResetBuffer |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CVtUiDTMFBuffer::ResetBuffer() |
|
214 { |
|
215 __VTPRINTENTER( "CVtUiDTMFBuffer.ResetBuffer" ) |
|
216 iBuffer.Zero(); |
|
217 __VTPRINTEXIT( "CVtUiDTMFBuffer.ResetBuffer" ) |
|
218 } |