Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chromeos/dbus/bluetooth_manager_client.h" | 5 #include "chromeos/dbus/bluetooth_manager_client.h" |
| 6 | 6 |
| 7 #include <vector> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 9 #include "chromeos/dbus/bluetooth_property.h" | 12 #include "chromeos/dbus/bluetooth_property.h" |
| 10 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
| 11 #include "dbus/message.h" | 14 #include "dbus/message.h" |
| 12 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 13 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
| 14 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 15 | 18 |
| 16 namespace chromeos { | 19 namespace chromeos { |
| 17 | 20 |
| 18 BluetoothManagerClient::Properties::Properties(dbus::ObjectProxy* object_proxy, | 21 BluetoothManagerClient::Properties::Properties(dbus::ObjectProxy* object_proxy, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 // List of observers interested in event notifications from us. | 266 // List of observers interested in event notifications from us. |
| 264 ObserverList<Observer> observers_; | 267 ObserverList<Observer> observers_; |
| 265 | 268 |
| 266 DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl); | 269 DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl); |
| 267 }; | 270 }; |
| 268 | 271 |
| 269 // The BluetoothManagerClient implementation used on Linux desktop, which does | 272 // The BluetoothManagerClient implementation used on Linux desktop, which does |
| 270 // nothing. | 273 // nothing. |
| 271 class BluetoothManagerClientStubImpl : public BluetoothManagerClient { | 274 class BluetoothManagerClientStubImpl : public BluetoothManagerClient { |
| 272 public: | 275 public: |
| 276 struct Properties : public BluetoothManagerClient::Properties { | |
| 277 explicit Properties(PropertyChangedCallback callback) | |
|
satorux1
2012/08/14 16:54:19
const &
keybuk
2012/08/14 17:40:32
Done.
| |
| 278 : BluetoothManagerClient::Properties(NULL, callback) { | |
| 279 } | |
| 280 | |
| 281 virtual ~Properties() { | |
| 282 } | |
| 283 | |
| 284 virtual void Get(dbus::PropertyBase* property, | |
| 285 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
| 286 VLOG(1) << "Get " << property->name(); | |
| 287 callback.Run(false); | |
| 288 } | |
| 289 | |
| 290 virtual void GetAll() OVERRIDE { | |
| 291 VLOG(1) << "GetAll"; | |
| 292 } | |
| 293 | |
| 294 virtual void Set(dbus::PropertyBase* property, | |
| 295 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
| 296 VLOG(1) << "Set " << property->name(); | |
| 297 callback.Run(false); | |
| 298 } | |
| 299 }; | |
| 300 | |
| 301 BluetoothManagerClientStubImpl() { | |
| 302 properties_.reset(new Properties(base::Bind( | |
| 303 &BluetoothManagerClientStubImpl::OnPropertyChanged, | |
| 304 base::Unretained(this)))); | |
| 305 | |
| 306 std::vector<dbus::ObjectPath> adapters; | |
| 307 adapters.push_back(dbus::ObjectPath("/fake/hci0")); | |
| 308 properties_->adapters.ReplaceValue(adapters); | |
| 309 } | |
| 310 | |
| 273 // BluetoothManagerClient override. | 311 // BluetoothManagerClient override. |
| 274 virtual void AddObserver(Observer* observer) OVERRIDE { | 312 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 313 observers_.AddObserver(observer); | |
| 275 } | 314 } |
| 276 | 315 |
| 277 // BluetoothManagerClient override. | 316 // BluetoothManagerClient override. |
| 278 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 317 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 318 observers_.RemoveObserver(observer); | |
| 279 } | 319 } |
| 280 | 320 |
| 281 // BluetoothManagerClient override. | 321 // BluetoothManagerClient override. |
| 282 virtual Properties* GetProperties() OVERRIDE { | 322 virtual Properties* GetProperties() OVERRIDE { |
| 283 VLOG(1) << "GetProperties"; | 323 VLOG(1) << "GetProperties"; |
| 284 return NULL; | 324 return properties_.get(); |
| 285 } | 325 } |
| 286 | 326 |
| 287 // BluetoothManagerClient override. | 327 // BluetoothManagerClient override. |
| 288 virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE { | 328 virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE { |
| 289 VLOG(1) << "DefaultAdapter."; | 329 VLOG(1) << "DefaultAdapter."; |
| 290 callback.Run(dbus::ObjectPath(), false); | 330 callback.Run(dbus::ObjectPath("/fake/hci0"), true); |
| 291 } | 331 } |
| 292 | 332 |
| 293 // BluetoothManagerClient override. | 333 // BluetoothManagerClient override. |
| 294 virtual void FindAdapter(const std::string& address, | 334 virtual void FindAdapter(const std::string& address, |
| 295 const AdapterCallback& callback) { | 335 const AdapterCallback& callback) { |
| 296 VLOG(1) << "FindAdapter: " << address; | 336 VLOG(1) << "FindAdapter: " << address; |
| 297 callback.Run(dbus::ObjectPath(), false); | 337 if (address == "hci0") |
| 338 callback.Run(dbus::ObjectPath("/fake/hci0"), true); | |
| 339 else | |
| 340 callback.Run(dbus::ObjectPath(), false); | |
| 298 } | 341 } |
| 342 | |
| 343 private: | |
| 344 void OnPropertyChanged(const std::string& property_name) { | |
| 345 FOR_EACH_OBSERVER(BluetoothManagerClient::Observer, observers_, | |
| 346 ManagerPropertyChanged(property_name)); | |
| 347 } | |
| 348 | |
| 349 // List of observers interested in event notifications from us. | |
| 350 ObserverList<Observer> observers_; | |
| 351 | |
| 352 // Static properties we return. | |
| 353 scoped_ptr<Properties> properties_; | |
| 299 }; | 354 }; |
| 300 | 355 |
| 301 BluetoothManagerClient::BluetoothManagerClient() { | 356 BluetoothManagerClient::BluetoothManagerClient() { |
| 302 } | 357 } |
| 303 | 358 |
| 304 BluetoothManagerClient::~BluetoothManagerClient() { | 359 BluetoothManagerClient::~BluetoothManagerClient() { |
| 305 } | 360 } |
| 306 | 361 |
| 307 BluetoothManagerClient* BluetoothManagerClient::Create( | 362 BluetoothManagerClient* BluetoothManagerClient::Create( |
| 308 DBusClientImplementationType type, | 363 DBusClientImplementationType type, |
| 309 dbus::Bus* bus) { | 364 dbus::Bus* bus) { |
| 310 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 365 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 311 return new BluetoothManagerClientImpl(bus); | 366 return new BluetoothManagerClientImpl(bus); |
| 312 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 367 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 313 return new BluetoothManagerClientStubImpl(); | 368 return new BluetoothManagerClientStubImpl(); |
| 314 } | 369 } |
| 315 | 370 |
| 316 } // namespace chromeos | 371 } // namespace chromeos |
| OLD | NEW |