OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_POLLING_THREAD_WIN_H_ | |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_POLLING_THREAD_WIN_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/synchronization/cancellation_flag.h" | |
10 #include "base/threading/thread.h" | |
11 #include "base/threading/thread_checker.h" | |
12 | |
13 namespace base { | |
14 | |
15 class CancellationFlag; | |
16 class ThreadChecker; | |
bryeung
2012/11/28 16:26:08
not needed with the headers above
youngki
2012/11/28 19:19:13
Done.
| |
17 | |
18 } // namespace base | |
19 | |
20 namespace device { | |
21 | |
22 // A thread dedicated to perform blocking bluetooth APIs on Windows. | |
23 class BluetoothPollingThreadWin : public base::Thread { | |
24 public: | |
25 struct AdapterState { | |
26 std::string name; | |
27 std::string address; | |
28 bool powered; | |
29 }; | |
30 | |
31 class Observer { | |
32 public: | |
33 virtual ~Observer() {} | |
34 | |
35 // This will always be called on the UI thread. | |
36 virtual void AdapterStateChanged(const AdapterState& state) {} | |
37 }; | |
38 | |
39 BluetoothPollingThreadWin(); | |
40 virtual ~BluetoothPollingThreadWin(); | |
41 | |
42 void AddObserver(Observer* observer); | |
43 void RemoveObserver(Observer* observer); | |
44 | |
45 void Init(); | |
46 | |
47 private: | |
48 // Populates bluetooth adapter state using adapter_handle. | |
49 static void GetAdapterState(const HANDLE adapter_handle, | |
bryeung
2012/11/28 16:26:08
this should go inside an anonymous namespace in th
youngki
2012/11/28 19:19:13
Done.
| |
50 AdapterState* state); | |
51 | |
52 // Polls Windows Bluetooth API on BluetoothPollingThread. | |
bryeung
2012/11/28 16:26:08
More descriptive comments would be nice, e.g.:
"Ca
youngki
2012/11/28 19:19:13
Done.
| |
53 void PollAdapter(base::WeakPtr<BluetoothPollingThreadWin> weak_ptr); | |
54 | |
55 // Callback to be run on the UI thread. | |
bryeung
2012/11/28 16:26:08
"Notify all Observers of updated AdapterState. Sh
youngki
2012/11/28 19:19:13
Done.
| |
56 void OnAdapterStateChanged(const AdapterState* state); | |
57 | |
58 static const int kPollIntervalMs; | |
59 | |
60 // Polling will be canceled when BluetoothPollingThread terminates. | |
61 base::CancellationFlag cancellation_flag_; | |
62 | |
63 // Checks that PollAdapter runs on BluetoothPollingThread. | |
64 base::ThreadChecker thread_checker_; | |
65 | |
66 // List of observers interested in event notifications from us. | |
bryeung
2012/11/28 16:26:08
s/from us//
youngki
2012/11/28 19:19:13
Done.
| |
67 ObserverList<Observer> observers_; | |
68 | |
69 // NOTE: This should remain the last member so it'll be destroyed and | |
70 // invalidate its weak pointers before any other members are destroyed. | |
71 base::WeakPtrFactory<BluetoothPollingThreadWin> weak_ptr_factory_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(BluetoothPollingThreadWin); | |
74 }; | |
75 | |
76 } // namespace device | |
77 | |
78 #endif // DEVICE_BLUETOOTH_BLUETOOTH_POLLING_THREAD_WIN_H_ | |
OLD | NEW |