Home | History | Annotate | Download | only in bluetooth
      1 // Copyright 2013 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_DEVICE_MAC_H_
      6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_
      7 
      8 #import <IOBluetooth/IOBluetooth.h>
      9 
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "base/mac/scoped_nsobject.h"
     14 #include "base/observer_list.h"
     15 #include "device/bluetooth/bluetooth_device.h"
     16 
     17 @class IOBluetoothDevice;
     18 
     19 namespace device {
     20 
     21 class BluetoothDeviceMac : public BluetoothDevice {
     22  public:
     23   explicit BluetoothDeviceMac(IOBluetoothDevice* device);
     24   virtual ~BluetoothDeviceMac();
     25 
     26   // BluetoothDevice override
     27   virtual void AddObserver(
     28       device::BluetoothDevice::Observer* observer) OVERRIDE;
     29   virtual void RemoveObserver(
     30       device::BluetoothDevice::Observer* observer) OVERRIDE;
     31   virtual uint32 GetBluetoothClass() const OVERRIDE;
     32   virtual std::string GetAddress() const OVERRIDE;
     33   virtual VendorIDSource GetVendorIDSource() const OVERRIDE;
     34   virtual uint16 GetVendorID() const OVERRIDE;
     35   virtual uint16 GetProductID() const OVERRIDE;
     36   virtual uint16 GetDeviceID() const OVERRIDE;
     37   virtual int GetRSSI() const OVERRIDE;
     38   virtual int GetCurrentHostTransmitPower() const OVERRIDE;
     39   virtual int GetMaximumHostTransmitPower() const OVERRIDE;
     40   virtual bool IsPaired() const OVERRIDE;
     41   virtual bool IsConnected() const OVERRIDE;
     42   virtual bool IsConnectable() const OVERRIDE;
     43   virtual bool IsConnecting() const OVERRIDE;
     44   virtual UUIDList GetUUIDs() const OVERRIDE;
     45   virtual bool ExpectingPinCode() const OVERRIDE;
     46   virtual bool ExpectingPasskey() const OVERRIDE;
     47   virtual bool ExpectingConfirmation() const OVERRIDE;
     48   virtual void Connect(
     49       PairingDelegate* pairing_delegate,
     50       const base::Closure& callback,
     51       const ConnectErrorCallback& error_callback) OVERRIDE;
     52   virtual void SetPinCode(const std::string& pincode) OVERRIDE;
     53   virtual void SetPasskey(uint32 passkey) OVERRIDE;
     54   virtual void ConfirmPairing() OVERRIDE;
     55   virtual void RejectPairing() OVERRIDE;
     56   virtual void CancelPairing() OVERRIDE;
     57   virtual void Disconnect(
     58       const base::Closure& callback,
     59       const ErrorCallback& error_callback) OVERRIDE;
     60   virtual void Forget(const ErrorCallback& error_callback) OVERRIDE;
     61   virtual void ConnectToService(
     62       const BluetoothUUID& uuid,
     63       const ConnectToServiceCallback& callback,
     64       const ConnectToServiceErrorCallback& error_callback) OVERRIDE;
     65   virtual void CreateGattConnection(
     66       const GattConnectionCallback& callback,
     67       const ConnectErrorCallback& error_callback) OVERRIDE;
     68   virtual void StartConnectionMonitor(
     69       const base::Closure& callback,
     70       const ErrorCallback& error_callback) OVERRIDE;
     71 
     72   // Returns the Bluetooth address for the |device|. The returned address has a
     73   // normalized format (see below).
     74   static std::string GetDeviceAddress(IOBluetoothDevice* device);
     75 
     76  protected:
     77   // BluetoothDevice override
     78   virtual std::string GetDeviceName() const OVERRIDE;
     79 
     80  private:
     81   friend class BluetoothAdapterMac;
     82 
     83   // Implementation to read the host's transmit power level of type
     84   // |power_level_type|.
     85   int GetHostTransmitPower(
     86       BluetoothHCITransmitPowerLevelType power_level_type) const;
     87 
     88   // List of observers interested in event notifications from us.
     89   ObserverList<Observer> observers_;
     90 
     91   base::scoped_nsobject<IOBluetoothDevice> device_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceMac);
     94 };
     95 
     96 }  // namespace device
     97 
     98 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_
     99