|
1 /* |
|
2 * Copyright (c) 2007 - 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: Base class for application states. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef T_VTUIAPPSTATEBASE_H |
|
20 #define T_VTUIAPPSTATEBASE_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <mvtengsessioninfo.h> |
|
24 #include "mvtuistatecontext.h" |
|
25 #include "mvtuishutterobserver.h" |
|
26 #include "tvtuistates.h" |
|
27 |
|
28 /** |
|
29 * Base class for application states related to application startup, normal |
|
30 * operation and shutdown. AppUi delegates decision making by forwarding |
|
31 * events/commands it receives to current state. |
|
32 * Not all event handlers declared by the base class are applicable in |
|
33 * all concrete states. All methods returning TEventResponse imply that it may |
|
34 * consume the event completely and caller should not process it further. |
|
35 * |
|
36 * It should be kept in mind that as new functionality is added to application, |
|
37 * state classes may need changes if e.g. handling of specific event should be |
|
38 * allowed in appUi. By default event handler in specific state may consume all |
|
39 * events. Note that in this context e.g. HandleCommandL is considered as an |
|
40 * event handler. |
|
41 * |
|
42 * @since S60 v3.2 |
|
43 */ |
|
44 class TVtUiAppStateBase : public MVtUiShutterObserver |
|
45 { |
|
46 public: // new functions |
|
47 |
|
48 /** |
|
49 * Return value from state's event handlers. |
|
50 */ |
|
51 enum TEventResponse |
|
52 { |
|
53 /** Event was handled by a state and should |
|
54 * not be further processed by caller. |
|
55 */ |
|
56 EEventHandled, |
|
57 /** Event can be handled by caller. */ |
|
58 EEventNotHandled |
|
59 }; |
|
60 |
|
61 /** |
|
62 * Performs state dependent actions when phase 1 of |
|
63 * startup is completed. |
|
64 */ |
|
65 virtual void AppUiStartupPhase1DoneL(); |
|
66 |
|
67 /** |
|
68 * Performs state dependent actions when startup fails. |
|
69 */ |
|
70 virtual void AppUiStartupFailedL(); |
|
71 |
|
72 /** |
|
73 * Performs state dependent actions when phase 2 of |
|
74 * startup is completed. |
|
75 */ |
|
76 virtual void AppUiStartupPhase2DoneL(); |
|
77 |
|
78 /** |
|
79 * Handles completion of shutdown. |
|
80 */ |
|
81 virtual void ShutdownDoneL(); |
|
82 |
|
83 /** |
|
84 * Handles completion of an VT engine command. |
|
85 * @param aCommand completed command |
|
86 * @param aError error |
|
87 * @return event response, is caller allowed to handle event |
|
88 */ |
|
89 virtual TEventResponse HandleVTCommandPerformedL( |
|
90 const TVtEngCommandId aCommand, |
|
91 const TInt aError ); |
|
92 |
|
93 /** |
|
94 * Handles event from the engine. |
|
95 * @param aEvent |
|
96 * @return event response, is caller allowed to handle event |
|
97 */ |
|
98 virtual TEventResponse HandleVtEventL( const TInt aEvent ); |
|
99 |
|
100 /** |
|
101 * Handles command from the user (or application framework). |
|
102 * @param aCommand |
|
103 * @return event response, is caller allowed to handle event |
|
104 */ |
|
105 virtual TEventResponse HandleCommandL( const TInt aCommand ); |
|
106 |
|
107 /** |
|
108 * Performs state dependent actions for foreground change event. |
|
109 * @param aIsForeground foreground status passed from UI framework |
|
110 * @return ETrue if application should behave as in foreground |
|
111 */ |
|
112 virtual TBool HandleForegroundChangedL( const TBool aIsForeground ); |
|
113 |
|
114 /** |
|
115 * Performs state dependent previous actions for foreground change event. |
|
116 * @param aIsForeground foreground status passed from UI framework |
|
117 * @return ETrue if application should behave as in foreground |
|
118 */ |
|
119 virtual TBool PreHandleForegroundChangedL( const TBool aIsForeground ); |
|
120 /** |
|
121 * Performs state dependent actions for layout change. |
|
122 */ |
|
123 virtual void HandleLayoutChangedL(); |
|
124 |
|
125 /** |
|
126 * Sends DTMF tone if allowed by current state. |
|
127 * @param aTone DTMF tone to send |
|
128 */ |
|
129 virtual void StartDtmfTone( const TChar& aTone ); |
|
130 |
|
131 /** |
|
132 * Stops DTMF tone if allowed by current state. |
|
133 */ |
|
134 virtual void StopDtmfTone(); |
|
135 |
|
136 /** |
|
137 * Sets initial application state. |
|
138 * @param aCtx state context providing services to states |
|
139 * @param aUiStates ui states |
|
140 */ |
|
141 static void SetInitialStateL( |
|
142 MVtUiStateContext& aCtx, |
|
143 TVtUiStates& aUiStates); |
|
144 |
|
145 protected: // for concrete state classes |
|
146 |
|
147 /** |
|
148 * Destructor, for cleanup. |
|
149 */ |
|
150 virtual ~TVtUiAppStateBase(); |
|
151 |
|
152 /** |
|
153 * Performs entry action for a state. |
|
154 */ |
|
155 virtual void OpenL(); |
|
156 |
|
157 /** |
|
158 * Performs exit action for a state and deletes that state. |
|
159 */ |
|
160 virtual void Close(); |
|
161 |
|
162 /** |
|
163 * Sets current state. |
|
164 */ |
|
165 void ChangeStateL( TVtUiAppStateBase& aNewState ); |
|
166 |
|
167 /** |
|
168 * Sets transition to resetting state as cleanup item. |
|
169 */ |
|
170 void CleanupResetPushL(); |
|
171 |
|
172 /** |
|
173 * Starts shutdown when leave occurred. |
|
174 */ |
|
175 static void TransitionToReset( TAny* aAny ); |
|
176 |
|
177 |
|
178 /** |
|
179 * Ends the call if necessary and starts shutdown. |
|
180 * @return ETrue if shutdown started. |
|
181 */ |
|
182 TBool CheckEndActiveCallL(); |
|
183 |
|
184 /** |
|
185 * Returns engine session state. |
|
186 * @param aUpdate is state forced to update |
|
187 * @return session state |
|
188 */ |
|
189 MVtEngSessionInfo::TSessionState SessionState( |
|
190 const TBool aUpdate ) const; |
|
191 |
|
192 /** |
|
193 * Sets forced lights state in the system. |
|
194 */ |
|
195 void SetLightsState( const TBool aOn ); |
|
196 |
|
197 /** |
|
198 * Delegates engine command execution to the state context. |
|
199 */ |
|
200 template < typename T > |
|
201 inline void ExecuteEngineCommand( |
|
202 TInt aCommand, T& aParam ); |
|
203 |
|
204 /** |
|
205 * Sets execution state. |
|
206 */ |
|
207 void SetExecState( const TVtUiStates::TVtUiExecState aState ); |
|
208 |
|
209 protected: // constructor |
|
210 |
|
211 // c++ constructor |
|
212 TVtUiAppStateBase( MVtUiStateContext& aCtx, TVtUiStates& aUiStates ); |
|
213 |
|
214 private: // from MVtUiShutterObserver |
|
215 |
|
216 /** |
|
217 * Handles 'shutdown ready' event. |
|
218 */ |
|
219 virtual void HandleShutdownReady(); |
|
220 |
|
221 private: // new functions |
|
222 |
|
223 /** |
|
224 * Updates applications lock state and sends to background if |
|
225 * the device is locked. |
|
226 */ |
|
227 void HandleDeviceLockEventL( const TBool aDeviceIsLocked ); |
|
228 |
|
229 protected: // data members |
|
230 |
|
231 // Context providing services to states |
|
232 MVtUiStateContext& iCtx; |
|
233 |
|
234 // Various application specific state information |
|
235 TVtUiStates& iUiStates; |
|
236 |
|
237 /** Prevents sending end call command to call handling if ETrue. |
|
238 * It is not allowed when call clearing is network originated. |
|
239 */ |
|
240 |
|
241 /** |
|
242 * shutdown request received |
|
243 */ |
|
244 static TBool iShutdownRequested; |
|
245 |
|
246 }; |
|
247 |
|
248 #include "tvtuiappstatebase.inl" |
|
249 |
|
250 #endif // T_VTUIAPPSTATEBASE_H |