Process Alt-Svc headers.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_low_energy_device_mac.h
blob502e082a185b97c6fb21cdde24ed75fad7ec1878
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
8 #if defined(OS_IOS)
9 #import <CoreBluetooth/CoreBluetooth.h>
10 #else // !defined(OS_IOS)
11 #import <IOBluetooth/IOBluetooth.h>
12 #endif // defined(OS_IOS)
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/mac/sdk_forward_declarations.h"
16 #include "crypto/sha2.h"
17 #include "device/bluetooth/bluetooth_device_mac.h"
19 namespace device {
21 class BluetoothLowEnergyDiscoverManagerMac;
23 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac
24 : public BluetoothDeviceMac {
25 public:
26 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral,
27 NSDictionary* advertisementData,
28 int rssi);
29 ~BluetoothLowEnergyDeviceMac() override;
31 int GetRSSI() const;
33 // BluetoothDevice overrides.
34 std::string GetIdentifier() const override;
35 uint32 GetBluetoothClass() const override;
36 std::string GetAddress() const override;
37 BluetoothDevice::VendorIDSource GetVendorIDSource() const override;
38 uint16 GetVendorID() const override;
39 uint16 GetProductID() const override;
40 uint16 GetDeviceID() const override;
41 bool IsPaired() const override;
42 bool IsConnected() const override;
43 bool IsConnectable() const override;
44 bool IsConnecting() const override;
45 BluetoothDevice::UUIDList GetUUIDs() const override;
46 int16 GetInquiryRSSI() const override;
47 int16 GetInquiryTxPower() const override;
48 bool ExpectingPinCode() const override;
49 bool ExpectingPasskey() const override;
50 bool ExpectingConfirmation() const override;
51 void GetConnectionInfo(const ConnectionInfoCallback& callback) override;
52 void Connect(PairingDelegate* pairing_delegate,
53 const base::Closure& callback,
54 const ConnectErrorCallback& error_callback) override;
55 void SetPinCode(const std::string& pincode) override;
56 void SetPasskey(uint32 passkey) override;
57 void ConfirmPairing() override;
58 void RejectPairing() override;
59 void CancelPairing() override;
60 void Disconnect(const base::Closure& callback,
61 const ErrorCallback& error_callback) override;
62 void Forget(const ErrorCallback& error_callback) override;
63 void ConnectToService(
64 const BluetoothUUID& uuid,
65 const ConnectToServiceCallback& callback,
66 const ConnectToServiceErrorCallback& error_callback) override;
67 void ConnectToServiceInsecurely(
68 const device::BluetoothUUID& uuid,
69 const ConnectToServiceCallback& callback,
70 const ConnectToServiceErrorCallback& error_callback) override;
71 void CreateGattConnection(
72 const GattConnectionCallback& callback,
73 const ConnectErrorCallback& error_callback) override;
75 // BluetoothDeviceMac override.
76 NSDate* GetLastUpdateTime() const override;
78 protected:
79 // BluetoothDevice override.
80 std::string GetDeviceName() const override;
82 // Updates information about the device.
83 virtual void Update(CBPeripheral* peripheral,
84 NSDictionary* advertisementData,
85 int rssi);
87 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral);
89 // Hashes and truncates the peripheral identifier to deterministically
90 // construct an address. The use of fake addresses is a temporary fix before
91 // we switch to using bluetooth identifiers throughout Chrome.
92 // http://crbug.com/507824
93 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral);
95 private:
96 friend class BluetoothAdapterMac;
97 friend class BluetoothAdapterMacTest;
99 // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6.
100 CBPeripheralState GetPeripheralState() const;
102 // CoreBluetooth data structure.
103 base::scoped_nsobject<CBPeripheral> peripheral_;
105 // RSSI value.
106 int rssi_;
108 // Whether the device is connectable.
109 bool connectable_;
111 // The peripheral's identifier, as returned by [CBPeripheral identifier].
112 std::string identifier_;
114 // A local address for the device created by hashing the peripheral
115 // identifier.
116 std::string hash_address_;
118 // Stores the time of the most recent call to Update().
119 base::scoped_nsobject<NSDate> last_update_time_;
121 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac);
124 } // namespace device
126 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_