15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <list> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map> 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <set> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <utility> 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/weak_ptr.h" 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "device/bluetooth/bluetooth_device.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace device { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class BluetoothDiscoverySession; 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class BluetoothGattCharacteristic; 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class BluetoothGattDescriptor; 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class BluetoothGattService; 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class BluetoothSocket; 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class BluetoothUUID; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BluetoothAdapter represents a local Bluetooth adapter which may be used to 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interact with remote Bluetooth devices. As well as providing support for 300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// determining whether an adapter is present and whether the radio is powered, 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this class also provides support for obtaining the list of remote devices 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// known to the adapter, discovering new devices, and providing notification of 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// updates to device information. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Interface for observing changes from bluetooth adapters. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class Observer { 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Observer() {} 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Called when the presence of the adapter |adapter| changes. When |present| 42c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // is true the adapter is now present, false means the adapter has been 43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // removed from the system. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AdapterPresentChanged(BluetoothAdapter* adapter, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool present) {} 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Called when the radio power state of the adapter |adapter| changes. When 48c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // |powered| is true the adapter radio is powered, false means the adapter 49c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // radio is off. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool powered) {} 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Called when the discoverability state of the adapter |adapter| changes. 540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // When |discoverable| is true the adapter is discoverable by other devices, 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // false means the adapter is not discoverable. 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void AdapterDiscoverableChanged(BluetoothAdapter* adapter, 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool discoverable) {} 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Called when the discovering state of the adapter |adapter| changes. When 60c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // |discovering| is true the adapter is seeking new devices, false means it 61c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // is not. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AdapterDiscoveringChanged(BluetoothAdapter* adapter, 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool discovering) {} 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when a new device |device| is added to the adapter |adapter|, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // either because it has been discovered or a connection made. |device| 670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // should not be cached. Instead, copy its Bluetooth address. 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DeviceAdded(BluetoothAdapter* adapter, 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BluetoothDevice* device) {} 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when properties of the device |device| known to the adapter 720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // |adapter| change. |device| should not be cached. Instead, copy its 730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Bluetooth address. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DeviceChanged(BluetoothAdapter* adapter, 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BluetoothDevice* device) {} 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the device |device| is removed from the adapter |adapter|, 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // either as a result of a discovered device being lost between discovering 790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // phases or pairing information deleted. |device| should not be 800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // cached. Instead, copy its Bluetooth address. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DeviceRemoved(BluetoothAdapter* adapter, 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BluetoothDevice* device) {} 835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when a new GATT service |service| is added to the device |device|, 855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // as the service is received from the device. Don't cache |service|. Store 865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // its identifier instead (i.e. BluetoothGattService::GetIdentifier). 875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattServiceAdded(BluetoothAdapter* adapter, 885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothDevice* device, 895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattService* service) {} 905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when the GATT service |service| is removed from the device 925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // |device|. This can happen if the attribute database of the remote device 935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // changes or when |device| gets removed. 945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattServiceRemoved(BluetoothAdapter* adapter, 955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothDevice* device, 965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattService* service) {} 975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when all characteristic and descriptor discovery procedures are 995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // known to be completed for the GATT service |service|. This method will be 1005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // called after the initial discovery of a GATT service and will usually be 1015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // preceded by calls to GattCharacteristicAdded and GattDescriptorAdded. 1025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattDiscoveryCompleteForService( 1035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothAdapter* adapter, 1045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattService* service) {} 1055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when properties of the remote GATT service |service| have changed. 1075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // This will get called for properties such as UUID, as well as for changes 1085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // to the list of known characteristics and included services. Observers 1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // should read all GATT characteristic and descriptors objects and do any 1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // necessary set up required for a changed service. 1115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattServiceChanged(BluetoothAdapter* adapter, 1125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattService* service) {} 1135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when the remote GATT characteristic |characteristic| has been 1155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // discovered. Use this to issue any initial read/write requests to the 1165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // characteristic but don't cache the pointer as it may become invalid. 1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Instead, use the specially assigned identifier to obtain a characteristic 1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // and cache that identifier as necessary, as it can be used to retrieve the 1195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // characteristic from its GATT service. The number of characteristics with 1205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the same UUID belonging to a service depends on the particular profile 1215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the remote device implements, hence the client of a GATT based profile 1225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // will usually operate on the whole set of characteristics and not just 1235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // one. 1245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattCharacteristicAdded( 1255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothAdapter* adapter, 1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattCharacteristic* characteristic) {} 1275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when a GATT characteristic |characteristic| has been removed from 1295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the system. 1305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattCharacteristicRemoved( 1315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothAdapter* adapter, 1325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattCharacteristic* characteristic) {} 1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when the remote GATT characteristic descriptor |descriptor| has 1355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // been discovered. Don't cache the arguments as the pointers may become 1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // invalid. Instead, use the specially assigned identifier to obtain a 1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // descriptor and cache that identifier as necessary. 1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattDescriptorAdded(BluetoothAdapter* adapter, 1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattDescriptor* descriptor) {} 1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when a GATT characteristic descriptor |descriptor| has been 1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // removed from the system. 1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattDescriptorRemoved(BluetoothAdapter* adapter, 1445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattDescriptor* descriptor) {} 1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when the value of a characteristic has changed. This might be a 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // result of a read/write request to, or a notification/indication from, a 1485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // remote GATT characteristic. 1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattCharacteristicValueChanged( 1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothAdapter* adapter, 1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattCharacteristic* characteristic, 1525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::vector<uint8>& value) {} 1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Called when the value of a characteristic descriptor has been updated. 1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void GattDescriptorValueChanged(BluetoothAdapter* adapter, 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) BluetoothGattDescriptor* descriptor, 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const std::vector<uint8>& value) {} 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 160116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Used to configure a listening servie. 161116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch struct ServiceOptions { 162116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ServiceOptions(); 163116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ~ServiceOptions(); 164116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 165116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_ptr<int> channel; 166116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_ptr<int> psm; 167116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_ptr<std::string> name; 168116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch }; 169116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 170c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // The ErrorCallback is used for methods that can fail in which case it is 171c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // called, in the success case the callback is simply not called. 172a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) typedef base::Closure ErrorCallback; 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // The InitCallback is used to trigger a callback after asynchronous 1750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // initialization, if initialization is asynchronous on the platform. 1760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch typedef base::Callback<void()> InitCallback; 1770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 1780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Returns a weak pointer to a new adapter. For platforms with asynchronous 1790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // initialization, the returned adapter will run the |init_callback| once 1800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // asynchronous initialization is complete. 1810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Caution: The returned pointer also transfers ownership of the adapter. The 1820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // caller is expected to call |AddRef()| on the returned pointer, typically by 1830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // storing it into a |scoped_refptr|. 1840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch static base::WeakPtr<BluetoothAdapter> CreateAdapter( 1850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const InitCallback& init_callback); 1860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 187010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Returns a weak pointer to an existing adapter for testing purposes only. 188010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::WeakPtr<BluetoothAdapter> GetWeakPtrForTesting(); 189010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 1900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Adds and removes observers for events on this bluetooth adapter. If 1910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // monitoring multiple adapters, check the |adapter| parameter of observer 192c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // methods to determine which adapter is issuing the event. 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AddObserver(BluetoothAdapter::Observer* observer) = 0; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RemoveObserver( 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BluetoothAdapter::Observer* observer) = 0; 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // The address of this adapter. The address format is "XX:XX:XX:XX:XX:XX", 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // where each XX is a hexadecimal number. 199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual std::string GetAddress() const = 0; 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The name of the adapter. 202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual std::string GetName() const = 0; 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set the human-readable name of the adapter to |name|. On success, 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |callback| will be called. On failure, |error_callback| will be called. 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void SetName(const std::string& name, 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ErrorCallback& error_callback) = 0; 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Indicates whether the adapter is initialized and ready to use. 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool IsInitialized() const = 0; 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Indicates whether the adapter is actually present on the system. For the 2140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // default adapter, this indicates whether any adapter is present. An adapter 215c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // is only considered present if the address has been obtained. 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsPresent() const = 0; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates whether the adapter radio is powered. 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsPowered() const = 0; 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Requests a change to the adapter radio power. Setting |powered| to true 2220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // will turn on the radio and false will turn it off. On success, |callback| 2230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // will be called. On failure, |error_callback| will be called. 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetPowered(bool powered, 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Closure& callback, 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ErrorCallback& error_callback) = 0; 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Indicates whether the adapter radio is discoverable. 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool IsDiscoverable() const = 0; 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Requests that the adapter change its discoverability state. If 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |discoverable| is true, then it will be discoverable by other Bluetooth 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // devices. On successly changing the adapter's discoverability, |callback| 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // will be called. On failure, |error_callback| will be called. 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void SetDiscoverable(bool discoverable, 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ErrorCallback& error_callback) = 0; 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Indicates whether the adapter is currently discovering new devices. 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsDiscovering() const = 0; 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Requests the adapter to start a new discovery session. On success, a new 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // instance of BluetoothDiscoverySession will be returned to the caller via 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |callback| and the adapter will be discovering nearby Bluetooth devices. 245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The returned BluetoothDiscoverySession is owned by the caller and it's the 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // owner's responsibility to properly clean it up and stop the session when 247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // device discovery is no longer needed. 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If clients desire device discovery to run, they should always call this 250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // method and never make it conditional on the value of IsDiscovering(), as 251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // another client might cause discovery to stop unexpectedly. Hence, clients 252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // should always obtain a BluetoothDiscoverySession and call 253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // BluetoothDiscoverySession::Stop when done. When this method gets called, 254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // device discovery may actually be in progress. Clients can call GetDevices() 255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // and check for those with IsPaired() as false to obtain the list of devices 256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // that have been discovered so far. Otherwise, clients can be notified of all 2570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // new and lost devices by implementing the Observer methods "DeviceAdded" and 2580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // "DeviceRemoved". 259a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) typedef base::Callback<void(scoped_ptr<BluetoothDiscoverySession>)> 260a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DiscoverySessionCallback; 261a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void StartDiscoverySession(const DiscoverySessionCallback& callback, 262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ErrorCallback& error_callback); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Requests the list of devices from the adapter. All devices are returned, 2650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // including those currently connected and those paired. Use the returned 2660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // device pointers to determine which they are. 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<BluetoothDevice*> DeviceList; 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual DeviceList GetDevices(); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<const BluetoothDevice*> ConstDeviceList; 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ConstDeviceList GetDevices() const; 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 272c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Returns a pointer to the device with the given address |address| or NULL if 273c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // no such device is known. 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual BluetoothDevice* GetDevice(const std::string& address); 2750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual const BluetoothDevice* GetDevice(const std::string& address) const; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Possible priorities for AddPairingDelegate(), low is intended for 278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // permanent UI and high is intended for interactive UI or applications. 279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) enum PairingDelegatePriority { 280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PAIRING_DELEGATE_PRIORITY_LOW, 281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PAIRING_DELEGATE_PRIORITY_HIGH 282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) }; 283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 2840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Adds a default pairing delegate with priority |priority|. Method calls 285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // will be made on |pairing_delegate| for incoming pairing requests if the 2860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // priority is higher than any other registered; or for those of the same 287a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // priority, the first registered. 288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |pairing_delegate| must not be freed without first calling 290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // RemovePairingDelegate(). 291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void AddPairingDelegate( 292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BluetoothDevice::PairingDelegate* pairing_delegate, 293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PairingDelegatePriority priority); 294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Removes a previously added pairing delegate. 296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RemovePairingDelegate( 297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BluetoothDevice::PairingDelegate* pairing_delegate); 298a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns the first registered pairing delegate with the highest priority, 300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // or NULL if no delegate is registered. Used to select the delegate for 301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // incoming pairing requests. 302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual BluetoothDevice::PairingDelegate* DefaultPairingDelegate(); 303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 304cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Creates an RFCOMM service on this adapter advertised with UUID |uuid|, 305116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // listening on channel |options.channel|, which may be left null to 306116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // automatically allocate one. The service will be advertised with 307116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // |options.name| as the English name of the service. |callback| will be 308116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // called on success with a BluetoothSocket instance that is to be owned by 309116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // the received. |error_callback| will be called on failure with a message 310116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // indicating the cause. 311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> 312cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CreateServiceCallback; 313cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) typedef base::Callback<void(const std::string& message)> 314cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CreateServiceErrorCallback; 315cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void CreateRfcommService( 316cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const BluetoothUUID& uuid, 317116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const ServiceOptions& options, 318cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const CreateServiceCallback& callback, 319cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const CreateServiceErrorCallback& error_callback) = 0; 320cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 321cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Creates an L2CAP service on this adapter advertised with UUID |uuid|, 322116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // listening on PSM |options.psm|, which may be left null to automatically 323116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // allocate one. The service will be advertised with |options.name| as the 324116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // English name of the service. |callback| will be called on success with a 325cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // BluetoothSocket instance that is to be owned by the received. 326cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |error_callback| will be called on failure with a message indicating the 327cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // cause. 328cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void CreateL2capService( 329cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const BluetoothUUID& uuid, 330116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const ServiceOptions& options, 331cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const CreateServiceCallback& callback, 332cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const CreateServiceErrorCallback& error_callback) = 0; 333cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class base::RefCounted<BluetoothAdapter>; 336a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) friend class BluetoothDiscoverySession; 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BluetoothAdapter(); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~BluetoothAdapter(); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 340a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Internal methods for initiating and terminating device discovery sessions. 341a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // An implementation of BluetoothAdapter keeps an internal reference count to 342a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // make sure that the underlying controller is constantly searching for nearby 343a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // devices and retrieving information from them as long as there are clients 344a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // who have requested discovery. These methods behave in the following way: 345a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 346a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // On a call to AddDiscoverySession: 347a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If there is a pending request to the subsystem, queue this request to 348a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // execute once the pending requests are done. 349a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If the count is 0, issue a request to the subsystem to start 350a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // device discovery. On success, increment the count to 1. 351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If the count is greater than 0, increment the count and return 352a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // success. 353a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // As long as the count is non-zero, the underlying controller will be 354a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // discovering for devices. This means that Chrome will restart device 355a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // scan and inquiry sessions if they ever end, unless these sessions 356a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // terminate due to an unexpected reason. 357a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 358a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // On a call to RemoveDiscoverySession: 359a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If there is a pending request to the subsystem, queue this request to 360a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // execute once the pending requests are done. 361a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If the count is 0, return failure, as there is no active discovery 362a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // session. 363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If the count is 1, issue a request to the subsystem to stop device 364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // discovery and decrement the count to 0 on success. 365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // - If the count is greater than 1, decrement the count and return 366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // success. 367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 368a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // These methods invoke |callback| for success and |error_callback| for 369a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // failures. 370a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void AddDiscoverySession(const base::Closure& callback, 371a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ErrorCallback& error_callback) = 0; 372a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RemoveDiscoverySession(const base::Closure& callback, 373a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ErrorCallback& error_callback) = 0; 374a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 375a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Called by RemovePairingDelegate() in order to perform any class-specific 376a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // internal functionality necessary to remove the pairing delegate, such as 377a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // cleaning up ongoing pairings using it. 378a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RemovePairingDelegateInternal( 379a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BluetoothDevice::PairingDelegate* pairing_delegate) = 0; 380a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 381a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Success callback passed to AddDiscoverySession by StartDiscoverySession. 382a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void OnStartDiscoverySession(const DiscoverySessionCallback& callback); 383a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 384a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Marks all known DiscoverySession instances as inactive. Called by 385a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // BluetoothAdapter in the event that the adapter unexpectedly stops 386a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // discovering. This should be called by all platform implementations. 387a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void MarkDiscoverySessionsAsInactive(); 388a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 389a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Removes |discovery_session| from |discovery_sessions_|, if its in there. 390a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Called by DiscoverySession when an instance is destroyed or becomes 391a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // inactive. 392a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void DiscoverySessionBecameInactive( 393a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BluetoothDiscoverySession* discovery_session); 394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Devices paired with, connected to, discovered by, or visible to the 396c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // adapter. The key is the Bluetooth address of the device and the value is 397c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // the BluetoothDevice object whose lifetime is managed by the adapter 398c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // instance. 3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef std::map<const std::string, BluetoothDevice*> DevicesMap; 4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DevicesMap devices_; 401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 402a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Default pairing delegates registered with the adapter. 403a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) typedef std::pair<BluetoothDevice::PairingDelegate*, 404a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PairingDelegatePriority> PairingDelegatePair; 405a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::list<PairingDelegatePair> pairing_delegates_; 406a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 407a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private: 408a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // List of active DiscoverySession objects. This is used to notify sessions to 409a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // become inactive in case of an unexpected change to the adapter discovery 410a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // state. We keep raw pointers, with the invariant that a DiscoverySession 411a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // will remove itself from this list when it gets destroyed or becomes 412a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // inactive by calling DiscoverySessionBecameInactive(), hence no pointers to 413a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // deallocated sessions are kept. 414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::set<BluetoothDiscoverySession*> discovery_sessions_; 415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 416a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note: This should remain the last member so it'll be destroyed and 417a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // invalidate its weak pointers before any other members are destroyed. 418a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace device 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ 424