OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
7 | 7 |
8 #if defined(OS_IOS) | |
9 #import <CoreBluetooth/CoreBluetooth.h> | |
10 #else | |
8 #import <IOBluetooth/IOBluetooth.h> | 11 #import <IOBluetooth/IOBluetooth.h> |
12 #endif | |
9 | 13 |
10 #include <string> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
14 #include "base/observer_list.h" | |
15 #include "device/bluetooth/bluetooth_device.h" | 15 #include "device/bluetooth/bluetooth_device.h" |
16 | 16 |
17 @class IOBluetoothDevice; | |
18 | |
19 namespace device { | 17 namespace device { |
20 | 18 |
21 class BluetoothDeviceMac : public BluetoothDevice { | 19 class BluetoothLowEnergyDiscoverManagerMac; |
20 | |
21 class BluetoothLowEnergyDeviceMac : public BluetoothDevice { | |
22 public: | 22 public: |
23 explicit BluetoothDeviceMac(IOBluetoothDevice* device); | 23 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral, |
24 ~BluetoothDeviceMac() override; | 24 NSDictionary* advertisementData, |
25 int rssi); | |
26 ~BluetoothLowEnergyDeviceMac() override; | |
25 | 27 |
26 // BluetoothDevice override | 28 virtual int GetRSSI() const; |
armansito
2015/02/05 19:54:12
nit: Does this need to be virtual?
dvh
2015/02/05 22:26:09
Acknowledged.
| |
29 | |
30 // BluetoothDevice overrides. | |
31 std::string GetIdentifier() const override; | |
27 uint32 GetBluetoothClass() const override; | 32 uint32 GetBluetoothClass() const override; |
28 std::string GetAddress() const override; | 33 std::string GetAddress() const override; |
29 VendorIDSource GetVendorIDSource() const override; | 34 BluetoothDevice::VendorIDSource GetVendorIDSource() const override; |
30 uint16 GetVendorID() const override; | 35 uint16 GetVendorID() const override; |
31 uint16 GetProductID() const override; | 36 uint16 GetProductID() const override; |
32 uint16 GetDeviceID() const override; | 37 uint16 GetDeviceID() const override; |
33 bool IsPaired() const override; | 38 bool IsPaired() const override; |
34 bool IsConnected() const override; | 39 bool IsConnected() const override; |
35 bool IsConnectable() const override; | 40 bool IsConnectable() const override; |
36 bool IsConnecting() const override; | 41 bool IsConnecting() const override; |
37 UUIDList GetUUIDs() const override; | 42 BluetoothDevice::UUIDList GetUUIDs() const override; |
38 bool ExpectingPinCode() const override; | 43 bool ExpectingPinCode() const override; |
39 bool ExpectingPasskey() const override; | 44 bool ExpectingPasskey() const override; |
40 bool ExpectingConfirmation() const override; | 45 bool ExpectingConfirmation() const override; |
41 void GetConnectionInfo(const ConnectionInfoCallback& callback) override; | 46 void GetConnectionInfo(const ConnectionInfoCallback& callback) override; |
42 void Connect(PairingDelegate* pairing_delegate, | 47 void Connect(PairingDelegate* pairing_delegate, |
43 const base::Closure& callback, | 48 const base::Closure& callback, |
44 const ConnectErrorCallback& error_callback) override; | 49 const ConnectErrorCallback& error_callback) override; |
45 void SetPinCode(const std::string& pincode) override; | 50 void SetPinCode(const std::string& pincode) override; |
46 void SetPasskey(uint32 passkey) override; | 51 void SetPasskey(uint32 passkey) override; |
47 void ConfirmPairing() override; | 52 void ConfirmPairing() override; |
48 void RejectPairing() override; | 53 void RejectPairing() override; |
49 void CancelPairing() override; | 54 void CancelPairing() override; |
50 void Disconnect(const base::Closure& callback, | 55 void Disconnect(const base::Closure& callback, |
51 const ErrorCallback& error_callback) override; | 56 const ErrorCallback& error_callback) override; |
52 void Forget(const ErrorCallback& error_callback) override; | 57 void Forget(const ErrorCallback& error_callback) override; |
53 void ConnectToService( | 58 void ConnectToService( |
54 const BluetoothUUID& uuid, | 59 const BluetoothUUID& uuid, |
55 const ConnectToServiceCallback& callback, | 60 const ConnectToServiceCallback& callback, |
56 const ConnectToServiceErrorCallback& error_callback) override; | 61 const ConnectToServiceErrorCallback& error_callback) override; |
57 void ConnectToServiceInsecurely( | 62 void ConnectToServiceInsecurely( |
58 const BluetoothUUID& uuid, | 63 const device::BluetoothUUID& uuid, |
59 const ConnectToServiceCallback& callback, | 64 const ConnectToServiceCallback& callback, |
60 const ConnectToServiceErrorCallback& error_callback) override; | 65 const ConnectToServiceErrorCallback& error_callback) override; |
61 void CreateGattConnection( | 66 void CreateGattConnection( |
62 const GattConnectionCallback& callback, | 67 const GattConnectionCallback& callback, |
63 const ConnectErrorCallback& error_callback) override; | 68 const ConnectErrorCallback& error_callback) override; |
64 | 69 |
65 // Returns the timestamp when the device was last seen during an inquiry. | |
66 // Returns nil if the device has never been seen during an inquiry. | |
67 NSDate* GetLastInquiryUpdate(); | |
68 | |
69 // Returns the Bluetooth address for the |device|. The returned address has a | |
70 // normalized format (see below). | |
71 static std::string GetDeviceAddress(IOBluetoothDevice* device); | |
72 | |
73 protected: | 70 protected: |
74 // BluetoothDevice override | 71 // BluetoothDevice override. |
75 std::string GetDeviceName() const override; | 72 std::string GetDeviceName() const override; |
76 | 73 |
74 // Updates information about the device. | |
75 virtual void Update(CBPeripheral* peripheral, | |
76 NSDictionary* advertisementData, | |
77 int rssi); | |
78 | |
79 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); | |
80 | |
77 private: | 81 private: |
78 friend class BluetoothAdapterMac; | 82 friend class BluetoothLowEnergyDiscoveryManagerMac; |
79 | 83 |
80 // Implementation to read the host's transmit power level of type | 84 // CoreBluetooth data structure. |
81 // |power_level_type|. | 85 base::scoped_nsobject<CBPeripheral> peripheral_; |
82 int GetHostTransmitPower( | |
83 BluetoothHCITransmitPowerLevelType power_level_type) const; | |
84 | 86 |
85 base::scoped_nsobject<IOBluetoothDevice> device_; | 87 // RSSI value. |
88 int rssi_; | |
86 | 89 |
87 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceMac); | 90 // Whether the device is connectable. |
91 bool connectable_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); | |
88 }; | 94 }; |
89 | 95 |
90 } // namespace device | 96 } // namespace device |
91 | 97 |
92 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_ | 98 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
OLD | NEW |