OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "components/proximity_auth/connection_finder.h" | |
16 #include "device/bluetooth/bluetooth_adapter.h" | |
17 #include "device/bluetooth/bluetooth_device.h" | |
18 #include "device/bluetooth/bluetooth_discovery_session.h" | |
19 #include "device/bluetooth/bluetooth_gatt_connection.h" | |
20 | |
21 namespace proximity_auth { | |
22 | |
23 // This ConnectionFinder implementation is specialized in finding a Bluetooth | |
24 // Low Energy remote device. | |
25 class BluetoothLowEnergyConnectionFinder | |
26 : public ConnectionFinder, | |
27 public device::BluetoothAdapter::Observer { | |
28 public: | |
29 BluetoothLowEnergyConnectionFinder(const std::string& remote_service_uuid); | |
30 ~BluetoothLowEnergyConnectionFinder() override; | |
31 | |
32 // Finds a connection the remote device, only the first one is functional. | |
msarda
2015/04/27 08:11:07
s/connection the/connection to the
| |
33 void Find(const device::BluetoothDevice::GattConnectionCallback& | |
34 connection_callback); | |
35 void Find(const ConnectionCallback& connection_callback) override; | |
36 | |
37 protected: | |
38 // device::BluetoothAdapter::Observer: | |
39 void DeviceAdded(device::BluetoothAdapter* adapter, | |
40 device::BluetoothDevice* device) override; | |
41 | |
42 private: | |
43 // Callback to be called when the Bluetooth adapter is initialized. | |
44 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | |
45 | |
46 // Checks if |remote_device| contains |remote_service_uuid| and creates a | |
47 // connection in that case. | |
48 void HandleDeviceAdded(device::BluetoothDevice* remote_device); | |
49 | |
50 // Callback called when a new discovery session is started. | |
51 void OnDiscoverySessionStarted( | |
52 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | |
53 | |
54 // Callback called when there is an error starting a new discovery session. | |
55 void OnStartDiscoverySessionError(); | |
56 | |
57 // Starts a discovery session for |adapter_|. | |
58 void StartDiscoverySession(); | |
59 | |
60 // Callback called when |discovery_session_| is stopped. | |
61 void OnDiscoverySessionStopped(); | |
62 | |
63 // Callback called when there is an error stopping |discovery_session_|. | |
64 void OnStopDiscoverySessionError(); | |
65 | |
66 // Stops the discovery session given by |discovery_session_|. | |
67 void StopDiscoverySession(); | |
68 | |
69 // Checks if a service with |service_uuid| is offered by |remote_device|. | |
70 bool HasService(device::BluetoothDevice* remote_device); | |
71 | |
72 // Callback called when there is an error creating the connection. | |
73 void OnCreateConnectionError( | |
74 device::BluetoothDevice::ConnectErrorCode error_code); | |
75 | |
76 // Callback called when the connection is created. | |
77 void OnConnectionCreated( | |
78 scoped_ptr<device::BluetoothGattConnection> connection); | |
79 | |
80 // Creates a GATT connection with |remote_device|, |connection_callback_| will | |
81 // be called once the connection is established. | |
82 void CreateConnection(device::BluetoothDevice* remote_device); | |
83 | |
84 // The uuid of the service it looks for to establish a GattConnection. | |
85 device::BluetoothUUID remote_service_uuid_; | |
86 | |
87 // The Bluetooth adapter over which the Bluetooth connection will be made. | |
88 scoped_refptr<device::BluetoothAdapter> adapter_; | |
89 | |
90 // The discovery session associated to this object. | |
91 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; | |
92 | |
93 // True if there is a connection. | |
94 bool connected_; | |
95 | |
96 // Callback called when the connection is established. | |
97 device::BluetoothDevice::GattConnectionCallback connection_callback_; | |
98 | |
99 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); | |
102 }; | |
103 | |
104 } // namespace proximity_auth | |
105 | |
106 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_CONNECTION_FINDER_H | |
OLD | NEW |