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

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: Use Observer pattern Created 8 years, 1 month 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 thread_(new BluetoothPollingThreadWin()),
18 adapter_handle_(NULL),
33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 19 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
20 thread_->AddObserver(this);
34 } 21 }
35 22
36 BluetoothAdapterWin::~BluetoothAdapterWin() { 23 BluetoothAdapterWin::~BluetoothAdapterWin() {
24 thread_->RemoveObserver(this);
37 } 25 }
38 26
39 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) { 27 void BluetoothAdapterWin::AddObserver(BluetoothAdapter::Observer* observer) {
40 NOTIMPLEMENTED(); 28 NOTIMPLEMENTED();
41 } 29 }
42 30
43 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { 31 void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) {
44 NOTIMPLEMENTED(); 32 NOTIMPLEMENTED();
45 } 33 }
46 34
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 NOTIMPLEMENTED(); 74 NOTIMPLEMENTED();
87 return NULL; 75 return NULL;
88 } 76 }
89 77
90 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData( 78 void BluetoothAdapterWin::ReadLocalOutOfBandPairingData(
91 const BluetoothOutOfBandPairingDataCallback& callback, 79 const BluetoothOutOfBandPairingDataCallback& callback,
92 const ErrorCallback& error_callback) { 80 const ErrorCallback& error_callback) {
93 NOTIMPLEMENTED(); 81 NOTIMPLEMENTED();
94 } 82 }
95 83
96 void BluetoothAdapterWin::UpdateAdapterState() { 84 void BluetoothAdapterWin::AdapterPropertyChanged(
97 HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL; 85 const BluetoothPollingThreadWin::Properties& properties) {
bryeung 2012/11/23 13:32:22 CHECK the thread here
youngki 2012/11/23 18:26:38 Done.
98 BLUETOOTH_RADIO_INFO bluetooth_adapter_info = 86 name_ = properties.name;
99 { sizeof(BLUETOOTH_RADIO_INFO), 0 }; 87 address_ = properties.address;
100 HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio( 88 powered_ = properties.powered;
101 &bluetooth_adapter_param, &bluetooth_adapter_handle);
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 } 89 }
126 90
127 void BluetoothAdapterWin::TrackDefaultAdapter() { 91 void BluetoothAdapterWin::TrackDefaultAdapter() {
128 PollAdapterState(); 92 thread_->Init();
129 } 93 }
130 94
131 void BluetoothAdapterWin::PollAdapterState() { 95 void BluetoothAdapterWin::SetBluetoothPollingThreadForTest(
132 UpdateAdapterState(); 96 BluetoothPollingThreadWin* thread) {
133 97 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 } 98 }
140 99
141 } // namespace device 100 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698