summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc
blob: d7e25bc10f1dff60fbf59287b8cf28f354f964b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h"

#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/extensions/api/experimental_bluetooth.h"
#include "device/bluetooth/bluetooth_device.h"

namespace extensions {
namespace api {
namespace experimental_bluetooth {

// Fill in a Device object from a BluetoothDevice.
void BluetoothDeviceToApiDevice(const device::BluetoothDevice& device,
                                Device* out) {
  out->name = UTF16ToUTF8(device.GetName());
  out->address = device.address();
  out->paired = device.IsPaired();
  out->bonded = device.IsBonded();
  out->connected = device.IsConnected();
}

// The caller takes ownership of the returned pointer.
base::Value* BluetoothDeviceToValue(const device::BluetoothDevice& device) {
  extensions::api::experimental_bluetooth::Device api_device;
  BluetoothDeviceToApiDevice(device, &api_device);
  return api_device.ToValue().release();
}

}  // namespace experimental_bluetooth
}  // namespace api
}  // namespace extensions