Home | History | Annotate | Download | only in bluetooth
      1 // Copyright (c) 2012 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_WIN_H_
      6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_WIN_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/observer_list.h"
     13 #include "device/bluetooth/bluetooth_device.h"
     14 #include "device/bluetooth/bluetooth_task_manager_win.h"
     15 
     16 namespace device {
     17 
     18 class BluetoothAdapterWin;
     19 class BluetoothServiceRecordWin;
     20 class BluetoothSocketThread;
     21 
     22 class BluetoothDeviceWin : public BluetoothDevice {
     23  public:
     24   explicit BluetoothDeviceWin(
     25       const BluetoothTaskManagerWin::DeviceState& device_state,
     26       const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
     27       const scoped_refptr<BluetoothSocketThread>& socket_thread,
     28       net::NetLog* net_log,
     29       const net::NetLog::Source& net_log_source);
     30   virtual ~BluetoothDeviceWin();
     31 
     32   // BluetoothDevice override
     33   virtual uint32 GetBluetoothClass() const OVERRIDE;
     34   virtual std::string GetAddress() const OVERRIDE;
     35   virtual VendorIDSource GetVendorIDSource() const OVERRIDE;
     36   virtual uint16 GetVendorID() const OVERRIDE;
     37   virtual uint16 GetProductID() const OVERRIDE;
     38   virtual uint16 GetDeviceID() const OVERRIDE;
     39   virtual int GetRSSI() const OVERRIDE;
     40   virtual int GetCurrentHostTransmitPower() const OVERRIDE;
     41   virtual int GetMaximumHostTransmitPower() const OVERRIDE;
     42   virtual bool IsPaired() const OVERRIDE;
     43   virtual bool IsConnected() const OVERRIDE;
     44   virtual bool IsConnectable() const OVERRIDE;
     45   virtual bool IsConnecting() const OVERRIDE;
     46   virtual UUIDList GetUUIDs() const OVERRIDE;
     47   virtual bool ExpectingPinCode() const OVERRIDE;
     48   virtual bool ExpectingPasskey() const OVERRIDE;
     49   virtual bool ExpectingConfirmation() const OVERRIDE;
     50   virtual void Connect(
     51       PairingDelegate* pairing_delegate,
     52       const base::Closure& callback,
     53       const ConnectErrorCallback& error_callback) OVERRIDE;
     54   virtual void SetPinCode(const std::string& pincode) OVERRIDE;
     55   virtual void SetPasskey(uint32 passkey) OVERRIDE;
     56   virtual void ConfirmPairing() OVERRIDE;
     57   virtual void RejectPairing() OVERRIDE;
     58   virtual void CancelPairing() OVERRIDE;
     59   virtual void Disconnect(
     60       const base::Closure& callback,
     61       const ErrorCallback& error_callback) OVERRIDE;
     62   virtual void Forget(const ErrorCallback& error_callback) OVERRIDE;
     63   virtual void ConnectToService(
     64       const BluetoothUUID& uuid,
     65       const ConnectToServiceCallback& callback,
     66       const ConnectToServiceErrorCallback& error_callback) OVERRIDE;
     67   virtual void CreateGattConnection(
     68       const GattConnectionCallback& callback,
     69       const ConnectErrorCallback& error_callback) OVERRIDE;
     70   virtual void StartConnectionMonitor(
     71       const base::Closure& callback,
     72       const ErrorCallback& error_callback) OVERRIDE;
     73 
     74   // Used by BluetoothProfileWin to retrieve the service record for the given
     75   // |uuid|.
     76   const BluetoothServiceRecordWin* GetServiceRecord(
     77       const device::BluetoothUUID& uuid) const;
     78 
     79   // Returns true if all fields and services of this instance are equal to the
     80   // fields and services stored in |device_state|.
     81   bool IsEqual(const BluetoothTaskManagerWin::DeviceState& device_state);
     82 
     83   // Updates this instance with all fields and properties stored in
     84   // |device_state|.
     85   void Update(const BluetoothTaskManagerWin::DeviceState& device_state);
     86 
     87  protected:
     88   // BluetoothDevice override
     89   virtual std::string GetDeviceName() const OVERRIDE;
     90 
     91  private:
     92   friend class BluetoothAdapterWin;
     93 
     94   // Used by BluetoothAdapterWin to update the visible state during
     95   // discovery.
     96   void SetVisible(bool visible);
     97 
     98   // Updates the services with services stored in |device_state|.
     99   void UpdateServices(const BluetoothTaskManagerWin::DeviceState& device_state);
    100 
    101   scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
    102   scoped_refptr<BluetoothSocketThread> socket_thread_;
    103   net::NetLog* net_log_;
    104   net::NetLog::Source net_log_source_;
    105 
    106   // The Bluetooth class of the device, a bitmask that may be decoded using
    107   // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
    108   uint32 bluetooth_class_;
    109 
    110   // The name of the device, as supplied by the remote device.
    111   std::string name_;
    112 
    113   // The Bluetooth address of the device.
    114   std::string address_;
    115 
    116   // Tracked device state, updated by the adapter managing the lifecycle of
    117   // the device.
    118   bool paired_;
    119   bool connected_;
    120 
    121   // Used to send change notifications when a device disappears during
    122   // discovery.
    123   bool visible_;
    124 
    125   // The services (identified by UUIDs) that this device provides.
    126   UUIDList uuids_;
    127 
    128   // The service records retrieved from SDP.
    129   typedef ScopedVector<BluetoothServiceRecordWin> ServiceRecordList;
    130   ServiceRecordList service_record_list_;
    131 
    132   DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceWin);
    133 };
    134 
    135 }  // namespace device
    136 
    137 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_WIN_H_
    138