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/threading/thread.h" | |
10 | |
11 namespace base { | |
12 | |
13 class CancellationFlag; | |
14 class ThreadChecker; | |
15 | |
16 } // namespace base | |
17 | |
18 namespace device { | |
19 | |
20 // A thread dedicated to perform blocking bluetooth APIs on Windows. | |
21 class BluetoothPollingThreadWin : public base::Thread { | |
22 public: | |
23 struct AdapterState { | |
24 std::string name; | |
25 std::string address; | |
26 bool powered; | |
27 }; | |
28 | |
29 class Observer { | |
30 public: | |
31 virtual ~Observer() {} | |
32 | |
33 // This will always be called on the UI thread. | |
34 virtual void AdapterStateChanged(const AdapterState& state) {} | |
35 }; | |
36 | |
37 BluetoothPollingThreadWin(); | |
38 virtual ~BluetoothPollingThreadWin(); | |
39 | |
40 void AddObserver(Observer* observer); | |
41 void RemoveObserver(Observer* observer); | |
42 | |
43 void Init(); | |
44 | |
45 private: | |
46 // Populates bluetooth adapter state using adapter_handle. | |
47 static void GetAdapterState(const HANDLE adapter_handle, | |
48 AdapterState* state); | |
49 | |
50 // Polls Windows Bluetooth API on BluetoothPollingThread. | |
51 void PollAdapter(base::WeakPtr<BluetoothPollingThreadWin> weak_ptr); | |
52 | |
53 // Callback to be run on the UI thread. | |
54 void OnAdapterStateChanged(const AdapterState* state); | |
55 | |
56 static const int kPollIntervalMs; | |
57 | |
58 // Polling will be canceled when BluetoothPollingThread terminates. | |
59 scoped_ptr<base::CancellationFlag> cancellation_flag_; | |
bryeung
2012/11/27 20:37:04
why a pointer?
youngki
2012/11/27 21:43:34
I want to forward-declare it instead of adding hea
| |
60 | |
61 // Checks that PollAdapter runs on BluetoothPollingThread. | |
62 scoped_ptr<base::ThreadChecker> thread_checker_; | |
63 | |
64 // List of observers interested in event notifications from us. | |
65 ObserverList<Observer> observers_; | |
66 | |
67 // NOTE: This should remain the last member so it'll be destroyed and | |
68 // invalidate its weak pointers before any other members are destroyed. | |
69 base::WeakPtrFactory<BluetoothPollingThreadWin> weak_ptr_factory_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(BluetoothPollingThreadWin); | |
72 }; | |
73 | |
74 } // namespace device | |
75 | |
76 #endif // DEVICE_BLUETOOTH_BLUETOOTH_POLLING_THREAD_WIN_H_ | |
OLD | NEW |