|
1 // Copyright (c) 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: Test wrapper for RSsmStateManager |
|
14 // |
|
15 // |
|
16 // |
|
17 |
|
18 #include <test/datawrapper.h> |
|
19 #include <ssm/ssmstates.hrh> |
|
20 #include <ssm/ssmsubstates.hrh> |
|
21 |
|
22 #include "t_ssmstatemanager.h" |
|
23 |
|
24 _LIT(KMainState, "mainState"); |
|
25 _LIT(KSubState, "subState"); |
|
26 _LIT(KReason, "reason"); |
|
27 _LIT(KAsync, "async"); |
|
28 |
|
29 //commands |
|
30 _LIT(KCmdNewL, "NewL"); |
|
31 _LIT(KCmdConnect, "Connect"); |
|
32 _LIT(KCmdClose, "Close"); |
|
33 _LIT(KCmdRequestStateTransition, "RequestStateTransition"); |
|
34 _LIT(KCmdRequestStateTransitionCancel, "RequestStateTransitionCancel"); |
|
35 _LIT(KCmdDestructor, "~"); |
|
36 |
|
37 /** |
|
38 * Two phase constructor |
|
39 */ |
|
40 CTestRSsmStateManager* CTestRSsmStateManager::NewL() |
|
41 { |
|
42 CTestRSsmStateManager* testSsmStateManager = new (ELeave) CTestRSsmStateManager(); |
|
43 CleanupStack::PushL(testSsmStateManager); |
|
44 testSsmStateManager->ConstructL(); |
|
45 CleanupStack::Pop(testSsmStateManager); |
|
46 return testSsmStateManager; |
|
47 } |
|
48 |
|
49 /** |
|
50 * GetObject |
|
51 */ |
|
52 TAny* CTestRSsmStateManager::GetObject() |
|
53 { |
|
54 return iSsmStateManager; |
|
55 } |
|
56 |
|
57 /** |
|
58 * SetObjectL |
|
59 */ |
|
60 void CTestRSsmStateManager::SetObjectL(TAny* aAny) |
|
61 { |
|
62 DoCleanup(); |
|
63 iSsmStateManager=static_cast<RSsmStateManager*> (aAny); |
|
64 } |
|
65 |
|
66 /** |
|
67 * DisownObjectL |
|
68 */ |
|
69 void CTestRSsmStateManager::DisownObjectL() |
|
70 { |
|
71 iSsmStateManager = NULL; |
|
72 } |
|
73 |
|
74 /** |
|
75 * Protected constructor. First phase construction |
|
76 */ |
|
77 CTestRSsmStateManager::CTestRSsmStateManager() |
|
78 :CDataWrapper() |
|
79 { |
|
80 } |
|
81 |
|
82 /** |
|
83 * Protected constructor. Second phase construction |
|
84 */ |
|
85 void CTestRSsmStateManager::ConstructL() |
|
86 { |
|
87 iActiveNotifyOnChange = CActiveCallback::NewL(*this); |
|
88 } |
|
89 |
|
90 /** |
|
91 * Destructor. |
|
92 */ |
|
93 CTestRSsmStateManager::~CTestRSsmStateManager() |
|
94 { |
|
95 DoCleanup(); |
|
96 delete iActiveNotifyOnChange; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Process a command read from the ini file |
|
101 * |
|
102 * @param aCommand the command to process |
|
103 * @param aSection the entry in the ini file requiring the command to be processed |
|
104 * |
|
105 * @return ETrue if the command is processed |
|
106 */ |
|
107 TBool CTestRSsmStateManager::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
108 { |
|
109 TBool retVal = ETrue; |
|
110 if (aCommand == KCmdNewL) |
|
111 { |
|
112 DoCmdNew(); |
|
113 } |
|
114 else if (aCommand == KCmdConnect) |
|
115 { |
|
116 DoCmdConnect(); |
|
117 } |
|
118 else if (aCommand == KCmdRequestStateTransition ) |
|
119 { |
|
120 DoCmdRequestStateTransition(aSection, aAsyncErrorIndex); |
|
121 } |
|
122 else if (aCommand == KCmdRequestStateTransitionCancel ) |
|
123 { |
|
124 DoCmdRequestStateTransitionCancel(); |
|
125 } |
|
126 else if (aCommand == KCmdClose) |
|
127 { |
|
128 DoCmdClose(); |
|
129 } |
|
130 else if (aCommand == KCmdDestructor) |
|
131 { |
|
132 DoCmdDestructor(); |
|
133 } |
|
134 else |
|
135 { |
|
136 retVal = EFalse; |
|
137 } |
|
138 |
|
139 return retVal; |
|
140 } |
|
141 |
|
142 /** |
|
143 * Creates RSSmStateAwareSession class instance |
|
144 */ |
|
145 void CTestRSsmStateManager::DoCmdNew() |
|
146 { |
|
147 INFO_PRINTF1(_L("Create RSsmStateManager instance")); |
|
148 DoCleanup(); |
|
149 |
|
150 TRAPD( err, iSsmStateManager = new (ELeave)RSsmStateManager()); |
|
151 if (err!=KErrNone) |
|
152 { |
|
153 ERR_PRINTF2(_L("new error %d"), err); |
|
154 SetError(err); |
|
155 } |
|
156 } |
|
157 |
|
158 /** |
|
159 * Close RSsmStateManager handle |
|
160 */ |
|
161 void CTestRSsmStateManager::DoCmdClose() |
|
162 { |
|
163 INFO_PRINTF1(_L("Close RSsmStateManager ")); |
|
164 iSsmStateManager->Close(); |
|
165 } |
|
166 |
|
167 /** |
|
168 * Contains cleanup implementation |
|
169 */ |
|
170 void CTestRSsmStateManager::DoCleanup() |
|
171 { |
|
172 if(iSsmStateManager != NULL) |
|
173 { |
|
174 INFO_PRINTF1(_L("Deleting current RSsmStateManager")); |
|
175 delete iSsmStateManager; |
|
176 iSsmStateManager = NULL; |
|
177 } |
|
178 } |
|
179 |
|
180 /** |
|
181 * Destroy RSsmStateManager object |
|
182 */ |
|
183 void CTestRSsmStateManager::DoCmdDestructor() |
|
184 { |
|
185 INFO_PRINTF1(_L("Destroying the object")); |
|
186 DoCleanup(); |
|
187 } |
|
188 |
|
189 /** |
|
190 * Connects to Ssm State Manager |
|
191 */ |
|
192 void CTestRSsmStateManager::DoCmdConnect() |
|
193 { |
|
194 TInt err = iSsmStateManager->Connect(); |
|
195 if (KErrNone != err) |
|
196 { |
|
197 ERR_PRINTF2(_L("Connect() error %d"), err); |
|
198 SetError(err); |
|
199 } |
|
200 } |
|
201 |
|
202 /** |
|
203 * RequestStateTransition in case of State transition request |
|
204 */ |
|
205 void CTestRSsmStateManager::DoCmdRequestStateTransition(const TDesC& aSection, const TInt aAsyncErrorIndex) |
|
206 { |
|
207 TPtrC getMainState; |
|
208 TPtrC getSubStates; |
|
209 if (!GetStringFromConfig(aSection, KMainState(), getMainState )) |
|
210 { |
|
211 //set default value if value is not provided in .ini file |
|
212 getMainState.Set( _L("ESsmNormal")); |
|
213 } |
|
214 if (!GetStringFromConfig(aSection, KSubState(), getSubStates )) |
|
215 { |
|
216 //set default value if value is not provided in .ini file |
|
217 getSubStates.Set(_L("ESsmNormalRfOffSubState")); |
|
218 } |
|
219 TUint16 mainState; |
|
220 TUint16 subState; |
|
221 if ( MapToMainState( getMainState, mainState )&& MapToSubState( getSubStates, subState )) |
|
222 { |
|
223 TInt reason; |
|
224 if (!GetIntFromConfig(aSection, KReason(), reason )) |
|
225 { |
|
226 //set default reason if value is not provided in .ini file |
|
227 reason = KErrNone; |
|
228 } |
|
229 |
|
230 TSsmStateTransition stateTransition(mainState, subState, reason ); |
|
231 //Call the API depending on async call or not |
|
232 TBool async; |
|
233 if (!GetBoolFromConfig(aSection, KAsync(), async )) |
|
234 { |
|
235 async = EFalse; |
|
236 } |
|
237 if (async) |
|
238 { |
|
239 iSsmStateManager->RequestStateTransition(stateTransition, iActiveNotifyOnChange->iStatus); |
|
240 iActiveNotifyOnChange->Activate(aAsyncErrorIndex); |
|
241 IncOutstanding(); |
|
242 } |
|
243 else |
|
244 { |
|
245 TInt err = iSsmStateManager->RequestStateTransition(stateTransition); |
|
246 if (err != KErrNone) |
|
247 { |
|
248 ERR_PRINTF2(_L("RequestStateTransition() failed with error %d"), err); |
|
249 SetError(err); |
|
250 } |
|
251 } |
|
252 } |
|
253 else |
|
254 { |
|
255 ERR_PRINTF1(_L(" Mapping state/substate failed%d")); |
|
256 SetBlockResult(EFail); |
|
257 } |
|
258 } |
|
259 |
|
260 /** |
|
261 * RequestStateTransitionCancel |
|
262 */ |
|
263 void CTestRSsmStateManager::DoCmdRequestStateTransitionCancel() |
|
264 { |
|
265 iSsmStateManager->RequestStateTransitionCancel(); |
|
266 } |
|
267 |
|
268 /** |
|
269 Virtual RunL - Called on completion of an asynchronous command |
|
270 @param aActive Active Object that RunL has been called on |
|
271 @pre N/A |
|
272 @post N/A |
|
273 @leave system wide error code |
|
274 @see MTPActiveCallback |
|
275 */ |
|
276 void CTestRSsmStateManager::RunL(CActive* aActive, TInt aIndex) |
|
277 { |
|
278 INFO_PRINTF1(_L("RSsmStateManager->RunL()is called")); |
|
279 if (aActive == iActiveNotifyOnChange) |
|
280 { |
|
281 TInt err=iActiveNotifyOnChange->iStatus.Int(); |
|
282 if ( err != KErrNone ) |
|
283 { |
|
284 ERR_PRINTF2(_L("RunL Error %d"), err); |
|
285 SetAsyncError(aIndex, err); |
|
286 } |
|
287 } |
|
288 DecOutstanding(); |
|
289 } |
|
290 |
|
291 /** |
|
292 Virtual DoCancel - Request to cancel the asynchronous command |
|
293 @param aActive Active Object that DoCancel has been called on |
|
294 @pre - N/A |
|
295 @post - N/A |
|
296 @leave system wide error code |
|
297 @see MTPActiveCallback |
|
298 */ |
|
299 void CTestRSsmStateManager::DoCancel(CActive* aActive, TInt aIndex) |
|
300 { |
|
301 INFO_PRINTF1(_L("DoCancel")); |
|
302 if( aActive == iActiveNotifyOnChange ) |
|
303 { |
|
304 TInt err = iActiveNotifyOnChange->iStatus.Int(); |
|
305 if (err!=KErrNone) |
|
306 { |
|
307 ERR_PRINTF2(_L("DoCancel Error %d"), err); |
|
308 SetAsyncError(aIndex, err); |
|
309 } |
|
310 } |
|
311 DecOutstanding(); |
|
312 } |
|
313 /** |
|
314 * Helper method to Map defined MainState on ssmstates.hrh |
|
315 */ |
|
316 TBool CTestRSsmStateManager::MapToMainState( TPtrC& aGetMainState, TUint16& aMainState ) |
|
317 { |
|
318 TInt ret = ETrue; |
|
319 if(!(aGetMainState.Compare(_L("ESsmStartup")))) |
|
320 { |
|
321 aMainState = ESsmStartup; |
|
322 } |
|
323 else if(!(aGetMainState.Compare(_L("ESsmNormal")))) |
|
324 { |
|
325 aMainState = ESsmNormal; |
|
326 } |
|
327 else if(!(aGetMainState.Compare(_L("ESsmShutdown")))) |
|
328 { |
|
329 aMainState = ESsmShutdown; |
|
330 } |
|
331 else if(!(aGetMainState.Compare(_L("ESsmFail")))) |
|
332 { |
|
333 aMainState = ESsmFail; |
|
334 } |
|
335 else if(!(aGetMainState.Compare(_L("ESsmRestore")))) |
|
336 { |
|
337 aMainState = ESsmRestore; |
|
338 } |
|
339 else if(!(aGetMainState.Compare(_L("ESsmEmergencyCallsOnly")))) |
|
340 { |
|
341 aMainState = ESsmEmergencyCallsOnly; |
|
342 } |
|
343 else |
|
344 { |
|
345 ret = EFalse; |
|
346 } |
|
347 return ret; |
|
348 } |
|
349 |
|
350 /** |
|
351 * Helper method to Map defined SubState in ssmsubstates.hrh..Need to be extended for other substates |
|
352 */ |
|
353 TBool CTestRSsmStateManager::MapToSubState( TPtrC& aGetSubState, TUint16& aSubState ) |
|
354 { |
|
355 TInt ret = ETrue; |
|
356 if(!(aGetSubState.Compare(_L("ESsmNormalRfOffSubState")))) |
|
357 { |
|
358 aSubState = ESsmNormalRfOffSubState; |
|
359 } |
|
360 else if(!(aGetSubState.Compare(_L("ESsmNormalSubState")))) |
|
361 { |
|
362 aSubState = ESsmNormalSubState; |
|
363 } |
|
364 else if(!(aGetSubState.Compare(_L("ESsmNormalRfOnSubState")))) |
|
365 { |
|
366 aSubState = ESsmNormalRfOnSubState; |
|
367 } |
|
368 else |
|
369 { |
|
370 ret = EFalse; |
|
371 } |
|
372 return ret; |
|
373 } |