examples/ForumNokia/BluetoothPMPExample/inc/ServiceDiscoverer.h

00001 /*
00002  * Copyright (c) 2009-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 <aknviewappui.h>
00036 
00037 #include <coecntrl.h>
00038 #include <es_sock.h>
00039 #include <btdevice.h>
00040 #include <bt_sock.h>
00041 #include <btsdp.h>
00042 
00043 #include "Common.h"
00044 
00045 class MServiceDiscoObserver
00046 {
00047 
00048 public:
00054     virtual void HandleServiceDiscoveryCompleteL()=0;
00055     virtual void ReportServiceDiscoveryErrorL(TInt aError)=0;
00056 };
00057 
00058 
00059 class CServiceDiscoverer : public CBase,
00060                            public MSdpAgentNotifier,
00061                            public MSdpAttributeValueVisitor
00062 {
00063 public:
00064 
00071     static CServiceDiscoverer* NewL(MServiceDiscoObserver& aObserver);
00072 
00077     static CServiceDiscoverer* NewLC(MServiceDiscoObserver& aObserver);
00078 
00084     ~CServiceDiscoverer();
00085 
00096     void DiscoverServicesOnDeviceL(TDeviceData* aDevData);
00097 
00105     void DiscoverServicesL(TDeviceDataList* aDevDataList);
00106 
00114     void FinishDiscovery();
00115 
00123     TBool HasServices();
00124 
00125 
00126 private:
00127 
00133     CServiceDiscoverer(MServiceDiscoObserver& aObserver);
00134 
00139     void ConstructL();
00140 
00147     void HandleServiceDiscoveryCompleteL();
00148 
00149 /*
00150  * NextRecordRequestComplete()
00151  *
00152  * discussion called when an service record
00153  *            (CSdpAgent::NextRecordRequestL()) operation completes.
00154  * param aError KErrNone, or an SDP error
00155  * param aHandle service record for which the query was made
00156  * param aTotalRecordsCount total number of matching records
00157  */
00158     void NextRecordRequestComplete(
00159         TInt aError,
00160         TSdpServRecordHandle aHandle,
00161         TInt aTotalRecordsCount);
00162 
00163 /*
00164  * AttributeRequestResult()
00165  *
00166  * discussion Called by the attribute request
00167  *            (CSdpAgent::AttributeRequestL()) to pass the results of
00168  *            a successful attribute request.
00169  *
00170  * param aHandle service record for which the query was made
00171  * param aAttrID ID of the attribute obtained
00172  * param aAttrValue attribute value obtained
00173  */
00174     void AttributeRequestResult(
00175         TSdpServRecordHandle aHandle,
00176         TSdpAttributeID aAttrID,
00177         CSdpAttrValue* aAttrValue);
00178 
00188     void AttributeRequestComplete(
00189         TSdpServRecordHandle aHandle,
00190         TInt aError);
00191 
00200     void VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType aType);
00201     // not needed -> not implemented
00202     void StartListL(CSdpAttrValueList &aList);
00203     // not needed -> not implemented
00204     void EndListL();
00205 
00206 public:
00207     // Service Discovery is running
00208     TBool iRunning;
00209 
00210 private:    // data
00211 
00212     // observer reference
00213     MServiceDiscoObserver& iObserver;
00214     // service discovery agent
00215     CSdpAgent* iAgent;
00216     // service discovery search pattern
00217     CSdpSearchPattern* iSpat;
00218     // last discovered uuid in the service attributes
00219     TUUID iLastUUID;
00220     // port (comm channel) found in the service attributes
00221     TUint iPort;
00222     // device data record reference
00223     TDeviceData* iDevData;
00224     // device data list reference
00225     TDeviceDataList* iDevDataList;
00226     // this indicates that a port number was found in the service attributes
00227     // and device data record for this device needs to be updated with the
00228     // port number.
00229     TBool iDevDataChanged;
00230     // index of device in device data list used for service discovery
00231     TInt iDeviceIdx;
00232 };
00233 
00234 #endif

Generated by  doxygen 1.6.2