Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: chromeos/dbus/fake_bluetooth_device_client.cc

Issue 14048007: Bluetooth: D-Bus client interface for org.bluez.Input1 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fake device simulates the input Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/fake_bluetooth_device_client.h" 5 #include "chromeos/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 19 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
20 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 20 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
21 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" 21 #include "chromeos/dbus/fake_bluetooth_agent_service_provider.h"
22 #include "chromeos/dbus/fake_bluetooth_input_client.h"
22 #include "dbus/object_path.h" 23 #include "dbus/object_path.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
24 25
25 namespace { 26 namespace {
26 27
27 // Default interval between simulated events. 28 // Default interval between simulated events.
28 const int kSimulationIntervalMs = 750; 29 const int kSimulationIntervalMs = 750;
29 30
30 } 31 }
31 32
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 410
410 PropertiesMap::iterator iter = properties_map_.find(device_path); 411 PropertiesMap::iterator iter = properties_map_.find(device_path);
411 Properties* properties = iter->second; 412 Properties* properties = iter->second;
412 413
413 VLOG(1) << "removing device: " << properties->alias.value(); 414 VLOG(1) << "removing device: " << properties->alias.value();
414 device_list_.erase(listiter); 415 device_list_.erase(listiter);
415 416
416 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, 417 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_,
417 DeviceRemoved(device_path)); 418 DeviceRemoved(device_path));
418 419
420 // Remove the Input interface if it exists.
421 FakeBluetoothInputClient* fake_bluetooth_input_client =
422 static_cast<FakeBluetoothInputClient*>(
423 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient());
424 fake_bluetooth_input_client->RemoveInputDevice(device_path);
425
419 delete properties; 426 delete properties;
420 properties_map_.erase(iter); 427 properties_map_.erase(iter);
421 } 428 }
422 429
423 void FakeBluetoothDeviceClient::OnPropertyChanged( 430 void FakeBluetoothDeviceClient::OnPropertyChanged(
424 const dbus::ObjectPath& object_path, 431 const dbus::ObjectPath& object_path,
425 const std::string& property_name) { 432 const std::string& property_name) {
426 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, 433 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_,
427 DevicePropertyChanged(object_path, property_name)); 434 DevicePropertyChanged(object_path, property_name));
428 } 435 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 if (pairing_cancelled_) { 628 if (pairing_cancelled_) {
622 pairing_cancelled_ = false; 629 pairing_cancelled_ = false;
623 630
624 error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled, 631 error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled,
625 "Cancaled"); 632 "Cancaled");
626 } else { 633 } else {
627 Properties* properties = GetProperties(object_path); 634 Properties* properties = GetProperties(object_path);
628 635
629 properties->paired.ReplaceValue(true); 636 properties->paired.ReplaceValue(true);
630 637
638 // If the paired device is a HID device based on it's bluetooth class,
639 // simulate the Input interface.
640 FakeBluetoothInputClient* fake_bluetooth_input_client =
641 static_cast<FakeBluetoothInputClient*>(
642 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient());
643
644 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) {
645 std::vector<std::string> uuids = properties->uuids.value();
646 if (std::find(uuids.begin(), uuids.end(),
647 "00001124-0000-1000-8000-00805f9b34fb") == uuids.end()) {
648 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
649 properties->uuids.ReplaceValue(uuids);
650 fake_bluetooth_input_client->AddInputDevice(object_path);
651 }
652 }
keybuk 2013/04/18 22:37:44 This also needs to be run in the Connect() functio
deymo 2013/04/18 23:21:02 CompleteSimulatedPairing is called also for the Mi
keybuk 2013/04/18 23:45:09 It is, but for the "test a connect failing after p
deymo 2013/04/19 01:23:22 Done.
653
631 callback.Run(); 654 callback.Run();
632 properties->NotifyPropertyChanged(properties->paired.name()); 655 properties->NotifyPropertyChanged(properties->paired.name());
633 } 656 }
634 } 657 }
635 658
636 void FakeBluetoothDeviceClient::TimeoutSimulatedPairing( 659 void FakeBluetoothDeviceClient::TimeoutSimulatedPairing(
637 const dbus::ObjectPath& object_path, 660 const dbus::ObjectPath& object_path,
638 const ErrorCallback& error_callback) { 661 const ErrorCallback& error_callback) {
639 VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value(); 662 VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value();
640 663
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 FROM_HERE, 821 FROM_HERE,
799 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, 822 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing,
800 base::Unretained(this), 823 base::Unretained(this),
801 object_path, callback, error_callback), 824 object_path, callback, error_callback),
802 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); 825 base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
803 826
804 } 827 }
805 } 828 }
806 829
807 } // namespace chromeos 830 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/experimental_bluetooth_input_client.cc ('k') | chromeos/dbus/fake_bluetooth_input_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698