|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "T_DataSdpAttrValueUUID.h" |
|
19 #include "T_BTUtil.h" |
|
20 #include <e32math.h> |
|
21 |
|
22 |
|
23 /*@{*/ |
|
24 |
|
25 //Parameters |
|
26 _LIT(KInputInt, "inputInt"); |
|
27 _LIT(KInputIntLL, "inputIntLL"); |
|
28 _LIT(KInputIntLH, "inputIntLH"); |
|
29 _LIT(KInputIntHL, "inputIntHL"); |
|
30 _LIT(KInputIntHH, "inputIntHH"); |
|
31 _LIT(KExpected, "expected"); |
|
32 _LIT(KExpectedLL, "expectedLL"); |
|
33 _LIT(KExpectedLH, "expectedLH"); |
|
34 _LIT(KExpectedHL, "expectedHL"); |
|
35 _LIT(KExpectedHH, "expectedHH"); |
|
36 //Commands |
|
37 _LIT(KCmdNewUUIDL, "NewUUIDL"); |
|
38 _LIT(KCmdDes, "Des"); |
|
39 _LIT(KCmdDestructor, "~"); |
|
40 //buffer index |
|
41 const TInt KOneByteValue =256; |
|
42 const TInt KMinRangeHH = 0; |
|
43 const TInt KMaxRangeHH = 3; |
|
44 const TInt KMinRangeHL = 4; |
|
45 const TInt KMaxRangeHL = 7; |
|
46 const TInt KMinRangeLH = 8; |
|
47 const TInt KMaxRangeLH = 11; |
|
48 const TInt KMinRangeLL = 12; |
|
49 const TInt KMaxRangeLL = 15; |
|
50 |
|
51 /*@}*/ |
|
52 |
|
53 ////////////////////////////////////////////////////////////////////// |
|
54 // Construction/Destruction |
|
55 ////////////////////////////////////////////////////////////////////// |
|
56 |
|
57 CT_DataSdpAttrValueUUID* CT_DataSdpAttrValueUUID::NewL() |
|
58 { |
|
59 CT_DataSdpAttrValueUUID* ret=new (ELeave) CT_DataSdpAttrValueUUID(); |
|
60 CleanupStack::PushL(ret); |
|
61 ret->ConstructL(); |
|
62 CleanupStack::Pop(ret); |
|
63 return ret; |
|
64 } |
|
65 |
|
66 CT_DataSdpAttrValueUUID::CT_DataSdpAttrValueUUID() |
|
67 : iAttrValUUID(NULL) |
|
68 { |
|
69 } |
|
70 |
|
71 void CT_DataSdpAttrValueUUID::ConstructL() |
|
72 { |
|
73 } |
|
74 |
|
75 CSdpAttrValue* CT_DataSdpAttrValueUUID::GetSdpAttrValue() const |
|
76 { |
|
77 return iAttrValUUID; |
|
78 } |
|
79 |
|
80 CT_DataSdpAttrValueUUID::~CT_DataSdpAttrValueUUID() |
|
81 { |
|
82 DestroyData(); |
|
83 } |
|
84 |
|
85 void CT_DataSdpAttrValueUUID::SetObjectL(TAny* aAny) |
|
86 { |
|
87 DestroyData(); |
|
88 iAttrValUUID = static_cast<CSdpAttrValueUUID*> (aAny); |
|
89 } |
|
90 |
|
91 void CT_DataSdpAttrValueUUID::DisownObjectL() |
|
92 { |
|
93 iAttrValUUID = NULL; |
|
94 } |
|
95 |
|
96 void CT_DataSdpAttrValueUUID::DestroyData() |
|
97 { |
|
98 delete iAttrValUUID; |
|
99 iAttrValUUID=NULL; |
|
100 } |
|
101 |
|
102 inline TCleanupOperation CT_DataSdpAttrValueUUID::CleanupOperation() |
|
103 { |
|
104 return CleanupOperation; |
|
105 } |
|
106 |
|
107 void CT_DataSdpAttrValueUUID::CleanupOperation(TAny* aAny) |
|
108 { |
|
109 CSdpAttrValueUUID* arg=static_cast<CSdpAttrValueUUID*>(aAny); |
|
110 delete arg; |
|
111 } |
|
112 |
|
113 /** |
|
114 * Process a command read from the ini file |
|
115 * |
|
116 * @param aCommand The command to process |
|
117 * @param aSection The section in the ini containing data for the command |
|
118 * @param aAsyncErrorIndex Command index for async calls to return errors to |
|
119 * |
|
120 * @return ETrue if the command is processed |
|
121 * |
|
122 * @leave System wide error |
|
123 */ |
|
124 TBool CT_DataSdpAttrValueUUID::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
125 { |
|
126 TBool ret=ETrue; |
|
127 |
|
128 if ( aCommand==KCmdNewUUIDL ) |
|
129 { |
|
130 DoCmdNewUUIDL(aSection); |
|
131 } |
|
132 else if ( aCommand==KCmdDes ) |
|
133 { |
|
134 DoCmdDes(aSection); |
|
135 } |
|
136 else if ( aCommand==KCmdDestructor ) |
|
137 { |
|
138 DoCmdDestructor(); |
|
139 } |
|
140 else |
|
141 { |
|
142 ret=CT_DataSdpAttrValue::DoCommandL(aCommand, aSection, aAsyncErrorIndex); |
|
143 } |
|
144 |
|
145 return ret; |
|
146 } |
|
147 |
|
148 void CT_DataSdpAttrValueUUID::DoCmdNewUUIDL(const TDesC& aSection) |
|
149 { |
|
150 TInt inputInt; |
|
151 TInt inputIntLL; |
|
152 TInt inputIntLH; |
|
153 TInt inputIntHL; |
|
154 TInt inputIntHH; |
|
155 TBool ifInputExit = EFalse; |
|
156 TBool ifInputHHExit = EFalse; |
|
157 TBool ifInputHLExit = EFalse; |
|
158 TBool ifInputLHExit = EFalse; |
|
159 TBool ifInputLLExit = EFalse; |
|
160 |
|
161 |
|
162 DestroyData(); |
|
163 |
|
164 if ( GetIntFromConfig(aSection, KInputInt(), inputInt) ) |
|
165 { |
|
166 ifInputExit = ETrue; |
|
167 } |
|
168 else //to get four input values for 128-bit TUUID object |
|
169 { |
|
170 |
|
171 if ( GetIntFromConfig(aSection, KInputIntHH(), inputIntHH)) |
|
172 { |
|
173 ifInputHHExit = ETrue; |
|
174 } |
|
175 else |
|
176 { |
|
177 ERR_PRINTF2(_L("Missing parameter %S"), &KInputIntHH()); |
|
178 SetBlockResult(EFail); |
|
179 } |
|
180 |
|
181 if ( GetIntFromConfig(aSection, KInputIntHL(), inputIntHL)) |
|
182 { |
|
183 ifInputHLExit = ETrue; |
|
184 } |
|
185 else |
|
186 { |
|
187 ERR_PRINTF2(_L("Missing parameter %S"), &KInputIntHL()); |
|
188 SetBlockResult(EFail); |
|
189 } |
|
190 |
|
191 if ( GetIntFromConfig(aSection, KInputIntLH(), inputIntLH)) |
|
192 { |
|
193 ifInputLHExit = ETrue; |
|
194 } |
|
195 else |
|
196 { |
|
197 ERR_PRINTF2(_L("Missing parameter %S"), &KInputIntLH()); |
|
198 SetBlockResult(EFail); |
|
199 } |
|
200 |
|
201 if ( GetIntFromConfig(aSection, KInputIntLL(), inputIntLL)) |
|
202 { |
|
203 ifInputLLExit = ETrue; |
|
204 } |
|
205 else |
|
206 { |
|
207 ERR_PRINTF2(_L("Missing parameter %S"), &KInputIntLL()); |
|
208 SetBlockResult(EFail); |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 if ( ifInputExit ) |
|
214 { |
|
215 |
|
216 TRAPD(err, iAttrValUUID = CSdpAttrValueUUID::NewUUIDL(inputInt)); |
|
217 |
|
218 if ( err!=KErrNone ) |
|
219 { |
|
220 ERR_PRINTF2(_L("CSdpAttrValueUUID::NewUUIDL failed with error %d"), err); |
|
221 SetError(err); |
|
222 } |
|
223 } |
|
224 else if( ifInputHHExit && ifInputHLExit && ifInputLHExit && ifInputLLExit) |
|
225 { |
|
226 INFO_PRINTF2(_L("NewUUIDL Highest order word (HH bits 96 - 127): %d"), inputIntHH); |
|
227 INFO_PRINTF2(_L("NewUUIDL Second highest order word (HL bits 64 - 95): %d"), inputIntHL); |
|
228 INFO_PRINTF2(_L("NewUUIDL Second lowest order word (LH bits 32 - 63): %d"), inputIntLH); |
|
229 INFO_PRINTF2(_L("NewUUIDL Low order word (LL bits 0 - 31): %d"), inputIntLL); |
|
230 |
|
231 TUUID objUUID(inputIntHH,inputIntHL,inputIntLH,inputIntLL); |
|
232 TRAPD(err, iAttrValUUID = CSdpAttrValueUUID::NewUUIDL(objUUID)); |
|
233 |
|
234 if ( err!=KErrNone ) |
|
235 { |
|
236 ERR_PRINTF2(_L("CSdpAttrValueUUID::NewUUIDL failed with error %d"), err); |
|
237 SetError(err); |
|
238 } |
|
239 } |
|
240 else |
|
241 { |
|
242 ERR_PRINTF2(_L("Missing parameter %S"), &KInputIntLL()); |
|
243 SetBlockResult(EFail); |
|
244 } |
|
245 } |
|
246 |
|
247 void CT_DataSdpAttrValueUUID::DoCmdDes(const TDesC& aSection) |
|
248 { |
|
249 TInt inputIntLL = 0; |
|
250 TInt inputIntLH = 0; |
|
251 TInt inputIntHL = 0; |
|
252 TInt inputIntHH = 0; |
|
253 TInt expected; |
|
254 TInt expectedLL; |
|
255 TInt expectedLH; |
|
256 TInt expectedHL; |
|
257 TInt expectedHH; |
|
258 TInt sumValue = 0; |
|
259 TInt curPowervalue; |
|
260 TInt curPowervalueHH = 0; |
|
261 TInt curPowervalueHL = 0; |
|
262 TInt curPowervalueLH = 0; |
|
263 TInt curPowervalueLL = 0; |
|
264 TUUID actualUUid = NULL; |
|
265 |
|
266 TBool ifExpectedExit = EFalse; |
|
267 TBool ifExpectedHHExit = EFalse; |
|
268 TBool ifExpectedHLExit = EFalse; |
|
269 TBool ifExpectedLHExit = EFalse; |
|
270 TBool ifExpectedLLExit = EFalse; |
|
271 TReal64 powValue; |
|
272 |
|
273 TPtrC8 actualDesUUid=GetSdpAttrValue()->Des(); |
|
274 HBufC* buffer=HBufC::NewLC(actualDesUUid.Length()); |
|
275 TPtr bufferPtr=buffer->Des(); |
|
276 bufferPtr.Copy(actualDesUUid); |
|
277 |
|
278 |
|
279 |
|
280 if ( GetIntFromConfig(aSection, KExpected(), expected)) |
|
281 { |
|
282 ifExpectedExit = ETrue; |
|
283 } |
|
284 else //to get four input values for 128-bit TUUID object |
|
285 { |
|
286 |
|
287 if ( GetIntFromConfig(aSection, KExpectedHH(), expectedHH)) |
|
288 { |
|
289 ifExpectedHHExit = ETrue; |
|
290 } |
|
291 else |
|
292 { |
|
293 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedHH()); |
|
294 SetBlockResult(EFail); |
|
295 } |
|
296 |
|
297 if ( GetIntFromConfig(aSection, KExpectedHL(), expectedHL)) |
|
298 { |
|
299 ifExpectedHLExit = ETrue; |
|
300 } |
|
301 else |
|
302 { |
|
303 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedHL()); |
|
304 SetBlockResult(EFail); |
|
305 } |
|
306 |
|
307 if ( GetIntFromConfig(aSection, KExpectedLH(), expectedLH)) |
|
308 { |
|
309 ifExpectedLHExit = ETrue; |
|
310 } |
|
311 else |
|
312 { |
|
313 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedLH()); |
|
314 SetBlockResult(EFail); |
|
315 } |
|
316 |
|
317 if ( GetIntFromConfig(aSection, KExpectedLL(), expectedLL)) |
|
318 { |
|
319 ifExpectedLLExit = ETrue; |
|
320 } |
|
321 else |
|
322 { |
|
323 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedLL()); |
|
324 SetBlockResult(EFail); |
|
325 } |
|
326 } |
|
327 |
|
328 |
|
329 if( ifExpectedExit ) |
|
330 { |
|
331 for(TInt numRange = actualDesUUid.Length() -1; numRange >= 0; numRange--) |
|
332 { |
|
333 curPowervalue=Abs(numRange-(actualDesUUid.Length()-1)); |
|
334 Math::Pow(powValue,TReal(KOneByteValue),TReal(curPowervalue)); |
|
335 sumValue +=buffer[0][numRange]*powValue; |
|
336 } |
|
337 |
|
338 if ( sumValue!=expected ) |
|
339 { |
|
340 ERR_PRINTF1(_L("Des is not as expected!")); |
|
341 SetBlockResult(EFail); |
|
342 } |
|
343 } |
|
344 else if(ifExpectedHHExit || ifExpectedHLExit || ifExpectedLHExit || ifExpectedLLExit) |
|
345 { |
|
346 for(TInt numRange = actualDesUUid.Length() -1; numRange >= 0; numRange--) |
|
347 { |
|
348 if( numRange >=KMinRangeLL && numRange <=KMaxRangeLL ) |
|
349 { |
|
350 Math::Pow(powValue,TReal(KOneByteValue),TReal(curPowervalueLL)); |
|
351 curPowervalueLL++; |
|
352 inputIntLL +=buffer[0][numRange]*powValue; |
|
353 } |
|
354 else if( numRange >=KMinRangeLH && numRange <=KMaxRangeLH ) |
|
355 { |
|
356 Math::Pow(powValue,TReal(KOneByteValue),TReal(curPowervalueLH)); |
|
357 curPowervalueLH++; |
|
358 inputIntLH +=buffer[0][numRange]*powValue; |
|
359 } |
|
360 else if( numRange >=KMinRangeHL && numRange <=KMaxRangeHL ) |
|
361 { |
|
362 Math::Pow(powValue,TReal(KOneByteValue),TReal(curPowervalueHL)); |
|
363 curPowervalueHL++; |
|
364 inputIntHL +=buffer[0][numRange]*powValue; |
|
365 } |
|
366 else if( numRange <=KMaxRangeHH && numRange >=KMinRangeHH ) |
|
367 { |
|
368 Math::Pow(powValue,TReal(KOneByteValue),TReal(curPowervalueHH)); |
|
369 curPowervalueHH++; |
|
370 inputIntHH +=buffer[0][numRange]*powValue; |
|
371 } |
|
372 } |
|
373 INFO_PRINTF2(_L("expected Highest order word (HH bits 96 - 127): %d"), expectedHH); |
|
374 INFO_PRINTF2(_L("expected Second highest order word (HL bits 64 - 95): %d"), expectedHL); |
|
375 INFO_PRINTF2(_L("expected Second lowest order word (LH bits 32 - 63): %d"), expectedLH); |
|
376 INFO_PRINTF2(_L("expected Low order word (LL bits 0 - 31): %d"), expectedLL); |
|
377 //to compare four values with input |
|
378 if ( inputIntHH!=expectedHH || inputIntHL!=expectedHL || inputIntLH!=expectedLH || inputIntLL!=expectedLL ) |
|
379 { |
|
380 ERR_PRINTF1(_L("Des is not as expected!")); |
|
381 SetBlockResult(EFail); |
|
382 } |
|
383 } |
|
384 |
|
385 CleanupStack::PopAndDestroy(buffer); |
|
386 } |
|
387 |
|
388 void CT_DataSdpAttrValueUUID::DoCmdDestructor() |
|
389 { |
|
390 DestroyData(); |
|
391 } |