|
1 // Copyright (c) 2007-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: |
|
14 // |
|
15 |
|
16 #include <s32mem.h> |
|
17 #include "saamiscadaptation.h" |
|
18 |
|
19 #include "startupadaptationadapter.h" |
|
20 #include "ssmdebug.h" |
|
21 #include "clayerpanic.h" |
|
22 /* |
|
23 * Creates a new object associated with the passed in CStartupAdaptationAdapter |
|
24 * |
|
25 * @internalComponent |
|
26 */ |
|
27 CSaaMiscAdaptation* CSaaMiscAdaptation::NewL(CStartupAdaptationAdapter* aAdapter) |
|
28 { |
|
29 CSaaMiscAdaptation* self = new (ELeave) CSaaMiscAdaptation(aAdapter); |
|
30 return self; |
|
31 } |
|
32 |
|
33 /* |
|
34 * Destructor for this object |
|
35 * |
|
36 * @internalComponent |
|
37 */ |
|
38 CSaaMiscAdaptation::~CSaaMiscAdaptation() |
|
39 { |
|
40 iLanguageList.Close(); |
|
41 } |
|
42 |
|
43 /* |
|
44 * Decrements the reference count for this object, deleting it if necessary |
|
45 * |
|
46 * @internalComponent |
|
47 */ |
|
48 void CSaaMiscAdaptation::Release() |
|
49 { |
|
50 // This MClass is owned by the singleton CStartupAdaptationAdapter class so |
|
51 // release should do nothing. |
|
52 } |
|
53 |
|
54 /* |
|
55 * |
|
56 * |
|
57 * @internalComponent |
|
58 */ |
|
59 void CSaaMiscAdaptation::SecurityStateChange(TInt aState, TDes8& aResponsePckg, TRequestStatus& aStatus) |
|
60 { |
|
61 // If this adaptation is busy then complete with KErrInUse |
|
62 if(Busy()) |
|
63 { |
|
64 TRequestStatus* statusPtr = &aStatus; |
|
65 User::RequestComplete(statusPtr, KErrInUse); |
|
66 return; |
|
67 } |
|
68 // Set this request status |
|
69 SetRequestStatus(&aStatus); |
|
70 aStatus = KRequestPending; |
|
71 // No outstanding requests so set up command id |
|
72 SetCommandId(StartupAdaptation::ESecurityStateChange); |
|
73 // Set parameters |
|
74 iSecurityStateChangePckg() = static_cast<StartupAdaptation::TSecurityState>(aState); |
|
75 // Set return descriptor |
|
76 iReturnPckg = &aResponsePckg; |
|
77 // Pass this to the adapter |
|
78 TRAPD(err, iAdapter->QueueDispatchL(this)); |
|
79 if(err != KErrNone) |
|
80 { |
|
81 // Failed to queue adaptation, complete with error |
|
82 SetRequestStatus(NULL); |
|
83 TRequestStatus* statusPtr = &aStatus; |
|
84 User::RequestComplete(statusPtr, err); |
|
85 } |
|
86 } |
|
87 |
|
88 /* |
|
89 * |
|
90 * |
|
91 * @internalComponent |
|
92 */ |
|
93 void CSaaMiscAdaptation::GetGlobalStartupMode(TDes8& aModePckg, TRequestStatus& aStatus) |
|
94 { |
|
95 // If this adaptation is busy then complete with KErrInUse |
|
96 if(Busy()) |
|
97 { |
|
98 TRequestStatus* statusPtr = &aStatus; |
|
99 User::RequestComplete(statusPtr, KErrInUse); |
|
100 return; |
|
101 } |
|
102 // Set this request status |
|
103 SetRequestStatus(&aStatus); |
|
104 aStatus = KRequestPending; |
|
105 // No outstanding requests so set up command id |
|
106 SetCommandId(StartupAdaptation::EGetGlobalStartupMode); |
|
107 |
|
108 // No parameters to set to pass in |
|
109 |
|
110 // Set return descriptor |
|
111 iReturnPckg = &aModePckg; |
|
112 // Pass this to the adapter |
|
113 TRAPD(err, iAdapter->QueueDispatchL(this)); |
|
114 if(err != KErrNone) |
|
115 { |
|
116 // Failed to queue adaptation, complete with error |
|
117 SetRequestStatus(NULL); |
|
118 TRequestStatus* statusPtr = &aStatus; |
|
119 User::RequestComplete(statusPtr, err); |
|
120 } |
|
121 |
|
122 } |
|
123 |
|
124 void CSaaMiscAdaptation::GetHiddenReset(TDes8& aHiddenResetPckg, TRequestStatus& aStatus) |
|
125 { |
|
126 // If this adaptation is busy then complete with KErrInUse |
|
127 if(Busy()) |
|
128 { |
|
129 TRequestStatus* statusPtr = &aStatus; |
|
130 User::RequestComplete(statusPtr, KErrInUse); |
|
131 return; |
|
132 } |
|
133 // Set this request status |
|
134 SetRequestStatus(&aStatus); |
|
135 aStatus = KRequestPending; |
|
136 // No outstanding requests so set up command id |
|
137 SetCommandId(StartupAdaptation::EGetHiddenReset); |
|
138 // No parameters to set to pass in |
|
139 |
|
140 // Set return package |
|
141 iReturnPckg = &aHiddenResetPckg; |
|
142 // Pass this to the adapter |
|
143 TRAPD(err, iAdapter->QueueDispatchL(this)); |
|
144 if(KErrNone != err) |
|
145 { |
|
146 // Failed to queue adaptation, complete with error |
|
147 SetRequestStatus(NULL); |
|
148 TRequestStatus* statusPtr = &aStatus; |
|
149 User::RequestComplete(statusPtr, err); |
|
150 } |
|
151 |
|
152 } |
|
153 |
|
154 /* |
|
155 * |
|
156 * |
|
157 * @internalComponent |
|
158 */ |
|
159 void CSaaMiscAdaptation::PrepareSimLanguages(TSsmLanguageListPriority aPriority, TDes8& aSizePckg, TRequestStatus& aStatus) |
|
160 { |
|
161 // If this adaptation is busy then complete with KErrInUse |
|
162 if(Busy()) |
|
163 { |
|
164 TRequestStatus* statusPtr = &aStatus; |
|
165 User::RequestComplete(statusPtr, KErrInUse); |
|
166 return; |
|
167 } |
|
168 // Set this request status |
|
169 SetRequestStatus(&aStatus); |
|
170 aStatus = KRequestPending; |
|
171 // No outstanding requests so set up command id |
|
172 SetCommandId(StartupAdaptation::EGetSIMLanguages); |
|
173 // Set up parameters |
|
174 switch(aPriority) |
|
175 { |
|
176 case EPrimaryLanguages: |
|
177 iLanguageListPriorityPckg() = StartupAdaptation::EPrimaryLanguages; |
|
178 break; |
|
179 case ESecondaryLanguages: |
|
180 iLanguageListPriorityPckg() = StartupAdaptation::ESecondaryLanguages; |
|
181 break; |
|
182 case ETertiaryLanguages: |
|
183 iLanguageListPriorityPckg() = StartupAdaptation::ETertiaryLanguages; |
|
184 break; |
|
185 default: |
|
186 // Unknown language, pass across unchanged |
|
187 iLanguageListPriorityPckg() = static_cast<StartupAdaptation::TLanguageListPriority>(aPriority); |
|
188 break; |
|
189 } |
|
190 // Set up the return value |
|
191 iReturnPckg = &aSizePckg; |
|
192 // Pass this to the adapter |
|
193 TRAPD(err, iAdapter->QueueDispatchL(this)); |
|
194 if(err != KErrNone) |
|
195 { |
|
196 // Failed to queue adaptation, complete with error |
|
197 SetRequestStatus(NULL); |
|
198 TRequestStatus* statusPtr = &aStatus; |
|
199 User::RequestComplete(statusPtr, err); |
|
200 } |
|
201 |
|
202 } |
|
203 |
|
204 /* |
|
205 * |
|
206 * |
|
207 * @internalComponent |
|
208 */ |
|
209 void CSaaMiscAdaptation::GetSimLanguagesL(CBufBase* aBuf, TInt aCount) |
|
210 { |
|
211 const TInt languageCount = iLanguageList.Count(); |
|
212 if(aCount < languageCount) |
|
213 { |
|
214 DEBUGPRINT3A("Language count(%d) given is less than prepared languages count(%d)", aCount, languageCount); |
|
215 // Buffer passed in isn't large enough |
|
216 User::Leave(KErrArgument); |
|
217 } |
|
218 |
|
219 RBufWriteStream writeStream(*aBuf); |
|
220 CleanupClosePushL(writeStream); |
|
221 |
|
222 for (TInt index =0; index < languageCount; ++index) |
|
223 { |
|
224 writeStream.WriteInt32L(iLanguageList[index]); |
|
225 } |
|
226 writeStream.CommitL(); |
|
227 CleanupStack::PopAndDestroy(); |
|
228 iLanguageList.Reset(); //iLanguageList is reset so that it can be used to contain new language list prepared by the method PrepareSimLanguages() |
|
229 } |
|
230 |
|
231 /* |
|
232 * |
|
233 * |
|
234 * @internalComponent |
|
235 */ |
|
236 void CSaaMiscAdaptation::Cancel() |
|
237 { |
|
238 CancelRequest(); |
|
239 } |
|
240 |
|
241 /* |
|
242 * Constructs a new state adaptation object and associates it with aAdapter |
|
243 * |
|
244 * @internalComponent |
|
245 */ |
|
246 CSaaMiscAdaptation::CSaaMiscAdaptation(CStartupAdaptationAdapter* aAdapter) |
|
247 : CAdaptationBase(aAdapter) |
|
248 { |
|
249 |
|
250 } |
|
251 |
|
252 /** |
|
253 * See CAdaptationBase for description of method. |
|
254 * |
|
255 * @internalComponent |
|
256 */ |
|
257 void CSaaMiscAdaptation::RequestComplete(const StartupAdaptation::TCommand __DEBUG_ONLY(aCommandId), TDesC8& aRetPckg) |
|
258 { |
|
259 DEBUGPRINT3A("SAA - Response received from adaptation with commandId: %d, expecting %d", aCommandId, CommandId()); |
|
260 __ASSERT_DEBUG(aCommandId == CommandId(), CLAYER_PANIC(ECLayerUnexpectedCommandResponse)); |
|
261 switch(CommandId()) |
|
262 { |
|
263 case StartupAdaptation::ESecurityStateChange: |
|
264 { |
|
265 StartupAdaptation::TSecurityStateResponsePckg responsePckg; |
|
266 responsePckg.Copy(aRetPckg); |
|
267 // Only copy across the response if it's error free |
|
268 if(responsePckg().iErrorCode == KErrNone) |
|
269 { |
|
270 TPckgBuf<TInt> replyPckg; |
|
271 replyPckg() = responsePckg().iValue; |
|
272 iReturnPckg->Copy(replyPckg); |
|
273 // Finished with iReturnPckg |
|
274 iReturnPckg = NULL; |
|
275 } |
|
276 CompleteRequestStatus(responsePckg().iErrorCode); |
|
277 break; |
|
278 } |
|
279 case StartupAdaptation::EGetSIMLanguages: |
|
280 { |
|
281 // aRetPckg contains an RClass so we use it in place by creating a reference to it |
|
282 StartupAdaptation::TLanguageListResponsePckg& languageListResponsePckg = |
|
283 *(static_cast<StartupAdaptation::TLanguageListResponsePckg*>(&aRetPckg)); |
|
284 if(languageListResponsePckg().iErrorCode == KErrNone) |
|
285 { |
|
286 // Clear array |
|
287 iLanguageList.Reset(); |
|
288 // make a copy of the array |
|
289 for(TInt i = 0; i < languageListResponsePckg().iLanguages.Count(); ++i) |
|
290 { |
|
291 iLanguageList.Append( languageListResponsePckg().iLanguages[i] ); // ignore errors for compatibility reasons |
|
292 } |
|
293 // Copy size into the return buffer |
|
294 TPckgBuf<TInt> sizeBuf(iLanguageList.Count()); |
|
295 iReturnPckg->Copy(sizeBuf); |
|
296 // done with return buffer |
|
297 iReturnPckg = NULL; |
|
298 } |
|
299 CompleteRequestStatus(languageListResponsePckg().iErrorCode); |
|
300 break; |
|
301 } |
|
302 case StartupAdaptation::EGetGlobalStartupMode: |
|
303 { |
|
304 StartupAdaptation::TGlobalStartupModeResponsePckg responsePckg; |
|
305 responsePckg.Copy(aRetPckg); |
|
306 // Only copy across the response if it's error free |
|
307 if(responsePckg().iErrorCode == KErrNone) |
|
308 { |
|
309 TPckgBuf<TInt> replyPckg; |
|
310 replyPckg() = responsePckg().iValue; |
|
311 iReturnPckg->Copy(replyPckg); |
|
312 // Finished with iReturnPckg |
|
313 iReturnPckg = NULL; |
|
314 } |
|
315 CompleteRequestStatus(responsePckg().iErrorCode); |
|
316 break; |
|
317 } |
|
318 case StartupAdaptation::EGetHiddenReset: |
|
319 { |
|
320 StartupAdaptation::TBooleanResponsePckg booleanResponsePckg; |
|
321 booleanResponsePckg.Copy(aRetPckg); |
|
322 if(KErrNone == booleanResponsePckg().iErrorCode) |
|
323 { |
|
324 // Copy the boolean value across to the descriptor passed in |
|
325 TPckgBuf<TBool> boolPckg; |
|
326 boolPckg() = booleanResponsePckg().iValue; |
|
327 iReturnPckg->Copy(boolPckg); |
|
328 // Null iReturnPckg as it has no further use |
|
329 iReturnPckg = NULL; |
|
330 } |
|
331 CompleteRequestStatus(booleanResponsePckg().iErrorCode); |
|
332 break; |
|
333 } |
|
334 |
|
335 default: |
|
336 CLAYER_PANIC(ECLayerUnknownCommandResponse); |
|
337 break; |
|
338 } |
|
339 } |
|
340 |
|
341 /** |
|
342 * See CAdaptationBase for description of method. |
|
343 * |
|
344 * @internalComponent |
|
345 */ |
|
346 TDesC8* CSaaMiscAdaptation::ParameterPckg() |
|
347 { |
|
348 TDesC8* ptr = NULL; |
|
349 switch(CommandId()) |
|
350 { |
|
351 case StartupAdaptation::ESecurityStateChange: |
|
352 ptr = &iSecurityStateChangePckg; |
|
353 break; |
|
354 case StartupAdaptation::EGetSIMLanguages: |
|
355 ptr = &iLanguageListPriorityPckg; |
|
356 break; |
|
357 case StartupAdaptation::EGetGlobalStartupMode: |
|
358 ptr = &iNullBuf; |
|
359 break; |
|
360 case StartupAdaptation::EGetHiddenReset: |
|
361 //No parameters to be passed |
|
362 ptr = &iNullBuf; |
|
363 break; |
|
364 default: |
|
365 ptr = NULL; |
|
366 break; |
|
367 } |
|
368 return ptr; |
|
369 } |