|
1 /* |
|
2 * Copyright (c) 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: Class for event context. Contains methods for |
|
15 * creating the state array and controlling current state. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "mcecomevent.h" |
|
23 #include "mceeventcontext.h" |
|
24 #include "mceeventstatebase.h" |
|
25 #include "mceeventsubscribemoestablishedstate.h" |
|
26 #include "mceeventsubscribemtestablishedstate.h" |
|
27 #include "mceeventsubscribeterminatingstate.h" |
|
28 #include "mceeventsubscribeterminatedstate.h" |
|
29 #include "mceeventrefermoestablishedstate.h" |
|
30 #include "mceeventrefermtestablishedstate.h" |
|
31 #include "mceeventreferterminatingstate.h" |
|
32 #include "mceeventreferterminatedstate.h" |
|
33 #include "mceeventsubscribemoidlestate.h" |
|
34 #include "mceeventsubscribemoestablishingstate.h" |
|
35 #include "mceeventrefermoidlestate.h" |
|
36 #include "mceeventrefermoestablishingstate.h" |
|
37 #include "mceeventsubscribemtidlestate.h" |
|
38 #include "mceeventsubscribemtestablishingstate.h" |
|
39 #include "mceeventrefermtidlestate.h" |
|
40 #include "mceeventrefermtestablishingstate.h" |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CMCEMoEventSubscribeContext::NewL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CMceEventContext* CMceEventContext::NewL( CMceComEvent& aEvent ) |
|
47 { |
|
48 CMceEventContext* self = new( ELeave ) CMceEventContext; |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( aEvent ); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CMceEventContext::CMceEventContext |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CMceEventContext::CMceEventContext() |
|
60 { |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CMceEventContext::ConstructL |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CMceEventContext::ConstructL( CMceComEvent& aEvent ) |
|
68 { |
|
69 InitializeStateArrayL(aEvent); |
|
70 SetCurrentStateL( aEvent, KMceIdleEventStateIndex ); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CMceEventContext::~CMceEventContext |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CMceEventContext::~CMceEventContext() |
|
78 { |
|
79 if ( iStates ) |
|
80 { |
|
81 iStates->ResetAndDestroy(); |
|
82 iStates->Close(); |
|
83 delete iStates; |
|
84 iStates = NULL; |
|
85 } |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CMceEventContext::SetCurrentState |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CMceEventContext::SetCurrentStateL( CMceComEvent& aEvent, |
|
93 TMceEventStateIndex aNewEventState ) |
|
94 { |
|
95 TInt leave = KErrNone; |
|
96 if (aNewEventState > KMceSrvEventStateArraySize-1) |
|
97 { |
|
98 leave = KMceEventStateError; |
|
99 } |
|
100 // Check, if the transition is valid |
|
101 if(aEvent.SIPEvent().EventStateType()==EMoSubscribe || |
|
102 aEvent.SIPEvent().EventStateType()==EMoRefer) |
|
103 { |
|
104 if ( !IsMoStateTransitionAccepted( aNewEventState ) ) |
|
105 { |
|
106 leave = KMceEventStateError; |
|
107 } |
|
108 else |
|
109 { |
|
110 iCurrentState = ( *iStates )[ aNewEventState ]; |
|
111 } |
|
112 } |
|
113 else //MT |
|
114 { |
|
115 if ( !IsMtStateTransitionAccepted( aNewEventState ) ) |
|
116 { |
|
117 leave = KMceEventStateError; |
|
118 } |
|
119 else |
|
120 { |
|
121 iCurrentState = ( *iStates )[ aNewEventState ]; |
|
122 } |
|
123 } |
|
124 User::LeaveIfError( leave ); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CMceEventContext::CurrentState() |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TMceEventStateIndex CMceEventContext::CurrentState() |
|
132 { |
|
133 return iStates->Find( iCurrentState ); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CMceEventContext::ProcessSubscribeEventL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CMceEventContext::ProcessEventL( CMceComEvent& aEvent ) |
|
141 { |
|
142 iCurrentState->ProcessStateL( aEvent ); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CMceEventContext::ProcessRequestReceivedEventL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CMceEventContext::ProcessRequestReceivedEventL( CMceComEvent& aEvent ) |
|
150 { |
|
151 iCurrentState->ProcessReqRecvStateL( aEvent ); |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CMceEventContext::ProcessIncomingResponseEventL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CMceEventContext::ProcessIncomingResponseEventL( CMceComEvent& aEvent ) |
|
159 { |
|
160 iCurrentState->ProcessRespRecvStateL( aEvent ); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CMceEventContext::InitializeStateArrayL |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CMceEventContext::InitializeStateArrayL( CMceComEvent& aEvent ) |
|
168 { |
|
169 // Create state array |
|
170 iStates = new ( ELeave ) RPointerArray< CMceEventStateBase >( |
|
171 KMceSrvEventStateArraySize ); |
|
172 |
|
173 // States common for MO and MT are created here. |
|
174 // Established event state |
|
175 if (aEvent.SIPEvent().EventStateType()==EMoSubscribe) |
|
176 { |
|
177 InitialSubscribeCommonStatesL(); |
|
178 //moSubscirbe State |
|
179 // MO Idle state |
|
180 CMceEventSubscribeMoIdleState* idleEvent = |
|
181 new( ELeave ) CMceEventSubscribeMoIdleState(); |
|
182 CleanupStack::PushL( idleEvent ); |
|
183 User::LeaveIfError( iStates->Insert( |
|
184 idleEvent, KMceIdleEventStateIndex ) ); |
|
185 CleanupStack::Pop( idleEvent ); |
|
186 |
|
187 // MO Establishing state |
|
188 |
|
189 CMceEventSubscribeMoEstablishingState* establishingEvent = |
|
190 new( ELeave ) CMceEventSubscribeMoEstablishingState(); |
|
191 CleanupStack::PushL( establishingEvent ); |
|
192 User::LeaveIfError( iStates->Insert( |
|
193 establishingEvent, KMceEstablishingEventStateIndex ) ); |
|
194 CleanupStack::Pop( establishingEvent ); |
|
195 |
|
196 CMceEventSubscribeMoEstablishedState* established = |
|
197 new( ELeave ) CMceEventSubscribeMoEstablishedState(); |
|
198 CleanupStack::PushL( established ); |
|
199 User::LeaveIfError( iStates->Insert( |
|
200 established, KMceEstablishedEventStateIndex ) ); |
|
201 CleanupStack::Pop( established ); |
|
202 } |
|
203 else if(aEvent.SIPEvent().EventStateType()==EMtSubscribe) |
|
204 { |
|
205 InitialSubscribeCommonStatesL(); |
|
206 //mtSubscribe State |
|
207 // MT Idle state |
|
208 CMceEventSubscribeMtIdleState* idleEvent = |
|
209 new( ELeave ) CMceEventSubscribeMtIdleState(); |
|
210 CleanupStack::PushL( idleEvent ); |
|
211 User::LeaveIfError( iStates->Insert( |
|
212 idleEvent, KMceIdleEventStateIndex ) ); |
|
213 CleanupStack::Pop( idleEvent ); |
|
214 |
|
215 // Mt establishing state |
|
216 CMceEventSubscribeMtEstablishingState* establishing = |
|
217 new ( ELeave ) CMceEventSubscribeMtEstablishingState(); |
|
218 CleanupStack::PushL( establishing ); |
|
219 User::LeaveIfError( iStates->Insert( |
|
220 establishing, KMceEstablishingEventStateIndex ) ); |
|
221 CleanupStack::Pop( establishing ); |
|
222 |
|
223 //Mt established |
|
224 CMceEventSubscribeMtEstablishedState* established = |
|
225 new( ELeave ) CMceEventSubscribeMtEstablishedState(); |
|
226 CleanupStack::PushL( established ); |
|
227 User::LeaveIfError( iStates->Insert( |
|
228 established, KMceEstablishedEventStateIndex ) ); |
|
229 CleanupStack::Pop( established ); |
|
230 } |
|
231 else if(aEvent.SIPEvent().EventStateType()==EMoRefer) |
|
232 { |
|
233 InitialReferCommonStatesL(); |
|
234 //moReferState |
|
235 // MO Idle state |
|
236 CMceEventReferMoIdleState* idleEvent = |
|
237 new( ELeave )CMceEventReferMoIdleState(); |
|
238 CleanupStack::PushL( idleEvent ); |
|
239 User::LeaveIfError( iStates->Insert( |
|
240 idleEvent, KMceIdleEventStateIndex ) ); |
|
241 CleanupStack::Pop( idleEvent ); |
|
242 |
|
243 // MO Establishing state |
|
244 CMceEventReferMoEstablishingState* establishingEvent = |
|
245 new( ELeave )CMceEventReferMoEstablishingState; |
|
246 CleanupStack::PushL( establishingEvent ); |
|
247 User::LeaveIfError( iStates->Insert( |
|
248 establishingEvent, KMceEstablishingEventStateIndex ) ); |
|
249 CleanupStack::Pop( establishingEvent ); |
|
250 //Mo Established |
|
251 CMceEventReferMoEstablishedState* established = |
|
252 new( ELeave ) CMceEventReferMoEstablishedState(); |
|
253 CleanupStack::PushL( established ); |
|
254 User::LeaveIfError( iStates->Insert( |
|
255 established, KMceEstablishedEventStateIndex ) ); |
|
256 CleanupStack::Pop( established ); |
|
257 } |
|
258 else |
|
259 { |
|
260 InitialReferCommonStatesL(); |
|
261 //mtReferState |
|
262 // MT Idle state |
|
263 CMceEventReferMtIdleState* idleEvent = |
|
264 new( ELeave ) CMceEventReferMtIdleState(); |
|
265 CleanupStack::PushL( idleEvent ); |
|
266 User::LeaveIfError( iStates->Insert( |
|
267 idleEvent, KMceIdleEventStateIndex ) ); |
|
268 CleanupStack::Pop( idleEvent ); |
|
269 |
|
270 // Server establishing state |
|
271 CMceEventReferMtEstablishingState* establishing = |
|
272 new( ELeave ) CMceEventReferMtEstablishingState(); |
|
273 CleanupStack::PushL( establishing ); |
|
274 User::LeaveIfError( iStates->Insert( |
|
275 establishing, KMceEstablishingEventStateIndex ) ); |
|
276 CleanupStack::Pop( establishing ); |
|
277 //Mt established |
|
278 CMceEventReferMtEstablishedState* established = |
|
279 new( ELeave )CMceEventReferMtEstablishedState(); |
|
280 CleanupStack::PushL( established ); |
|
281 User::LeaveIfError( iStates->Insert( |
|
282 established, KMceEstablishedEventStateIndex ) ); |
|
283 CleanupStack::Pop( established ); |
|
284 } |
|
285 |
|
286 } |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CMceEventContext::InitialSubscribeCommonStates |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CMceEventContext::InitialSubscribeCommonStatesL() |
|
292 { |
|
293 // Terminating event state |
|
294 CMceEventSubscribeTerminatingState* terminating = |
|
295 new( ELeave )CMceEventSubscribeTerminatingState(); |
|
296 CleanupStack::PushL( terminating ); |
|
297 User::LeaveIfError( iStates->Insert( |
|
298 terminating, KMceTerminatingEventStateIndex ) ); |
|
299 CleanupStack::Pop( terminating ); |
|
300 |
|
301 // Terminated event state |
|
302 CMceEventSubscribeTerminatedState* terminated = |
|
303 new( ELeave ) CMceEventSubscribeTerminatedState(); |
|
304 CleanupStack::PushL( terminated ); |
|
305 User::LeaveIfError( iStates->Insert( |
|
306 terminated, KMceTerminatedEventStateIndex ) ); |
|
307 CleanupStack::Pop( terminated ); |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // CMceEventContext::InitialReferCommonStates |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 void CMceEventContext::InitialReferCommonStatesL() |
|
315 { |
|
316 // Terminating event state |
|
317 CMceEventReferTerminatingState* terminating = |
|
318 new( ELeave ) CMceEventReferTerminatingState(); |
|
319 CleanupStack::PushL( terminating ); |
|
320 User::LeaveIfError( iStates->Insert( |
|
321 terminating, KMceTerminatingEventStateIndex ) ); |
|
322 CleanupStack::Pop( terminating ); |
|
323 |
|
324 // Terminated event state |
|
325 CMceEventReferTerminatedState* terminated = |
|
326 new( ELeave ) CMceEventReferTerminatedState(); |
|
327 CleanupStack::PushL( terminated ); |
|
328 User::LeaveIfError( iStates->Insert( |
|
329 terminated, KMceTerminatedEventStateIndex ) ); |
|
330 CleanupStack::Pop( terminated ); |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CMCEMoEventSubscribeContext::IsMoStateTransitionAccepted |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 TBool CMceEventContext::IsMoStateTransitionAccepted( |
|
338 TMceEventStateIndex aNewState ) |
|
339 { |
|
340 // Call the parent function. |
|
341 return IsStateTransitionAccepted( aNewState ); |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CMceSrvMoEventContext::IsMtStateTransitionAccepted |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 TBool CMceEventContext::IsMtStateTransitionAccepted( |
|
349 TMceEventStateIndex aNewState ) |
|
350 { |
|
351 TMceEventStateIndex currentState = CurrentState(); |
|
352 TBool ret = IsStateTransitionAccepted( aNewState ); |
|
353 if ( !ret ) |
|
354 { |
|
355 switch ( currentState ) |
|
356 { |
|
357 case KMceIdleEventStateIndex: |
|
358 { |
|
359 // From MT event idle state, transition to client establishing |
|
360 // state is allowed. |
|
361 if (KMceEstablishedEventStateIndex == aNewState || |
|
362 KMceTerminatedEventStateIndex == aNewState ) |
|
363 { |
|
364 ret = ETrue; |
|
365 } |
|
366 break; |
|
367 } |
|
368 |
|
369 default: |
|
370 { |
|
371 ret = EFalse; |
|
372 break; |
|
373 } |
|
374 } |
|
375 } |
|
376 return ret; |
|
377 } |
|
378 |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CMceEventContext::IsStateTransitionAccepted |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TMceEventStateIndex CMceEventContext::IsStateTransitionAccepted( |
|
385 TMceEventStateIndex aNewState ) |
|
386 { |
|
387 TMceEventStateIndex current = CurrentState(); |
|
388 switch( current ) |
|
389 { |
|
390 case KErrNotFound: |
|
391 { |
|
392 // Only idle state can be the first one. |
|
393 if ( KMceIdleEventStateIndex == aNewState ) |
|
394 { |
|
395 return ETrue; |
|
396 } |
|
397 else |
|
398 { |
|
399 return EFalse; |
|
400 } |
|
401 } |
|
402 |
|
403 case KMceIdleEventStateIndex: |
|
404 { |
|
405 if ( KMceEstablishingEventStateIndex == aNewState ) |
|
406 { |
|
407 return ETrue; |
|
408 } |
|
409 else |
|
410 { |
|
411 return EFalse; |
|
412 } |
|
413 } |
|
414 |
|
415 case KMceEstablishingEventStateIndex: |
|
416 { |
|
417 if ( KMceEstablishedEventStateIndex == aNewState || |
|
418 KMceTerminatedEventStateIndex == aNewState ) |
|
419 { |
|
420 return ETrue; |
|
421 } |
|
422 else |
|
423 { |
|
424 return EFalse; |
|
425 } |
|
426 } |
|
427 |
|
428 case KMceEstablishedEventStateIndex: |
|
429 { |
|
430 if ( KMceEstablishingEventStateIndex == aNewState || |
|
431 KMceEstablishedEventStateIndex == aNewState || |
|
432 KMceTerminatingEventStateIndex == aNewState || |
|
433 KMceTerminatedEventStateIndex == aNewState ) |
|
434 { |
|
435 return ETrue; |
|
436 } |
|
437 else |
|
438 { |
|
439 return EFalse; |
|
440 } |
|
441 } |
|
442 |
|
443 case KMceTerminatingEventStateIndex: |
|
444 { |
|
445 // From terminating state, transition to terminated is accepted. |
|
446 if ( KMceTerminatedEventStateIndex == aNewState ) |
|
447 { |
|
448 return ETrue; |
|
449 } |
|
450 else |
|
451 { |
|
452 return EFalse; |
|
453 } |
|
454 } |
|
455 |
|
456 default: |
|
457 { |
|
458 // From terminated state no transition is allowed. |
|
459 // All the states are handled either here or in separate methods |
|
460 // for MO or MT events. |
|
461 return EFalse; |
|
462 } |
|
463 |
|
464 } |
|
465 |
|
466 } |
|
467 |