OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_gatt_descriptor_client.h" | 5 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "third_party/cros_system_api/dbus/service_constants.h" | 11 #include "third_party/cros_system_api/dbus/service_constants.h" |
10 | 12 |
11 namespace chromeos { | 13 namespace chromeos { |
12 | 14 |
13 const char FakeBluetoothGattDescriptorClient:: | 15 const char FakeBluetoothGattDescriptorClient:: |
14 kClientCharacteristicConfigurationPathComponent[] = "desc0000"; | 16 kClientCharacteristicConfigurationPathComponent[] = "desc0000"; |
15 const char FakeBluetoothGattDescriptorClient:: | 17 const char FakeBluetoothGattDescriptorClient:: |
16 kClientCharacteristicConfigurationUUID[] = | 18 kClientCharacteristicConfigurationUUID[] = |
17 "00002902-0000-1000-8000-00805f9b34fb"; | 19 "00002902-0000-1000-8000-00805f9b34fb"; |
18 | 20 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 void FakeBluetoothGattDescriptorClient::ReadValue( | 96 void FakeBluetoothGattDescriptorClient::ReadValue( |
95 const dbus::ObjectPath& object_path, | 97 const dbus::ObjectPath& object_path, |
96 const ValueCallback& callback, | 98 const ValueCallback& callback, |
97 const ErrorCallback& error_callback) { | 99 const ErrorCallback& error_callback) { |
98 PropertiesMap::iterator iter = properties_.find(object_path); | 100 PropertiesMap::iterator iter = properties_.find(object_path); |
99 if (iter == properties_.end()) { | 101 if (iter == properties_.end()) { |
100 error_callback.Run(kUnknownDescriptorError, ""); | 102 error_callback.Run(kUnknownDescriptorError, ""); |
101 return; | 103 return; |
102 } | 104 } |
103 | 105 |
104 callback.Run(iter->second->value); | 106 // Assign the value of the descriptor as necessary |
| 107 Properties* properties = iter->second->properties.get(); |
| 108 if (properties->uuid.value() == kClientCharacteristicConfigurationUUID) { |
| 109 BluetoothGattCharacteristicClient::Properties* chrc_props = |
| 110 DBusThreadManager::Get() |
| 111 ->GetBluetoothGattCharacteristicClient() |
| 112 ->GetProperties(properties->characteristic.value()); |
| 113 DCHECK(chrc_props); |
| 114 |
| 115 uint8_t value_byte = chrc_props->notifying.value() ? 0x01 : 0x00; |
| 116 const std::vector<uint8_t>& cur_value = properties->value.value(); |
| 117 |
| 118 if (!cur_value.size() || cur_value[0] != value_byte) { |
| 119 std::vector<uint8_t> value = {value_byte, 0x00}; |
| 120 properties->value.ReplaceValue(value); |
| 121 } |
| 122 } |
| 123 |
| 124 callback.Run(iter->second->properties->value.value()); |
105 } | 125 } |
106 | 126 |
107 void FakeBluetoothGattDescriptorClient::WriteValue( | 127 void FakeBluetoothGattDescriptorClient::WriteValue( |
108 const dbus::ObjectPath& object_path, | 128 const dbus::ObjectPath& object_path, |
109 const std::vector<uint8>& value, | 129 const std::vector<uint8>& value, |
110 const base::Closure& callback, | 130 const base::Closure& callback, |
111 const ErrorCallback& error_callback) { | 131 const ErrorCallback& error_callback) { |
112 if (properties_.find(object_path) == properties_.end()) { | 132 if (properties_.find(object_path) == properties_.end()) { |
113 error_callback.Run(kUnknownDescriptorError, ""); | 133 error_callback.Run(kUnknownDescriptorError, ""); |
114 return; | 134 return; |
(...skipping 29 matching lines...) Expand all Loading... |
144 Properties* properties = new Properties(base::Bind( | 164 Properties* properties = new Properties(base::Bind( |
145 &FakeBluetoothGattDescriptorClient::OnPropertyChanged, | 165 &FakeBluetoothGattDescriptorClient::OnPropertyChanged, |
146 weak_ptr_factory_.GetWeakPtr(), | 166 weak_ptr_factory_.GetWeakPtr(), |
147 object_path)); | 167 object_path)); |
148 properties->uuid.ReplaceValue(uuid); | 168 properties->uuid.ReplaceValue(uuid); |
149 properties->characteristic.ReplaceValue(characteristic_path); | 169 properties->characteristic.ReplaceValue(characteristic_path); |
150 | 170 |
151 DescriptorData* data = new DescriptorData(); | 171 DescriptorData* data = new DescriptorData(); |
152 data->properties.reset(properties); | 172 data->properties.reset(properties); |
153 | 173 |
154 data->value.push_back(1); // Notifications enabled. | |
155 data->value.push_back(0); | |
156 | |
157 properties_[object_path] = data; | 174 properties_[object_path] = data; |
158 | 175 |
159 NotifyDescriptorAdded(object_path); | 176 NotifyDescriptorAdded(object_path); |
160 | 177 |
161 return object_path; | 178 return object_path; |
162 } | 179 } |
163 | 180 |
164 void FakeBluetoothGattDescriptorClient::HideDescriptor( | 181 void FakeBluetoothGattDescriptorClient::HideDescriptor( |
165 const dbus::ObjectPath& descriptor_path) { | 182 const dbus::ObjectPath& descriptor_path) { |
166 PropertiesMap::iterator iter = properties_.find(descriptor_path); | 183 PropertiesMap::iterator iter = properties_.find(descriptor_path); |
(...skipping 24 matching lines...) Expand all Loading... |
191 GattDescriptorAdded(object_path)); | 208 GattDescriptorAdded(object_path)); |
192 } | 209 } |
193 | 210 |
194 void FakeBluetoothGattDescriptorClient::NotifyDescriptorRemoved( | 211 void FakeBluetoothGattDescriptorClient::NotifyDescriptorRemoved( |
195 const dbus::ObjectPath& object_path) { | 212 const dbus::ObjectPath& object_path) { |
196 FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, | 213 FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, |
197 GattDescriptorRemoved(object_path)); | 214 GattDescriptorRemoved(object_path)); |
198 } | 215 } |
199 | 216 |
200 } // namespace chromeos | 217 } // namespace chromeos |
OLD | NEW |