|
1 // Copyright (c) 2001-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 #ifndef __OBEXSDPUTILS_H__ |
|
17 #define __OBEXSDPUTILS_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <bttypes.h> |
|
21 #include <btsdp.h> |
|
22 |
|
23 |
|
24 const TInt KMaxObexSupportedFormats = 7; //SDP Query will complete with KErrTooBig if remote device returns more than KMaxObexSupportedFormats format codes |
|
25 typedef TBuf8<KMaxObexSupportedFormats> TObexSupportedFormatsList; |
|
26 |
|
27 /** |
|
28 * Observer class for CObexSdpUtils. Contains one method which indicates the results of |
|
29 * an SDP query. |
|
30 */ |
|
31 class MObexSdpUtilsObserver |
|
32 /** |
|
33 @internalTechnology |
|
34 @released |
|
35 */ |
|
36 { |
|
37 public: |
|
38 /** |
|
39 * SDP Query result |
|
40 * |
|
41 * @param aError If this is anything but KErrNone then the query has not completed correctly and all other parameters are meaningless. |
|
42 * @param aPortNumber The RFCOMM port number that the remote device supports OBEX on |
|
43 * @param aObexObjectPushProfileSupported ETrue if the remote device supports the Bluetooth OBEX Push Profile |
|
44 * @param aObexObjectPushProfileVersion Version of Bluetooth OBEX Push Profile supported (only valid if aObexObjectPushProfileSupported == ETrue) |
|
45 * @param aSupportedFormats Structure containing a list of the OBEX Object formats supported by the remote device |
|
46 */ |
|
47 virtual void RemoteBtObexQueryResult(TInt aError, |
|
48 TInt aPortNumber, |
|
49 TBool aObexObjectPushProfileSupported, |
|
50 TInt aObexObjectPushProfileVersion, |
|
51 TObexSupportedFormatsList aSupportedFormats) = 0; |
|
52 }; |
|
53 |
|
54 |
|
55 /** |
|
56 * This class provides a single exported method to perform an SDP Query on a remote Bluetooth |
|
57 * device, the results of which are returned via the MObexSdpUtilsObserver observer. |
|
58 * |
|
59 * This class uses a CSdpAgent object (and it's various observers) to process SDP records |
|
60 * received from the remote Bluetooth device. Each SDP record is made up of attributes which |
|
61 * in turn contain attribute components. CObexSdpUtils simply goes through these attribute |
|
62 * components checking that we receive what we expect to and logging important information |
|
63 * (e.g. port number OBEX is supported on). |
|
64 */ |
|
65 class CObexSdpUtils : public CBase, public MSdpAgentNotifier, public MSdpElementBuilder |
|
66 /** |
|
67 @internalTechnology |
|
68 @released |
|
69 */ |
|
70 { |
|
71 public: |
|
72 |
|
73 /** |
|
74 * Leave safe constructor |
|
75 * |
|
76 * @param aObserver Used to indicate results of SDP query |
|
77 */ |
|
78 |
|
79 IMPORT_C static CObexSdpUtils* NewL(MObexSdpUtilsObserver& aObserver); |
|
80 |
|
81 /** |
|
82 * Leave safe constructor (which adds the newly created object to the cleanup stack) |
|
83 * |
|
84 * @param aObserver Used to indicate results of SDP query |
|
85 */ |
|
86 |
|
87 IMPORT_C static CObexSdpUtils* NewLC(MObexSdpUtilsObserver& aObserver); |
|
88 |
|
89 /** |
|
90 * Destructor. This can be called before the SDP Query completes to safely cancel the |
|
91 * query - N.B. this is the only way to cancel a pending query |
|
92 */ |
|
93 |
|
94 ~CObexSdpUtils(); |
|
95 |
|
96 /** |
|
97 * Perform SDP query on a remote bluetooth device. Result is returned through the MObexSdpUtilsObserver |
|
98 * observer class. The query can be cancelled at any time by destroying this CObexSdpUtils |
|
99 * object. |
|
100 * |
|
101 * @param aBtDevAddr The address of the bluetooth device |
|
102 */ |
|
103 |
|
104 IMPORT_C void RemoteBtObexQueryL(TBTDevAddr aBtDevAddr); |
|
105 |
|
106 public: //from MSdpAgentNotifier |
|
107 |
|
108 /** |
|
109 * Got an SDP record from the remote device, so check for errors and then request the |
|
110 * first attribute. |
|
111 * |
|
112 * @param aError Error code |
|
113 * @param aHandle Handle to the service recorde |
|
114 * @param aTotalRecordsCount The total number of records |
|
115 */ |
|
116 |
|
117 virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount); |
|
118 |
|
119 /** |
|
120 * The overload of AttributeRequestL() that we are using in NextRecordRequestComplete() |
|
121 * should NOT result in this function being called, if it does then halt the query with an |
|
122 * error. |
|
123 * |
|
124 * @param aHandle The handle to the service record |
|
125 * @param aAttrID The SDP Attribute ID |
|
126 * @param aAttrValue The SDP Attribute Value |
|
127 */ |
|
128 |
|
129 virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue); |
|
130 |
|
131 /** |
|
132 * Called after we have got all the attribute components for current attribute being |
|
133 * processed. If everything is OK get the next attribute or record. |
|
134 * |
|
135 * @param aHandle The handle to the service record |
|
136 * @param aError The error code |
|
137 */ |
|
138 |
|
139 virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError); |
|
140 |
|
141 public: //from MSdpElementBuilder |
|
142 |
|
143 /** |
|
144 * Not required for our SDP query, so we provide an empty implementation. |
|
145 */ |
|
146 |
|
147 virtual MSdpElementBuilder* BuildUnknownL(TUint8 aType, TUint8 aSizeDesc, const TDesC8& aData); |
|
148 |
|
149 /** |
|
150 * Not required for our SDP query, so we provide an empty implementation. |
|
151 */ |
|
152 |
|
153 virtual MSdpElementBuilder* BuildNilL(); |
|
154 |
|
155 /** |
|
156 * Got a Uint attribute componet. Check it is what we expected to receive. Get the next attribute component. |
|
157 * |
|
158 * @param aUint Attribute as Uint contained in a descriptor |
|
159 */ |
|
160 |
|
161 virtual MSdpElementBuilder* BuildUintL(const TDesC8& aUint); |
|
162 |
|
163 /** |
|
164 * Not required for our SDP query, so we provide an empty implementation. |
|
165 */ |
|
166 |
|
167 virtual MSdpElementBuilder* BuildIntL(const TDesC8& aInt); |
|
168 |
|
169 /** |
|
170 * Got a UUID attribute component. Check it is what we expected to receive. Get the next attribute component. |
|
171 * |
|
172 * @param aUUID The Bluetooth UUID of attribute |
|
173 */ |
|
174 |
|
175 virtual MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID); |
|
176 |
|
177 /** |
|
178 * Not required for our SDP query, so we provide an empty implementation. |
|
179 */ |
|
180 |
|
181 virtual MSdpElementBuilder* BuildBooleanL(TBool aBool); |
|
182 |
|
183 /** |
|
184 * Not required for our SDP query, so we provide an empty implementation. |
|
185 */ |
|
186 |
|
187 virtual MSdpElementBuilder* BuildStringL(const TDesC8& aString); |
|
188 |
|
189 /** |
|
190 * Not required for our SDP query, so we provide an empty implementation. |
|
191 */ |
|
192 |
|
193 virtual MSdpElementBuilder* BuildDESL(); |
|
194 |
|
195 /** |
|
196 * Not required for our SDP query, so we provide an empty implementation. |
|
197 */ |
|
198 |
|
199 virtual MSdpElementBuilder* BuildDEAL(); |
|
200 |
|
201 /** |
|
202 * Not required for our SDP query, so we provide an empty implementation. |
|
203 */ |
|
204 |
|
205 virtual MSdpElementBuilder* StartListL(); |
|
206 |
|
207 /** |
|
208 * Not required for our SDP query, so we provide an empty implementation. |
|
209 */ |
|
210 |
|
211 virtual MSdpElementBuilder* EndListL(); |
|
212 |
|
213 /** |
|
214 * Not required for our SDP query, so we provide an empty implementation. |
|
215 */ |
|
216 |
|
217 virtual MSdpElementBuilder* BuildURLL(const TDesC8& aURL); |
|
218 |
|
219 private: |
|
220 |
|
221 /** |
|
222 * Simple constructor |
|
223 * |
|
224 * @param aObserver Used to indicate results of SDP query |
|
225 */ |
|
226 |
|
227 CObexSdpUtils(MObexSdpUtilsObserver& aObserver); |
|
228 |
|
229 /** |
|
230 * Necessary initial construction - Creates various structures used to check |
|
231 * results obtained through CSdpAgent |
|
232 */ |
|
233 |
|
234 void ConstructL(); |
|
235 |
|
236 /** |
|
237 * Halt the current SDP query by destroying the CSdpAgent. |
|
238 */ |
|
239 |
|
240 void HaltQuery(); |
|
241 |
|
242 /** |
|
243 * Halt the current SDP query by destroying the CSdpAgent. Inform MObexSdpUtilsObserver |
|
244 * observer that query has completed with an error. |
|
245 * |
|
246 * @param aError The error code |
|
247 */ |
|
248 |
|
249 void HaltQueryWithError(TInt aError); |
|
250 |
|
251 /** |
|
252 * Convert descriptor containing Uint to a numeric Uint. |
|
253 * |
|
254 * The Uints can be 1, 2, 4, 8 or 16 bytes long in theory. It is doubtful |
|
255 * that the 8 or 16 byte variety would actually be used in our Obex Object |
|
256 * Push Service case. The attribute Id will always be a 2 byte Uint but it |
|
257 * is unclear from the spec what size the the port number should be. It is |
|
258 * implied that it should only be 1 byte but in the EPOC implementation, it |
|
259 * is returned as whatever size is it registered as (there is no type/size |
|
260 * checking carried out in the SDP server). |
|
261 * |
|
262 * @param aUint The Uint as a descriptor |
|
263 */ |
|
264 |
|
265 TUint32 UInt32(const TDesC8& aUint); |
|
266 |
|
267 /** |
|
268 * Get next attribute if we are expecting another attribute. |
|
269 * |
|
270 * @param aHandle The handle to the service records |
|
271 */ |
|
272 |
|
273 void RequestNextAttribute(TSdpServRecordHandle aHandle); |
|
274 |
|
275 /** |
|
276 * Get next attribute component if we are expecting another attribute component. Set |
|
277 * internal expectations for the next attribute component we receive. |
|
278 */ |
|
279 |
|
280 void NextAttributeComponent(); |
|
281 |
|
282 public: |
|
283 enum TType |
|
284 { |
|
285 ENoComponent, |
|
286 EAnythingUntilNextExpectedValue, |
|
287 EUUID, |
|
288 EUint, |
|
289 EUintPossible, |
|
290 EUintListUntilEnd, //expected to get a list Uints for the rest of this attribute |
|
291 EAnythingUntilEnd //not interested in what we get for this attribute anymore |
|
292 }; |
|
293 |
|
294 private: |
|
295 class TAttributeComponent |
|
296 { |
|
297 public: |
|
298 TType iType; |
|
299 TBool iSpecificValue; |
|
300 TUint32 iValue; |
|
301 }; |
|
302 |
|
303 class CAttribute |
|
304 { |
|
305 public: |
|
306 |
|
307 /** |
|
308 * Simple constructor |
|
309 */ |
|
310 |
|
311 CAttribute(); |
|
312 |
|
313 /** |
|
314 * Destructor deletes array of attributes |
|
315 */ |
|
316 |
|
317 ~CAttribute(); |
|
318 |
|
319 TUint16 iAttributeId; |
|
320 CArrayFixFlat<TAttributeComponent>* iAttributeComponentArray; |
|
321 }; |
|
322 |
|
323 private: |
|
324 MObexSdpUtilsObserver& iObserver; //< Observer used to indicate result of SDP query |
|
325 CSdpAgent* iSdpAgent; //< Makes SDP requests from remote SDP server |
|
326 TBool iIsActiveSDPQuery; //< Indicates an SDP query has yet to complete |
|
327 TInt iSdpRecordCount; //< Index of current record in the SDP query |
|
328 TBool iNotThisSdpRecord; //< Indicates in remote device complies fully with obex object push profile |
|
329 |
|
330 CArrayPtrFlat<CAttribute>* iAttributeArray; //< |
|
331 TInt iAttribute; //< |
|
332 TInt iAttributeComponent; //< |
|
333 TUUID iCurrentUUID; //< |
|
334 TUint32 iCurrentAttributeId; //< |
|
335 TType iExpectedType; //< |
|
336 TBool iExpectingSpecific; //< |
|
337 TUint32 iExpectedValue; //< |
|
338 TType iNextExpectedType; //< |
|
339 TUint32 iNextExpectedValue; //< |
|
340 |
|
341 TInt iRemoteObexPort; //< Port for sending obex message |
|
342 TBool iFullComplianceWithObexObjectPush; //< |
|
343 TInt iObexObjectPushProfileVersion; //< |
|
344 TObexSupportedFormatsList iSupportedFormatsList; //< |
|
345 }; |
|
346 |
|
347 #endif // __OBEXSDPUTILS_H__ |