Skip to content

Commit

Permalink
Implemented BluetoothAdapterWin::IsPowered().
Browse files Browse the repository at this point in the history
I didn't include SetPowered() implementation here because SetPowered() requires a reference to bluetooth adapter handle and right now that is only created within the polling method. I will refactor this in the next CL to have BluetoothAdapterWin hold a bluetooth adapter handle pointer so that we can call SetPowered() using it.


BUG=135470


Review URL: https://chromiumcodereview.appspot.com/11420074

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168875 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
youngki@chromium.org committed Nov 20, 2012
1 parent 38c054d commit fbc7bb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
43 changes: 26 additions & 17 deletions device/bluetooth/bluetooth_adapter_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const int BluetoothAdapterWin::kPollIntervalMs = 500;

BluetoothAdapterWin::BluetoothAdapterWin()
: BluetoothAdapter(),
powered_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}

Expand All @@ -48,8 +49,7 @@ bool BluetoothAdapterWin::IsPresent() const {
}

bool BluetoothAdapterWin::IsPowered() const {
NOTIMPLEMENTED();
return false;
return powered_;
}

void BluetoothAdapterWin::SetPowered(
Expand Down Expand Up @@ -97,22 +97,31 @@ void BluetoothAdapterWin::UpdateAdapterState() {
HBLUETOOTH_RADIO_FIND bluetooth_adapter_handle = NULL;
BLUETOOTH_RADIO_INFO bluetooth_adapter_info =
{ sizeof(BLUETOOTH_RADIO_INFO), 0 };
BluetoothFindFirstRadio(&bluetooth_adapter_param, &bluetooth_adapter_handle);
if (bluetooth_adapter_handle &&
ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle,
&bluetooth_adapter_info)) {
name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName);
address_ = base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
bluetooth_adapter_info.address.rgBytes[5],
bluetooth_adapter_info.address.rgBytes[4],
bluetooth_adapter_info.address.rgBytes[3],
bluetooth_adapter_info.address.rgBytes[2],
bluetooth_adapter_info.address.rgBytes[1],
bluetooth_adapter_info.address.rgBytes[0]);
} else {
name_.clear();
address_.clear();
HBLUETOOTH_RADIO_FIND bluetooth_handle = BluetoothFindFirstRadio(
&bluetooth_adapter_param, &bluetooth_adapter_handle);

if (bluetooth_adapter_handle) {
if (ERROR_SUCCESS == BluetoothGetRadioInfo(bluetooth_adapter_handle,
&bluetooth_adapter_info)) {
name_ = base::SysWideToUTF8(bluetooth_adapter_info.szName);
address_ = base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
bluetooth_adapter_info.address.rgBytes[5],
bluetooth_adapter_info.address.rgBytes[4],
bluetooth_adapter_info.address.rgBytes[3],
bluetooth_adapter_info.address.rgBytes[2],
bluetooth_adapter_info.address.rgBytes[1],
bluetooth_adapter_info.address.rgBytes[0]);
powered_ = BluetoothIsConnectable(bluetooth_adapter_handle) ||
BluetoothIsDiscoverable(bluetooth_adapter_handle);
} else {
name_.clear();
address_.clear();
powered_ = false;
}
}

if (bluetooth_handle)
BluetoothFindRadioClose(bluetooth_handle);
}

void BluetoothAdapterWin::TrackDefaultAdapter() {
Expand Down
2 changes: 2 additions & 0 deletions device/bluetooth/bluetooth_adapter_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class BluetoothAdapterWin : public BluetoothAdapter {

static const int kPollIntervalMs;

bool powered_;

// NOTE: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
Expand Down

0 comments on commit fbc7bb6

Please sign in to comment.