Home | History | Annotate | Download | only in bluetooth
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_MANAGER_MAC_H_
      6 #define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_MANAGER_MAC_H_
      7 
      8 #include "base/macros.h"
      9 
     10 @class IOBluetoothDevice;
     11 
     12 namespace device {
     13 
     14 // Class used by BluetoothAdapterMac to manage classic and LE device discovery.
     15 // For Bluetooth Classic, this class is responsible for keeping device inquiry
     16 // running if device discovery is initiated.
     17 class BluetoothDiscoveryManagerMac {
     18  public:
     19   // Interface for being notified of events during a device discovery session.
     20   class Observer {
     21    public:
     22     // Called when |manager| has found a device through classic device inquiry
     23     // in the form of a IOBluetoothDevice.
     24     virtual void DeviceFound(BluetoothDiscoveryManagerMac* manager,
     25                              IOBluetoothDevice* device) {}
     26 
     27     // Called when device discovery is no longer running, due to either a call
     28     // to BluetoothDiscoveryManagerMac::StopDiscovery or an unexpected reason,
     29     // such as when a user disables the controller, in which case the value of
     30     // |unexpected| will be true.
     31     virtual void DiscoveryStopped(BluetoothDiscoveryManagerMac* manager,
     32                                   bool unexpected) {}
     33   };
     34 
     35   virtual ~BluetoothDiscoveryManagerMac();
     36 
     37   // Returns true, if discovery is currently being performed.
     38   virtual bool IsDiscovering() const = 0;
     39 
     40   // Initiates a discovery session. Returns true on success or if discovery
     41   // is already running. Returns false on failure.
     42   virtual bool StartDiscovery() = 0;
     43 
     44   // Stops a discovery session. Returns true on success or if discovery is
     45   // already not running. Returns false on failure.
     46   virtual bool StopDiscovery() = 0;
     47 
     48   // Creates a discovery manager for Bluetooth Classic device discovery with
     49   // observer |observer|. Note that the life-time of |observer| should not
     50   // end before that of the returned BluetoothDiscoveryManager, as that may
     51   // lead to use after free errors.
     52   static BluetoothDiscoveryManagerMac* CreateClassic(Observer* observer);
     53 
     54  protected:
     55   explicit BluetoothDiscoveryManagerMac(Observer* observer);
     56 
     57   // Observer interested in notifications from us.
     58   Observer* observer_;
     59 
     60  private:
     61   DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoveryManagerMac);
     62 };
     63 
     64 }  // namespace device
     65 
     66 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_MANAGER_MAC_H_
     67