|
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_DataSdpAgent.h" |
|
19 #include "T_BTDevAddrData.h" |
|
20 #include "T_DataCSdpSearchPattern.h" |
|
21 #include "T_DataSdpAttrIdMatchList.h" |
|
22 #include "T_BTUtil.h" |
|
23 /*@{*/ |
|
24 |
|
25 //CSdpAgent commands |
|
26 _LIT(KCmdNewL, "NewL"); |
|
27 _LIT(KCmdNewLC, "NewLC"); |
|
28 _LIT(KCmdSetRecordFilterL, "SetRecordFilterL"); |
|
29 _LIT(KCmdSetAttributePredictorListL, "SetAttributePredictorListL"); |
|
30 _LIT(KCmdNextRecordRequestL, "NextRecordRequestL"); |
|
31 _LIT(KCmdAttributeRequestL, "AttributeRequestL"); |
|
32 _LIT(KCmdCancel, "Cancel"); |
|
33 _LIT(KCmdDestructor, "~"); |
|
34 _LIT(KCmdMSAN_ExtensionInterfaceL, "MSAN_ExtensionInterfaceL"); |
|
35 |
|
36 //CSdpAgent Parameters |
|
37 _LIT(KAttrid, "Attrid"); |
|
38 _LIT(KTBTDevAddr, "tbtdevaddr"); |
|
39 _LIT(KIntDevAddr, "integerdevaddr"); |
|
40 _LIT(KTBTSearchPattern, "tbtsearchpattern"); |
|
41 _LIT(KTBTAttrIdList, "tbtattridlist"); |
|
42 _LIT(KAttrValListName, "tbtattrvaluelist"); |
|
43 _LIT(KListType, "type"); |
|
44 _LIT(KExpectedRecordsCount, "expectedServRecCount"); |
|
45 |
|
46 const TInt KDefaultCount = -1; |
|
47 /*@}*/ |
|
48 |
|
49 ////////////////////////////////////////////////////////////////////// |
|
50 // Construction/Destruction |
|
51 ////////////////////////////////////////////////////////////////////// |
|
52 |
|
53 CT_DataSdpAgent* CT_DataSdpAgent::NewL() |
|
54 { |
|
55 CT_DataSdpAgent* ret=new (ELeave) CT_DataSdpAgent(); |
|
56 CleanupStack::PushL(ret); |
|
57 ret->ConstructL(); |
|
58 CleanupStack::Pop(ret); |
|
59 return ret; |
|
60 } |
|
61 |
|
62 CT_DataSdpAgent::CT_DataSdpAgent() |
|
63 : iSdpAgent(NULL) |
|
64 , iAttrValueList(NULL) |
|
65 , iExpectedRecordsCount(KDefaultCount) |
|
66 , iAttrValArray() |
|
67 , iAttrReqIndex(0) |
|
68 , iNextRecReqIndex(0) |
|
69 { |
|
70 } |
|
71 |
|
72 void CT_DataSdpAgent::ConstructL() |
|
73 { |
|
74 } |
|
75 |
|
76 CT_DataSdpAgent::~CT_DataSdpAgent() |
|
77 { |
|
78 DestroyData(); |
|
79 } |
|
80 |
|
81 void CT_DataSdpAgent::SetObjectL(TAny* aAny) |
|
82 { |
|
83 DestroyData(); |
|
84 iSdpAgent = static_cast<CSdpAgent*> (aAny); |
|
85 } |
|
86 |
|
87 void CT_DataSdpAgent::DisownObjectL() |
|
88 { |
|
89 iSdpAgent = NULL; |
|
90 } |
|
91 |
|
92 void CT_DataSdpAgent::DestroyData() |
|
93 { |
|
94 delete iSdpAgent; |
|
95 iSdpAgent=NULL; |
|
96 |
|
97 // Do not delete these as we do not own them |
|
98 iAttrValueList=NULL; |
|
99 } |
|
100 |
|
101 inline TCleanupOperation CT_DataSdpAgent::CleanupOperation() |
|
102 { |
|
103 return CleanupOperation; |
|
104 } |
|
105 |
|
106 void CT_DataSdpAgent::CleanupOperation(TAny* aAny) |
|
107 { |
|
108 CSdpAgent* agent=static_cast<CSdpAgent*>(aAny); |
|
109 delete agent; |
|
110 } |
|
111 |
|
112 void CT_DataSdpAgent::AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError) |
|
113 { |
|
114 INFO_PRINTF2(_L("MSdpAttributeValueVisitor::AttributeRequestComplete Call: aHandle = %d"),aHandle); |
|
115 DecOutstanding(); |
|
116 if ( aHandle!=iSSRHandle) |
|
117 { |
|
118 ERR_PRINTF2(_L("Service record handle not as expected: expected = %d"), iSSRHandle); |
|
119 SetAsyncError(iAttrReqIndex, KErrGeneral); |
|
120 } |
|
121 if ( aError!=KErrNone) |
|
122 { |
|
123 ERR_PRINTF2(_L("AttributeRequestComplete Call failed: aError = %d"),aError); |
|
124 SetAsyncError(iAttrReqIndex, aError); |
|
125 } |
|
126 } |
|
127 |
|
128 void CT_DataSdpAgent::AttributeRequestResult(TSdpServRecordHandle aHandle, |
|
129 TSdpAttributeID /*aAttrID*/, CSdpAttrValue* aAttrValue) |
|
130 { |
|
131 INFO_PRINTF2(_L("MSdpAttributeValueVisitor::AttributeRequestResult Call: aHandle = %d"),aHandle); |
|
132 if ( aHandle!=iSSRHandle) |
|
133 { |
|
134 ERR_PRINTF2(_L("Service record handle not as expected: expected = %d"), iSSRHandle); |
|
135 SetAsyncError(iAttrReqIndex, KErrGeneral); |
|
136 } |
|
137 if (aAttrValue) |
|
138 { |
|
139 INFO_PRINTF1(_L("Append to Array!")); |
|
140 iAttrValArray.Append(aAttrValue); |
|
141 } |
|
142 } |
|
143 |
|
144 void CT_DataSdpAgent::NextRecordRequestComplete(TInt aError, |
|
145 TSdpServRecordHandle aHandle, TInt aTotalRecordsCount) |
|
146 { |
|
147 DecOutstanding(); |
|
148 INFO_PRINTF2(_L("MSdpAttributeValueVisitor::NextRecordRequestComplete Call ! Number of records: %d"),aTotalRecordsCount); |
|
149 if (aError!=KErrNone) |
|
150 { |
|
151 ERR_PRINTF2(_L("Disconnected: %d"), aError); |
|
152 SetAsyncError(iNextRecReqIndex, aError); |
|
153 } |
|
154 else |
|
155 { |
|
156 if(aTotalRecordsCount!=iExpectedRecordsCount && iExpectedRecordsCount!=KDefaultCount) |
|
157 { |
|
158 ERR_PRINTF2(_L("Number of service records not as expected: expected = %d"),iExpectedRecordsCount); |
|
159 SetBlockResult(EFail); |
|
160 } |
|
161 if(aTotalRecordsCount!=0) |
|
162 { |
|
163 INFO_PRINTF1(_L("Found Service.")); |
|
164 iSSRHandle = aHandle; |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 |
|
170 const RPointerArray<CSdpAttrValue>& CT_DataSdpAgent::GetAttrValArray() |
|
171 { |
|
172 return iAttrValArray; |
|
173 } |
|
174 |
|
175 |
|
176 /** |
|
177 * Process a command read from the ini file |
|
178 * |
|
179 * @param aCommand The command to process |
|
180 * @param aSection The section in the ini containing data for the command |
|
181 * @param aAsyncErrorIndex Command index for async calls to return errors to |
|
182 * |
|
183 * @return ETrue if the command is processed |
|
184 * |
|
185 * @leave System wide error |
|
186 */ |
|
187 TBool CT_DataSdpAgent::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
188 { |
|
189 TBool ret = ETrue; |
|
190 |
|
191 //------------------------------------------------------------------------- |
|
192 // CSdpAgent |
|
193 //------------------------------------------------------------------------- |
|
194 if ( aCommand==KCmdNewL ) |
|
195 { |
|
196 DoCmdNewL(aSection); |
|
197 } |
|
198 else if ( aCommand==KCmdNewLC ) |
|
199 { |
|
200 DoCmdNewLC(aSection); |
|
201 } |
|
202 else if ( aCommand==KCmdSetRecordFilterL ) |
|
203 { |
|
204 DoCmdSetRecordFilterL(aSection); |
|
205 } |
|
206 else if ( aCommand==KCmdNextRecordRequestL ) |
|
207 { |
|
208 DoCmdNextRecordRequestL(aSection, aAsyncErrorIndex); |
|
209 } |
|
210 else if ( aCommand==KCmdSetAttributePredictorListL ) |
|
211 { |
|
212 DoCmdSetAttributePredictorListL(aSection); |
|
213 } |
|
214 else if ( aCommand==KCmdAttributeRequestL ) |
|
215 { |
|
216 DoCmdAttributeRequestL(aSection, aAsyncErrorIndex); |
|
217 } |
|
218 else if ( aCommand==KCmdCancel ) |
|
219 { |
|
220 DoCmdCancel(); |
|
221 } |
|
222 else if ( aCommand==KCmdDestructor ) |
|
223 { |
|
224 DoCmdDestructor(); |
|
225 } |
|
226 else if ( aCommand==KCmdMSAN_ExtensionInterfaceL ) |
|
227 { |
|
228 DoCmdMSAN_ExtensionInterfaceL(); |
|
229 } |
|
230 else |
|
231 { |
|
232 ret=EFalse; |
|
233 } |
|
234 |
|
235 return ret; |
|
236 } |
|
237 //CSdpAgent helper methods |
|
238 |
|
239 void CT_DataSdpAgent::DoCmdNewL(const TDesC& aSection) |
|
240 { |
|
241 DestroyData(); |
|
242 TPtrC tBTDevAddrName; |
|
243 TBool foundParameter=EFalse; |
|
244 INFO_PRINTF1(_L("CSdpAgent NewL call")); |
|
245 if( GetStringFromConfig(aSection, KTBTDevAddr(), tBTDevAddrName)) |
|
246 { |
|
247 foundParameter=ETrue; |
|
248 CT_BTDevAddrData* tBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(tBTDevAddrName)); |
|
249 const TBTDevAddr* btDevAddr = tBTDevAddrData->GetAddress(); |
|
250 TRAPD(err, iSdpAgent = CSdpAgent::NewL(*this, *btDevAddr)); |
|
251 if(err != KErrNone) |
|
252 { |
|
253 ERR_PRINTF2(_L("CSdpAgent NewL failed with error %d"), err); |
|
254 SetError(err); |
|
255 } |
|
256 } |
|
257 TInt intBtDevAddr=0; |
|
258 if( GetIntFromConfig(aSection, KIntDevAddr(), intBtDevAddr)) |
|
259 { |
|
260 foundParameter=ETrue; |
|
261 const TBTDevAddr btDevAddr(intBtDevAddr); |
|
262 TRAPD(err, iSdpAgent = CSdpAgent::NewL(*this, btDevAddr)); |
|
263 if(err != KErrNone) |
|
264 { |
|
265 ERR_PRINTF2(_L("CSdpAgent NewL failed with error %d"), err); |
|
266 SetError(err); |
|
267 } |
|
268 } |
|
269 |
|
270 if( !foundParameter ) |
|
271 { |
|
272 ERR_PRINTF2(_L("Missing parameter %S"), &KIntDevAddr()); |
|
273 SetBlockResult(EFail); |
|
274 } |
|
275 } |
|
276 |
|
277 void CT_DataSdpAgent::DoCmdNewLC(const TDesC& aSection) |
|
278 { |
|
279 DestroyData(); |
|
280 TPtrC tBTDevAddrName; |
|
281 TBool foundParameter=EFalse; |
|
282 |
|
283 if( GetStringFromConfig(aSection, KTBTDevAddr(), tBTDevAddrName)) |
|
284 { |
|
285 foundParameter=ETrue; |
|
286 CT_BTDevAddrData* tBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(tBTDevAddrName)); |
|
287 TBTDevAddr btDevAddr = *tBTDevAddrData->GetAddress(); |
|
288 TBuf<KMaxSockAddrSize> tmpBuf2; |
|
289 btDevAddr.GetReadable(tmpBuf2); |
|
290 |
|
291 TRAPD(err, iSdpAgent = CSdpAgent::NewLC(*this, btDevAddr); CleanupStack::Pop(iSdpAgent)); |
|
292 if(err != KErrNone) |
|
293 { |
|
294 ERR_PRINTF2(_L("CSdpAgent NewLC failed with error %d"), err); |
|
295 SetError(err); |
|
296 } |
|
297 } |
|
298 |
|
299 TInt intBtDevAddr=0; |
|
300 if( GetIntFromConfig(aSection, KIntDevAddr(), intBtDevAddr)) |
|
301 { |
|
302 foundParameter=ETrue; |
|
303 const TBTDevAddr btDevAddr(intBtDevAddr); |
|
304 TRAPD(err, iSdpAgent = CSdpAgent::NewLC(*this, btDevAddr)); |
|
305 if(err != KErrNone) |
|
306 { |
|
307 ERR_PRINTF2(_L("CSdpAgent NewLC failed with error %d"), err); |
|
308 SetError(err); |
|
309 } |
|
310 } |
|
311 |
|
312 if( !foundParameter ) |
|
313 { |
|
314 ERR_PRINTF2(_L("Missing parameter %S"), &KIntDevAddr()); |
|
315 SetBlockResult(EFail); |
|
316 } |
|
317 } |
|
318 |
|
319 void CT_DataSdpAgent::DoCmdSetRecordFilterL(const TDesC& aSection) |
|
320 { |
|
321 INFO_PRINTF1(_L("CSdpAgent SetRecordFilterL call")); |
|
322 TPtrC searchPatternName; |
|
323 if( GetStringFromConfig(aSection, KTBTSearchPattern(), searchPatternName)) |
|
324 { |
|
325 CSdpSearchPattern* searchPattern = static_cast<CSdpSearchPattern*>(GetDataObjectL(searchPatternName)); |
|
326 // Set the search pattern on the agent |
|
327 TRAPD(err, iSdpAgent->SetRecordFilterL(*searchPattern)); |
|
328 if(err != KErrNone) |
|
329 { |
|
330 ERR_PRINTF2(_L("CSdpAgent SetRecordFilterL failed with error %d"), err); |
|
331 SetError(err); |
|
332 } |
|
333 } |
|
334 else |
|
335 { |
|
336 ERR_PRINTF2(_L("Missing parameter %S"), &KTBTSearchPattern()); |
|
337 SetBlockResult(EFail); |
|
338 } |
|
339 } |
|
340 |
|
341 void CT_DataSdpAgent::DoCmdNextRecordRequestL(const TDesC& aSection, const TInt aIndex) |
|
342 { |
|
343 INFO_PRINTF1(_L("CSdpAgent NextRecordRequestL call")); |
|
344 iExpectedRecordsCount = KDefaultCount; |
|
345 TRAPD(err, iSdpAgent->NextRecordRequestL()); |
|
346 if(err != KErrNone) |
|
347 { |
|
348 ERR_PRINTF2(_L("CSdpAgent NextRecordRequestL failed with error %d"), err); |
|
349 SetError(err); |
|
350 } |
|
351 else |
|
352 { |
|
353 IncOutstanding(); |
|
354 iNextRecReqIndex = aIndex; |
|
355 /* |
|
356 The expected count is optional. |
|
357 This API will be called in most of test cases and it's probably not neccessary to |
|
358 check the count everytime. Especially when this class isn't the focus of testing. |
|
359 */ |
|
360 GetIntFromConfig(aSection, KExpectedRecordsCount(), iExpectedRecordsCount); |
|
361 } |
|
362 } |
|
363 |
|
364 void CT_DataSdpAgent::DoCmdSetAttributePredictorListL(const TDesC& aSection) |
|
365 { |
|
366 INFO_PRINTF1(_L("CSdpAgent SetAttributePredictorListL call")); |
|
367 TPtrC dataAttrIdListName; |
|
368 |
|
369 if( GetStringFromConfig(aSection, KTBTAttrIdList(), dataAttrIdListName)) |
|
370 { |
|
371 CSdpAttrIdMatchList* attrIdList = static_cast<CSdpAttrIdMatchList*>(GetDataObjectL(dataAttrIdListName)); |
|
372 |
|
373 TRAPD(err, iSdpAgent->SetAttributePredictorListL(*attrIdList)); |
|
374 if(err != KErrNone) |
|
375 { |
|
376 ERR_PRINTF2(_L("CSdpAgent SetAttributePredictorListL failed with error %d"), err); |
|
377 SetError(err); |
|
378 } |
|
379 } |
|
380 else |
|
381 { |
|
382 ERR_PRINTF2(_L("Missing parameter %S"), &KTBTAttrIdList()); |
|
383 SetBlockResult(EFail); |
|
384 } |
|
385 } |
|
386 |
|
387 void CT_DataSdpAgent::DoCmdCancel() |
|
388 { |
|
389 iSdpAgent->Cancel(); |
|
390 } |
|
391 |
|
392 void CT_DataSdpAgent::DoCmdDestructor() |
|
393 { |
|
394 DestroyData(); |
|
395 } |
|
396 |
|
397 void CT_DataSdpAgent::DoCmdMSAN_ExtensionInterfaceL() |
|
398 { |
|
399 INFO_PRINTF1(_L("MSdpAgentNotifier MSAN_ExtensionInterfaceL call")); |
|
400 void* tmpVoid; |
|
401 TRAPD(err, this->MSAN_ExtensionInterfaceL(KNullUid, tmpVoid)); |
|
402 if(err != KErrNone) |
|
403 { |
|
404 ERR_PRINTF2(_L("MSdpAgentNotifier MSAN_ExtensionInterfaceL failed with error %d"), err); |
|
405 SetError(err); |
|
406 } |
|
407 } |
|
408 |
|
409 void CT_DataSdpAgent::DoCmdAttributeRequestL(const TDesC& aSection, const TInt aIndex) |
|
410 { |
|
411 TInt attrId; |
|
412 TPtrC attrValListName; |
|
413 TPtrC theType; |
|
414 TPtrC dataAttrIdListName; |
|
415 TPtrC expectedAttrValListName; |
|
416 CSdpAttrIdMatchList* attrIdList=NULL; |
|
417 TBool ifAttrIdExist=EFalse; |
|
418 TBool ifAttrValListExist=EFalse; |
|
419 TBool ifAttrIdListExist=EFalse; |
|
420 |
|
421 |
|
422 // Get AttrId from config (test data) file |
|
423 if( GetIntFromConfig(aSection, KAttrid(), attrId) ) |
|
424 { |
|
425 ifAttrIdExist=ETrue; |
|
426 } |
|
427 |
|
428 //Get dictionary name of AttrValueList Wrapper |
|
429 if( GetStringFromConfig(aSection, KAttrValListName(), attrValListName) ) |
|
430 { |
|
431 //Get the list type to cast to |
|
432 if( GetStringFromConfig(aSection, KListType(), theType) ) |
|
433 { |
|
434 ifAttrValListExist=ETrue; |
|
435 iAttrValueList = CT_BTUtil::AttrValueListCastL(*this, attrValListName, theType); |
|
436 } |
|
437 } |
|
438 |
|
439 //Get the dictionary name of AttrIdMatchList Wrapper |
|
440 if( GetStringFromConfig(aSection, KTBTAttrIdList(), dataAttrIdListName) ) |
|
441 { |
|
442 ifAttrIdListExist=ETrue; |
|
443 attrIdList = static_cast<CSdpAttrIdMatchList*>(GetDataObjectL(dataAttrIdListName)); |
|
444 } |
|
445 |
|
446 TInt err=KErrNone; |
|
447 iAttrReqIndex = aIndex; |
|
448 if(!ifAttrValListExist && ifAttrIdExist) |
|
449 { |
|
450 INFO_PRINTF1(_L("CSdpAgent AttributeRequestL(TSdpServRecordHandle, TSdpAttributeID) call")); |
|
451 TRAP(err, iSdpAgent->AttributeRequestL(iSSRHandle, attrId)); |
|
452 if(err != KErrNone) |
|
453 { |
|
454 ERR_PRINTF2(_L("CSdpAgent AttributeRequestL failed with error %d"), err); |
|
455 SetError(err); |
|
456 } |
|
457 else |
|
458 { |
|
459 IncOutstanding(); |
|
460 } |
|
461 } |
|
462 else if(ifAttrValListExist && ifAttrIdExist) |
|
463 { |
|
464 INFO_PRINTF1(_L("CSdpAgent AttributeRequestL(MSdpElementBuilder, TSdpServRecordHandle, TSdpAttributeID) call")); |
|
465 TRAP(err, iSdpAgent->AttributeRequestL(iAttrValueList, iSSRHandle, attrId)); |
|
466 if(err != KErrNone) |
|
467 { |
|
468 ERR_PRINTF2(_L("CSdpAgent AttributeRequestL failed with error %d"), err); |
|
469 SetError(err); |
|
470 } |
|
471 else |
|
472 { |
|
473 IncOutstanding(); |
|
474 } |
|
475 } |
|
476 else if(!ifAttrValListExist && ifAttrIdListExist) |
|
477 { |
|
478 INFO_PRINTF1(_L("CSdpAgent AttributeRequestL(TSdpServRecordHandle, const CSdpAttrIdMatchList&) call")); |
|
479 TRAP(err, iSdpAgent->AttributeRequestL(iSSRHandle, *attrIdList)); |
|
480 if(err != KErrNone) |
|
481 { |
|
482 ERR_PRINTF2(_L("CSdpAgent AttributeRequestL failed with error %d"), err); |
|
483 SetError(err); |
|
484 } |
|
485 else |
|
486 { |
|
487 IncOutstanding(); |
|
488 } |
|
489 } |
|
490 else if(ifAttrValListExist && ifAttrIdListExist) |
|
491 { |
|
492 INFO_PRINTF1(_L("CSdpAgent AttributeRequestL(MSdpElementBuilder, TSdpServRecordHandle, const CSdpAttrIdMatchList&) call")); |
|
493 TRAP(err, iSdpAgent->AttributeRequestL(iAttrValueList, iSSRHandle, *attrIdList)); |
|
494 if(err != KErrNone) |
|
495 { |
|
496 ERR_PRINTF2(_L("CSdpAgent AttributeRequestL failed with error %d"), err); |
|
497 SetError(err); |
|
498 } |
|
499 else |
|
500 { |
|
501 IncOutstanding(); |
|
502 } |
|
503 } |
|
504 else |
|
505 { |
|
506 ERR_PRINTF2(_L("Missing parameter %S"), &KTBTAttrIdList()); |
|
507 SetBlockResult(EFail); |
|
508 } |
|
509 } |