|
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: Class declaration for DiagFwInternal::CStateMachine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef DIAGENGINESTATEMACHINE_H |
|
20 #define DIAGENGINESTATEMACHINE_H |
|
21 |
|
22 // system include |
|
23 #include <e32base.h> |
|
24 |
|
25 // user include |
|
26 #include "diagenginestates.h" // DiagFwInternal::TState |
|
27 #include "diagengineevents.h" // DiagFwInternal::TEvent |
|
28 |
|
29 |
|
30 namespace DiagFwInternal |
|
31 { |
|
32 // forward declaration |
|
33 class CEventBasic; |
|
34 class MStateMachineObserver; |
|
35 |
|
36 /** |
|
37 * Diagnostics Framework Engine State Machine |
|
38 * |
|
39 * This class implements state machine for CDiagEngine. |
|
40 * |
|
41 */ |
|
42 NONSHARABLE_CLASS( CStateMachine ) : public CActive |
|
43 { |
|
44 public: |
|
45 /** |
|
46 * Two-phased constructor. |
|
47 * |
|
48 * @param aObserver Engine observer. |
|
49 * @return New instance of CStateMachine |
|
50 */ |
|
51 static CStateMachine* NewL( MStateMachineObserver& aObserver ); |
|
52 static CStateMachine* NewLC( MStateMachineObserver& aObserver ); |
|
53 |
|
54 /** |
|
55 * Queue a new event into event queue. |
|
56 * |
|
57 * @param aEvent New event. CStateMachine will own |
|
58 * the object from this point on. |
|
59 * It will be freed by CStateMachine when |
|
60 * the event is processed. |
|
61 */ |
|
62 void AddEventL( CEventBasic* aEvent ); |
|
63 |
|
64 /** |
|
65 * Queue a new event into event queue. |
|
66 * |
|
67 * @param aEventId Event Id of new event. CEventBasic will be created. |
|
68 */ |
|
69 void AddEventL( TEvent aEventId ); |
|
70 |
|
71 /** |
|
72 * Current State. |
|
73 * |
|
74 * @return Current state. |
|
75 */ |
|
76 TState CurrentState() const; |
|
77 |
|
78 /** |
|
79 * Handle error. This should be called when an abnormal error |
|
80 * occurs (e.g. leave that cannot be handled.) |
|
81 * |
|
82 * @param aError - Error number. |
|
83 */ |
|
84 void HandleError( TInt aError ); |
|
85 |
|
86 /** |
|
87 * State Name. |
|
88 * Debugging purpose only. In release build, this function will |
|
89 * return empty string. |
|
90 * |
|
91 * @param aState - a state |
|
92 * @return Name of the state |
|
93 */ |
|
94 const TDesC& StateName( TState aState ) const; |
|
95 |
|
96 /** |
|
97 * C++ Destructor |
|
98 */ |
|
99 ~CStateMachine(); |
|
100 |
|
101 protected: // from CActive |
|
102 /** |
|
103 * @see CActive::RunL |
|
104 */ |
|
105 virtual void RunL(); |
|
106 |
|
107 /** |
|
108 * @see CActive::DoCancel |
|
109 */ |
|
110 virtual void DoCancel(); |
|
111 |
|
112 /** |
|
113 * @see CActive::RunError |
|
114 */ |
|
115 virtual TInt RunError( TInt aError ); |
|
116 |
|
117 private: // private constructors |
|
118 /** |
|
119 * C++ constructor |
|
120 */ |
|
121 CStateMachine( MStateMachineObserver& iObserver ); |
|
122 |
|
123 /** |
|
124 * 2nd phase constructor |
|
125 * |
|
126 */ |
|
127 virtual void ConstructL(); |
|
128 |
|
129 private: // private functions |
|
130 /** |
|
131 * Match states in state table. |
|
132 */ |
|
133 TState CheckStateTable( TState aCurrState, TEvent aEvent ) const; |
|
134 |
|
135 /** |
|
136 * Complete request and set itself to be active so that the next |
|
137 * item in the queue can be executed. |
|
138 */ |
|
139 void ReactivateQueue(); |
|
140 |
|
141 |
|
142 private: // private data |
|
143 /** |
|
144 * iObserver - Observer. |
|
145 */ |
|
146 MStateMachineObserver& iObserver; |
|
147 |
|
148 /** |
|
149 * iEventQueue - array of events to process. |
|
150 */ |
|
151 RPointerArray<CEventBasic> iEventQueue; |
|
152 |
|
153 /** |
|
154 * iState - Current state. |
|
155 */ |
|
156 TState iState; |
|
157 }; |
|
158 } // end of namespace DiagFwInternal |
|
159 #endif // DIAGENGINESTATEMACHINE_H |
|
160 |
|
161 // End of File |
|
162 |