00001 /* 00002 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * * Redistributions of source code must retain the above copyright notice, this 00008 * list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright notice, 00010 * this list of conditions and the following disclaimer in the documentation 00011 * and/or other materials provided with the distribution. 00012 * * Neither the name of Nokia Corporation nor the names of its contributors 00013 * may be used to endorse or promote products derived from this software 00014 * without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00020 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00022 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00023 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00024 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00025 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 * Description: 00028 */ 00029 00030 #ifndef SERVICEDISCOVERER_H 00031 #define SERVICEDISCOVERER_H 00032 00033 // INCLUDES 00034 #include <e32base.h> 00035 #include <es_sock.h> 00036 #include <btdevice.h> 00037 #include <bt_sock.h> 00038 #include <btsdp.h> 00039 00040 #include "Common.h" 00041 00042 class MServiceDiscoObserver 00043 { 00044 00045 public: 00051 virtual void HandleServiceDiscoveryCompleteL()=0; 00052 virtual void ReportServiceDiscoveryErrorL(TInt aError)=0; 00053 }; 00054 00055 00056 class CServiceDiscoverer : public CBase, 00057 public MSdpAgentNotifier, 00058 public MSdpAttributeValueVisitor 00059 { 00060 public: 00061 00068 static CServiceDiscoverer* NewL(MServiceDiscoObserver& aObserver); 00069 00074 static CServiceDiscoverer* NewLC(MServiceDiscoObserver& aObserver); 00075 00081 ~CServiceDiscoverer(); 00082 00093 void DiscoverServicesOnDeviceL(TDeviceData* aDevData); 00094 00102 void DiscoverServicesL(TDeviceDataList* aDevDataList); 00103 00111 void FinishDiscovery(); 00112 00120 TBool HasServices(); 00121 00122 00123 private: 00124 00130 CServiceDiscoverer(MServiceDiscoObserver& aObserver); 00131 00136 void ConstructL(); 00137 00144 void HandleServiceDiscoveryCompleteL(); 00145 00146 /* 00147 * NextRecordRequestComplete() 00148 * 00149 * discussion called when an service record 00150 * (CSdpAgent::NextRecordRequestL()) operation completes. 00151 * param aError KErrNone, or an SDP error 00152 * param aHandle service record for which the query was made 00153 * param aTotalRecordsCount total number of matching records 00154 */ 00155 void NextRecordRequestComplete( 00156 TInt aError, 00157 TSdpServRecordHandle aHandle, 00158 TInt aTotalRecordsCount); 00159 00160 /* 00161 * AttributeRequestResult() 00162 * 00163 * discussion Called by the attribute request 00164 * (CSdpAgent::AttributeRequestL()) to pass the results of 00165 * a successful attribute request. 00166 * 00167 * param aHandle service record for which the query was made 00168 * param aAttrID ID of the attribute obtained 00169 * param aAttrValue attribute value obtained 00170 */ 00171 void AttributeRequestResult( 00172 TSdpServRecordHandle aHandle, 00173 TSdpAttributeID aAttrID, 00174 CSdpAttrValue* aAttrValue); 00175 00185 void AttributeRequestComplete( 00186 TSdpServRecordHandle aHandle, 00187 TInt aError); 00188 00197 void VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType aType); 00198 // not needed -> not implemented 00199 void StartListL(CSdpAttrValueList &aList); 00200 // not needed -> not implemented 00201 void EndListL(); 00202 00203 public: 00204 // Service Discovery is running 00205 TBool iRunning; 00206 00207 private: // data 00208 00209 // observer reference 00210 MServiceDiscoObserver& iObserver; 00211 // service discovery agent 00212 CSdpAgent* iAgent; 00213 // service discovery search pattern 00214 CSdpSearchPattern* iSpat; 00215 // last discovered uuid in the service attributes 00216 TUUID iLastUUID; 00217 // port (comm channel) found in the service attributes 00218 TUint iPort; 00219 // device data record reference 00220 TDeviceData* iDevData; 00221 // device data list reference 00222 TDeviceDataList* iDevDataList; 00223 // this indicates that a port number was found in the service attributes 00224 // and device data record for this device needs to be updated with the 00225 // port number. 00226 TBool iDevDataChanged; 00227 // index of device in device data list used for service discovery 00228 TInt iDeviceIdx; 00229 }; 00230 00231 #endif