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 // TODO(youngki): Implement this file. | 5 // TODO(youngki): Implement this file. |
6 | 6 |
7 #include "device/bluetooth/bluetooth_adapter_win.h" | 7 #include "device/bluetooth/bluetooth_adapter_win.h" |
8 | 8 |
9 #include <BluetoothAPIs.h> | |
9 #include <string> | 10 #include <string> |
11 #include "base/bind.h" | |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | |
14 #include "base/stringprintf.h" | |
15 #include "base/sys_string_conversions.h" | |
16 | |
17 # pragma comment(lib, "Bthprops.lib") | |
18 | |
19 namespace { | |
20 | |
21 const BLUETOOTH_FIND_RADIO_PARAMS bluetooth_adapter_param = | |
22 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; | |
23 | |
24 } // namespace | |
11 | 25 |
12 namespace device { | 26 namespace device { |
13 | 27 |
28 const int BluetoothAdapterWin::kPollIntervalMs = 500; | |
29 | |
14 BluetoothAdapterWin::BluetoothAdapterWin() | 30 BluetoothAdapterWin::BluetoothAdapterWin() |
15 : BluetoothAdapter(), | 31 : BluetoothAdapter(), |
16 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 32 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
17 } | 33 } |
18 | 34 |
19 BluetoothAdapterWin::~BluetoothAdapterWin() { | 35 BluetoothAdapterWin::~BluetoothAdapterWin() { |
20 } | 36 } |
21 | 37 |
22 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { | 38 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { |
23 NOTIMPLEMENTED(); | 39 NOTIMPLEMENTED(); |
24 } | 40 } |
25 | 41 |
26 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { | 42 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { |
27 NOTIMPLEMENTED(); | 43 NOTIMPLEMENTED(); |
28 } | 44 } |
29 | 45 |
30 bool BluetoothAdapterWin::IsPresent() const { | 46 bool BluetoothAdapterWin::IsPresent() const { |
31 NOTIMPLEMENTED(); | 47 return !address_.empty(); |
32 return false; | |
33 } | 48 } |
34 | 49 |
35 bool BluetoothAdapterWin::IsPowered() const { | 50 bool BluetoothAdapterWin::IsPowered() const { |
36 NOTIMPLEMENTED(); | 51 NOTIMPLEMENTED(); |
37 return false; | 52 return false; |
38 } | 53 } |
39 | 54 |
40 void BluetoothAdapterWin::SetPowered( | 55 void BluetoothAdapterWin::SetPowered( |
41 bool powered, | 56 bool powered, |
42 const base::Closure& callback, | 57 const base::Closure& callback, |
(...skipping 28 matching lines...) Expand all Loading... | |
71 NOTIMPLEMENTED(); | 86 NOTIMPLEMENTED(); |
72 return NULL; | 87 return NULL; |
73 } | 88 } |
74 | 89 |
75 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( | 90 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( |
76 const BluetoothOutOfBandPairingDataCallback& callback, | 91 const BluetoothOutOfBandPairingDataCallback& callback, |
77 const ErrorCallback& error_callback) { | 92 const ErrorCallback& error_callback) { |
78 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
79 } | 94 } |
80 | 95 |
96 void BluetoothAdapterWin::TrackDefaultAdapter() { | |
97 PollAdapterState(); | |
98 } | |
99 | |
100 void BluetoothAdapterWin::UpdateAdapterState() { | |
101 HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; | |
102 BLUETOOTH_RADIO_INFO bluetooth_adapter_info = | |
103 { sizeof(BLUETOOTH_RADIO_INFO), 0 }; | |
104 BluetoothFindFirstRadio(&bluetooth_adapter_param, &bluetooth_adapter_handle); | |
105 if (bluetooth_adapter_handle && | |
106 ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle, | |
107 &bluetooth_adapter_info)) { | |
108 name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName); | |
109 address_ = base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", | |
110 bluetooth_adapter_info.address.rgBytes[5], | |
111 bluetooth_adapter_info.address.rgBytes[4], | |
112 bluetooth_adapter_info.address.rgBytes[3], | |
113 bluetooth_adapter_info.address.rgBytes[2], | |
114 bluetooth_adapter_info.address.rgBytes[1], | |
115 bluetooth_adapter_info.address.rgBytes[0]); | |
116 } else { | |
117 name_.clear(); | |
118 address_.clear(); | |
119 } | |
120 } | |
121 | |
122 void BluetoothAdapterWin::PollAdapterState() { | |
123 UpdateAdapterState(); | |
124 | |
125 MessageLoop::current()->PostDelayedTask( | |
126 FROM_HERE, | |
127 base::Bind(&BluetoothAdapterWin::PollAdapterState, | |
128 weak_ptr_factory_.GetWeakPtr()), | |
bryeung
2012/11/09 21:55:48
Since this is a weak_ptr, couldn't the adapter hav
youngki
2012/11/12 16:42:53
I ran a simple test by queuing this to message loo
| |
129 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); | |
130 } | |
131 | |
81 } // namespace device | 132 } // namespace device |
OLD | NEW |