Home | History | Annotate | Download | only in bluetooth
      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
      3 // found in the LICENSE file.
      4 
      5 #include "device/bluetooth/bluetooth_adapter.h"
      6 
      7 #include "base/stl_util.h"
      8 #include "device/bluetooth/bluetooth_device.h"
      9 
     10 namespace device {
     11 
     12 BluetoothAdapter::BluetoothAdapter() {
     13 }
     14 
     15 BluetoothAdapter::~BluetoothAdapter() {
     16   STLDeleteValues(&devices_);
     17 }
     18 
     19 BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() {
     20   ConstDeviceList const_devices =
     21     const_cast<const BluetoothAdapter *>(this)->GetDevices();
     22 
     23   DeviceList devices;
     24   for (ConstDeviceList::const_iterator i = const_devices.begin();
     25        i != const_devices.end(); ++i)
     26     devices.push_back(const_cast<BluetoothDevice *>(*i));
     27 
     28   return devices;
     29 }
     30 
     31 BluetoothAdapter::ConstDeviceList BluetoothAdapter::GetDevices() const {
     32   ConstDeviceList devices;
     33   for (DevicesMap::const_iterator iter = devices_.begin();
     34        iter != devices_.end();
     35        ++iter)
     36     devices.push_back(iter->second);
     37 
     38   return devices;
     39 }
     40 
     41 BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) {
     42   return const_cast<BluetoothDevice *>(
     43       const_cast<const BluetoothAdapter *>(this)->GetDevice(address));
     44 }
     45 
     46 const BluetoothDevice* BluetoothAdapter::GetDevice(
     47     const std::string& address) const {
     48   DevicesMap::const_iterator iter = devices_.find(address);
     49   if (iter != devices_.end())
     50     return iter->second;
     51 
     52   return NULL;
     53 }
     54 
     55 }  // namespace device
     56