|
1 /* |
|
2 * Copyright (c) 2006-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: State machine for DTMF payload format encoding and sending. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "dtmfencstatemachine.h" |
|
23 #include "dtmfpayloadformatdefs.h" |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CDtmfEncStateMachine::CMccSymDtmfStream |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CDtmfEncStateMachine::CDtmfEncStateMachine( MDtmfEncClient& aClient ) |
|
35 : CActive( EPriorityStandard ), iClient( aClient ), |
|
36 iState( EStateSendingIdle ) |
|
37 { |
|
38 CActiveScheduler::Add( this ); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CDtmfEncStateMachine::NewL |
|
43 // Two-phased constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CDtmfEncStateMachine* CDtmfEncStateMachine::NewL( MDtmfEncClient& aClient ) |
|
47 { |
|
48 CDtmfEncStateMachine* self = |
|
49 new( ELeave ) CDtmfEncStateMachine( aClient ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CDtmfEncStateMachine::~CDtmfEncStateMachine |
|
55 // Destructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CDtmfEncStateMachine::~CDtmfEncStateMachine() |
|
59 { |
|
60 Cancel(); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CDtmfEncStateMachine::State |
|
65 // Returns current state. |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 TDTMFSendingState CDtmfEncStateMachine::State() const |
|
69 { |
|
70 return iState; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CDtmfEncStateMachine::ChangeStateTo |
|
75 // Changes state to the new one if transition is valid. |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CDtmfEncStateMachine::ChangeStateTo( TDTMFSendingState aNewState ) |
|
79 { |
|
80 DP_DTMF_WRITE3( _L("CDtmfEncStateMachine::ChangeStateTo aNewState: %d iState: %d"), |
|
81 aNewState, iState ); |
|
82 |
|
83 TBool validTransition( EFalse ); |
|
84 switch ( aNewState ) |
|
85 { |
|
86 case EStateSendingIdle: |
|
87 DP_DTMF_WRITE( _L("ChangeStateTo: EStateSendingIdle") ); |
|
88 |
|
89 if ( EStateEncodeNextDigit == iState || |
|
90 EStateSendStopped == iState ) |
|
91 { |
|
92 validTransition = ETrue; |
|
93 } |
|
94 break; |
|
95 |
|
96 case EStateEncodeNextDigit: |
|
97 DP_DTMF_WRITE( _L("ChangeStateTo: EStateEncodeNextDigit") ); |
|
98 |
|
99 if ( EStateToneOn != iState ) |
|
100 { |
|
101 validTransition = ETrue; |
|
102 } |
|
103 break; |
|
104 |
|
105 case EStateToneOn: |
|
106 DP_DTMF_WRITE( _L("ChangeStateTo: EStateToneOn") ); |
|
107 |
|
108 if ( EStateEncodeNextDigit == iState ) |
|
109 { |
|
110 validTransition = ETrue; |
|
111 } |
|
112 break; |
|
113 |
|
114 case EStateToneOff: |
|
115 DP_DTMF_WRITE( _L("ChangeStateTo: EStateToneOff") ); |
|
116 |
|
117 if ( EStateToneOn == iState ) |
|
118 { |
|
119 validTransition = ETrue; |
|
120 } |
|
121 break; |
|
122 |
|
123 case EStateSendPaused: |
|
124 DP_DTMF_WRITE( _L("ChangeStateTo: EStateSendPaused") ); |
|
125 |
|
126 if ( EStateEncodeNextDigit == iState ) |
|
127 { |
|
128 validTransition = ETrue; |
|
129 } |
|
130 break; |
|
131 |
|
132 case EStateSendStopped: |
|
133 DP_DTMF_WRITE( _L("ChangeStateTo: EStateSendStopped") ); |
|
134 |
|
135 if ( EStateEncodeNextDigit == iState ) |
|
136 { |
|
137 validTransition = ETrue; |
|
138 } |
|
139 break; |
|
140 |
|
141 default: |
|
142 DP_DTMF_WRITE( _L("ChangeStateTo: default") ); |
|
143 break; |
|
144 } |
|
145 |
|
146 // Change the state if everything is OK. |
|
147 if ( validTransition && !IsActive() ) |
|
148 { |
|
149 iState = aNewState; |
|
150 |
|
151 // Do the active state transfer only if needed. This saves again a |
|
152 // few cycles by not doing idle rounds trough activescheduler. |
|
153 if ( EStateEncodeNextDigit == iState || |
|
154 EStateToneOn == iState || |
|
155 EStateToneOff == iState ) |
|
156 { |
|
157 TRequestStatus* stat = &iStatus; |
|
158 User::RequestComplete( stat, KErrNone ); |
|
159 SetActive(); |
|
160 } |
|
161 } |
|
162 |
|
163 DP_DTMF_WRITE3( _L("ChangeStateTo - VALIDITY: %d, ACTIVE: %d"), |
|
164 validTransition, IsActive() ); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CDtmfEncStateMachine::RunL |
|
169 // Handles an active object’s request completion event. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CDtmfEncStateMachine::RunL() |
|
173 { |
|
174 DP_DTMF_WRITE2( _L("CDtmfEncStateMachine::RunL - status: %d"), |
|
175 iStatus.Int() ); |
|
176 |
|
177 if ( KErrNone == iStatus.Int() ) |
|
178 { |
|
179 switch ( iState ) |
|
180 { |
|
181 case EStateEncodeNextDigit: |
|
182 iClient.EncodeNextDigitL(); |
|
183 break; |
|
184 case EStateToneOn: |
|
185 iClient.DoToneOnActionsL( ETrue ); |
|
186 break; |
|
187 case EStateToneOff: |
|
188 iClient.DoToneOffActionsL( ETrue ); |
|
189 break; |
|
190 case EStateSendingIdle: |
|
191 case EStateSendPaused: |
|
192 case EStateSendStopped: |
|
193 break; |
|
194 default: |
|
195 break; |
|
196 } |
|
197 } |
|
198 else |
|
199 { |
|
200 User::Leave( iStatus.Int() ); |
|
201 } |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CDtmfEncStateMachine::DoCancel |
|
206 // Implements cancellation of an outstanding request. |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CDtmfEncStateMachine::DoCancel() |
|
210 { |
|
211 DP_DTMF_WRITE( _L("CDtmfEncStateMachine::DoCancel") ); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CDtmfEncStateMachine::RunError |
|
216 // Error handling of the active object. |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CDtmfEncStateMachine::RunError( TInt aError ) |
|
220 { |
|
221 DP_DTMF_WRITE2( _L("CDtmfEncStateMachine::RunError aError: %d"), aError ); |
|
222 |
|
223 if ( KErrNoMemory == aError ) |
|
224 { |
|
225 return KErrNoMemory; |
|
226 } |
|
227 else |
|
228 { |
|
229 return KErrNone; |
|
230 } |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CDtmfEncStateMachine::ResetStateMachine |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CDtmfEncStateMachine::ResetStateMachine() |
|
238 { |
|
239 Cancel(); |
|
240 iState = EStateSendingIdle; |
|
241 } |
|
242 |
|
243 // End of File |