Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: device/bluetooth/bluetooth_adapter_win.cc

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added BluetoothTaskManagerWin class Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
10 #include <string> 9 #include <string>
11 #include "base/bind.h"
12 #include "base/logging.h" 10 #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
25 11
26 namespace device { 12 namespace device {
27 13
28 const int BluetoothAdapterWin::kPollIntervalMs = 500;
29
30 BluetoothAdapterWin::BluetoothAdapterWin() 14 BluetoothAdapterWin::BluetoothAdapterWin()
31 : BluetoothAdapter(), 15 : BluetoothAdapter(),
32 powered_(false), 16 powered_(false),
17 task_manager_(new BluetoothTaskManagerWin()),
33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 18 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
19 task_manager_->AddObserver(this);
34 } 20 }
35 21
36 BluetoothAdapterWin::~BluetoothAdapterWin() { 22 BluetoothAdapterWin::~BluetoothAdapterWin() {
23 task_manager_->RemoveObserver(this);
24
25 // We explicitly call StopThread() here; we cannot rely on |task_manager_|
26 // destructor because it is reference counted.
bryeung 2012/12/10 19:51:28 who else would be holding a reference to it?
youngki 2012/12/17 17:17:23 BluetoothPollingThreadWin::PollAdapter() queues ba
27 task_manager_->StopThread();
37 } 28 }
38 29
39 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { 30 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) {
40 NOTIMPLEMENTED(); 31 NOTIMPLEMENTED();
41 } 32 }
42 33
43 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { 34 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) {
44 NOTIMPLEMENTED(); 35 NOTIMPLEMENTED();
45 } 36 }
46 37
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 NOTIMPLEMENTED(); 77 NOTIMPLEMENTED();
87 return NULL; 78 return NULL;
88 } 79 }
89 80
90 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( 81 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData(
91 const BluetoothOutOfBandPairingDataCallback& callback, 82 const BluetoothOutOfBandPairingDataCallback& callback,
92 const ErrorCallback& error_callback) { 83 const ErrorCallback& error_callback) {
93 NOTIMPLEMENTED(); 84 NOTIMPLEMENTED();
94 } 85 }
95 86
96 void BluetoothAdapterWin::UpdateAdapterState() { 87 void BluetoothAdapterWin::AdapterStateChanged(
97 HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; 88 const BluetoothTaskManagerWin::AdapterState& state) {
98 BLUETOOTH_RADIO_INFO bluetooth_adapter_info = 89 DCHECK(thread_checker_.CalledOnValidThread());
99 { sizeof(BLUETOOTH_RADIO_INFO), 0 }; 90 name_ = state.name;
100 HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio( 91 address_ = state.address;
101 &bluetooth_adapter_param, &bluetooth_adapter_handle); 92 powered_ = state.powered;
102
103 if (bluetooth_adapter_handle) {
104 if (ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle,
105 &bluetooth_adapter_info)) {
106 name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName);
107 address_ = base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
108 bluetooth_adapter_info.address.rgBytes[5],
109 bluetooth_adapter_info.address.rgBytes[4],
110 bluetooth_adapter_info.address.rgBytes[3],
111 bluetooth_adapter_info.address.rgBytes[2],
112 bluetooth_adapter_info.address.rgBytes[1],
113 bluetooth_adapter_info.address.rgBytes[0]);
114 powered_ = BluetoothIsConnectable(bluetooth_adapter_handle) ||
115 BluetoothIsDiscoverable(bluetooth_adapter_handle);
116 } else {
117 name_.clear();
118 address_.clear();
119 powered_ = false;
120 }
121 }
122
123 if (bluetooth_handle)
124 BluetoothFindRadioClose(bluetooth_handle);
125 } 93 }
126 94
127 void BluetoothAdapterWin::TrackDefaultAdapter() { 95 void BluetoothAdapterWin::TrackDefaultAdapter() {
128 PollAdapterState(); 96 task_manager_->StartThread();
129 }
130
131 void BluetoothAdapterWin::PollAdapterState() {
132 UpdateAdapterState();
133
134 MessageLoop::current()->PostDelayedTask(
135 FROM_HERE,
136 base::Bind(&BluetoothAdapterWin::PollAdapterState,
137 weak_ptr_factory_.GetWeakPtr()),
138 base::TimeDelta::FromMilliseconds(kPollIntervalMs));
139 } 97 }
140 98
141 } // namespace device 99 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698