|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // StateMachineImpl.cpp |
|
15 // This is the header file for StateMachine test implementation |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef STATEMACHINEIMPL_H_ |
|
20 #define STATEMACHINEIMPL_H_ |
|
21 |
|
22 #include "ElementServer.h" |
|
23 #include <comms-infras/asynchevent.h> |
|
24 #include <comms-infras/statemachine.h> |
|
25 |
|
26 /* |
|
27 * @file StateMachineImpl.h |
|
28 */ |
|
29 |
|
30 const TInt KElementStateMachineError = -12056; |
|
31 |
|
32 /* |
|
33 * Possible states the state machine can be in. |
|
34 */ |
|
35 enum TAsyncEventTest |
|
36 { |
|
37 EGreenAsyncEvent, |
|
38 EYellowAsyncEvent, |
|
39 ERedAsyncEvent, |
|
40 EErroringAsyncEvent, |
|
41 EErrorAsyncEvent, |
|
42 EForcedErrorAsyncEvent, |
|
43 EPanicAsyncEvent, |
|
44 ECancelAsyncEvent, |
|
45 ESuspendAsyncEvent |
|
46 }; |
|
47 |
|
48 /* |
|
49 * Interface to allow an AsyncEvent to pass information back to the test step. |
|
50 */ |
|
51 class MStateMachineStepLogger |
|
52 { |
|
53 public: |
|
54 /* |
|
55 * Checks if the correct state has been taken by the state machine. |
|
56 * |
|
57 * @param TAsyncEventTest The state that the machine is currently in. |
|
58 */ |
|
59 virtual void LogStateChange(TAsyncEventTest aAsyncEvent) = 0; |
|
60 }; |
|
61 |
|
62 /* |
|
63 * Class that implements the notification interface. |
|
64 */ |
|
65 class CStateMachineNotifyImpl : public MStateMachineNotify |
|
66 { |
|
67 public: |
|
68 /* |
|
69 * Runs completion code and determines if the machine should be deleted. |
|
70 * |
|
71 * @param CStateMachine* The state machine that has completed. |
|
72 * @return Whether the machine should delete itself. |
|
73 */ |
|
74 TBool OnCompletion( CStateMachine* aStateMachine ) |
|
75 { |
|
76 if (aStateMachine->SuspendRequest()) |
|
77 aStateMachine->Start(aStateMachine->ClientStatus(), NULL, this); |
|
78 return EFalse; |
|
79 } |
|
80 }; |
|
81 |
|
82 /* |
|
83 * Extended state machine object that provides getter and setter methods that are used by the |
|
84 * test steps. |
|
85 */ |
|
86 class CStateMachineImpl : public CStateMachine |
|
87 { |
|
88 public: |
|
89 static CStateMachineImpl* NewL(); |
|
90 MStateMachineNotify* StateMachineNotifier(); |
|
91 void SetFragment(HBufC8* aFragment); |
|
92 void OnCompletion(); |
|
93 static CActiveScheduler* StartActiveSchedulerL(); |
|
94 }; |
|
95 |
|
96 /* |
|
97 * Implementation of a async event that determines the state of the machine. |
|
98 */ |
|
99 class CAsyncEventImpl : public CAsynchEvent |
|
100 { |
|
101 public: |
|
102 /* |
|
103 * Constructor. |
|
104 */ |
|
105 CAsyncEventImpl(TAsyncEventTest aAsyncEvent, MStateMachineStepLogger* aTestStep, CStateMachineImpl& aStateMachine, TInt aError) : |
|
106 CAsynchEvent(&aStateMachine) |
|
107 { |
|
108 iRuns = 0; |
|
109 iError = aError; |
|
110 iAsyncEvent = aAsyncEvent; |
|
111 iTestStep = aTestStep; |
|
112 } |
|
113 CAsynchEvent* ProcessL(TRequestStatus& aStatus); |
|
114 public: |
|
115 MStateMachineStepLogger* iTestStep; |
|
116 TAsyncEventTest iAsyncEvent; |
|
117 TInt iRuns; |
|
118 TInt iError; |
|
119 }; |
|
120 |
|
121 #endif /* STATEMACHINEIMPL_H_ */ |