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