|
1 // Copyright (c) 2004-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 <bluetooth/logger.h> |
|
17 #include "panhelperlog.h" |
|
18 #include "panhelperremotesdp.h" |
|
19 |
|
20 #ifdef __FLOG_ACTIVE |
|
21 _LIT8(KLogComponent, LOG_COMPONENT_PAN_HELPERS); |
|
22 #endif |
|
23 |
|
24 using namespace PanHelper; |
|
25 |
|
26 CPanHelperRemoteSdpQuerier* CPanHelperRemoteSdpQuerier::NewL() |
|
27 /** |
|
28 Return a newly constructed remote SDP querier |
|
29 */ |
|
30 { |
|
31 CPanHelperRemoteSdpQuerier* self = new(ELeave) CPanHelperRemoteSdpQuerier(); |
|
32 return(self); |
|
33 } |
|
34 |
|
35 CPanHelperRemoteSdpQuerier::CPanHelperRemoteSdpQuerier() : iMatchesFound(EFalse) |
|
36 /** |
|
37 Do nothing |
|
38 */ |
|
39 { } |
|
40 |
|
41 CPanHelperRemoteSdpQuerier::~CPanHelperRemoteSdpQuerier() |
|
42 /** |
|
43 |
|
44 */ |
|
45 { |
|
46 delete iSdpAgent; |
|
47 } |
|
48 |
|
49 void CPanHelperRemoteSdpQuerier::QueryL(const TBTDevAddr& aAddr, TDes8& aSupportedRemoteRoles, TRequestStatus& aStatus) |
|
50 /** |
|
51 Perform an SDP query on the client |
|
52 */ |
|
53 { |
|
54 if(iSdpAgent) |
|
55 { |
|
56 __ASSERT_DEBUG(EFalse, PanHelperPanic(ESecondQueryWhileFirstStillActive)); |
|
57 User::Leave(KErrInUse); |
|
58 } |
|
59 iClientStatus = &aStatus; |
|
60 iSupportedRemoteRoles = &(STATIC_CAST(TPckg<PanHelper::TPanDeviceRolesList>&,aSupportedRemoteRoles)()); |
|
61 #ifdef __FLOG_ACTIVE |
|
62 TBuf<KMaxBtAddrSize> tempDevAddrBuf; |
|
63 aAddr.GetReadable(tempDevAddrBuf, KNullDesC, KBtAddrSeparator, KNullDesC); |
|
64 LOG2(_L("CPanHelperRemoteSdpQuerier[%x]: Performing remote SDP query on %S..."), this, &tempDevAddrBuf); |
|
65 #endif |
|
66 CSdpAgent* sdpAgent = CSdpAgent::NewL(*this, aAddr); |
|
67 CleanupStack::PushL(sdpAgent); |
|
68 |
|
69 // create the attribute ID list to match against |
|
70 CSdpSearchPattern* searchPattern = CSdpSearchPattern::NewL(); |
|
71 CleanupStack::PushL(searchPattern); |
|
72 |
|
73 // search for BNEP, as it's the common field in all PAN records |
|
74 searchPattern->AddL(KBnepUUID); |
|
75 |
|
76 // Set Record Filter copies searchPattern |
|
77 sdpAgent->SetRecordFilterL(*searchPattern); |
|
78 CleanupStack::PopAndDestroy(searchPattern); |
|
79 |
|
80 sdpAgent->NextRecordRequestL(); |
|
81 |
|
82 // Now we have successfully issued the request we know that it will later be |
|
83 // completed, so we can keep sdpAgent and it will be deleted on request |
|
84 // completion. |
|
85 CleanupStack::Pop(sdpAgent); |
|
86 iSdpAgent = sdpAgent; |
|
87 } |
|
88 |
|
89 void CPanHelperRemoteSdpQuerier::CancelQuery() |
|
90 /** |
|
91 Cancel any queries in progress |
|
92 */ |
|
93 { |
|
94 if(iSdpAgent) |
|
95 { |
|
96 iSdpAgent->Cancel(); |
|
97 } |
|
98 |
|
99 delete iSdpAgent; |
|
100 iSdpAgent = NULL; |
|
101 User::RequestComplete(iClientStatus, KErrCancel); |
|
102 } |
|
103 |
|
104 void CPanHelperRemoteSdpQuerier::NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt /*aTotalRecordsCount*/) |
|
105 /** |
|
106 We've got another SDP record, so parse it to (eventually) find out what PAN role it's advertising |
|
107 */ |
|
108 { |
|
109 TInt err = aError; |
|
110 |
|
111 if(err == KErrNone) //more results available |
|
112 { |
|
113 iMatchesFound = ETrue; |
|
114 // Check the attributes of the returned record to see if it's a U, GN, or NAP record |
|
115 TRAP(err,iSdpAgent->AttributeRequestL(aHandle, KSdpAttrIdBluetoothProfileDescriptorList)); |
|
116 if(err == KErrNone) |
|
117 { |
|
118 return; |
|
119 } |
|
120 } |
|
121 |
|
122 //Request has completed or error has occured |
|
123 |
|
124 if(err != KErrEof) |
|
125 { |
|
126 // A 'real' error has occured, cancel the query |
|
127 if(iSdpAgent) |
|
128 { |
|
129 iSdpAgent->Cancel(); |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 // err == KErrEof when no more results available so complete the request |
|
135 // with KErrNone as KErrEof not a 'real' error |
|
136 err = iMatchesFound?KErrNone:KErrNotFound; |
|
137 } |
|
138 |
|
139 delete iSdpAgent; |
|
140 iSdpAgent = NULL; |
|
141 User::RequestComplete(iClientStatus, err); |
|
142 } |
|
143 |
|
144 void CPanHelperRemoteSdpQuerier::AttributeRequestResult(TSdpServRecordHandle /*aHandle*/, TSdpAttributeID /*aAttrID*/, CSdpAttrValue* aAttrValue) |
|
145 /** |
|
146 |
|
147 */ |
|
148 { |
|
149 __ASSERT_ALWAYS(aAttrValue, PanHelperPanic(ENullSdpAttrValue)); |
|
150 |
|
151 if(aAttrValue->Type()==ETypeDES) |
|
152 { |
|
153 CSdpAttrValueDES* sdpProfileDesList = static_cast<CSdpAttrValueDES*>(aAttrValue); |
|
154 |
|
155 // cycle through the contents of the DES to find the remote role |
|
156 TRAPD(err, sdpProfileDesList->AcceptVisitorL(*this)); |
|
157 if(err) |
|
158 { |
|
159 LOG1(_L("CPanHelperRemoteSdpQuerier[%x]: attempting to read supplied DES failed, erroring client"), this); |
|
160 } |
|
161 } |
|
162 else // we've been given a non-DES structure for an attribute that is supposed to be a DES |
|
163 { |
|
164 LOG1(_L("CPanHelperRemoteSdpQuerier[%x]: attribute request result passed back a non-DES attribute, erroring client"), this); |
|
165 } |
|
166 |
|
167 // Delete the attribute value now that we've finished with it |
|
168 delete aAttrValue; |
|
169 |
|
170 // there shouldn't be another profile descriptor list, so we should now get AttributeRequestComplete() called |
|
171 } |
|
172 |
|
173 void CPanHelperRemoteSdpQuerier::AttributeRequestComplete(TSdpServRecordHandle, TInt /*aError*/) |
|
174 /** |
|
175 |
|
176 */ |
|
177 { |
|
178 // examine the next record returned |
|
179 TRAPD(err, iSdpAgent->NextRecordRequestL()); |
|
180 if(err) |
|
181 { |
|
182 LOG2(_L("CPanHelperRemoteSdpQuerier[%x]: next record request failed with error %d"), this, err); |
|
183 } |
|
184 } |
|
185 |
|
186 |
|
187 void CPanHelperRemoteSdpQuerier::StartListL(CSdpAttrValueList& /*aList*/) |
|
188 /** |
|
189 |
|
190 */ |
|
191 { |
|
192 // not interested in this |
|
193 } |
|
194 |
|
195 void CPanHelperRemoteSdpQuerier::EndListL() |
|
196 /** |
|
197 |
|
198 */ |
|
199 { |
|
200 // not interested in this |
|
201 } |
|
202 |
|
203 void CPanHelperRemoteSdpQuerier::VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType) |
|
204 /** |
|
205 Process an attribute from a DES - specifically attributes from the profile descriptor list |
|
206 */ |
|
207 { |
|
208 if(aType==ETypeUUID) |
|
209 { |
|
210 //CSdpAttrValueUUID* sdpUuidValue = static_cast<CSdpAttrValueUUID*>(&aValue); |
|
211 if(aValue.UUID()==KPanUUUID) |
|
212 { |
|
213 LOG1(_L("CPanHelperRemoteSdpQuerier[%x]: ...remote device supports PAN-U role..."), this); |
|
214 iSupportedRemoteRoles->SetSupportsU(); |
|
215 } |
|
216 else if(aValue.UUID()==KPanGnUUID) |
|
217 { |
|
218 LOG1(_L("CPanHelperRemoteSdpQuerier[%x]: ...remote device supports PAN-GN role..."), this); |
|
219 iSupportedRemoteRoles->SetSupportsGn(); |
|
220 } |
|
221 else if(aValue.UUID()==KPanNapUUID) |
|
222 { |
|
223 LOG1(_L("CPanHelperRemoteSdpQuerier[%x]: ...remote device supports PAN-NAP role..."), this); |
|
224 iSupportedRemoteRoles->SetSupportsNap(); |
|
225 } |
|
226 } |
|
227 // otherwise, it's just the version or something, and we don't care |
|
228 } |