1 /* |
|
2 * Copyright (c) 2005-2006 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: Plugin state machine impl |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "aipluginstatemachineimpl.h" |
|
20 #include "aipluginstatemachine.h" |
|
21 #include "aipluginlifecycleobserver.h" |
|
22 #include "aipluginstate.h" |
|
23 #include "aifwpanic.h" |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CAiPluginStateMachine::CAiPluginStateMachine() |
|
29 // ---------------------------------------------------------------------------- |
|
30 // |
|
31 CAiPluginStateMachine::CAiPluginStateMachine( |
|
32 MAiPluginStateResources& aPluginStateResource, |
|
33 CAiContentPublisher& aPlugin ) |
|
34 : iAlive( *this ), |
|
35 iCurrentState( NULL ), |
|
36 iPluginStateResource( aPluginStateResource ), |
|
37 iPlugin( aPlugin ) |
|
38 { |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CAiPluginStateMachine::SwitchToState() |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 void CAiPluginStateMachine::SwitchToState( TAiState aState, |
|
46 TAiStateChanges aStateChange ) |
|
47 { |
|
48 // Store previous state |
|
49 MAiPluginState* previousState( iCurrentState ); |
|
50 |
|
51 // Determine new current state |
|
52 switch( aState ) |
|
53 { |
|
54 case EAiAlive: |
|
55 { |
|
56 iCurrentState = &iAlive; |
|
57 break; |
|
58 } |
|
59 case EAiSuspended: |
|
60 { |
|
61 iCurrentState = &iSuspended; |
|
62 break; |
|
63 } |
|
64 case EAiIdle: |
|
65 { |
|
66 iCurrentState = &iIdle; |
|
67 break; |
|
68 } |
|
69 default: |
|
70 { |
|
71 #ifdef _DEBUG |
|
72 AiFwPanic::Panic( AiFwPanic::EAiFwPanic_IllegalPluginStateChange ); |
|
73 #endif |
|
74 break; |
|
75 } |
|
76 } |
|
77 |
|
78 if( previousState != iCurrentState ) |
|
79 { |
|
80 if( previousState ) |
|
81 { |
|
82 // Exit the previous state |
|
83 previousState->Exit( *this, aStateChange ); |
|
84 } |
|
85 |
|
86 if( iCurrentState ) |
|
87 { |
|
88 // Enter the new state |
|
89 iCurrentState->Enter( *this, aStateChange ); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CAiPluginStateMachine::StateVariable() |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 TBool CAiPluginStateMachine::StateVariable( TAiStateVariable aStateVariable ) |
|
99 { |
|
100 return iPluginStateResource.StateVariable( aStateVariable ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CAiPluginStateMachine::Plugin() |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 CAiContentPublisher& CAiPluginStateMachine::Plugin() const |
|
108 { |
|
109 return iPlugin; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CAiPluginStateMachine::HandleEvent() |
|
114 // ---------------------------------------------------------------------------- |
|
115 // |
|
116 TBool CAiPluginStateMachine::HandleEvent( TAiStateChanges aStateChange ) |
|
117 { |
|
118 // State machine handles some state changes directly. |
|
119 switch( aStateChange ) |
|
120 { |
|
121 case ESMAISystemBoot: |
|
122 { |
|
123 // State machine handles startup event(boot/theme change). |
|
124 // Check if backup is ongoing |
|
125 if( iPluginStateResource.StateVariable( ESMAIBackupRestoreStatus ) ) |
|
126 { |
|
127 SwitchToState( EAiIdle, aStateChange ); |
|
128 } |
|
129 else |
|
130 { |
|
131 SwitchToState( EAiAlive, aStateChange ); |
|
132 } |
|
133 break; |
|
134 } |
|
135 case ESMAIBackupOn: |
|
136 { |
|
137 // Backup/restore directs straight to idle state. |
|
138 SwitchToState( EAiIdle, aStateChange ); |
|
139 break; |
|
140 } |
|
141 case ESMAIReportThemeChangeStarted: |
|
142 case ESMAISystemShutdown: |
|
143 { |
|
144 // Shutdown drives directly to idle state. |
|
145 ChangePluginState( iPluginStateResource.TranslateReason( aStateChange ), |
|
146 CAiContentPublisher::Stop ); |
|
147 break; |
|
148 } |
|
149 case ESMAIOnLine: |
|
150 { |
|
151 if( !iOnline && iCurrentState ) |
|
152 { |
|
153 iOnline = ETrue; |
|
154 |
|
155 return iCurrentState->HandleEvent( *this, aStateChange ); |
|
156 } |
|
157 break; |
|
158 } |
|
159 case ESMAIOffLine: |
|
160 { |
|
161 if( iCurrentState ) |
|
162 { |
|
163 iOnline = EFalse; |
|
164 |
|
165 return iCurrentState->HandleEvent( *this, aStateChange ); |
|
166 } |
|
167 break; |
|
168 } |
|
169 default: |
|
170 { |
|
171 if( ( aStateChange == ESMAIBacklightOn ) && |
|
172 !iPluginStateResource.StateVariable( ESMAIIdleFocusStatus ) ) |
|
173 { |
|
174 // Ignore lights on when on background |
|
175 return ETrue; |
|
176 } |
|
177 |
|
178 if( iCurrentState ) |
|
179 { |
|
180 // Other events are handled by the current set state. |
|
181 // Current state determines return value. |
|
182 return iCurrentState->HandleEvent( *this, aStateChange ); |
|
183 } |
|
184 } |
|
185 } |
|
186 |
|
187 // Return event handled. |
|
188 return ETrue; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CAiPluginStateMachine::TranslateReason() |
|
193 // ---------------------------------------------------------------------------- |
|
194 // |
|
195 TAiTransitionReason CAiPluginStateMachine::TranslateReason( |
|
196 TAiStateChanges aStateChange ) |
|
197 { |
|
198 return iPluginStateResource.TranslateReason( aStateChange ); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CAiPluginStateMachine::RestartSuspendTimer() |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 void CAiPluginStateMachine::RestartSuspendTimer() |
|
206 { |
|
207 iPluginStateResource.RestartSuspendTimer(); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CAiPluginStateMachine::ChangePluginState() |
|
212 // ---------------------------------------------------------------------------- |
|
213 // |
|
214 void CAiPluginStateMachine::ChangePluginState( TAiTransitionReason aReason, |
|
215 void (CAiContentPublisher::*aStateChangeMethod)( TAiTransitionReason ) ) |
|
216 { |
|
217 TRAP_IGNORE( ( iPlugin.*aStateChangeMethod)( aReason ) ); |
|
218 } |
|
219 |
|
220 // End of file. |
|