|
1 /* |
|
2 * Copyright (c) 2002-2005 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: StateMachine for payloadformat plugins. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "formatstatemachine.h" |
|
24 |
|
25 |
|
26 // ============================= LOCAL FUNCTIONS =============================== |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CFormatEncodeStateMachine::CFormatEncodeStateMachine |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CFormatEncodeStateMachine::CFormatEncodeStateMachine( |
|
37 MPayloadFormatWrite* aClient ) : CActive( EPriorityStandard ), |
|
38 iClient( aClient ), iState( EEncodeIdle ) |
|
39 { |
|
40 CActiveScheduler::Add( this ); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CFormatEncodeStateMachine::ConstructL() |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CFormatEncodeStateMachine::ConstructL() |
|
49 { |
|
50 User::LeaveIfNull( iClient ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CFormatEncodeStateMachine::NewL |
|
55 // Static constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CFormatEncodeStateMachine* CFormatEncodeStateMachine::NewL( |
|
59 MPayloadFormatWrite* aClient ) |
|
60 { |
|
61 CFormatEncodeStateMachine* self = |
|
62 new ( ELeave ) CFormatEncodeStateMachine( aClient ); |
|
63 |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop( self ); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ------------------------------------------------------------------------------ |
|
72 // CFormatEncodeStateMachine::~CFormatEncodeStateMachine |
|
73 // Destructor |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CFormatEncodeStateMachine::~CFormatEncodeStateMachine() |
|
77 { |
|
78 Cancel(); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CFormatEncodeStateMachine::ChangeState |
|
83 // Changes state |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CFormatEncodeStateMachine::ChangeState( TFormatEncodeState aNewState ) |
|
87 { |
|
88 // Observe the transition rules |
|
89 TBool changeState = EFalse; |
|
90 switch ( aNewState ) |
|
91 { |
|
92 case EEncodeIdle: |
|
93 // Can change to EEncodeIdle state from any other state. |
|
94 changeState = ETrue; |
|
95 break; |
|
96 |
|
97 case EEmptySourceBuffer: |
|
98 if ( ESourceBufferEmptied == iState || EEncodeIdle == iState ) |
|
99 { |
|
100 changeState = ETrue; |
|
101 } |
|
102 break; |
|
103 |
|
104 case ESourceBufferEmptied: |
|
105 if ( EEmptySourceBuffer == iState ) |
|
106 { |
|
107 changeState = ETrue; |
|
108 } |
|
109 break; |
|
110 |
|
111 default: |
|
112 break; |
|
113 } |
|
114 |
|
115 // Change the state if everything is OK. |
|
116 if ( changeState ) |
|
117 { |
|
118 iState = aNewState; |
|
119 |
|
120 // Idle states, no callbacks to client, thus no need for activation. |
|
121 if ( EEncodeIdle != iState ) |
|
122 { |
|
123 TRequestStatus* stat = &iStatus; |
|
124 Cancel(); |
|
125 User::RequestComplete( stat, KErrNone ); |
|
126 SetActive(); |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CFormatEncodeStateMachine::CurrentState |
|
133 // Returns the current state |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 TFormatEncodeState CFormatEncodeStateMachine::CurrentState() const |
|
137 { |
|
138 return iState; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CFormatEncodeStateMachine::RunL |
|
143 // From CActive Handles an active object’s request completion event. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CFormatEncodeStateMachine::RunL() |
|
147 { |
|
148 if ( KErrNone == iStatus.Int() ) |
|
149 { |
|
150 switch ( iState ) |
|
151 { |
|
152 case EEncodeIdle: |
|
153 // Do nothing but wait. |
|
154 break; |
|
155 |
|
156 case EEmptySourceBuffer: |
|
157 iClient->EmptySourceBufferL(); |
|
158 break; |
|
159 |
|
160 case ESourceBufferEmptied: |
|
161 iClient->SourceBufferEmptiedL(); |
|
162 break; |
|
163 |
|
164 default: |
|
165 User::Leave( KErrArgument ); |
|
166 break; |
|
167 } |
|
168 } |
|
169 else |
|
170 { |
|
171 User::Leave( iStatus.Int() ); |
|
172 } |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CFormatEncodeStateMachine::DoCancel |
|
177 // From CActive Implements cancellation of an outstanding request. |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CFormatEncodeStateMachine::DoCancel() |
|
181 { |
|
182 |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CFormatEncodeStateMachine::RunError |
|
187 // Handle the leave occured in RunL() function |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CFormatEncodeStateMachine::RunError( TInt /*aError*/ ) |
|
191 { |
|
192 return KErrNone; |
|
193 }; |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CFormatDecodeStateMachine::CFormatDecodeStateMachine |
|
197 // C++ default constructor can NOT contain any code, that |
|
198 // might leave |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 CFormatDecodeStateMachine::CFormatDecodeStateMachine( |
|
202 MPayloadFormatRead* aClient ) : CActive( EPriorityStandard ), |
|
203 iClient( aClient ), iState( EDecodeIdle ) |
|
204 { |
|
205 CActiveScheduler::Add( this ); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CFormatDecodeStateMachine::ConstructL |
|
210 // Symbian 2nd phase constructor can leave. |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CFormatDecodeStateMachine::ConstructL() |
|
214 { |
|
215 User::LeaveIfNull( iClient ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CFormatDecodeStateMachine::NewL |
|
220 // Static constructor. |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 CFormatDecodeStateMachine* CFormatDecodeStateMachine::NewL( |
|
224 MPayloadFormatRead* aClient ) |
|
225 { |
|
226 CFormatDecodeStateMachine* self = |
|
227 new ( ELeave ) CFormatDecodeStateMachine( aClient ); |
|
228 |
|
229 CleanupStack::PushL( self ); |
|
230 self->ConstructL(); |
|
231 CleanupStack::Pop( self ); |
|
232 |
|
233 return self; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CFormatDecodeStateMachine::~CFormatDecodeStateMachine |
|
238 // Destructor |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 CFormatDecodeStateMachine::~CFormatDecodeStateMachine() |
|
242 { |
|
243 Cancel(); |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CFormatDecodeStateMachine::ChangeState |
|
248 // Change State |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CFormatDecodeStateMachine::ChangeState( TFormatDecodeState aNewState ) |
|
252 { |
|
253 // Observe the state transition rules. |
|
254 TBool changeState = EFalse; |
|
255 switch ( aNewState ) |
|
256 { |
|
257 // These state transitions allowed from all states. |
|
258 case EDecodeIdle: |
|
259 case ESourceDataReady: |
|
260 changeState = ETrue; |
|
261 break; |
|
262 |
|
263 case EEmptyDataToSink: |
|
264 if ( ESourceDataReady == iState || EEmptyDataToSink == iState ) |
|
265 { |
|
266 changeState = ETrue; |
|
267 } |
|
268 break; |
|
269 |
|
270 default: |
|
271 break; |
|
272 } |
|
273 |
|
274 if ( changeState ) |
|
275 { |
|
276 iState = aNewState; |
|
277 |
|
278 // Idle state, no callbacks to client, thus no need for activation. |
|
279 if ( EDecodeIdle != iState ) |
|
280 { |
|
281 TRequestStatus* stat = &iStatus; |
|
282 Cancel(); |
|
283 User::RequestComplete( stat, KErrNone ); |
|
284 SetActive(); |
|
285 } |
|
286 } |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CFormatDecodeStateMachine::CurrentState |
|
291 // Get current state |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 TFormatDecodeState CFormatDecodeStateMachine::CurrentState() const |
|
295 { |
|
296 return iState; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CFormatDecodeStateMachine::RunL |
|
301 // From CActive Handles an active object’s request completion event. |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 void CFormatDecodeStateMachine::RunL() |
|
305 { |
|
306 if ( KErrNone == iStatus.Int() ) |
|
307 { |
|
308 switch ( iState ) |
|
309 { |
|
310 case EDecodeIdle: |
|
311 // TBD: Do idle processing. |
|
312 break; |
|
313 |
|
314 case ESourceDataReady: |
|
315 iClient->FillSinkBufferL(); |
|
316 break; |
|
317 |
|
318 case EEmptyDataToSink: |
|
319 iClient->SendDataToSinkL(); |
|
320 break; |
|
321 |
|
322 default: |
|
323 User::Leave( KErrArgument ); |
|
324 break; |
|
325 } |
|
326 } |
|
327 else |
|
328 { |
|
329 User::Leave( iStatus.Int() ); |
|
330 } |
|
331 }; |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CFormatDecodeStateMachine::DoCancel |
|
335 // From CActive Implements cancellation of an outstanding request. |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CFormatDecodeStateMachine::DoCancel() |
|
339 { |
|
340 |
|
341 }; |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CFormatDecodeStateMachine::RunError |
|
345 // Handle the leave occured in RunL() function |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 TInt CFormatDecodeStateMachine::RunError( TInt /*aError*/ ) |
|
349 { |
|
350 return KErrNone; |
|
351 }; |
|
352 |
|
353 // End of File |