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

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: Renamed properties to adapter state 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" 11 #include "base/threading/thread_checker.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 12
26 namespace device { 13 namespace device {
27 14
28 const int BluetoothAdapterWin::kPollIntervalMs = 500;
29
30 BluetoothAdapterWin::BluetoothAdapterWin() 15 BluetoothAdapterWin::BluetoothAdapterWin()
31 : BluetoothAdapter(), 16 : BluetoothAdapter(),
32 powered_(false), 17 powered_(false),
18 thread_(new BluetoothPollingThreadWin()),
19 thread_checker_(new base::ThreadChecker()),
33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 20 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
21 thread_->AddObserver(this);
34 } 22 }
35 23
36 BluetoothAdapterWin::~BluetoothAdapterWin() { 24 BluetoothAdapterWin::~BluetoothAdapterWin() {
25 thread_->RemoveObserver(this);
37 } 26 }
38 27
39 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { 28 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) {
40 NOTIMPLEMENTED(); 29 NOTIMPLEMENTED();
41 } 30 }
42 31
43 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { 32 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) {
44 NOTIMPLEMENTED(); 33 NOTIMPLEMENTED();
45 } 34 }
46 35
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 NOTIMPLEMENTED(); 75 NOTIMPLEMENTED();
87 return NULL; 76 return NULL;
88 } 77 }
89 78
90 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( 79 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData(
91 const BluetoothOutOfBandPairingDataCallback& callback, 80 const BluetoothOutOfBandPairingDataCallback& callback,
92 const ErrorCallback& error_callback) { 81 const ErrorCallback& error_callback) {
93 NOTIMPLEMENTED(); 82 NOTIMPLEMENTED();
94 } 83 }
95 84
96 void BluetoothAdapterWin::UpdateAdapterState() { 85 void BluetoothAdapterWin::AdapterStateChanged(
97 HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; 86 const BluetoothPollingThreadWin::AdapterState& state) {
98 BLUETOOTH_RADIO_INFO bluetooth_adapter_info = 87 DCHECK(thread_checker_->CalledOnValidThread());
99 { sizeof(BLUETOOTH_RADIO_INFO), 0 }; 88 name_ = state.name;
100 HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio( 89 address_ = state.address;
101 &bluetooth_adapter_param, &bluetooth_adapter_handle); 90 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 } 91 }
126 92
127 void BluetoothAdapterWin::TrackDefaultAdapter() { 93 void BluetoothAdapterWin::TrackDefaultAdapter() {
128 PollAdapterState(); 94 thread_->Init();
129 } 95 }
130 96
131 void BluetoothAdapterWin::PollAdapterState() { 97 void BluetoothAdapterWin::SetBluetoothPollingThreadForTest(
132 UpdateAdapterState(); 98 BluetoothPollingThreadWin* thread) {
133 99 thread_.reset(thread);
134 MessageLoop::current()->PostDelayedTask(
135 FROM_HERE,
136 base::Bind(&BluetoothAdapterWin::PollAdapterState,
137 weak_ptr_factory_.GetWeakPtr()),
138 base::TimeDelta::FromMilliseconds(kPollIntervalMs));
139 } 100 }
140 101
141 } // namespace device 102 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698