bluetoothengine/btserviceutil/inc/basicdevdiscoverer.h
branchRCL_3
changeset 55 613943a21004
equal deleted inserted replaced
54:0ba996a9b75d 55:613943a21004
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Declares Bluetooth device inquiry helper class.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef BASICDEVDISCOVERER_H
       
    19 #define BASICDEVDISCOVERER_H
       
    20 
       
    21 #include <btdevice.h>
       
    22 #include <bt_sock.h>
       
    23 #include <btservices/btsimpleactive.h>
       
    24 
       
    25 class MDevDiscoveryObserver;
       
    26 
       
    27 class CDeviceSearchRecord : public CBase
       
    28     {
       
    29 public:
       
    30     TInquirySockAddr iAddr;
       
    31     TBTDeviceName iName;
       
    32     };
       
    33 
       
    34 /**
       
    35 * A basic implementation for searching nearby Bluetooth devices.
       
    36 */
       
    37 NONSHARABLE_CLASS(CBasicDevDiscoverer) : public CBase, public MBtSimpleActiveObserver
       
    38     {
       
    39 public:
       
    40 
       
    41     /**
       
    42      * factory method
       
    43      */
       
    44     static CBasicDevDiscoverer* NewL( MDevDiscoveryObserver& aObserver );
       
    45     
       
    46     /**
       
    47     * Destructor.
       
    48     */
       
    49     virtual ~CBasicDevDiscoverer();
       
    50     
       
    51     /**
       
    52      * sets the inquiry result observer.
       
    53      * 
       
    54      * @param aObserver the new observer to receive inquiry results
       
    55      */
       
    56     void SetObserver( MDevDiscoveryObserver& aObserver );
       
    57     
       
    58     /**
       
    59     * Cancels all inquiry activity.
       
    60     */
       
    61     void Cancel();
       
    62     
       
    63     /**
       
    64     * Discover currently in-range devices that matches the given major device class type.
       
    65     * Found devices will be informed by 
       
    66     * MDevDiscoveryObserver::HandleNextDiscoveryResult().
       
    67     * 
       
    68     * When no device can be found any more, 
       
    69     * MDevDiscoveryObserver::HandleDiscoveryCompleted() will be issued.
       
    70     * 
       
    71     * @param aDeviceClass the major device class device must match.
       
    72     */
       
    73     void DiscoverDeviceL( TBTMajorDeviceClass aDeviceClass  = EMajorDeviceMisc );
       
    74     
       
    75 private: // from MBtSimpleActiveObserver
       
    76     
       
    77     /**
       
    78      * Callback to notify that an outstanding request has completed.
       
    79      *
       
    80      * @param aActive Pointer to the active object that completed.
       
    81      * @param aStatus The status of the completed request.
       
    82      */
       
    83     void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus );
       
    84     
       
    85     /**
       
    86      * Callback for handling cancelation of an outstanding request.
       
    87      *
       
    88      * @param aId The ID that identifies the outstanding request.
       
    89      */
       
    90     void CancelRequest( TInt aId );
       
    91     
       
    92     /**
       
    93      * Callback to notify that an error has occurred in RunL.
       
    94      *
       
    95      * @param aActive Pointer to the active object that completed.
       
    96      * @param aError The error occurred in RunL.
       
    97      */
       
    98     void HandleError( CBtSimpleActive* aActive, TInt aError );
       
    99     
       
   100 private:
       
   101     
       
   102     /**
       
   103     * C++ default constructor.
       
   104     */
       
   105     CBasicDevDiscoverer( MDevDiscoveryObserver& aObserver );
       
   106     
       
   107     /**
       
   108     * The 2nd phase constructor
       
   109     */
       
   110     void ConstructL();
       
   111 
       
   112     /*
       
   113      * retrieves the device name of the device pointed by 
       
   114      * iPagingNamePos to local array.
       
   115      */
       
   116     void PageNextDeviceName();
       
   117     
       
   118     /**
       
   119      * Performs the result from an inquiry operation.
       
   120      */
       
   121     TInt HandleInquiryResultL();
       
   122     
       
   123     /**
       
   124      * Create a heap object of CDeviceSearchRecord.
       
   125      */
       
   126     CDeviceSearchRecord* NewInstanceL( 
       
   127         const TInquirySockAddr& aAddr, const TDesC& aName = KNullDesC );
       
   128 
       
   129     /**
       
   130      * resets the state and memory caused by a client request.
       
   131      */
       
   132     void Reset();
       
   133     
       
   134 private:  // Data
       
   135 
       
   136     // Not own
       
   137     MDevDiscoveryObserver& iObserver; 
       
   138     
       
   139     // The major device class filter from the client.
       
   140     TBTMajorDeviceClass iMajorDeviceClassFilter;
       
   141     
       
   142     // For inquiry and paging names:
       
   143     CBtSimpleActive* iActive;
       
   144 
       
   145     RSocketServ iSocketServer;
       
   146     RHostResolver iHostResolver;
       
   147     TInquirySockAddr iInquirySockAddr;
       
   148     TNameEntry iEntry; // Inquiry result record
       
   149     
       
   150     // Devices found so far
       
   151     RPointerArray<CDeviceSearchRecord> iDevices;
       
   152     
       
   153     // position in array iDevices: the item the current name paging operation is for
       
   154     TInt iPagingNamePos;
       
   155 
       
   156     };
       
   157 
       
   158 #endif
       
   159 
       
   160 // End of File