OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/experimental_bluetooth_device_client.h" | 5 #include "chromeos/dbus/experimental_bluetooth_device_client.h" |
6 | 6 |
7 #include <map> | |
8 #include <utility> | |
9 | |
10 #include "base/bind.h" | 7 #include "base/bind.h" |
11 #include "base/logging.h" | 8 #include "base/logging.h" |
12 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
13 #include "chromeos/dbus/bluetooth_property.h" | 10 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
14 #include "dbus/bus.h" | 11 #include "dbus/bus.h" |
15 #include "dbus/message.h" | 12 #include "dbus/message.h" |
16 #include "dbus/object_manager.h" | 13 #include "dbus/object_manager.h" |
17 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 17 |
21 namespace chromeos { | 18 namespace chromeos { |
22 | 19 |
23 const char ExperimentalBluetoothDeviceClient::kNoResponseError[] = | 20 const char ExperimentalBluetoothDeviceClient::kNoResponseError[] = |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 333 |
337 // Weak pointer factory for generating 'this' pointers that might live longer | 334 // Weak pointer factory for generating 'this' pointers that might live longer |
338 // than we do. | 335 // than we do. |
339 // Note: This should remain the last member so it'll be destroyed and | 336 // Note: This should remain the last member so it'll be destroyed and |
340 // invalidate its weak pointers before any other members are destroyed. | 337 // invalidate its weak pointers before any other members are destroyed. |
341 base::WeakPtrFactory<ExperimentalBluetoothDeviceClientImpl> weak_ptr_factory_; | 338 base::WeakPtrFactory<ExperimentalBluetoothDeviceClientImpl> weak_ptr_factory_; |
342 | 339 |
343 DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothDeviceClientImpl); | 340 DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothDeviceClientImpl); |
344 }; | 341 }; |
345 | 342 |
346 // The ExperimentalBluetoothDeviceClient implementation used on Linux desktop, | |
347 // which does nothing. | |
348 class ExperimentalBluetoothDeviceClientStubImpl | |
349 : public ExperimentalBluetoothDeviceClient { | |
350 public: | |
351 struct Properties : public ExperimentalBluetoothDeviceClient::Properties { | |
352 explicit Properties(const PropertyChangedCallback& callback) | |
353 : ExperimentalBluetoothDeviceClient::Properties( | |
354 NULL, | |
355 bluetooth_device::kExperimentalBluetoothDeviceInterface, | |
356 callback) { | |
357 } | |
358 | |
359 virtual ~Properties() { | |
360 } | |
361 | |
362 virtual void Get(dbus::PropertyBase* property, | |
363 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
364 VLOG(1) << "Get " << property->name(); | |
365 callback.Run(false); | |
366 } | |
367 | |
368 virtual void GetAll() OVERRIDE { | |
369 VLOG(1) << "GetAll"; | |
370 } | |
371 | |
372 virtual void Set(dbus::PropertyBase *property, | |
373 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
374 VLOG(1) << "Set " << property->name(); | |
375 callback.Run(false); | |
376 } | |
377 }; | |
378 | |
379 ExperimentalBluetoothDeviceClientStubImpl() { | |
380 dbus::ObjectPath dev0("/fake/hci0/dev0"); | |
381 | |
382 Properties* properties = new Properties(base::Bind( | |
383 &ExperimentalBluetoothDeviceClientStubImpl::OnPropertyChanged, | |
384 base::Unretained(this), | |
385 dev0)); | |
386 properties->address.ReplaceValue("00:11:22:33:44:55"); | |
387 properties->name.ReplaceValue("Fake Device"); | |
388 properties->paired.ReplaceValue(true); | |
389 properties->trusted.ReplaceValue(true); | |
390 | |
391 properties_map_[dev0] = properties; | |
392 } | |
393 | |
394 virtual ~ExperimentalBluetoothDeviceClientStubImpl() { | |
395 // Clean up Properties structures | |
396 STLDeleteValues(&properties_map_); | |
397 } | |
398 | |
399 // ExperimentalBluetoothDeviceClient override. | |
400 virtual void AddObserver(Observer* observer) OVERRIDE { | |
401 observers_.AddObserver(observer); | |
402 } | |
403 | |
404 // ExperimentalBluetoothDeviceClient override. | |
405 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
406 observers_.RemoveObserver(observer); | |
407 } | |
408 | |
409 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( | |
410 const dbus::ObjectPath& adapter_path) OVERRIDE { | |
411 std::vector<dbus::ObjectPath> object_paths; | |
412 if (adapter_path.value() == "/fake/hci0") | |
413 object_paths.push_back(dbus::ObjectPath("/fake/hci0/dev0")); | |
414 return object_paths; | |
415 } | |
416 | |
417 // ExperimentalBluetoothDeviceClient override. | |
418 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | |
419 OVERRIDE { | |
420 VLOG(1) << "GetProperties: " << object_path.value(); | |
421 PropertiesMap::iterator iter = properties_map_.find(object_path); | |
422 if (iter != properties_map_.end()) | |
423 return iter->second; | |
424 return NULL; | |
425 } | |
426 | |
427 // ExperimentalBluetoothDeviceClient override. | |
428 virtual void Connect(const dbus::ObjectPath& object_path, | |
429 const base::Closure& callback, | |
430 const ErrorCallback& error_callback) OVERRIDE { | |
431 VLOG(1) << "Connect: " << object_path.value(); | |
432 error_callback.Run(kNoResponseError, ""); | |
433 } | |
434 | |
435 // ExperimentalBluetoothDeviceClient override. | |
436 virtual void Disconnect(const dbus::ObjectPath& object_path, | |
437 const base::Closure& callback, | |
438 const ErrorCallback& error_callback) OVERRIDE { | |
439 VLOG(1) << "Disconnect: " << object_path.value(); | |
440 error_callback.Run(kNoResponseError, ""); | |
441 } | |
442 | |
443 // ExperimentalBluetoothDeviceClient override. | |
444 virtual void ConnectProfile(const dbus::ObjectPath& object_path, | |
445 const std::string& uuid, | |
446 const base::Closure& callback, | |
447 const ErrorCallback& error_callback) | |
448 OVERRIDE { | |
449 VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; | |
450 error_callback.Run(kNoResponseError, ""); | |
451 } | |
452 | |
453 // ExperimentalBluetoothDeviceClient override. | |
454 virtual void DisconnectProfile(const dbus::ObjectPath& object_path, | |
455 const std::string& uuid, | |
456 const base::Closure& callback, | |
457 const ErrorCallback& error_callback) | |
458 OVERRIDE { | |
459 VLOG(1) << "DisconnectProfile: " << object_path.value() << " " << uuid; | |
460 error_callback.Run(kNoResponseError, ""); | |
461 } | |
462 | |
463 // ExperimentalBluetoothDeviceClient override. | |
464 virtual void Pair(const dbus::ObjectPath& object_path, | |
465 const base::Closure& callback, | |
466 const ErrorCallback& error_callback) OVERRIDE { | |
467 VLOG(1) << "Pair: " << object_path.value(); | |
468 error_callback.Run(kNoResponseError, ""); | |
469 } | |
470 | |
471 // ExperimentalBluetoothDeviceClient override. | |
472 virtual void CancelPairing(const dbus::ObjectPath& object_path, | |
473 const base::Closure& callback, | |
474 const ErrorCallback& error_callback) | |
475 OVERRIDE { | |
476 VLOG(1) << "CancelPairing: " << object_path.value(); | |
477 error_callback.Run(kNoResponseError, ""); | |
478 } | |
479 | |
480 private: | |
481 void OnPropertyChanged(dbus::ObjectPath object_path, | |
482 const std::string& property_name) { | |
483 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, | |
484 DevicePropertyChanged(object_path, property_name)); | |
485 } | |
486 | |
487 // List of observers interested in event notifications from us. | |
488 ObserverList<Observer> observers_; | |
489 | |
490 // Static properties we typedef. | |
491 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; | |
492 PropertiesMap properties_map_; | |
493 }; | |
494 | |
495 ExperimentalBluetoothDeviceClient::ExperimentalBluetoothDeviceClient() { | 343 ExperimentalBluetoothDeviceClient::ExperimentalBluetoothDeviceClient() { |
496 } | 344 } |
497 | 345 |
498 ExperimentalBluetoothDeviceClient::~ExperimentalBluetoothDeviceClient() { | 346 ExperimentalBluetoothDeviceClient::~ExperimentalBluetoothDeviceClient() { |
499 } | 347 } |
500 | 348 |
501 ExperimentalBluetoothDeviceClient* ExperimentalBluetoothDeviceClient::Create( | 349 ExperimentalBluetoothDeviceClient* ExperimentalBluetoothDeviceClient::Create( |
502 DBusClientImplementationType type, | 350 DBusClientImplementationType type, |
503 dbus::Bus* bus) { | 351 dbus::Bus* bus) { |
504 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 352 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
505 return new ExperimentalBluetoothDeviceClientImpl(bus); | 353 return new ExperimentalBluetoothDeviceClientImpl(bus); |
506 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 354 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
507 return new ExperimentalBluetoothDeviceClientStubImpl(); | 355 return new FakeBluetoothDeviceClient(); |
508 } | 356 } |
509 | 357 |
510 } // namespace chromeos | 358 } // namespace chromeos |
OLD | NEW |