|
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_InquirySockAddrData.h" |
|
19 #include "T_SockAddrData.h" |
|
20 #include "T_BTDevAddrData.h" |
|
21 #include "T_CBluetoothSocketData.h" |
|
22 #include "T_BTUtil.h" |
|
23 |
|
24 /*@{*/ |
|
25 //Parameters |
|
26 _LIT(KExpected, "expected"); |
|
27 _LIT(KTSockAddr, "sockaddr"); |
|
28 _LIT(KTBTDevAddr, "tbtdevaddr"); |
|
29 _LIT(KClass, "class"); |
|
30 _LIT(KIAC, "iac"); |
|
31 _LIT(KFlag, "flag"); |
|
32 _LIT(KIntDevAddr, "integerdevaddr"); |
|
33 _LIT(KVersionName, "name"); |
|
34 _LIT(KVersionBuild, "build"); |
|
35 _LIT(KVersionMajor, "major"); |
|
36 _LIT(KVersionMinor, "minor"); |
|
37 _LIT(KBTSocket, "btsocket"); |
|
38 _LIT(KDeviceName, "devicename"); |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 //Commands |
|
44 _LIT(KCmdTInquirySockAddr, "TInquirySockAddr"); |
|
45 _LIT(KCmdBTAddr, "BTAddr"); |
|
46 _LIT(KCmdSetBTAddr, "SetBTAddr"); |
|
47 _LIT(KCmdCast, "Cast"); |
|
48 _LIT(KCmdMajorServiceClass, "MajorServiceClass"); |
|
49 _LIT(KCmdSetMajorServiceClass, "SetMajorServiceClass"); |
|
50 _LIT(KCmdMajorClassOfDevice, "MajorClassOfDevice"); |
|
51 _LIT(KCmdSetMajorClassOfDevice, "SetMajorClassOfDevice"); |
|
52 _LIT(KCmdMinorClassOfDevice, "MinorClassOfDevice"); |
|
53 _LIT(KCmdSetMinorClassOfDevice, "SetMinorClassOfDevice"); |
|
54 _LIT(KCmdIAC, "IAC"); |
|
55 _LIT(KCmdSetIAC, "SetIAC"); |
|
56 _LIT(KCmdAction, "Action"); |
|
57 _LIT(KCmdSetAction, "SetAction"); |
|
58 _LIT(KCmdVersion, "Version"); |
|
59 //Use of Protected method |
|
60 _LIT(KCmdFormatTypeField, "PROTECTED-FormatTypeField"); |
|
61 |
|
62 //Commands |
|
63 _LIT(KCmdOpenHostResolver, "OpenHostResolver"); |
|
64 _LIT(KCmdGetByAddress, "GetByAddress"); |
|
65 _LIT(KCmdSetHostName, "SetHostName"); |
|
66 _LIT(KCmdSetDiscoverable, "SetDiscoverable"); |
|
67 |
|
68 // Logging |
|
69 _LIT(KLogMissingParameters, "Missing parameters '%S' or '%S'"); |
|
70 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
71 /*@}*/ |
|
72 |
|
73 ////////////////////////////////////////////////////////////////////// |
|
74 // Construction/Destruction |
|
75 ////////////////////////////////////////////////////////////////////// |
|
76 |
|
77 CT_InquirySockAddrData* CT_InquirySockAddrData::NewL() |
|
78 { |
|
79 CT_InquirySockAddrData* ret=new (ELeave) CT_InquirySockAddrData(); |
|
80 CleanupStack::PushL(ret); |
|
81 ret->ConstructL(); |
|
82 CleanupStack::Pop(ret); |
|
83 return ret; |
|
84 } |
|
85 |
|
86 CT_InquirySockAddrData::CT_InquirySockAddrData() |
|
87 : iData(NULL) |
|
88 , iTInquirySockAddrOwned(EFalse) |
|
89 , iActive(NULL) |
|
90 , iHostResolverOpen(EFalse) |
|
91 { |
|
92 } |
|
93 |
|
94 void CT_InquirySockAddrData::ConstructL() |
|
95 { |
|
96 iActive = CActiveCallback::NewL(*this); |
|
97 } |
|
98 |
|
99 |
|
100 CT_InquirySockAddrData::~CT_InquirySockAddrData() |
|
101 { |
|
102 DestroyData(); |
|
103 if ( iHostResolverOpen ) |
|
104 { |
|
105 iHostResolver.Close(); |
|
106 } |
|
107 delete iActive; |
|
108 iActive = NULL; |
|
109 } |
|
110 |
|
111 TAny* CT_InquirySockAddrData::GetObject() |
|
112 { |
|
113 return iData; |
|
114 } |
|
115 |
|
116 void CT_InquirySockAddrData::DestroyData() |
|
117 { |
|
118 if (iTInquirySockAddrOwned) |
|
119 { |
|
120 delete iData; |
|
121 } |
|
122 iData=NULL; |
|
123 } |
|
124 |
|
125 void CT_InquirySockAddrData::SetObjectL(TAny* aAny) |
|
126 { |
|
127 DestroyData(); |
|
128 iData = static_cast<T_InquirySockAddrChild*> (aAny); |
|
129 } |
|
130 |
|
131 void CT_InquirySockAddrData::DisownObjectL() |
|
132 { |
|
133 iData = NULL; |
|
134 } |
|
135 |
|
136 inline TCleanupOperation CT_InquirySockAddrData::CleanupOperation() |
|
137 { |
|
138 return CleanupOperation; |
|
139 } |
|
140 |
|
141 void CT_InquirySockAddrData::CleanupOperation(TAny* aAny) |
|
142 { |
|
143 //may be unnecessary |
|
144 T_InquirySockAddrChild* arg=static_cast<T_InquirySockAddrChild*>(aAny); |
|
145 delete arg; |
|
146 } |
|
147 |
|
148 |
|
149 TBool CT_InquirySockAddrData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
150 { |
|
151 TBool ret = ETrue; |
|
152 |
|
153 if ( aCommand==KCmdTInquirySockAddr ) |
|
154 { |
|
155 DoCmdTInquirySockAddr(aSection); |
|
156 } |
|
157 else if ( aCommand==KCmdBTAddr ) |
|
158 { |
|
159 DoCmdBTAddr(aSection); |
|
160 } |
|
161 else if ( aCommand==KCmdSetBTAddr ) |
|
162 { |
|
163 DoCmdSetBTAddr(aSection); |
|
164 } |
|
165 else if ( aCommand==KCmdCast ) |
|
166 { |
|
167 DoCmdCast(aSection); |
|
168 } |
|
169 else if ( aCommand==KCmdMajorServiceClass ) |
|
170 { |
|
171 DoCmdMajorServiceClass(aSection); |
|
172 } |
|
173 else if ( aCommand==KCmdSetMajorServiceClass ) |
|
174 { |
|
175 DoCmdSetMajorServiceClass(aSection); |
|
176 } |
|
177 else if ( aCommand==KCmdMajorClassOfDevice ) |
|
178 { |
|
179 DoCmdMajorClassOfDevice(aSection); |
|
180 } |
|
181 else if ( aCommand==KCmdSetMajorClassOfDevice ) |
|
182 { |
|
183 DoCmdSetMajorClassOfDevice(aSection); |
|
184 } |
|
185 else if ( aCommand==KCmdMinorClassOfDevice ) |
|
186 { |
|
187 DoCmdMinorClassOfDevice(aSection); |
|
188 } |
|
189 else if ( aCommand==KCmdSetMinorClassOfDevice ) |
|
190 { |
|
191 DoCmdSetMinorClassOfDevice(aSection); |
|
192 } |
|
193 else if ( aCommand==KCmdIAC ) |
|
194 { |
|
195 DoCmdIAC(aSection); |
|
196 } |
|
197 else if ( aCommand==KCmdSetIAC ) |
|
198 { |
|
199 DoCmdSetIAC(aSection); |
|
200 } |
|
201 else if ( aCommand==KCmdAction ) |
|
202 { |
|
203 DoCmdAction(aSection); |
|
204 } |
|
205 else if ( aCommand==KCmdSetAction ) |
|
206 { |
|
207 DoCmdSetAction(aSection); |
|
208 } |
|
209 else if ( aCommand==KCmdVersion ) |
|
210 { |
|
211 DoCmdVersion(aSection); |
|
212 } |
|
213 else if ( aCommand==KCmdFormatTypeField ) |
|
214 { |
|
215 DoCmdPROTECTEDFormatTypeField(aSection); |
|
216 } |
|
217 else if ( aCommand==KCmdOpenHostResolver ) |
|
218 { |
|
219 DoCmdOpenHostResolver(aSection); |
|
220 } |
|
221 else if ( aCommand==KCmdGetByAddress ) |
|
222 { |
|
223 DoCmdGetByAddress(aSection, aAsyncErrorIndex); |
|
224 } |
|
225 else if ( aCommand==KCmdSetHostName ) |
|
226 { |
|
227 DoCmdSetHostName(aSection); |
|
228 } |
|
229 else if ( aCommand==KCmdSetDiscoverable ) |
|
230 { |
|
231 SetDiscoverable(aSection); |
|
232 } |
|
233 else |
|
234 { |
|
235 ret=EFalse; |
|
236 } |
|
237 |
|
238 return ret; |
|
239 } |
|
240 |
|
241 |
|
242 /** |
|
243 Test TInquirySockAddr() |
|
244 */ |
|
245 void CT_InquirySockAddrData::DoCmdTInquirySockAddr(const TDesC& aSection) |
|
246 { |
|
247 TPtrC myTSockAddrName; |
|
248 TSockAddr* myTSockAddr = NULL; |
|
249 if ( !GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName) ) |
|
250 { |
|
251 DestroyData(); |
|
252 //Use default constructor |
|
253 INFO_PRINTF1(_L("TInquirySockAddr Constructor Call")); |
|
254 iData = new (ELeave) T_InquirySockAddrChild(); |
|
255 iTInquirySockAddrOwned=ETrue; |
|
256 } |
|
257 else |
|
258 { |
|
259 myTSockAddr = static_cast<TSockAddr*>(GetDataObjectL(myTSockAddrName)); |
|
260 |
|
261 if ( myTSockAddr!=NULL ) |
|
262 { |
|
263 DestroyData(); |
|
264 INFO_PRINTF1(_L("TInquirySockAddr Constructor Call")); |
|
265 iData = new (ELeave) T_InquirySockAddrChild(*myTSockAddr); |
|
266 iTInquirySockAddrOwned=ETrue; |
|
267 } |
|
268 else |
|
269 { |
|
270 ERR_PRINTF1(_L("TInquirySockAddr Construct From TSockAddr. TSockAddr is NULL")); |
|
271 SetBlockResult(EFail); |
|
272 } |
|
273 } |
|
274 if ( iData == NULL ) |
|
275 { |
|
276 ERR_PRINTF1(_L("TInquirySockAddr is NULL")); |
|
277 SetBlockResult(EFail); |
|
278 } |
|
279 } |
|
280 |
|
281 |
|
282 /** |
|
283 Test BTAddr() |
|
284 */ |
|
285 void CT_InquirySockAddrData::DoCmdBTAddr(const TDesC& aSection) |
|
286 { |
|
287 INFO_PRINTF1(_L("TInquirySockAddr BTAddr Call")); |
|
288 TBTDevAddr btDevAddr = iData->BTAddr(); |
|
289 |
|
290 TBuf<KMaxSockAddrSize> tmpbtDevAddr; |
|
291 btDevAddr.GetReadable(tmpbtDevAddr); |
|
292 INFO_PRINTF2(_L("Returned BT Addres = (%S)"), &tmpbtDevAddr); |
|
293 TBuf<KMaxSockAddrSize> tmptBTDevAddrData; |
|
294 |
|
295 TPtrC tBTDevAddrName; |
|
296 TBool foundParameter=EFalse; |
|
297 TBool result = EFalse; |
|
298 |
|
299 if(GetStringFromConfig(aSection, KTBTDevAddr(), tBTDevAddrName)) |
|
300 { |
|
301 foundParameter=ETrue; |
|
302 TBTDevAddr* tBTDevAddrData=static_cast<TBTDevAddr*>(GetDataObjectL(tBTDevAddrName)); |
|
303 |
|
304 tBTDevAddrData->GetReadable(tmptBTDevAddrData); |
|
305 INFO_PRINTF2(_L("Expected BT address = (%S) from ini file"), &tmptBTDevAddrData); |
|
306 |
|
307 result = btDevAddr==(*tBTDevAddrData); |
|
308 |
|
309 if ( !result ) |
|
310 { |
|
311 ERR_PRINTF3(_L("BT Address (%S) is not as expected (%S)"),&tmpbtDevAddr, &tmptBTDevAddrData); |
|
312 SetBlockResult(EFail); |
|
313 } |
|
314 } |
|
315 |
|
316 TInt intBtDevAddr=0; |
|
317 if(GetIntFromConfig(aSection, KIntDevAddr(), intBtDevAddr)) |
|
318 { |
|
319 foundParameter=ETrue; |
|
320 const TBTDevAddr expectedBTAddr(intBtDevAddr); |
|
321 |
|
322 result = btDevAddr==(expectedBTAddr); |
|
323 btDevAddr.GetReadable(tmpbtDevAddr); |
|
324 if ( !result ) |
|
325 { |
|
326 ERR_PRINTF3(_L("BT Address (%S) is not as expected (%d)"), &tmpbtDevAddr, intBtDevAddr); |
|
327 SetBlockResult(EFail); |
|
328 } |
|
329 } |
|
330 |
|
331 if( !foundParameter ) |
|
332 { |
|
333 ERR_PRINTF3(KLogMissingParameters, &KTBTDevAddr(), &KIntDevAddr()); |
|
334 SetBlockResult(EFail); |
|
335 } |
|
336 } |
|
337 |
|
338 |
|
339 /** |
|
340 Test SetBTAddr() |
|
341 */ |
|
342 void CT_InquirySockAddrData::DoCmdSetBTAddr(const TDesC& aSection) |
|
343 { |
|
344 TPtrC tBTDevAddrName; |
|
345 TBool foundParameter=EFalse; |
|
346 |
|
347 if(GetStringFromConfig(aSection, KTBTDevAddr(), tBTDevAddrName)) |
|
348 { |
|
349 foundParameter=ETrue; |
|
350 CT_BTDevAddrData* tBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(tBTDevAddrName)); |
|
351 const TBTDevAddr* btDevAddr = tBTDevAddrData->GetAddress(); |
|
352 |
|
353 INFO_PRINTF1(_L("TInquirySockAddr SetBTAddr Call")); |
|
354 iData->SetBTAddr(*btDevAddr); |
|
355 } |
|
356 |
|
357 TInt intBtDevAddr=0; |
|
358 if(GetIntFromConfig(aSection, KIntDevAddr(), intBtDevAddr)) |
|
359 { |
|
360 foundParameter=ETrue; |
|
361 const TBTDevAddr btDevAddr(intBtDevAddr); |
|
362 |
|
363 INFO_PRINTF1(_L("TInquirySockAddr SetBTAddr Call")); |
|
364 iData->SetBTAddr(btDevAddr); |
|
365 } |
|
366 |
|
367 if( !foundParameter ) |
|
368 { |
|
369 ERR_PRINTF3(KLogMissingParameters, &KTBTDevAddr(), &KIntDevAddr()); |
|
370 SetBlockResult(EFail); |
|
371 } |
|
372 } |
|
373 |
|
374 |
|
375 /** |
|
376 Test Cast() |
|
377 */ |
|
378 void CT_InquirySockAddrData::DoCmdCast(const TDesC& aSection) |
|
379 { |
|
380 TPtrC myTSockAddrName; |
|
381 TSockAddr* myTSockAddr = NULL; |
|
382 |
|
383 if (GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName) ) |
|
384 { |
|
385 myTSockAddr = static_cast<TSockAddr*>(GetDataObjectL(myTSockAddrName)); |
|
386 if ( myTSockAddr!=NULL ) |
|
387 { |
|
388 DestroyData(); |
|
389 |
|
390 INFO_PRINTF1(_L("TInquirySockAddr Cast Call")); |
|
391 iData = &T_InquirySockAddrChild::Cast(*myTSockAddr); |
|
392 iTInquirySockAddrOwned=EFalse; |
|
393 } |
|
394 else |
|
395 { |
|
396 ERR_PRINTF1(_L("TSockAddr is NULL")); |
|
397 SetBlockResult(EFail); |
|
398 } |
|
399 } |
|
400 else |
|
401 { |
|
402 ERR_PRINTF2(KLogMissingParameter, &KTSockAddr()); |
|
403 SetBlockResult(EFail); |
|
404 } |
|
405 } |
|
406 |
|
407 |
|
408 /** |
|
409 Test MajorServiceClass() |
|
410 */ |
|
411 void CT_InquirySockAddrData::DoCmdMajorServiceClass(const TDesC& aSection) |
|
412 { |
|
413 INFO_PRINTF1(_L("TInquirySockAddr MajorServiceClass Call")); |
|
414 TUint16 result = iData->MajorServiceClass(); |
|
415 |
|
416 TInt expected = 0; |
|
417 if(GetIntFromConfig(aSection, KExpected(), expected) ) |
|
418 { |
|
419 if ( result != (TUint16)expected ) |
|
420 { |
|
421 ERR_PRINTF3(_L("Return value (%d) is not as expected (%d)"), result, expected); |
|
422 SetBlockResult(EFail); |
|
423 } |
|
424 } |
|
425 else |
|
426 { |
|
427 ERR_PRINTF2(KLogMissingParameter, &KExpected()); |
|
428 SetBlockResult(EFail); |
|
429 } |
|
430 } |
|
431 |
|
432 |
|
433 |
|
434 /** |
|
435 Test SetMajorServiceClass() |
|
436 */ |
|
437 void CT_InquirySockAddrData::DoCmdSetMajorServiceClass(const TDesC& aSection) |
|
438 { |
|
439 TInt classValue = 0; |
|
440 |
|
441 if (GetIntFromConfig(aSection, KClass(), classValue) ) |
|
442 { |
|
443 INFO_PRINTF1(_L("TInquirySockAddr SetMajorServiceClass Call")); |
|
444 iData->SetMajorServiceClass((TUint16)classValue); |
|
445 } |
|
446 else |
|
447 { |
|
448 ERR_PRINTF2(KLogMissingParameter, &KClass()); |
|
449 SetBlockResult(EFail); |
|
450 } |
|
451 } |
|
452 |
|
453 |
|
454 /** |
|
455 Test MajorClassOfDevice() |
|
456 */ |
|
457 void CT_InquirySockAddrData::DoCmdMajorClassOfDevice(const TDesC& aSection) |
|
458 { |
|
459 INFO_PRINTF1(_L("TInquirySockAddr MajorClassOfDevice Call")); |
|
460 TUint8 result = iData->MajorClassOfDevice(); |
|
461 |
|
462 TInt expected = 0; |
|
463 if(GetIntFromConfig(aSection, KExpected(), expected) ) |
|
464 { |
|
465 if ( result != (TUint8)expected ) |
|
466 { |
|
467 ERR_PRINTF3(_L("Return value (%d) is not as expected (%d)"), result, expected); |
|
468 SetBlockResult(EFail); |
|
469 } |
|
470 } |
|
471 else |
|
472 { |
|
473 ERR_PRINTF2(KLogMissingParameter, &KExpected()); |
|
474 SetBlockResult(EFail); |
|
475 } |
|
476 } |
|
477 |
|
478 |
|
479 |
|
480 /** |
|
481 Test SetMajorClassOfDevice() |
|
482 */ |
|
483 void CT_InquirySockAddrData::DoCmdSetMajorClassOfDevice(const TDesC& aSection) |
|
484 { |
|
485 TInt classValue = 0; |
|
486 |
|
487 if (GetIntFromConfig(aSection, KClass(), classValue) ) |
|
488 { |
|
489 INFO_PRINTF1(_L("TInquirySockAddr SetMajorClassOfDevice Call")); |
|
490 iData->SetMajorClassOfDevice((TUint8)classValue); |
|
491 } |
|
492 else |
|
493 { |
|
494 ERR_PRINTF2(KLogMissingParameter, &KClass()); |
|
495 SetBlockResult(EFail); |
|
496 } |
|
497 } |
|
498 |
|
499 |
|
500 /** |
|
501 Test MinorClassOfDevice() |
|
502 */ |
|
503 void CT_InquirySockAddrData::DoCmdMinorClassOfDevice(const TDesC& aSection) |
|
504 { |
|
505 INFO_PRINTF1(_L("TInquirySockAddr MinorClassOfDevice Call")); |
|
506 TUint8 result = iData->MinorClassOfDevice(); |
|
507 |
|
508 TInt expected = 0; |
|
509 if(GetIntFromConfig(aSection, KExpected(), expected) ) |
|
510 { |
|
511 if ( result != (TUint8)expected ) |
|
512 { |
|
513 ERR_PRINTF3(_L("Return value (%d) is not as expected (%d)"), result, expected); |
|
514 SetBlockResult(EFail); |
|
515 } |
|
516 } |
|
517 else |
|
518 { |
|
519 ERR_PRINTF2(KLogMissingParameter, &KExpected()); |
|
520 SetBlockResult(EFail); |
|
521 } |
|
522 } |
|
523 |
|
524 |
|
525 |
|
526 /** |
|
527 Test SetMinorClassOfDevice() |
|
528 */ |
|
529 void CT_InquirySockAddrData::DoCmdSetMinorClassOfDevice(const TDesC& aSection) |
|
530 { |
|
531 TInt classValue = 0; |
|
532 |
|
533 if (GetIntFromConfig(aSection, KClass(), classValue) ) |
|
534 { |
|
535 INFO_PRINTF1(_L("TInquirySockAddr SetMinorClassOfDevice Call")); |
|
536 iData->SetMinorClassOfDevice((TUint8)classValue); |
|
537 } |
|
538 else |
|
539 { |
|
540 ERR_PRINTF2(KLogMissingParameter, &KClass()); |
|
541 SetBlockResult(EFail); |
|
542 } |
|
543 } |
|
544 |
|
545 |
|
546 /** |
|
547 Test IAC() |
|
548 */ |
|
549 void CT_InquirySockAddrData::DoCmdIAC(const TDesC& aSection) |
|
550 { |
|
551 INFO_PRINTF1(_L("TInquirySockAddr IAC Call")); |
|
552 TUint result = iData->IAC(); |
|
553 |
|
554 TInt expected = 0; |
|
555 if(GetIntFromConfig(aSection, KExpected(), expected) ) |
|
556 { |
|
557 if ( result != (TUint)expected ) |
|
558 { |
|
559 ERR_PRINTF3(_L("Return value (%d) is not as expected (%d)"), result, expected); |
|
560 SetBlockResult(EFail); |
|
561 } |
|
562 } |
|
563 else |
|
564 { |
|
565 ERR_PRINTF2(KLogMissingParameter, &KExpected()); |
|
566 SetBlockResult(EFail); |
|
567 } |
|
568 } |
|
569 |
|
570 |
|
571 |
|
572 /** |
|
573 Test SetIAC() |
|
574 */ |
|
575 void CT_InquirySockAddrData::DoCmdSetIAC(const TDesC& aSection) |
|
576 { |
|
577 TInt theIAC = 0; |
|
578 |
|
579 if (GetIntFromConfig(aSection, KIAC(), theIAC) ) |
|
580 { |
|
581 INFO_PRINTF1(_L("TInquirySockAddr SetIAC Call")); |
|
582 iData->SetIAC((TUint)theIAC); |
|
583 } |
|
584 else |
|
585 { |
|
586 ERR_PRINTF2(KLogMissingParameter, &KIAC()); |
|
587 SetBlockResult(EFail); |
|
588 } |
|
589 } |
|
590 |
|
591 |
|
592 /** |
|
593 Test Action() |
|
594 */ |
|
595 void CT_InquirySockAddrData::DoCmdAction(const TDesC& aSection) |
|
596 { |
|
597 INFO_PRINTF1(_L("TInquirySockAddr Action Call")); |
|
598 TUint8 result = iData->Action(); |
|
599 |
|
600 TInt expected = 0; |
|
601 if(GetIntFromConfig(aSection, KExpected(), expected) ) |
|
602 { |
|
603 if ( result != (TUint8)expected ) |
|
604 { |
|
605 ERR_PRINTF3(_L("Return value (%d) is not as expected (%d)"), result, expected); |
|
606 SetBlockResult(EFail); |
|
607 } |
|
608 } |
|
609 else |
|
610 { |
|
611 ERR_PRINTF2(KLogMissingParameter, &KExpected()); |
|
612 SetBlockResult(EFail); |
|
613 } |
|
614 } |
|
615 |
|
616 |
|
617 /** |
|
618 Test SetAction() |
|
619 */ |
|
620 void CT_InquirySockAddrData::DoCmdSetAction(const TDesC& aSection) |
|
621 { |
|
622 TBool foundParameter=EFalse; |
|
623 TPtrC flagName; |
|
624 TInt flagValue=0; |
|
625 if (GetStringFromConfig(aSection, KFlag(), flagName) ) |
|
626 { |
|
627 foundParameter=ETrue; |
|
628 if (CT_BTUtil::GetIntValue(flagName, flagValue)) |
|
629 { |
|
630 INFO_PRINTF3(_L("The flag to set: %S , its value: %d" ), &flagName, flagValue); |
|
631 |
|
632 INFO_PRINTF1(_L("TInquirySockAddr SetAction Call")); |
|
633 iData->SetAction(KHostResInquiry | KHostResName); |
|
634 } |
|
635 } |
|
636 |
|
637 if ( !foundParameter ) |
|
638 { |
|
639 ERR_PRINTF2(KLogMissingParameter, &KFlag()); |
|
640 SetBlockResult(EFail); |
|
641 } |
|
642 } |
|
643 |
|
644 |
|
645 /** |
|
646 Test Version() |
|
647 */ |
|
648 void CT_InquirySockAddrData::DoCmdVersion(const TDesC& aSection) |
|
649 { |
|
650 INFO_PRINTF1(_L("TInquirySockAddr Version Call")); |
|
651 TVersion version=iData->Version(); |
|
652 TVersionName versionName = version.Name(); |
|
653 |
|
654 INFO_PRINTF1(_L("Version name :")); |
|
655 INFO_PRINTF1(versionName); |
|
656 INFO_PRINTF2(_L("Version build : %d"), (TInt)version.iBuild); |
|
657 INFO_PRINTF2(_L("Version major : %d"), (TInt)version.iMajor); |
|
658 INFO_PRINTF2(_L("Version minor : %d"), (TInt)version.iMinor); |
|
659 |
|
660 TPtrC name; |
|
661 if (GetStringFromConfig(aSection, KVersionName(), name) ) |
|
662 { |
|
663 if ( name != versionName ) |
|
664 { |
|
665 ERR_PRINTF1(_L("Name does not match expected name")); |
|
666 SetBlockResult(EFail); |
|
667 } |
|
668 } |
|
669 else |
|
670 { |
|
671 ERR_PRINTF2(KLogMissingParameter, &KVersionName()); |
|
672 SetBlockResult(EFail); |
|
673 } |
|
674 |
|
675 /* |
|
676 The following expected values are optional since the version name already includes these info. |
|
677 */ |
|
678 TInt intTemp = 0; |
|
679 if (GetIntFromConfig(aSection, KVersionBuild(), intTemp) ) |
|
680 { |
|
681 if ( intTemp != version.iBuild ) |
|
682 { |
|
683 ERR_PRINTF1(_L("Build does not match expected build")); |
|
684 SetBlockResult(EFail); |
|
685 } |
|
686 } |
|
687 |
|
688 if (GetIntFromConfig(aSection, KVersionMajor(), intTemp) ) |
|
689 { |
|
690 if ( intTemp != version.iMajor ) |
|
691 { |
|
692 ERR_PRINTF1(_L("Major does not match expected major")); |
|
693 SetBlockResult(EFail); |
|
694 } |
|
695 } |
|
696 |
|
697 if (GetIntFromConfig(aSection, KVersionMinor(), intTemp) ) |
|
698 { |
|
699 if ( intTemp != version.iMinor ) |
|
700 { |
|
701 ERR_PRINTF1(_L("Minor does not match expected minor")); |
|
702 SetBlockResult(EFail); |
|
703 } |
|
704 } |
|
705 |
|
706 if (versionName == _L("") && version.iBuild == 0) |
|
707 { |
|
708 ERR_PRINTF1(_L("Some version fields are not set!")); |
|
709 SetBlockResult(EFail); |
|
710 } |
|
711 |
|
712 if (version.iMajor == 0 && version.iMinor == 0) |
|
713 { |
|
714 ERR_PRINTF1(_L("Some version fields are not set!")); |
|
715 SetBlockResult(EFail); |
|
716 } |
|
717 } |
|
718 |
|
719 |
|
720 /** |
|
721 Test FormatTypeField() - protected method |
|
722 */ |
|
723 void CT_InquirySockAddrData::DoCmdPROTECTEDFormatTypeField(const TDesC& aSection) |
|
724 { |
|
725 INFO_PRINTF1(_L("TInquirySockAddr FormatTypeField Call")); |
|
726 TUint8 result = iData->T_FormatTypeField(); |
|
727 |
|
728 TInt expected = 0; |
|
729 if(GetIntFromConfig(aSection, KExpected(), expected) ) |
|
730 { |
|
731 if ( result > (TUint8)expected ) |
|
732 { |
|
733 ERR_PRINTF3(_L("Return value (%d) is not as expected (%d)"), result, expected); |
|
734 SetBlockResult(EFail); |
|
735 } |
|
736 } |
|
737 else |
|
738 { |
|
739 ERR_PRINTF2(KLogMissingParameter, &KExpected()); |
|
740 SetBlockResult(EFail); |
|
741 } |
|
742 } |
|
743 |
|
744 /** |
|
745 RHostResolver::Open() |
|
746 */ |
|
747 void CT_InquirySockAddrData::DoCmdOpenHostResolver(const TDesC& aSection) |
|
748 { |
|
749 RSocketServ sockServ; |
|
750 TPtrC bluetoothSocketName; |
|
751 if(GetStringFromConfig(aSection, KBTSocket(), bluetoothSocketName)) |
|
752 { |
|
753 CT_BluetoothSocketNotifier* bluetoothSocketData=static_cast<CT_BluetoothSocketNotifier*>(GetDataObjectL(bluetoothSocketName)); |
|
754 if ( bluetoothSocketData!=NULL ) |
|
755 { |
|
756 sockServ = bluetoothSocketData->iSocketServer; |
|
757 } |
|
758 else |
|
759 { |
|
760 ERR_PRINTF1(_L("CT_CBluetoothSocketDataPersistentObject is NULL")); |
|
761 SetBlockResult(EFail); |
|
762 } |
|
763 } |
|
764 |
|
765 |
|
766 // Find protocol from socket |
|
767 TProtocolDesc protocolDesc; |
|
768 TInt err=sockServ.FindProtocol(_L("BTLinkManager"), protocolDesc); |
|
769 if ( err!=KErrNone ) |
|
770 { |
|
771 ERR_PRINTF2(_L("iSockServ.FindProtocol(aProtocolName, protocolDesc) = %d"), err); |
|
772 SetBlockResult(EFail); |
|
773 } |
|
774 if ( protocolDesc.iAddrFamily != KBTAddrFamily ) |
|
775 { |
|
776 ERR_PRINTF1(_L("Wrong iAddrFamily")); |
|
777 SetBlockResult(EFail); |
|
778 } |
|
779 |
|
780 INFO_PRINTF1(_L("Close a RHostResolver first...")); |
|
781 iHostResolver.Close(); |
|
782 // Open host resolver |
|
783 INFO_PRINTF1(_L("Create and initialise an RHostResolver")); |
|
784 err=iHostResolver.Open(sockServ, protocolDesc.iAddrFamily, protocolDesc.iProtocol); |
|
785 if ( err!=KErrNone ) |
|
786 { |
|
787 ERR_PRINTF2(_L("iHostResolver.Open(iSockServ, protocolDesc.iAddrFamily, protocolDesc.iProtocol) = %d"), err); |
|
788 SetError(err); |
|
789 } |
|
790 else |
|
791 { |
|
792 iHostResolverOpen = ETrue; |
|
793 INFO_PRINTF1(_L("Create and initialise an RHostResolver Completed...")); |
|
794 } |
|
795 } |
|
796 |
|
797 |
|
798 /** |
|
799 RHostResolver::SetHostName() |
|
800 */ |
|
801 void CT_InquirySockAddrData::DoCmdSetHostName(const TDesC& aSection) |
|
802 { |
|
803 TPtrC deviceName; |
|
804 if(GetStringFromConfig(aSection, KDeviceName(), deviceName) ) |
|
805 { |
|
806 INFO_PRINTF1(_L("Call RHostResolver::SetHostName()")); |
|
807 TInt err=iHostResolver.SetHostName(deviceName); |
|
808 INFO_PRINTF2(_L("iHostResolver.SetHostName(%S)"), &deviceName); |
|
809 |
|
810 if( err!=KErrNone ) |
|
811 { |
|
812 ERR_PRINTF2(_L("iHostResolver.SetHostName() = %d"), err); |
|
813 SetError(err); |
|
814 } |
|
815 } |
|
816 else |
|
817 { |
|
818 ERR_PRINTF1(_L("No HostName given")); |
|
819 SetBlockResult(EFail); |
|
820 } |
|
821 } |
|
822 |
|
823 /** |
|
824 SetDiscoverable |
|
825 */ |
|
826 void CT_InquirySockAddrData::SetDiscoverable(const TDesC& /*aSection*/) |
|
827 { |
|
828 TInt err = RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetLimitedDiscoverableStatus, EFalse); |
|
829 INFO_PRINTF1(_L("RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetLimitedDiscoverableStatus, EFalse) called")); |
|
830 if( err!=KErrNone ) |
|
831 { |
|
832 ERR_PRINTF2(_L("RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetLimitedDiscoverableStatus, EFalse) = %d"), err); |
|
833 SetBlockResult(EFail); |
|
834 } |
|
835 |
|
836 err = RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EInquiryAndPageScan); |
|
837 INFO_PRINTF1(_L("RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EInquiryAndPageScan) called")); |
|
838 if( err!=KErrNone ) |
|
839 { |
|
840 ERR_PRINTF2(_L("RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EInquiryAndPageScan) = %d"), err); |
|
841 SetBlockResult(EFail); |
|
842 } |
|
843 } |
|
844 |
|
845 |
|
846 /** |
|
847 RHostResolver::GetByAddress() |
|
848 */ |
|
849 void CT_InquirySockAddrData::DoCmdGetByAddress(const TDesC& aSection, const TInt aAsyncErrorIndex) |
|
850 { |
|
851 if(GetStringFromConfig(aSection, KDeviceName(), iDeviceName) ) |
|
852 { |
|
853 iSockAddr = *iData; |
|
854 |
|
855 INFO_PRINTF1(_L("Call RHostResolver::GetByAddress()")); |
|
856 iHostResolver.GetByAddress(iSockAddr, iBtNameEntry, iActive->iStatus); |
|
857 INFO_PRINTF1(_L("RHostResolver::GetByAddress() completed")); |
|
858 |
|
859 iActive->Activate(aAsyncErrorIndex); |
|
860 IncOutstanding(); |
|
861 } |
|
862 else |
|
863 { |
|
864 ERR_PRINTF2(KLogMissingParameter, &KDeviceName()); |
|
865 SetBlockResult(EFail); |
|
866 } |
|
867 } |
|
868 |
|
869 /** |
|
870 Virtual RunL - Called on completion of an a Synchronous command |
|
871 @publishedInternal |
|
872 @see MT_MMActiveCallback |
|
873 @param aActive Active Object that RunL has been called on |
|
874 @pre N/A |
|
875 @post N/A |
|
876 @leave system wide error code |
|
877 */ |
|
878 void CT_InquirySockAddrData::RunL(CActive* aActive, TInt aIndex) |
|
879 { |
|
880 if ( aActive==iActive ) |
|
881 { |
|
882 RunGetDeviceAddress(aIndex); |
|
883 } |
|
884 else |
|
885 { |
|
886 ERR_PRINTF1(_L("Stray signal")); |
|
887 SetBlockResult(EFail); |
|
888 } |
|
889 } |
|
890 |
|
891 /** |
|
892 Virtual DoCancel - Request to cancel the asynchronous command |
|
893 @publishedInternal |
|
894 @see - MTPActiveCallback |
|
895 @param aActive Active Object that DoCancel has been called on |
|
896 @pre - N/A |
|
897 @post - N/A |
|
898 @leave system wide error code |
|
899 */ |
|
900 void CT_InquirySockAddrData::DoCancel(CActive* aActive, TInt /*aIndex*/) |
|
901 { |
|
902 if ( aActive==iActive ) |
|
903 { |
|
904 DoCancelGetDeviceAddress(); |
|
905 } |
|
906 else |
|
907 { |
|
908 ERR_PRINTF1(_L("Stray signal")); |
|
909 SetBlockResult(EFail); |
|
910 } |
|
911 } |
|
912 |
|
913 /** |
|
914 RunCustomCommand - Process RunL for iActive |
|
915 @publishedInternal |
|
916 @pre N/A |
|
917 @post N/A |
|
918 @leave system wide error code |
|
919 */ |
|
920 void CT_InquirySockAddrData::RunGetDeviceAddress(TInt aIndex) |
|
921 { |
|
922 TInt err = iActive->iStatus.Int(); |
|
923 if ( err == KErrNone ) |
|
924 { |
|
925 THostName deviceName = iBtNameEntry().iName; |
|
926 INFO_PRINTF2(_L("Device %S Found"), &deviceName); |
|
927 |
|
928 if( deviceName == iDeviceName ) |
|
929 { |
|
930 INFO_PRINTF2(_L("Found required device %S"), &deviceName); |
|
931 |
|
932 INFO_PRINTF1(_L("Cast TSockAddr to the iData...")); |
|
933 *iData = iSockAddr.Cast(iBtNameEntry().iAddr); |
|
934 INFO_PRINTF1(_L("Cast completed")); |
|
935 |
|
936 iBTDevAddr = new (ELeave)TBTDevAddr(); |
|
937 *iBTDevAddr = iData->BTAddr(); |
|
938 TBuf<KMaxSockAddrSize> tmpBuf; |
|
939 iBTDevAddr->GetReadable(tmpBuf); |
|
940 INFO_PRINTF2(_L("Required Device BT Address = %S"), &tmpBuf); |
|
941 DecOutstanding(); |
|
942 } |
|
943 else |
|
944 { |
|
945 INFO_PRINTF1(_L("Still Searching...")); |
|
946 //Grab the details of the next device |
|
947 iHostResolver.Next(iBtNameEntry, iActive->iStatus); |
|
948 iActive->Activate(aIndex); |
|
949 } |
|
950 } |
|
951 else |
|
952 { |
|
953 ERR_PRINTF2(_L("RunL Error %d"), err); |
|
954 SetAsyncError(aIndex, err); |
|
955 DecOutstanding(); |
|
956 } |
|
957 } |
|
958 |
|
959 |
|
960 /** |
|
961 DoCancelActive - Process DoCancel for iActive |
|
962 @publishedInternal |
|
963 @pre N/A |
|
964 @post N/A |
|
965 @leave system wide error code |
|
966 */ |
|
967 void CT_InquirySockAddrData::DoCancelGetDeviceAddress() |
|
968 { |
|
969 } |
|
970 |