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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 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/bluetooth_gatt_descriptor_service_provider.h" 5 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.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 "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_service_provider.h"
14 #include "dbus/exported_object.h" 12 #include "dbus/exported_object.h"
15 #include "dbus/message.h" 13 #include "dbus/message.h"
14 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
15 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider. h"
16 #include "third_party/cros_system_api/dbus/service_constants.h" 16 #include "third_party/cros_system_api/dbus/service_constants.h"
17 17
18 namespace chromeos { 18 namespace bluez {
19 namespace { 19 namespace {
20 const char kErrorInvalidArgs[] = 20 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs";
21 "org.freedesktop.DBus.Error.InvalidArgs";
22 const char kErrorPropertyReadOnly[] = 21 const char kErrorPropertyReadOnly[] =
23 "org.freedesktop.DBus.Error.PropertyReadOnly"; 22 "org.freedesktop.DBus.Error.PropertyReadOnly";
24 const char kErrorFailed[] = 23 const char kErrorFailed[] = "org.freedesktop.DBus.Error.Failed";
25 "org.freedesktop.DBus.Error.Failed";
26 } // namespace 24 } // namespace
27 25
28 // The BluetoothGattDescriptorServiceProvider implementation used in production. 26 // The BluetoothGattDescriptorServiceProvider implementation used in production.
29 class BluetoothGattDescriptorServiceProviderImpl 27 class BluetoothGattDescriptorServiceProviderImpl
30 : public BluetoothGattDescriptorServiceProvider { 28 : public BluetoothGattDescriptorServiceProvider {
31 public: 29 public:
32 BluetoothGattDescriptorServiceProviderImpl( 30 BluetoothGattDescriptorServiceProviderImpl(
33 dbus::Bus* bus, 31 dbus::Bus* bus,
34 const dbus::ObjectPath& object_path, 32 const dbus::ObjectPath& object_path,
35 Delegate* delegate, 33 Delegate* delegate,
(...skipping 14 matching lines...) Expand all
50 DCHECK(!uuid_.empty()); 48 DCHECK(!uuid_.empty());
51 DCHECK(object_path_.IsValid()); 49 DCHECK(object_path_.IsValid());
52 DCHECK(characteristic_path_.IsValid()); 50 DCHECK(characteristic_path_.IsValid());
53 DCHECK(base::StartsWith(object_path_.value(), 51 DCHECK(base::StartsWith(object_path_.value(),
54 characteristic_path_.value() + "/", 52 characteristic_path_.value() + "/",
55 base::CompareCase::SENSITIVE)); 53 base::CompareCase::SENSITIVE));
56 54
57 exported_object_ = bus_->GetExportedObject(object_path_); 55 exported_object_ = bus_->GetExportedObject(object_path_);
58 56
59 exported_object_->ExportMethod( 57 exported_object_->ExportMethod(
60 dbus::kDBusPropertiesInterface, 58 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGet,
61 dbus::kDBusPropertiesGet,
62 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::Get, 59 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::Get,
63 weak_ptr_factory_.GetWeakPtr()), 60 weak_ptr_factory_.GetWeakPtr()),
64 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported, 61 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
65 weak_ptr_factory_.GetWeakPtr())); 62 weak_ptr_factory_.GetWeakPtr()));
66 63
67 exported_object_->ExportMethod( 64 exported_object_->ExportMethod(
68 dbus::kDBusPropertiesInterface, 65 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesSet,
69 dbus::kDBusPropertiesSet,
70 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::Set, 66 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::Set,
71 weak_ptr_factory_.GetWeakPtr()), 67 weak_ptr_factory_.GetWeakPtr()),
72 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported, 68 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
73 weak_ptr_factory_.GetWeakPtr())); 69 weak_ptr_factory_.GetWeakPtr()));
74 70
75 exported_object_->ExportMethod( 71 exported_object_->ExportMethod(
76 dbus::kDBusPropertiesInterface, 72 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGetAll,
77 dbus::kDBusPropertiesGetAll,
78 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::GetAll, 73 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::GetAll,
79 weak_ptr_factory_.GetWeakPtr()), 74 weak_ptr_factory_.GetWeakPtr()),
80 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported, 75 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
81 weak_ptr_factory_.GetWeakPtr())); 76 weak_ptr_factory_.GetWeakPtr()));
82 } 77 }
83 78
84 ~BluetoothGattDescriptorServiceProviderImpl() override { 79 ~BluetoothGattDescriptorServiceProviderImpl() override {
85 VLOG(1) << "Cleaning up Bluetooth GATT characteristic descriptor: " 80 VLOG(1) << "Cleaning up Bluetooth GATT characteristic descriptor: "
86 << object_path_.value(); 81 << object_path_.value();
87 bus_->UnregisterExportedObject(object_path_); 82 bus_->UnregisterExportedObject(object_path_);
88 } 83 }
89 84
90 // BluetoothGattDescriptorServiceProvider override. 85 // BluetoothGattDescriptorServiceProvider override.
91 void SendValueChanged(const std::vector<uint8>& value) override { 86 void SendValueChanged(const std::vector<uint8>& value) override {
92 VLOG(2) << "Emitting a PropertiesChanged signal for descriptor value."; 87 VLOG(2) << "Emitting a PropertiesChanged signal for descriptor value.";
93 dbus::Signal signal( 88 dbus::Signal signal(dbus::kDBusPropertiesInterface,
94 dbus::kDBusPropertiesInterface, 89 dbus::kDBusPropertiesChangedSignal);
95 dbus::kDBusPropertiesChangedSignal);
96 dbus::MessageWriter writer(&signal); 90 dbus::MessageWriter writer(&signal);
97 dbus::MessageWriter array_writer(NULL); 91 dbus::MessageWriter array_writer(NULL);
98 dbus::MessageWriter dict_entry_writer(NULL); 92 dbus::MessageWriter dict_entry_writer(NULL);
99 dbus::MessageWriter variant_writer(NULL); 93 dbus::MessageWriter variant_writer(NULL);
100 94
101 // interface_name 95 // interface_name
102 writer.AppendString( 96 writer.AppendString(
103 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface); 97 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface);
104 98
105 // changed_properties 99 // changed_properties
(...skipping 25 matching lines...) Expand all
131 dbus::ExportedObject::ResponseSender response_sender) { 125 dbus::ExportedObject::ResponseSender response_sender) {
132 VLOG(2) << "BluetoothGattDescriptorServiceProvider::Get: " 126 VLOG(2) << "BluetoothGattDescriptorServiceProvider::Get: "
133 << object_path_.value(); 127 << object_path_.value();
134 DCHECK(OnOriginThread()); 128 DCHECK(OnOriginThread());
135 129
136 dbus::MessageReader reader(method_call); 130 dbus::MessageReader reader(method_call);
137 131
138 std::string interface_name; 132 std::string interface_name;
139 std::string property_name; 133 std::string property_name;
140 if (!reader.PopString(&interface_name) || 134 if (!reader.PopString(&interface_name) ||
141 !reader.PopString(&property_name) || 135 !reader.PopString(&property_name) || reader.HasMoreData()) {
142 reader.HasMoreData()) {
143 scoped_ptr<dbus::ErrorResponse> error_response = 136 scoped_ptr<dbus::ErrorResponse> error_response =
144 dbus::ErrorResponse::FromMethodCall( 137 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs,
145 method_call, kErrorInvalidArgs, "Expected 'ss'."); 138 "Expected 'ss'.");
146 response_sender.Run(error_response.Pass()); 139 response_sender.Run(error_response.Pass());
147 return; 140 return;
148 } 141 }
149 142
150 // Only the GATT descriptor interface is supported. 143 // Only the GATT descriptor interface is supported.
151 if (interface_name != 144 if (interface_name !=
152 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface) { 145 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface) {
153 scoped_ptr<dbus::ErrorResponse> error_response = 146 scoped_ptr<dbus::ErrorResponse> error_response =
154 dbus::ErrorResponse::FromMethodCall( 147 dbus::ErrorResponse::FromMethodCall(
155 method_call, kErrorInvalidArgs, 148 method_call, kErrorInvalidArgs,
156 "No such interface: '" + interface_name + "'."); 149 "No such interface: '" + interface_name + "'.");
157 response_sender.Run(error_response.Pass()); 150 response_sender.Run(error_response.Pass());
158 return; 151 return;
159 } 152 }
160 153
161 // If getting the "Value" property, obtain the value from the delegate. 154 // If getting the "Value" property, obtain the value from the delegate.
162 if (property_name == bluetooth_gatt_descriptor::kValueProperty) { 155 if (property_name == bluetooth_gatt_descriptor::kValueProperty) {
163 DCHECK(delegate_); 156 DCHECK(delegate_);
164 delegate_->GetDescriptorValue( 157 delegate_->GetDescriptorValue(
165 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnGet, 158 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnGet,
166 weak_ptr_factory_.GetWeakPtr(), 159 weak_ptr_factory_.GetWeakPtr(), method_call,
167 method_call, response_sender), 160 response_sender),
168 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure, 161 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure,
169 weak_ptr_factory_.GetWeakPtr(), 162 weak_ptr_factory_.GetWeakPtr(), method_call,
170 method_call, response_sender)); 163 response_sender));
171 return; 164 return;
172 } 165 }
173 166
174 scoped_ptr<dbus::Response> response = 167 scoped_ptr<dbus::Response> response =
175 dbus::Response::FromMethodCall(method_call); 168 dbus::Response::FromMethodCall(method_call);
176 dbus::MessageWriter writer(response.get()); 169 dbus::MessageWriter writer(response.get());
177 dbus::MessageWriter variant_writer(NULL); 170 dbus::MessageWriter variant_writer(NULL);
178 171
179 // TODO(armansito): Process the "Permissions" property below. 172 // TODO(armansito): Process the "Permissions" property below.
180 if (property_name == bluetooth_gatt_descriptor::kUUIDProperty) { 173 if (property_name == bluetooth_gatt_descriptor::kUUIDProperty) {
181 writer.OpenVariant("s", &variant_writer); 174 writer.OpenVariant("s", &variant_writer);
182 variant_writer.AppendString(uuid_); 175 variant_writer.AppendString(uuid_);
183 writer.CloseContainer(&variant_writer); 176 writer.CloseContainer(&variant_writer);
184 } else if (property_name == 177 } else if (property_name ==
185 bluetooth_gatt_descriptor::kCharacteristicProperty) { 178 bluetooth_gatt_descriptor::kCharacteristicProperty) {
186 writer.OpenVariant("o", &variant_writer); 179 writer.OpenVariant("o", &variant_writer);
187 variant_writer.AppendObjectPath(characteristic_path_); 180 variant_writer.AppendObjectPath(characteristic_path_);
188 writer.CloseContainer(&variant_writer); 181 writer.CloseContainer(&variant_writer);
189 } else { 182 } else {
190 response = dbus::ErrorResponse::FromMethodCall( 183 response = dbus::ErrorResponse::FromMethodCall(
191 method_call, 184 method_call, kErrorInvalidArgs,
192 kErrorInvalidArgs,
193 "No such property: '" + property_name + "'."); 185 "No such property: '" + property_name + "'.");
194 } 186 }
195 187
196 response_sender.Run(response.Pass()); 188 response_sender.Run(response.Pass());
197 } 189 }
198 190
199 // Called by dbus:: when the Bluetooth daemon sets a single property of the 191 // Called by dbus:: when the Bluetooth daemon sets a single property of the
200 // descriptor. 192 // descriptor.
201 void Set(dbus::MethodCall* method_call, 193 void Set(dbus::MethodCall* method_call,
202 dbus::ExportedObject::ResponseSender response_sender) { 194 dbus::ExportedObject::ResponseSender response_sender) {
203 VLOG(2) << "BluetoothGattDescriptorServiceProvider::Set: " 195 VLOG(2) << "BluetoothGattDescriptorServiceProvider::Set: "
204 << object_path_.value(); 196 << object_path_.value();
205 DCHECK(OnOriginThread()); 197 DCHECK(OnOriginThread());
206 198
207 dbus::MessageReader reader(method_call); 199 dbus::MessageReader reader(method_call);
208 200
209 std::string interface_name; 201 std::string interface_name;
210 std::string property_name; 202 std::string property_name;
211 dbus::MessageReader variant_reader(NULL); 203 dbus::MessageReader variant_reader(NULL);
212 if (!reader.PopString(&interface_name) || 204 if (!reader.PopString(&interface_name) ||
213 !reader.PopString(&property_name) || 205 !reader.PopString(&property_name) ||
214 !reader.PopVariant(&variant_reader) || 206 !reader.PopVariant(&variant_reader) || reader.HasMoreData()) {
215 reader.HasMoreData()) {
216 scoped_ptr<dbus::ErrorResponse> error_response = 207 scoped_ptr<dbus::ErrorResponse> error_response =
217 dbus::ErrorResponse::FromMethodCall( 208 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs,
218 method_call, kErrorInvalidArgs, "Expected 'ssv'."); 209 "Expected 'ssv'.");
219 response_sender.Run(error_response.Pass()); 210 response_sender.Run(error_response.Pass());
220 return; 211 return;
221 } 212 }
222 213
223 // Only the GATT descriptor interface is allowed. 214 // Only the GATT descriptor interface is allowed.
224 if (interface_name != 215 if (interface_name !=
225 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface) { 216 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface) {
226 scoped_ptr<dbus::ErrorResponse> error_response = 217 scoped_ptr<dbus::ErrorResponse> error_response =
227 dbus::ErrorResponse::FromMethodCall( 218 dbus::ErrorResponse::FromMethodCall(
228 method_call, kErrorInvalidArgs, 219 method_call, kErrorInvalidArgs,
229 "No such interface: '" + interface_name + "'."); 220 "No such interface: '" + interface_name + "'.");
230 response_sender.Run(error_response.Pass()); 221 response_sender.Run(error_response.Pass());
231 return; 222 return;
232 } 223 }
233 224
234 // Only the "Value" property is writeable. 225 // Only the "Value" property is writeable.
235 if (property_name != bluetooth_gatt_descriptor::kValueProperty) { 226 if (property_name != bluetooth_gatt_descriptor::kValueProperty) {
236 std::string error_name; 227 std::string error_name;
237 std::string error_message; 228 std::string error_message;
238 if (property_name == bluetooth_gatt_descriptor::kUUIDProperty || 229 if (property_name == bluetooth_gatt_descriptor::kUUIDProperty ||
239 property_name == bluetooth_gatt_descriptor::kCharacteristicProperty) { 230 property_name == bluetooth_gatt_descriptor::kCharacteristicProperty) {
240 error_name = kErrorPropertyReadOnly; 231 error_name = kErrorPropertyReadOnly;
241 error_message = "Read-only property: '" + property_name + "'."; 232 error_message = "Read-only property: '" + property_name + "'.";
242 } else { 233 } else {
243 error_name = kErrorInvalidArgs; 234 error_name = kErrorInvalidArgs;
244 error_message = "No such property: '" + property_name + "'."; 235 error_message = "No such property: '" + property_name + "'.";
245 } 236 }
246 scoped_ptr<dbus::ErrorResponse> error_response = 237 scoped_ptr<dbus::ErrorResponse> error_response =
247 dbus::ErrorResponse::FromMethodCall( 238 dbus::ErrorResponse::FromMethodCall(method_call, error_name,
248 method_call, error_name, error_message); 239 error_message);
249 response_sender.Run(error_response.Pass()); 240 response_sender.Run(error_response.Pass());
250 return; 241 return;
251 } 242 }
252 243
253 // Obtain the value. 244 // Obtain the value.
254 const uint8* bytes = NULL; 245 const uint8* bytes = NULL;
255 size_t length = 0; 246 size_t length = 0;
256 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) { 247 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) {
257 scoped_ptr<dbus::ErrorResponse> error_response = 248 scoped_ptr<dbus::ErrorResponse> error_response =
258 dbus::ErrorResponse::FromMethodCall( 249 dbus::ErrorResponse::FromMethodCall(
259 method_call, kErrorInvalidArgs, 250 method_call, kErrorInvalidArgs,
260 "Property '" + property_name + "' has type 'ay'."); 251 "Property '" + property_name + "' has type 'ay'.");
261 response_sender.Run(error_response.Pass()); 252 response_sender.Run(error_response.Pass());
262 return; 253 return;
263 } 254 }
264 255
265 // Pass the set request onto the delegate. 256 // Pass the set request onto the delegate.
266 std::vector<uint8> value(bytes, bytes + length); 257 std::vector<uint8> value(bytes, bytes + length);
267 DCHECK(delegate_); 258 DCHECK(delegate_);
268 delegate_->SetDescriptorValue( 259 delegate_->SetDescriptorValue(
269 value, 260 value, base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnSet,
270 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnSet, 261 weak_ptr_factory_.GetWeakPtr(), method_call,
271 weak_ptr_factory_.GetWeakPtr(), 262 response_sender),
272 method_call, response_sender),
273 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure, 263 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure,
274 weak_ptr_factory_.GetWeakPtr(), 264 weak_ptr_factory_.GetWeakPtr(), method_call,
275 method_call, response_sender)); 265 response_sender));
276 } 266 }
277 267
278 // Called by dbus:: when the Bluetooth daemon fetches all properties of the 268 // Called by dbus:: when the Bluetooth daemon fetches all properties of the
279 // descriptor. 269 // descriptor.
280 void GetAll(dbus::MethodCall* method_call, 270 void GetAll(dbus::MethodCall* method_call,
281 dbus::ExportedObject::ResponseSender response_sender) { 271 dbus::ExportedObject::ResponseSender response_sender) {
282 VLOG(2) << "BluetoothGattDescriptorServiceProvider::GetAll: " 272 VLOG(2) << "BluetoothGattDescriptorServiceProvider::GetAll: "
283 << object_path_.value(); 273 << object_path_.value();
284 DCHECK(OnOriginThread()); 274 DCHECK(OnOriginThread());
285 275
286 dbus::MessageReader reader(method_call); 276 dbus::MessageReader reader(method_call);
287 277
288 std::string interface_name; 278 std::string interface_name;
289 if (!reader.PopString(&interface_name) || reader.HasMoreData()) { 279 if (!reader.PopString(&interface_name) || reader.HasMoreData()) {
290 scoped_ptr<dbus::ErrorResponse> error_response = 280 scoped_ptr<dbus::ErrorResponse> error_response =
291 dbus::ErrorResponse::FromMethodCall( 281 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs,
292 method_call, kErrorInvalidArgs, "Expected 's'."); 282 "Expected 's'.");
293 response_sender.Run(error_response.Pass()); 283 response_sender.Run(error_response.Pass());
294 return; 284 return;
295 } 285 }
296 286
297 // Only the GATT descriptor interface is supported. 287 // Only the GATT descriptor interface is supported.
298 if (interface_name != 288 if (interface_name !=
299 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface) { 289 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface) {
300 scoped_ptr<dbus::ErrorResponse> error_response = 290 scoped_ptr<dbus::ErrorResponse> error_response =
301 dbus::ErrorResponse::FromMethodCall( 291 dbus::ErrorResponse::FromMethodCall(
302 method_call, kErrorInvalidArgs, 292 method_call, kErrorInvalidArgs,
303 "No such interface: '" + interface_name + "'."); 293 "No such interface: '" + interface_name + "'.");
304 response_sender.Run(error_response.Pass()); 294 response_sender.Run(error_response.Pass());
305 return; 295 return;
306 } 296 }
307 297
308 // Try to obtain the value from the delegate. We will construct the 298 // Try to obtain the value from the delegate. We will construct the
309 // response in the success callback. 299 // response in the success callback.
310 DCHECK(delegate_); 300 DCHECK(delegate_);
311 delegate_->GetDescriptorValue( 301 delegate_->GetDescriptorValue(
312 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnGetAll, 302 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnGetAll,
313 weak_ptr_factory_.GetWeakPtr(), 303 weak_ptr_factory_.GetWeakPtr(), method_call,
314 method_call, response_sender), 304 response_sender),
315 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure, 305 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure,
316 weak_ptr_factory_.GetWeakPtr(), 306 weak_ptr_factory_.GetWeakPtr(), method_call,
317 method_call, response_sender)); 307 response_sender));
318 } 308 }
319 309
320 // Called by dbus:: when a method is exported. 310 // Called by dbus:: when a method is exported.
321 void OnExported(const std::string& interface_name, 311 void OnExported(const std::string& interface_name,
322 const std::string& method_name, 312 const std::string& method_name,
323 bool success) { 313 bool success) {
324 LOG_IF(WARNING, !success) << "Failed to export " 314 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "."
325 << interface_name << "." << method_name; 315 << method_name;
326 } 316 }
327 317
328 // Called by the Delegate in response to a method to call to get all 318 // Called by the Delegate in response to a method to call to get all
329 // properties, in which the delegate has successfully returned the 319 // properties, in which the delegate has successfully returned the
330 // descriptor value. 320 // descriptor value.
331 void OnGetAll(dbus::MethodCall* method_call, 321 void OnGetAll(dbus::MethodCall* method_call,
332 dbus::ExportedObject::ResponseSender response_sender, 322 dbus::ExportedObject::ResponseSender response_sender,
333 const std::vector<uint8>& value) { 323 const std::vector<uint8>& value) {
334 VLOG(2) << "Descriptor value obtained from delegate. Responding to " 324 VLOG(2) << "Descriptor value obtained from delegate. Responding to "
335 << "GetAll."; 325 << "GetAll.";
336 326
337 scoped_ptr<dbus::Response> response = 327 scoped_ptr<dbus::Response> response =
338 dbus::Response::FromMethodCall(method_call); 328 dbus::Response::FromMethodCall(method_call);
339 dbus::MessageWriter writer(response.get()); 329 dbus::MessageWriter writer(response.get());
340 dbus::MessageWriter array_writer(NULL); 330 dbus::MessageWriter array_writer(NULL);
341 dbus::MessageWriter dict_entry_writer(NULL); 331 dbus::MessageWriter dict_entry_writer(NULL);
342 dbus::MessageWriter variant_writer(NULL); 332 dbus::MessageWriter variant_writer(NULL);
343 333
344 writer.OpenArray("{sv}", &array_writer); 334 writer.OpenArray("{sv}", &array_writer);
345 335
346 array_writer.OpenDictEntry(&dict_entry_writer); 336 array_writer.OpenDictEntry(&dict_entry_writer);
347 dict_entry_writer.AppendString( 337 dict_entry_writer.AppendString(bluetooth_gatt_descriptor::kUUIDProperty);
348 bluetooth_gatt_descriptor::kUUIDProperty);
349 dict_entry_writer.AppendVariantOfString(uuid_); 338 dict_entry_writer.AppendVariantOfString(uuid_);
350 array_writer.CloseContainer(&dict_entry_writer); 339 array_writer.CloseContainer(&dict_entry_writer);
351 340
352 array_writer.OpenDictEntry(&dict_entry_writer); 341 array_writer.OpenDictEntry(&dict_entry_writer);
353 dict_entry_writer.AppendString( 342 dict_entry_writer.AppendString(
354 bluetooth_gatt_descriptor::kCharacteristicProperty); 343 bluetooth_gatt_descriptor::kCharacteristicProperty);
355 dict_entry_writer.AppendVariantOfObjectPath(characteristic_path_); 344 dict_entry_writer.AppendVariantOfObjectPath(characteristic_path_);
356 array_writer.CloseContainer(&dict_entry_writer); 345 array_writer.CloseContainer(&dict_entry_writer);
357 346
358 array_writer.OpenDictEntry(&dict_entry_writer); 347 array_writer.OpenDictEntry(&dict_entry_writer);
359 dict_entry_writer.AppendString( 348 dict_entry_writer.AppendString(bluetooth_gatt_descriptor::kValueProperty);
360 bluetooth_gatt_descriptor::kValueProperty);
361 dict_entry_writer.OpenVariant("ay", &variant_writer); 349 dict_entry_writer.OpenVariant("ay", &variant_writer);
362 variant_writer.AppendArrayOfBytes(value.data(), value.size()); 350 variant_writer.AppendArrayOfBytes(value.data(), value.size());
363 dict_entry_writer.CloseContainer(&variant_writer); 351 dict_entry_writer.CloseContainer(&variant_writer);
364 array_writer.CloseContainer(&dict_entry_writer); 352 array_writer.CloseContainer(&dict_entry_writer);
365 353
366 // TODO(armansito): Process "Permissions" property. 354 // TODO(armansito): Process "Permissions" property.
367 355
368 writer.CloseContainer(&array_writer); 356 writer.CloseContainer(&array_writer);
369 357
370 response_sender.Run(response.Pass()); 358 response_sender.Run(response.Pass());
(...skipping 25 matching lines...) Expand all
396 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 384 response_sender.Run(dbus::Response::FromMethodCall(method_call));
397 } 385 }
398 386
399 // Called by the Delegate in response to a failed method call to get or set 387 // Called by the Delegate in response to a failed method call to get or set
400 // the descriptor value. 388 // the descriptor value.
401 void OnFailure(dbus::MethodCall* method_call, 389 void OnFailure(dbus::MethodCall* method_call,
402 dbus::ExportedObject::ResponseSender response_sender) { 390 dbus::ExportedObject::ResponseSender response_sender) {
403 VLOG(2) << "Failed to get/set descriptor value. Report error."; 391 VLOG(2) << "Failed to get/set descriptor value. Report error.";
404 scoped_ptr<dbus::ErrorResponse> error_response = 392 scoped_ptr<dbus::ErrorResponse> error_response =
405 dbus::ErrorResponse::FromMethodCall( 393 dbus::ErrorResponse::FromMethodCall(
406 method_call, kErrorFailed, 394 method_call, kErrorFailed, "Failed to get/set descriptor value.");
407 "Failed to get/set descriptor value.");
408 response_sender.Run(error_response.Pass()); 395 response_sender.Run(error_response.Pass());
409 } 396 }
410 397
411 // Origin thread (i.e. the UI thread in production). 398 // Origin thread (i.e. the UI thread in production).
412 base::PlatformThreadId origin_thread_id_; 399 base::PlatformThreadId origin_thread_id_;
413 400
414 // 128-bit descriptor UUID of this object. 401 // 128-bit descriptor UUID of this object.
415 std::string uuid_; 402 std::string uuid_;
416 403
417 // D-Bus bus object is exported on, not owned by this object and must 404 // D-Bus bus object is exported on, not owned by this object and must
(...skipping 20 matching lines...) Expand all
438 // than we do. 425 // than we do.
439 // Note: This should remain the last member so it'll be destroyed and 426 // Note: This should remain the last member so it'll be destroyed and
440 // invalidate its weak pointers before any other members are destroyed. 427 // invalidate its weak pointers before any other members are destroyed.
441 base::WeakPtrFactory<BluetoothGattDescriptorServiceProviderImpl> 428 base::WeakPtrFactory<BluetoothGattDescriptorServiceProviderImpl>
442 weak_ptr_factory_; 429 weak_ptr_factory_;
443 430
444 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorServiceProviderImpl); 431 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptorServiceProviderImpl);
445 }; 432 };
446 433
447 BluetoothGattDescriptorServiceProvider:: 434 BluetoothGattDescriptorServiceProvider::
448 BluetoothGattDescriptorServiceProvider() { 435 BluetoothGattDescriptorServiceProvider() {}
449 }
450 436
451 BluetoothGattDescriptorServiceProvider:: 437 BluetoothGattDescriptorServiceProvider::
452 ~BluetoothGattDescriptorServiceProvider() { 438 ~BluetoothGattDescriptorServiceProvider() {}
453 }
454 439
455 // static 440 // static
456 BluetoothGattDescriptorServiceProvider* 441 BluetoothGattDescriptorServiceProvider*
457 BluetoothGattDescriptorServiceProvider::Create( 442 BluetoothGattDescriptorServiceProvider::Create(
458 dbus::Bus* bus, 443 dbus::Bus* bus,
459 const dbus::ObjectPath& object_path, 444 const dbus::ObjectPath& object_path,
460 Delegate* delegate, 445 Delegate* delegate,
461 const std::string& uuid, 446 const std::string& uuid,
462 const std::vector<std::string>& permissions, 447 const std::vector<std::string>& permissions,
463 const dbus::ObjectPath& characteristic_path) { 448 const dbus::ObjectPath& characteristic_path) {
464 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { 449 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) {
465 return new BluetoothGattDescriptorServiceProviderImpl( 450 return new BluetoothGattDescriptorServiceProviderImpl(
466 bus, object_path, delegate, uuid, permissions, characteristic_path); 451 bus, object_path, delegate, uuid, permissions, characteristic_path);
467 } 452 }
468 return new FakeBluetoothGattDescriptorServiceProvider( 453 return new FakeBluetoothGattDescriptorServiceProvider(
469 object_path, delegate, uuid, permissions, characteristic_path); 454 object_path, delegate, uuid, permissions, characteristic_path);
470 } 455 }
471 456
472 } // namespace chromeos 457 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698