1 // Copyright 2013 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_ADAPTER_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_
8 #include <IOKit/IOReturn.h>
13 #include "base/containers/hash_tables.h"
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
18 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_discovery_manager_mac.h"
21 @
class IOBluetoothDevice
;
27 class SequencedTaskRunner
;
33 class BluetoothAdapterMacTest
;
35 class BluetoothAdapterMac
: public BluetoothAdapter
,
36 public BluetoothDiscoveryManagerMac::Observer
{
38 static base::WeakPtr
<BluetoothAdapter
> CreateAdapter();
41 virtual void AddObserver(BluetoothAdapter::Observer
* observer
) OVERRIDE
;
42 virtual void RemoveObserver(BluetoothAdapter::Observer
* observer
) OVERRIDE
;
43 virtual std::string
GetAddress() const OVERRIDE
;
44 virtual std::string
GetName() const OVERRIDE
;
45 virtual void SetName(const std::string
& name
,
46 const base::Closure
& callback
,
47 const ErrorCallback
& error_callback
) OVERRIDE
;
48 virtual bool IsInitialized() const OVERRIDE
;
49 virtual bool IsPresent() const OVERRIDE
;
50 virtual bool IsPowered() const OVERRIDE
;
51 virtual void SetPowered(
53 const base::Closure
& callback
,
54 const ErrorCallback
& error_callback
) OVERRIDE
;
55 virtual bool IsDiscoverable() const OVERRIDE
;
56 virtual void SetDiscoverable(
58 const base::Closure
& callback
,
59 const ErrorCallback
& error_callback
) OVERRIDE
;
60 virtual bool IsDiscovering() const OVERRIDE
;
61 virtual void CreateRfcommService(
62 const BluetoothUUID
& uuid
,
63 const ServiceOptions
& options
,
64 const CreateServiceCallback
& callback
,
65 const CreateServiceErrorCallback
& error_callback
) OVERRIDE
;
66 virtual void CreateL2capService(
67 const BluetoothUUID
& uuid
,
68 const ServiceOptions
& options
,
69 const CreateServiceCallback
& callback
,
70 const CreateServiceErrorCallback
& error_callback
) OVERRIDE
;
72 // BluetoothDiscoveryManagerMac::Observer overrides
73 virtual void DeviceFound(IOBluetoothDevice
* device
) OVERRIDE
;
74 virtual void DiscoveryStopped(bool unexpected
) OVERRIDE
;
76 // Registers that a new |device| has connected to the local host.
77 void DeviceConnected(IOBluetoothDevice
* device
);
81 virtual void RemovePairingDelegateInternal(
82 device::BluetoothDevice::PairingDelegate
* pairing_delegate
) OVERRIDE
;
85 friend class BluetoothAdapterMacTest
;
87 BluetoothAdapterMac();
88 virtual ~BluetoothAdapterMac();
91 virtual void AddDiscoverySession(
92 const base::Closure
& callback
,
93 const ErrorCallback
& error_callback
) OVERRIDE
;
94 virtual void RemoveDiscoverySession(
95 const base::Closure
& callback
,
96 const ErrorCallback
& error_callback
) OVERRIDE
;
99 void InitForTest(scoped_refptr
<base::SequencedTaskRunner
> ui_task_runner
);
102 // Registers that a new |device| has replied to an Inquiry, is paired, or has
103 // connected to the local host.
104 void DeviceAdded(IOBluetoothDevice
* device
);
106 // Updates |devices_| to include the currently paired devices, as well as any
107 // connected, but unpaired, devices. Notifies observers if any previously
108 // paired or connected devices are no longer present.
109 void UpdateDevices();
111 std::string address_
;
115 int num_discovery_sessions_
;
117 // Discovery manager for Bluetooth Classic.
118 scoped_ptr
<BluetoothDiscoveryManagerMac
> classic_discovery_manager_
;
120 scoped_refptr
<base::SequencedTaskRunner
> ui_task_runner_
;
122 // List of observers interested in event notifications from us.
123 ObserverList
<BluetoothAdapter::Observer
> observers_
;
125 base::WeakPtrFactory
<BluetoothAdapterMac
> weak_ptr_factory_
;
127 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac
);
130 } // namespace device
132 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_