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_TASK_MANAGER_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
16 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
| 17 #include "device/bluetooth/bluetooth_export.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
21 class SequencedWorkerPool; | 22 class SequencedWorkerPool; |
22 | 23 |
23 } // namespace base | 24 } // namespace base |
24 | 25 |
25 namespace device { | 26 namespace device { |
26 | 27 |
27 // Manages the blocking Bluetooth tasks using |SequencedWorkerPool|. It runs | 28 // Manages the blocking Bluetooth tasks using |SequencedWorkerPool|. It runs |
28 // bluetooth tasks using |SequencedWorkerPool| and informs its observers of | 29 // bluetooth tasks using |SequencedWorkerPool| and informs its observers of |
29 // bluetooth adapter state changes and any other bluetooth device inquiry | 30 // bluetooth adapter state changes and any other bluetooth device inquiry |
30 // result. | 31 // result. |
31 // | 32 // |
32 // It delegates the blocking Windows API calls to |bluetooth_task_runner_|'s | 33 // It delegates the blocking Windows API calls to |bluetooth_task_runner_|'s |
33 // message loop, and receives responses via methods like OnAdapterStateChanged | 34 // message loop, and receives responses via methods like OnAdapterStateChanged |
34 // posted to UI thread. | 35 // posted to UI thread. |
35 class BluetoothTaskManagerWin | 36 class DEVICE_BLUETOOTH_EXPORT BluetoothTaskManagerWin |
36 : public base::RefCountedThreadSafe<BluetoothTaskManagerWin> { | 37 : public base::RefCountedThreadSafe<BluetoothTaskManagerWin> { |
37 public: | 38 public: |
38 struct AdapterState { | 39 struct DEVICE_BLUETOOTH_EXPORT AdapterState { |
39 AdapterState(); | 40 AdapterState(); |
40 ~AdapterState(); | 41 ~AdapterState(); |
41 std::string name; | 42 std::string name; |
42 std::string address; | 43 std::string address; |
43 bool powered; | 44 bool powered; |
44 }; | 45 }; |
45 | 46 |
46 struct ServiceRecordState { | 47 struct DEVICE_BLUETOOTH_EXPORT ServiceRecordState { |
47 ServiceRecordState(); | 48 ServiceRecordState(); |
48 ~ServiceRecordState(); | 49 ~ServiceRecordState(); |
49 // Properties common to Bluetooth Classic and LE devices. | 50 // Properties common to Bluetooth Classic and LE devices. |
50 std::string name; | 51 std::string name; |
51 // Properties specific to Bluetooth Classic devices. | 52 // Properties specific to Bluetooth Classic devices. |
52 std::vector<uint8> sdp_bytes; | 53 std::vector<uint8> sdp_bytes; |
53 // Properties specific to Bluetooth LE devices. | 54 // Properties specific to Bluetooth LE devices. |
54 BluetoothUUID gatt_uuid; | 55 BluetoothUUID gatt_uuid; |
55 }; | 56 }; |
56 | 57 |
57 struct DeviceState { | 58 struct DEVICE_BLUETOOTH_EXPORT DeviceState { |
58 DeviceState(); | 59 DeviceState(); |
59 ~DeviceState(); | 60 ~DeviceState(); |
60 | 61 |
61 bool is_bluetooth_classic() const { return path.empty(); } | 62 bool is_bluetooth_classic() const { return path.empty(); } |
62 | 63 |
63 // Properties common to Bluetooth Classic and LE devices. | 64 // Properties common to Bluetooth Classic and LE devices. |
64 std::string address; // This uniquely identifies the device. | 65 std::string address; // This uniquely identifies the device. |
65 std::string name; // Friendly name | 66 std::string name; // Friendly name |
66 bool visible; | 67 bool visible; |
67 bool connected; | 68 bool connected; |
68 bool authenticated; | 69 bool authenticated; |
69 ScopedVector<ServiceRecordState> service_record_states; | 70 ScopedVector<ServiceRecordState> service_record_states; |
70 // Properties specific to Bluetooth Classic devices. | 71 // Properties specific to Bluetooth Classic devices. |
71 uint32 bluetooth_class; | 72 uint32 bluetooth_class; |
72 // Properties specific to Bluetooth LE devices. | 73 // Properties specific to Bluetooth LE devices. |
73 base::FilePath path; | 74 base::FilePath path; |
74 }; | 75 }; |
75 | 76 |
76 class Observer { | 77 class DEVICE_BLUETOOTH_EXPORT Observer { |
77 public: | 78 public: |
78 virtual ~Observer() {} | 79 virtual ~Observer() {} |
79 | 80 |
80 virtual void AdapterStateChanged(const AdapterState& state) {} | 81 virtual void AdapterStateChanged(const AdapterState& state) {} |
81 virtual void DiscoveryStarted(bool success) {} | 82 virtual void DiscoveryStarted(bool success) {} |
82 virtual void DiscoveryStopped() {} | 83 virtual void DiscoveryStopped() {} |
83 // Called when the adapter has just been polled for the list of *all* known | 84 // Called when the adapter has just been polled for the list of *all* known |
84 // devices. This includes devices previously paired, devices paired using | 85 // devices. This includes devices previously paired, devices paired using |
85 // the underlying Operating System UI, and devices discovered recently due | 86 // the underlying Operating System UI, and devices discovered recently due |
86 // to an active discovery session. Note that for a given device (address), | 87 // to an active discovery session. Note that for a given device (address), |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // Use for discarding too many log messages. | 211 // Use for discarding too many log messages. |
211 base::TimeTicks current_logging_batch_ticks_; | 212 base::TimeTicks current_logging_batch_ticks_; |
212 int current_logging_batch_count_; | 213 int current_logging_batch_count_; |
213 | 214 |
214 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); | 215 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); |
215 }; | 216 }; |
216 | 217 |
217 } // namespace device | 218 } // namespace device |
218 | 219 |
219 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | 220 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
OLD | NEW |