|
1 /* |
|
2 * Copyright (c) 2008-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: Finite State Machine class for Charging Context Controller. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32def.h> |
|
21 #include <e32cmn.h> |
|
22 #include <hwrmpowerstatesdkpskeys.h> |
|
23 |
|
24 |
|
25 #include "ChargingContextFSMBody.h" |
|
26 #include "ChargingContextStateWFCharger.h" |
|
27 #include "ChargingContextStateCharging.h" |
|
28 #include "ChargingContextStateMaintainActivity.h" |
|
29 #include "acc_debug.h" |
|
30 |
|
31 |
|
32 // ======== LOCAL FUNCTIONS ======== |
|
33 |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Symbian two-phased constructor |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CChargingContextFSMBody* CChargingContextFSMBody::NewL( |
|
43 CAccSrvChargingContextController* aChargingContextController ) |
|
44 { |
|
45 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::NewL()" ); |
|
46 |
|
47 CChargingContextFSMBody* self = new ( ELeave ) CChargingContextFSMBody(); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL( aChargingContextController ); |
|
50 CleanupStack::Pop( self ); |
|
51 |
|
52 COM_TRACE_1( "[AccFW:AccServer] CChargingContextFSMBody::NewL - return %p", self ); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Destructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CChargingContextFSMBody::~CChargingContextFSMBody() |
|
62 { |
|
63 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::~CChargingContextFSMBody()" ); |
|
64 iCurrentStateId = EChargerContextStateUndefined; |
|
65 if ( NULL != iChargingContextController ) |
|
66 { |
|
67 if ( NULL != iChargingContextController->iDisplayOrientationChannelPtr ) |
|
68 { |
|
69 iChargingContextController->iDisplayOrientationChannelPtr->StopDataListening(); |
|
70 iChargingContextController->iDisplayOrientationChannelPtr->CloseChannel(); |
|
71 } |
|
72 if ( NULL != iChargingContextController->iChargerStatusWatchPtr ) |
|
73 { |
|
74 if ( iChargingContextController->iChargerStatusWatchPtr->IsActive() ) |
|
75 { |
|
76 iChargingContextController->iChargerStatusWatchPtr->Cancel(); |
|
77 } |
|
78 } |
|
79 } |
|
80 // Delete state objects |
|
81 for (TInt i = 1; i <= EChargerContextStateMaxValue; i++ ) |
|
82 { |
|
83 delete iStateArray[i]; |
|
84 iStateArray[i] = NULL; |
|
85 } |
|
86 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::~CChargingContextFSMBody" ); |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // From MFSMBody. |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CChargingContextFSMBody::Start() |
|
95 { |
|
96 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::Start()" ); |
|
97 // Step to the initial state. |
|
98 iCurrentStateId = EChargerContextStateWaitForCharger; |
|
99 iStateArray[iCurrentStateId]->Enter(); |
|
100 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::Start" ); |
|
101 return; |
|
102 } |
|
103 |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // From MFSMBody. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 TBool CChargingContextFSMBody::Transit( TFSMState aNextState ) |
|
110 { |
|
111 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::Transit()" ); |
|
112 TBool retVal(EFalse); |
|
113 if ( ( EChargerContextStateUndefined < aNextState ) && |
|
114 ( EChargerContextStateMaxValue >= aNextState ) ) |
|
115 { |
|
116 iCurrentStateId = aNextState; |
|
117 if ( NULL != iStateArray[iCurrentStateId]) |
|
118 { |
|
119 retVal = ETrue; |
|
120 iStateArray[iCurrentStateId]->Enter(); |
|
121 } |
|
122 } |
|
123 if ( EFalse == retVal ) |
|
124 { |
|
125 //Something is wrong |
|
126 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::Transit - incorrect nextstate"); |
|
127 } |
|
128 COM_TRACE_1( "[AccFW:AccServer] CChargingContextFSMBody::Transit - TBool retVal %i", retVal ); |
|
129 return retVal; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // From MFSMBody. |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 TFSMState CChargingContextFSMBody::CurrentStateID() |
|
137 { |
|
138 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CurrentStateID()" ); |
|
139 TFSMState currentState( EChargerContextStateUndefined ); |
|
140 if ( ( EChargerContextStateUndefined < iCurrentStateId ) && |
|
141 ( EChargerContextStateMaxValue >= iCurrentStateId )) |
|
142 { |
|
143 currentState = iCurrentStateId; |
|
144 } |
|
145 COM_TRACE_1( "[AccFW:AccServer] CChargingContextFSMBody::CurrentStateID - CurrentStateId %i", currentState ); |
|
146 return currentState; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // From MFSMBody. |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CChargingContextFSMBody::Input() |
|
154 { |
|
155 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::Input()" ); |
|
156 if ( EChargerContextStateUndefined != iCurrentStateId ) |
|
157 { |
|
158 if ( NULL != iStateArray[iCurrentStateId] ) |
|
159 { |
|
160 iStateArray[iCurrentStateId]->Input(); |
|
161 } |
|
162 } |
|
163 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::Input" ); |
|
164 return; |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // From MFSMBody. |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 MFSMState* CChargingContextFSMBody::CurrentState() |
|
172 { |
|
173 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CurrentState()" ); |
|
174 MFSMState* currentState( NULL ); |
|
175 if ( ( EChargerContextStateUndefined < iCurrentStateId ) && |
|
176 ( EChargerContextStateMaxValue >= iCurrentStateId )) |
|
177 { |
|
178 currentState = iStateArray[iCurrentStateId]; |
|
179 } |
|
180 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CurrentState" ); |
|
181 return currentState; |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // From MFSMBody. |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 TPtrC CChargingContextFSMBody::CurrentStateName() |
|
189 { |
|
190 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CurrentStateName()" ); |
|
191 TPtrC currentStateName; |
|
192 currentStateName.Set( KNullDesC ); |
|
193 if ( ( EChargerContextStateUndefined < iCurrentStateId ) && |
|
194 ( EChargerContextStateMaxValue >= iCurrentStateId )) |
|
195 { |
|
196 currentStateName.Set( iStateArray[iCurrentStateId]->Name() ); |
|
197 } |
|
198 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CurrentStateName" ); |
|
199 return currentStateName; |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------- |
|
203 // C++ constructor |
|
204 // --------------------------------------------------------- |
|
205 // |
|
206 CChargingContextFSMBody::CChargingContextFSMBody() |
|
207 { |
|
208 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CChargingContextFSMBody()" ); |
|
209 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::CChargingContextFSMBody - return" ); |
|
210 } |
|
211 |
|
212 |
|
213 // --------------------------------------------------------- |
|
214 // ConstructL |
|
215 // --------------------------------------------------------- |
|
216 // |
|
217 void CChargingContextFSMBody::ConstructL( |
|
218 CAccSrvChargingContextController* aChargingContextController ) |
|
219 { |
|
220 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::ConstructL()" ); |
|
221 iChargingContextController = aChargingContextController; |
|
222 // Create state objects here. |
|
223 iStateArray[ EChargerContextStateWaitForCharger ] = CChargingContextStateWFCharger::NewL( this, aChargingContextController ); |
|
224 iStateArray[ EChargerContextStateCharging ] = CChargingContextStateCharging::NewL( this, aChargingContextController ); |
|
225 iStateArray[ EChargerContextStateMaintainActivity ] = CChargingContextStateMaintainActivity::NewL( this, aChargingContextController ); |
|
226 |
|
227 #ifdef __MODULE_TEST__ |
|
228 aChargingContextController->iModuleTestOrientationWatchPtr = CAccSrvPSIntPropertyWatch::NewL( |
|
229 aChargingContextController, |
|
230 KModuleTestUid, |
|
231 KModuleTestKeyOrientation, |
|
232 EOwnerThread ); |
|
233 aChargingContextController->iModuleTestOrientationWatchPtr->Watch(); |
|
234 aChargingContextController->iModuleTestChargerWatchPtr = CAccSrvPSIntPropertyWatch::NewL( |
|
235 aChargingContextController, |
|
236 KModuleTestUid, |
|
237 KModuleTestKeyCharger, |
|
238 EOwnerThread ); |
|
239 aChargingContextController->iModuleTestChargerWatchPtr->Watch(); |
|
240 #endif //__MODULE_TEST__ |
|
241 |
|
242 // Create Charger status watcher. |
|
243 aChargingContextController->iChargerStatusWatchPtr = CAccSrvPSIntPropertyWatch::NewL( |
|
244 aChargingContextController, |
|
245 KPSUidHWRMPowerState, |
|
246 KHWRMChargingStatus, |
|
247 EOwnerThread ); |
|
248 aChargingContextController->GetCurrentChargerStatus(); |
|
249 aChargingContextController->iChargerStatusWatchPtr->Watch(); |
|
250 |
|
251 // Create ResetInactivityTime timer. |
|
252 aChargingContextController->iResetInactivityTimeTimerPtr = CAccSrvResetInactivityTimeTimer::NewL( |
|
253 aChargingContextController ); |
|
254 // Create channel finder watcher. |
|
255 aChargingContextController->iChannelFinder = CSensrvChannelFinder::NewL(); |
|
256 |
|
257 //List of found channels. |
|
258 RSensrvChannelInfoList channelInfoList; |
|
259 CleanupClosePushL( channelInfoList ); |
|
260 |
|
261 //Create and fill channel search criteria. |
|
262 //Here the device orientation channel is searched. |
|
263 TSensrvChannelInfo channelInfo; |
|
264 channelInfo.iChannelType = TSensrvOrientationData::KDataTypeId; |
|
265 |
|
266 //Find the orientation channel. |
|
267 aChargingContextController->iChannelFinder->FindChannelsL( channelInfoList, channelInfo ); |
|
268 |
|
269 if( channelInfoList.Count() != 1 ) |
|
270 { |
|
271 //The device doesn’t support orientation channel or |
|
272 //there are several orientation channels. |
|
273 COM_TRACE_1( "[AccFW:AccServer] CChargingContextFSMBody::ConstructL - User::Leave( error ) %d", KErrNone ); |
|
274 User::Leave( KErrNotFound); |
|
275 } |
|
276 |
|
277 //Open the orientation channel. |
|
278 //When the channel object is created the channel info object |
|
279 //must be an object returned by CSensrvChannelFinder::FindChannelsL(). |
|
280 aChargingContextController->iDisplayOrientationChannelPtr = CSensrvChannel::NewL( channelInfoList[ 0 ] ); |
|
281 COM_TRACE_1( "[AccFW:AccServer] CChargingContextFSMBody::ConstructL - iDisplayOrientationChannelPtr %p", aChargingContextController->iDisplayOrientationChannelPtr ); |
|
282 |
|
283 CleanupStack::PopAndDestroy( &channelInfoList ); //Close() is being called on "channelInfoList" |
|
284 |
|
285 COM_TRACE_( "[AccFW:AccServer] CChargingContextFSMBody::ConstructL - return void" ); |
|
286 return; |
|
287 } |
|
288 |
|
289 // ======== GLOBAL FUNCTIONS ======== |
|
290 |