Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_device_win.h
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 BluetoothServiceRecord;
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 ConnectToProfile(
68       device::BluetoothProfile* profile,
69       const base::Closure& callback,
70       const ConnectToProfileErrorCallback& error_callback) OVERRIDE;
71   virtual void ConnectToService(
72       const BluetoothUUID& uuid,
73       const ConnectToServiceCallback& callback,
74       const ConnectToServiceErrorCallback& error_callback) OVERRIDE;
75   virtual void SetOutOfBandPairingData(
76       const BluetoothOutOfBandPairingData& data,
77       const base::Closure& callback,
78       const ErrorCallback& error_callback) OVERRIDE;
79   virtual void ClearOutOfBandPairingData(
80       const base::Closure& callback,
81       const ErrorCallback& error_callback) OVERRIDE;
82   virtual void StartConnectionMonitor(
83       const base::Closure& callback,
84       const ErrorCallback& error_callback) OVERRIDE;
85
86   // Used by BluetoothProfileWin to retrieve the service record for the given
87   // |uuid|.
88   const BluetoothServiceRecord* GetServiceRecord(
89       const device::BluetoothUUID& uuid) const;
90
91  protected:
92   // BluetoothDevice override
93   virtual std::string GetDeviceName() const OVERRIDE;
94
95  private:
96   friend class BluetoothAdapterWin;
97
98   // Used by BluetoothAdapterWin to update the visible state during
99   // discovery.
100   void SetVisible(bool visible);
101
102   scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
103   scoped_refptr<BluetoothSocketThread> socket_thread_;
104   net::NetLog* net_log_;
105   net::NetLog::Source net_log_source_;
106
107   // List of observers interested in event notifications from us.
108   ObserverList<Observer> observers_;
109
110   // The Bluetooth class of the device, a bitmask that may be decoded using
111   // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
112   uint32 bluetooth_class_;
113
114   // The name of the device, as supplied by the remote device.
115   std::string name_;
116
117   // The Bluetooth address of the device.
118   std::string address_;
119
120   // Tracked device state, updated by the adapter managing the lifecycle of
121   // the device.
122   bool paired_;
123   bool connected_;
124
125   // Used to send change notifications when a device disappears during
126   // discovery.
127   bool visible_;
128
129   // The services (identified by UUIDs) that this device provides.
130   UUIDList uuids_;
131
132   // The service records retrieved from SDP.
133   typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList;
134   ServiceRecordList service_record_list_;
135
136   DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceWin);
137 };
138
139 }  // namespace device
140
141 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_WIN_H_