| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_ADAPTER_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "device/bluetooth/bluetooth_device.h" | 17 #include "device/bluetooth/bluetooth_device.h" |
| 18 | 18 |
| 19 namespace device { | 19 namespace device { |
| 20 | 20 |
| 21 class BluetoothDiscoverySession; | 21 class BluetoothDiscoverySession; |
| 22 class BluetoothGattCharacteristic; |
| 23 class BluetoothGattDescriptor; |
| 24 class BluetoothGattService; |
| 22 class BluetoothSocket; | 25 class BluetoothSocket; |
| 23 class BluetoothUUID; | 26 class BluetoothUUID; |
| 24 | 27 |
| 25 // BluetoothAdapter represents a local Bluetooth adapter which may be used to | 28 // BluetoothAdapter represents a local Bluetooth adapter which may be used to |
| 26 // interact with remote Bluetooth devices. As well as providing support for | 29 // interact with remote Bluetooth devices. As well as providing support for |
| 27 // determining whether an adapter is present and whether the radio is powered, | 30 // determining whether an adapter is present and whether the radio is powered, |
| 28 // this class also provides support for obtaining the list of remote devices | 31 // this class also provides support for obtaining the list of remote devices |
| 29 // known to the adapter, discovering new devices, and providing notification of | 32 // known to the adapter, discovering new devices, and providing notification of |
| 30 // updates to device information. | 33 // updates to device information. |
| 31 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { | 34 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // Bluetooth address. | 73 // Bluetooth address. |
| 71 virtual void DeviceChanged(BluetoothAdapter* adapter, | 74 virtual void DeviceChanged(BluetoothAdapter* adapter, |
| 72 BluetoothDevice* device) {} | 75 BluetoothDevice* device) {} |
| 73 | 76 |
| 74 // Called when the device |device| is removed from the adapter |adapter|, | 77 // Called when the device |device| is removed from the adapter |adapter|, |
| 75 // either as a result of a discovered device being lost between discovering | 78 // either as a result of a discovered device being lost between discovering |
| 76 // phases or pairing information deleted. |device| should not be | 79 // phases or pairing information deleted. |device| should not be |
| 77 // cached. Instead, copy its Bluetooth address. | 80 // cached. Instead, copy its Bluetooth address. |
| 78 virtual void DeviceRemoved(BluetoothAdapter* adapter, | 81 virtual void DeviceRemoved(BluetoothAdapter* adapter, |
| 79 BluetoothDevice* device) {} | 82 BluetoothDevice* device) {} |
| 83 |
| 84 // Called when a new GATT service |service| is added to the device |device|, |
| 85 // as the service is received from the device. Don't cache |service|. Store |
| 86 // its identifier instead (i.e. BluetoothGattService::GetIdentifier). |
| 87 virtual void GattServiceAdded(BluetoothAdapter* adapter, |
| 88 BluetoothDevice* device, |
| 89 BluetoothGattService* service) {} |
| 90 |
| 91 // Called when the GATT service |service| is removed from the device |
| 92 // |device|. This can happen if the attribute database of the remote device |
| 93 // changes or when |device| gets removed. |
| 94 virtual void GattServiceRemoved(BluetoothAdapter* adapter, |
| 95 BluetoothDevice* device, |
| 96 BluetoothGattService* service) {} |
| 97 |
| 98 // Called when all characteristic and descriptor discovery procedures are |
| 99 // known to be completed for the GATT service |service|. This method will be |
| 100 // called after the initial discovery of a GATT service and will usually be |
| 101 // preceded by calls to GattCharacteristicAdded and GattDescriptorAdded. |
| 102 virtual void GattDiscoveryCompleteForService( |
| 103 BluetoothAdapter* adapter, |
| 104 BluetoothGattService* service) {} |
| 105 |
| 106 // Called when properties of the remote GATT service |service| have changed. |
| 107 // This will get called for properties such as UUID, as well as for changes |
| 108 // to the list of known characteristics and included services. Observers |
| 109 // should read all GATT characteristic and descriptors objects and do any |
| 110 // necessary set up required for a changed service. |
| 111 virtual void GattServiceChanged(BluetoothAdapter* adapter, |
| 112 BluetoothGattService* service) {} |
| 113 |
| 114 // Called when the remote GATT characteristic |characteristic| has been |
| 115 // discovered. Use this to issue any initial read/write requests to the |
| 116 // characteristic but don't cache the pointer as it may become invalid. |
| 117 // Instead, use the specially assigned identifier to obtain a characteristic |
| 118 // and cache that identifier as necessary, as it can be used to retrieve the |
| 119 // characteristic from its GATT service. The number of characteristics with |
| 120 // the same UUID belonging to a service depends on the particular profile |
| 121 // the remote device implements, hence the client of a GATT based profile |
| 122 // will usually operate on the whole set of characteristics and not just |
| 123 // one. |
| 124 virtual void GattCharacteristicAdded( |
| 125 BluetoothAdapter* adapter, |
| 126 BluetoothGattCharacteristic* characteristic) {} |
| 127 |
| 128 // Called when a GATT characteristic |characteristic| has been removed from |
| 129 // the system. |
| 130 virtual void GattCharacteristicRemoved( |
| 131 BluetoothAdapter* adapter, |
| 132 BluetoothGattCharacteristic* characteristic) {} |
| 133 |
| 134 // Called when the remote GATT characteristic descriptor |descriptor| has |
| 135 // been discovered. Don't cache the arguments as the pointers may become |
| 136 // invalid. Instead, use the specially assigned identifier to obtain a |
| 137 // descriptor and cache that identifier as necessary. |
| 138 virtual void GattDescriptorAdded(BluetoothAdapter* adapter, |
| 139 BluetoothGattDescriptor* descriptor) {} |
| 140 |
| 141 // Called when a GATT characteristic descriptor |descriptor| has been |
| 142 // removed from the system. |
| 143 virtual void GattDescriptorRemoved(BluetoothAdapter* adapter, |
| 144 BluetoothGattDescriptor* descriptor) {} |
| 145 |
| 146 // Called when the value of a characteristic has changed. This might be a |
| 147 // result of a read/write request to, or a notification/indication from, a |
| 148 // remote GATT characteristic. |
| 149 virtual void GattCharacteristicValueChanged( |
| 150 BluetoothAdapter* adapter, |
| 151 BluetoothGattCharacteristic* characteristic, |
| 152 const std::vector<uint8>& value) {} |
| 153 |
| 154 // Called when the value of a characteristic descriptor has been updated. |
| 155 virtual void GattDescriptorValueChanged(BluetoothAdapter* adapter, |
| 156 BluetoothGattDescriptor* descriptor, |
| 157 const std::vector<uint8>& value) {} |
| 80 }; | 158 }; |
| 81 | 159 |
| 82 // Used to configure a listening servie. | 160 // Used to configure a listening servie. |
| 83 struct ServiceOptions { | 161 struct ServiceOptions { |
| 84 ServiceOptions(); | 162 ServiceOptions(); |
| 85 ~ServiceOptions(); | 163 ~ServiceOptions(); |
| 86 | 164 |
| 87 scoped_ptr<int> channel; | 165 scoped_ptr<int> channel; |
| 88 scoped_ptr<int> psm; | 166 scoped_ptr<int> psm; |
| 89 scoped_ptr<std::string> name; | 167 scoped_ptr<std::string> name; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 std::set<BluetoothDiscoverySession*> discovery_sessions_; | 414 std::set<BluetoothDiscoverySession*> discovery_sessions_; |
| 337 | 415 |
| 338 // Note: This should remain the last member so it'll be destroyed and | 416 // Note: This should remain the last member so it'll be destroyed and |
| 339 // invalidate its weak pointers before any other members are destroyed. | 417 // invalidate its weak pointers before any other members are destroyed. |
| 340 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; | 418 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; |
| 341 }; | 419 }; |
| 342 | 420 |
| 343 } // namespace device | 421 } // namespace device |
| 344 | 422 |
| 345 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 423 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| OLD | NEW |