OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 9 |
| 10 namespace chromeos { |
| 11 |
| 12 class BluetoothDeviceImpl : public BluetoothDevice { |
| 13 public: |
| 14 BluetoothDeviceImpl(const std::string& address, |
| 15 uint32 bluetooth_class, |
| 16 const std::string& icon, |
| 17 const std::string& name, |
| 18 bool paired, |
| 19 const DictionaryValue& properties) |
| 20 : address_(address), |
| 21 bluetooth_class_(bluetooth_class), |
| 22 icon_(icon), |
| 23 name_(name), |
| 24 paired_(paired), |
| 25 dictionary_rep_(properties.DeepCopy()) { |
| 26 CHECK(dictionary_rep_ != NULL); |
| 27 } |
| 28 |
| 29 virtual ~BluetoothDeviceImpl() { |
| 30 delete dictionary_rep_; |
| 31 } |
| 32 |
| 33 virtual const std::string& address() const { |
| 34 return address_; |
| 35 } |
| 36 |
| 37 virtual uint32 bluetooth_class() const { |
| 38 return bluetooth_class_; |
| 39 } |
| 40 |
| 41 virtual const std::string& icon() const { |
| 42 return icon_; |
| 43 } |
| 44 |
| 45 virtual const std::string& name() const { |
| 46 return name_; |
| 47 } |
| 48 |
| 49 virtual bool paired() const { |
| 50 return paired_; |
| 51 } |
| 52 |
| 53 virtual const DictionaryValue& dictionary_rep() const { |
| 54 CHECK(dictionary_rep_ != NULL); |
| 55 return *dictionary_rep_; |
| 56 } |
| 57 |
| 58 private: |
| 59 const std::string address_; |
| 60 uint32 bluetooth_class_; |
| 61 const std::string icon_; |
| 62 const std::string name_; |
| 63 bool paired_; |
| 64 DictionaryValue* dictionary_rep_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceImpl); |
| 67 }; |
| 68 |
| 69 BluetoothDevice::BluetoothDevice() { |
| 70 } |
| 71 |
| 72 BluetoothDevice::~BluetoothDevice() { |
| 73 } |
| 74 |
| 75 // static |
| 76 BluetoothDevice* BluetoothDevice::Create(const DictionaryValue& properties) { |
| 77 std::string address; |
| 78 uint32 bluetooth_class = 0; |
| 79 std::string icon; |
| 80 std::string name; |
| 81 bool paired = false; |
| 82 |
| 83 if (!properties.GetString(bluetooth_device::kAddressProperty, &address)) { |
| 84 LOG(ERROR) << "No address property"; |
| 85 return NULL; // mandatory |
| 86 } |
| 87 VLOG(1) << "address = " << address; |
| 88 |
| 89 // Note: DictionaryValue is Javascript-oriented and doesn't support unsigned |
| 90 // integers. |
| 91 if (!properties.GetInteger(bluetooth_device::kClassProperty, |
| 92 reinterpret_cast<int*>(&bluetooth_class))) { |
| 93 LOG(ERROR) << "No bluetooth_class property"; |
| 94 return NULL; // mandatory |
| 95 } |
| 96 VLOG(1) << "bluetooth_class = " << bluetooth_class; |
| 97 |
| 98 if (!properties.GetString(bluetooth_device::kIconProperty, &icon)) { |
| 99 LOG(WARNING) << "No icon property"; |
| 100 } |
| 101 VLOG(1) << "icon = " << icon; |
| 102 |
| 103 if (!properties.GetString(bluetooth_device::kNameProperty, &name)) { |
| 104 LOG(WARNING) << "No name property. Substituting MAC address."; |
| 105 // Populate name with mac address so that UI doesn't display a blank name. |
| 106 name = address; |
| 107 } |
| 108 VLOG(1) << "name = " << name; |
| 109 |
| 110 if (!properties.GetBoolean(bluetooth_device::kPairedProperty, &paired)) { |
| 111 LOG(ERROR) << "No paired property"; |
| 112 return NULL; // mandatory |
| 113 } |
| 114 |
| 115 return new BluetoothDeviceImpl(address, bluetooth_class, icon, name, paired, |
| 116 properties); |
| 117 } |
| 118 |
| 119 } // namespace chromeos |
OLD | NEW |