• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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& state,
26       scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
27       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 void AddObserver(
34       device::BluetoothDevice::Observer* observer) OVERRIDE;
35   virtual void RemoveObserver(
36       device::BluetoothDevice::Observer* observer) OVERRIDE;
37   virtual uint32 GetBluetoothClass() const OVERRIDE;
38   virtual std::string GetAddress() const OVERRIDE;
39   virtual VendorIDSource GetVendorIDSource() const OVERRIDE;
40   virtual uint16 GetVendorID() const OVERRIDE;
41   virtual uint16 GetProductID() const OVERRIDE;
42   virtual uint16 GetDeviceID() const OVERRIDE;
43   virtual int GetRSSI() const OVERRIDE;
44   virtual int GetCurrentHostTransmitPower() const OVERRIDE;
45   virtual int GetMaximumHostTransmitPower() const OVERRIDE;
46   virtual bool IsPaired() const OVERRIDE;
47   virtual bool IsConnected() const OVERRIDE;
48   virtual bool IsConnectable() const OVERRIDE;
49   virtual bool IsConnecting() const OVERRIDE;
50   virtual UUIDList GetUUIDs() const OVERRIDE;
51   virtual bool ExpectingPinCode() const OVERRIDE;
52   virtual bool ExpectingPasskey() const OVERRIDE;
53   virtual bool ExpectingConfirmation() const OVERRIDE;
54   virtual void Connect(
55       PairingDelegate* pairing_delegate,
56       const base::Closure& callback,
57       const ConnectErrorCallback& error_callback) OVERRIDE;
58   virtual void SetPinCode(const std::string& pincode) OVERRIDE;
59   virtual void SetPasskey(uint32 passkey) OVERRIDE;
60   virtual void ConfirmPairing() OVERRIDE;
61   virtual void RejectPairing() OVERRIDE;
62   virtual void CancelPairing() OVERRIDE;
63   virtual void Disconnect(
64       const base::Closure& callback,
65       const ErrorCallback& error_callback) OVERRIDE;
66   virtual void Forget(const ErrorCallback& error_callback) OVERRIDE;
67   virtual void ConnectToService(
68       const BluetoothUUID& uuid,
69       const ConnectToServiceCallback& callback,
70       const ConnectToServiceErrorCallback& error_callback) OVERRIDE;
71   virtual void CreateGattConnection(
72       const GattConnectionCallback& callback,
73       const ConnectErrorCallback& error_callback) OVERRIDE;
74   virtual void StartConnectionMonitor(
75       const base::Closure& callback,
76       const ErrorCallback& error_callback) OVERRIDE;
77 
78   // Used by BluetoothProfileWin to retrieve the service record for the given
79   // |uuid|.
80   const BluetoothServiceRecordWin* GetServiceRecord(
81       const device::BluetoothUUID& uuid) const;
82 
83  protected:
84   // BluetoothDevice override
85   virtual std::string GetDeviceName() const OVERRIDE;
86 
87  private:
88   friend class BluetoothAdapterWin;
89 
90   // Used by BluetoothAdapterWin to update the visible state during
91   // discovery.
92   void SetVisible(bool visible);
93 
94   scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
95   scoped_refptr<BluetoothSocketThread> socket_thread_;
96   net::NetLog* net_log_;
97   net::NetLog::Source net_log_source_;
98 
99   // List of observers interested in event notifications from us.
100   ObserverList<Observer> observers_;
101 
102   // The Bluetooth class of the device, a bitmask that may be decoded using
103   // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
104   uint32 bluetooth_class_;
105 
106   // The name of the device, as supplied by the remote device.
107   std::string name_;
108 
109   // The Bluetooth address of the device.
110   std::string address_;
111 
112   // Tracked device state, updated by the adapter managing the lifecycle of
113   // the device.
114   bool paired_;
115   bool connected_;
116 
117   // Used to send change notifications when a device disappears during
118   // discovery.
119   bool visible_;
120 
121   // The services (identified by UUIDs) that this device provides.
122   UUIDList uuids_;
123 
124   // The service records retrieved from SDP.
125   typedef ScopedVector<BluetoothServiceRecordWin> ServiceRecordList;
126   ServiceRecordList service_record_list_;
127 
128   DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceWin);
129 };
130 
131 }  // namespace device
132 
133 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_WIN_H_
134