OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
6 | |
7 #include <map> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/stl_util.h" | |
11 #include "chromeos/dbus/fake_bluetooth_device_client.h" | |
12 #include "dbus/bus.h" | |
13 #include "dbus/message.h" | |
14 #include "dbus/object_manager.h" | |
15 #include "dbus/object_proxy.h" | |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 FakeBluetoothInputClient::Properties::Properties( | |
21 const PropertyChangedCallback& callback) | |
22 : BluetoothInputClient::Properties( | |
23 NULL, | |
24 bluetooth_input::kBluetoothInputInterface, | |
25 callback) { | |
26 } | |
27 | |
28 FakeBluetoothInputClient::Properties::~Properties() { | |
29 } | |
30 | |
31 void FakeBluetoothInputClient::Properties::Get( | |
32 dbus::PropertyBase* property, | |
33 dbus::PropertySet::GetCallback callback) { | |
34 VLOG(1) << "Get " << property->name(); | |
35 callback.Run(false); | |
36 } | |
37 | |
38 void FakeBluetoothInputClient::Properties::GetAll() { | |
39 VLOG(1) << "GetAll"; | |
40 } | |
41 | |
42 void FakeBluetoothInputClient::Properties::Set( | |
43 dbus::PropertyBase *property, | |
44 dbus::PropertySet::SetCallback callback) { | |
45 VLOG(1) << "Set " << property->name(); | |
46 callback.Run(false); | |
47 } | |
48 | |
49 | |
50 FakeBluetoothInputClient::FakeBluetoothInputClient() { | |
51 } | |
52 | |
53 FakeBluetoothInputClient::~FakeBluetoothInputClient() { | |
54 // Clean up Properties structures | |
55 STLDeleteValues(&properties_map_); | |
56 } | |
57 | |
58 void FakeBluetoothInputClient::Init(dbus::Bus* bus) { | |
59 } | |
60 | |
61 void FakeBluetoothInputClient::AddObserver(Observer* observer) { | |
62 observers_.AddObserver(observer); | |
63 } | |
64 | |
65 void FakeBluetoothInputClient::RemoveObserver(Observer* observer) { | |
66 observers_.RemoveObserver(observer); | |
67 } | |
68 | |
69 FakeBluetoothInputClient::Properties* | |
70 FakeBluetoothInputClient::GetProperties(const dbus::ObjectPath& object_path) { | |
71 PropertiesMap::iterator iter = properties_map_.find(object_path); | |
72 if (iter != properties_map_.end()) | |
73 return iter->second; | |
74 return NULL; | |
75 } | |
76 | |
77 void FakeBluetoothInputClient::AddInputDevice( | |
78 const dbus::ObjectPath& object_path) { | |
79 if (properties_map_.find(object_path) != properties_map_.end()) | |
80 return; | |
81 | |
82 Properties* properties = new Properties(base::Bind( | |
83 &FakeBluetoothInputClient::OnPropertyChanged, | |
84 base::Unretained(this), | |
85 object_path)); | |
86 | |
87 // The LegacyAutopair and DisplayPinCode devices represent a typical mouse | |
88 // and keyboard respectively, so mark them as ReconnectMode "any". The | |
89 // DisplayPasskey device represents a Bluetooth 2.1+ keyboard and the | |
90 // ConnectUnpairable device represents a pre-standardization mouse, so mark | |
91 // them as ReconnectMode "device". | |
92 if (object_path.value() == FakeBluetoothDeviceClient::kDisplayPasskeyPath || | |
93 object_path.value() == | |
94 FakeBluetoothDeviceClient::kConnectUnpairablePath) { | |
95 properties->reconnect_mode.ReplaceValue( | |
96 bluetooth_input::kDeviceReconnectModeProperty); | |
97 } else { | |
98 properties->reconnect_mode.ReplaceValue( | |
99 bluetooth_input::kAnyReconnectModeProperty); | |
100 } | |
101 | |
102 properties_map_[object_path] = properties; | |
103 | |
104 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, | |
105 InputAdded(object_path)); | |
106 } | |
107 | |
108 void FakeBluetoothInputClient::RemoveInputDevice( | |
109 const dbus::ObjectPath& object_path) { | |
110 PropertiesMap::iterator it = properties_map_.find(object_path); | |
111 | |
112 if (it == properties_map_.end()) | |
113 return; | |
114 | |
115 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, | |
116 InputRemoved(object_path)); | |
117 | |
118 delete it->second; | |
119 properties_map_.erase(it); | |
120 } | |
121 | |
122 void FakeBluetoothInputClient::OnPropertyChanged( | |
123 const dbus::ObjectPath& object_path, | |
124 const std::string& property_name) { | |
125 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, | |
126 InputPropertyChanged(object_path, property_name)); | |
127 } | |
128 | |
129 } // namespace chromeos | |
OLD | NEW |