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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_bluetooth_input_client.h"
9 #include "base/logging.h"
10 #include "base/stl_util.h"
11 #include "chromeos/dbus/fake_bluetooth_device_client.h"
13 #include "dbus/message.h"
14 #include "dbus/object_manager.h"
15 #include "dbus/object_path.h"
16 #include "dbus/object_proxy.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h"
21 FakeBluetoothInputClient::Properties::Properties(
22 const PropertyChangedCallback& callback)
23 : BluetoothInputClient::Properties(
25 bluetooth_input::kBluetoothInputInterface,
29 FakeBluetoothInputClient::Properties::~Properties() {
32 void FakeBluetoothInputClient::Properties::Get(
33 dbus::PropertyBase* property,
34 dbus::PropertySet::GetCallback callback) {
35 VLOG(1) << "Get " << property->name();
39 void FakeBluetoothInputClient::Properties::GetAll() {
43 void FakeBluetoothInputClient::Properties::Set(
44 dbus::PropertyBase *property,
45 dbus::PropertySet::SetCallback callback) {
46 VLOG(1) << "Set " << property->name();
51 FakeBluetoothInputClient::FakeBluetoothInputClient() {
54 FakeBluetoothInputClient::~FakeBluetoothInputClient() {
55 // Clean up Properties structures
56 STLDeleteValues(&properties_map_);
59 void FakeBluetoothInputClient::Init(dbus::Bus* bus) {
62 void FakeBluetoothInputClient::AddObserver(Observer* observer) {
63 observers_.AddObserver(observer);
66 void FakeBluetoothInputClient::RemoveObserver(Observer* observer) {
67 observers_.RemoveObserver(observer);
70 FakeBluetoothInputClient::Properties*
71 FakeBluetoothInputClient::GetProperties(const dbus::ObjectPath& object_path) {
72 PropertiesMap::iterator iter = properties_map_.find(object_path);
73 if (iter != properties_map_.end())
78 void FakeBluetoothInputClient::AddInputDevice(
79 const dbus::ObjectPath& object_path) {
80 if (properties_map_.find(object_path) != properties_map_.end())
83 Properties* properties = new Properties(base::Bind(
84 &FakeBluetoothInputClient::OnPropertyChanged,
85 base::Unretained(this),
88 // Mark Apple mouse and keyboard as ReconnectMode "any" and the Motorola and
89 // Microsoft devices as ReconnectMode "device".
90 if (object_path.value() == FakeBluetoothDeviceClient::kMotorolaKeyboardPath ||
91 object_path.value() == FakeBluetoothDeviceClient::kMicrosoftMousePath) {
92 properties->reconnect_mode.ReplaceValue(
93 bluetooth_input::kDeviceReconnectModeProperty);
95 properties->reconnect_mode.ReplaceValue(
96 bluetooth_input::kAnyReconnectModeProperty);
99 properties_map_[object_path] = properties;
101 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_,
102 InputAdded(object_path));
105 void FakeBluetoothInputClient::RemoveInputDevice(
106 const dbus::ObjectPath& object_path) {
107 PropertiesMap::iterator it = properties_map_.find(object_path);
109 if (it == properties_map_.end())
112 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_,
113 InputRemoved(object_path));
116 properties_map_.erase(it);
119 void FakeBluetoothInputClient::OnPropertyChanged(
120 const dbus::ObjectPath& object_path,
121 const std::string& property_name) {
122 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_,
123 InputPropertyChanged(object_path, property_name));
126 } // namespace chromeos