OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_le_advertisement_service_provider.h" | 5 #include "chromeos/dbus/bluetooth_le_advertisement_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/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 dbus::MessageWriter writer(response.get()); | 251 dbus::MessageWriter writer(response.get()); |
252 dbus::MessageWriter variant_writer(NULL); | 252 dbus::MessageWriter variant_writer(NULL); |
253 | 253 |
254 writer.OpenVariant("ay", &variant_writer); | 254 writer.OpenVariant("ay", &variant_writer); |
255 variant_writer.AppendArrayOfBytes(value.data(), value.size()); | 255 variant_writer.AppendArrayOfBytes(value.data(), value.size()); |
256 writer.CloseContainer(&variant_writer); | 256 writer.CloseContainer(&variant_writer); |
257 | 257 |
258 response_sender.Run(response.Pass()); | 258 response_sender.Run(response.Pass()); |
259 } | 259 } |
260 | 260 |
261 void AppendArrayVariantOfStrings(dbus::MessageWriter* dict_writer, | |
armansito
2015/07/09 21:03:35
Do you mean AppendVariantArrayOfStrings?
rkc
2015/07/15 20:03:54
Done.
| |
262 const UUIDList& strings) { | |
263 dbus::MessageWriter strings_array_variant(nullptr); | |
264 dict_writer->OpenVariant("as", &strings_array_variant); | |
265 dbus::MessageWriter strings_array(nullptr); | |
266 strings_array_variant.OpenArray("s", &strings_array); | |
armansito
2015/07/09 21:03:35
You should be able to just call strings_array_vari
rkc
2015/07/15 20:03:54
Done.
| |
267 | |
268 for (auto& it : strings) | |
269 strings_array.AppendString(it); | |
270 | |
271 strings_array_variant.CloseContainer(&strings_array); | |
272 dict_writer->CloseContainer(&strings_array_variant); | |
273 } | |
274 | |
261 void AppendType(dbus::MessageWriter* array_writer) { | 275 void AppendType(dbus::MessageWriter* array_writer) { |
262 dbus::MessageWriter dict_entry_writer(NULL); | 276 dbus::MessageWriter dict_entry_writer(NULL); |
263 array_writer->OpenDictEntry(&dict_entry_writer); | 277 array_writer->OpenDictEntry(&dict_entry_writer); |
264 dict_entry_writer.AppendString(bluetooth_advertisement::kTypeProperty); | 278 dict_entry_writer.AppendString(bluetooth_advertisement::kTypeProperty); |
265 if (type_ == ADVERTISEMENT_TYPE_BROADCAST) { | 279 if (type_ == ADVERTISEMENT_TYPE_BROADCAST) { |
266 dict_entry_writer.AppendString("broadcast"); | 280 dict_entry_writer.AppendVariantOfString("broadcast"); |
267 } else { | 281 } else { |
268 dict_entry_writer.AppendString("peripheral"); | 282 dict_entry_writer.AppendVariantOfString("peripheral"); |
269 } | 283 } |
270 array_writer->CloseContainer(&dict_entry_writer); | 284 array_writer->CloseContainer(&dict_entry_writer); |
271 } | 285 } |
272 | 286 |
273 void AppendServiceUUIDs(dbus::MessageWriter* array_writer) { | 287 void AppendServiceUUIDs(dbus::MessageWriter* array_writer) { |
288 if (!service_uuids_) | |
289 return; | |
274 dbus::MessageWriter dict_entry_writer(NULL); | 290 dbus::MessageWriter dict_entry_writer(NULL); |
275 array_writer->OpenDictEntry(&dict_entry_writer); | 291 array_writer->OpenDictEntry(&dict_entry_writer); |
276 dict_entry_writer.AppendString( | 292 dict_entry_writer.AppendString( |
277 bluetooth_advertisement::kServiceUUIDsProperty); | 293 bluetooth_advertisement::kServiceUUIDsProperty); |
278 dict_entry_writer.AppendArrayOfStrings(*service_uuids_); | 294 AppendArrayVariantOfStrings(&dict_entry_writer, *service_uuids_); |
279 array_writer->CloseContainer(&dict_entry_writer); | 295 array_writer->CloseContainer(&dict_entry_writer); |
280 } | 296 } |
281 | 297 |
282 void AppendManufacturerData(dbus::MessageWriter* array_writer) { | 298 void AppendManufacturerData(dbus::MessageWriter* array_writer) { |
299 if (!manufacturer_data_) | |
300 return; | |
283 dbus::MessageWriter dict_entry_writer(NULL); | 301 dbus::MessageWriter dict_entry_writer(NULL); |
284 array_writer->OpenDictEntry(&dict_entry_writer); | 302 array_writer->OpenDictEntry(&dict_entry_writer); |
285 dict_entry_writer.AppendString( | 303 dict_entry_writer.AppendString( |
286 bluetooth_advertisement::kManufacturerDataProperty); | 304 bluetooth_advertisement::kManufacturerDataProperty); |
287 dbus::MessageWriter variant_writer(NULL); | 305 dbus::MessageWriter variant_writer(NULL); |
288 dict_entry_writer.OpenVariant("a{qay}", &variant_writer); | 306 dict_entry_writer.OpenVariant("a{qay}", &variant_writer); |
289 AppendManufacturerDataVariant(&variant_writer); | 307 AppendManufacturerDataVariant(&variant_writer); |
290 dict_entry_writer.CloseContainer(&variant_writer); | 308 dict_entry_writer.CloseContainer(&variant_writer); |
291 array_writer->CloseContainer(&dict_entry_writer); | 309 array_writer->CloseContainer(&dict_entry_writer); |
292 } | 310 } |
293 | 311 |
294 void AppendSolicitUUIDs(dbus::MessageWriter* array_writer) { | 312 void AppendSolicitUUIDs(dbus::MessageWriter* array_writer) { |
313 if (!solicit_uuids_) | |
314 return; | |
295 dbus::MessageWriter dict_entry_writer(NULL); | 315 dbus::MessageWriter dict_entry_writer(NULL); |
296 array_writer->OpenDictEntry(&dict_entry_writer); | 316 array_writer->OpenDictEntry(&dict_entry_writer); |
297 dict_entry_writer.AppendString( | 317 dict_entry_writer.AppendString( |
298 bluetooth_advertisement::kSolicitUUIDsProperty); | 318 bluetooth_advertisement::kSolicitUUIDsProperty); |
299 dict_entry_writer.AppendArrayOfStrings(*solicit_uuids_); | 319 AppendArrayVariantOfStrings(&dict_entry_writer, *solicit_uuids_); |
300 array_writer->CloseContainer(&dict_entry_writer); | 320 array_writer->CloseContainer(&dict_entry_writer); |
301 } | 321 } |
302 | 322 |
303 void AppendServiceData(dbus::MessageWriter* array_writer) { | 323 void AppendServiceData(dbus::MessageWriter* array_writer) { |
324 if (!service_data_) | |
325 return; | |
304 dbus::MessageWriter dict_entry_writer(NULL); | 326 dbus::MessageWriter dict_entry_writer(NULL); |
305 array_writer->OpenDictEntry(&dict_entry_writer); | 327 array_writer->OpenDictEntry(&dict_entry_writer); |
306 dict_entry_writer.AppendString( | 328 dict_entry_writer.AppendString( |
307 bluetooth_advertisement::kServiceDataProperty); | 329 bluetooth_advertisement::kServiceDataProperty); |
308 dbus::MessageWriter variant_writer(NULL); | 330 dbus::MessageWriter variant_writer(NULL); |
309 dict_entry_writer.OpenVariant("a{say}", &variant_writer); | 331 dict_entry_writer.OpenVariant("a{say}", &variant_writer); |
310 AppendServiceDataVariant(&variant_writer); | 332 AppendServiceDataVariant(&variant_writer); |
311 dict_entry_writer.CloseContainer(&variant_writer); | 333 dict_entry_writer.CloseContainer(&variant_writer); |
312 array_writer->CloseContainer(&dict_entry_writer); | 334 array_writer->CloseContainer(&dict_entry_writer); |
313 } | 335 } |
314 | 336 |
315 void AppendManufacturerDataVariant(dbus::MessageWriter* writer) { | 337 void AppendManufacturerDataVariant(dbus::MessageWriter* writer) { |
338 DCHECK(manufacturer_data_); | |
316 dbus::MessageWriter array_writer(NULL); | 339 dbus::MessageWriter array_writer(NULL); |
317 writer->OpenArray("{qay}", &array_writer); | 340 writer->OpenArray("{qay}", &array_writer); |
318 for (const auto& m : *manufacturer_data_) { | 341 for (const auto& m : *manufacturer_data_) { |
319 dbus::MessageWriter entry_writer(NULL); | 342 dbus::MessageWriter entry_writer(NULL); |
320 | 343 |
321 array_writer.OpenDictEntry(&entry_writer); | 344 array_writer.OpenDictEntry(&entry_writer); |
322 | 345 |
323 entry_writer.AppendUint32(m.first); | 346 entry_writer.AppendUint32(m.first); |
324 entry_writer.AppendArrayOfBytes(vector_as_array(&m.second), | 347 entry_writer.AppendArrayOfBytes(vector_as_array(&m.second), |
325 m.second.size()); | 348 m.second.size()); |
326 | 349 |
327 array_writer.CloseContainer(&entry_writer); | 350 array_writer.CloseContainer(&entry_writer); |
328 } | 351 } |
329 writer->CloseContainer(&array_writer); | 352 writer->CloseContainer(&array_writer); |
330 } | 353 } |
331 | 354 |
332 void AppendServiceDataVariant(dbus::MessageWriter* writer) { | 355 void AppendServiceDataVariant(dbus::MessageWriter* writer) { |
356 DCHECK(service_data_); | |
333 dbus::MessageWriter array_writer(NULL); | 357 dbus::MessageWriter array_writer(NULL); |
334 writer->OpenArray("{say}", &array_writer); | 358 writer->OpenArray("{say}", &array_writer); |
335 for (const auto& m : *service_data_) { | 359 for (const auto& m : *service_data_) { |
336 dbus::MessageWriter entry_writer(NULL); | 360 dbus::MessageWriter entry_writer(NULL); |
337 | 361 |
338 array_writer.OpenDictEntry(&entry_writer); | 362 array_writer.OpenDictEntry(&entry_writer); |
339 | 363 |
340 entry_writer.AppendString(m.first); | 364 entry_writer.AppendVariantOfString(m.first); |
341 entry_writer.AppendArrayOfBytes(vector_as_array(&m.second), | 365 entry_writer.AppendArrayOfBytes(vector_as_array(&m.second), |
342 m.second.size()); | 366 m.second.size()); |
343 | 367 |
344 array_writer.CloseContainer(&entry_writer); | 368 array_writer.CloseContainer(&entry_writer); |
345 } | 369 } |
346 writer->CloseContainer(&array_writer); | 370 writer->CloseContainer(&array_writer); |
347 } | 371 } |
348 | 372 |
349 // Origin thread (i.e. the UI thread in production). | 373 // Origin thread (i.e. the UI thread in production). |
350 base::PlatformThreadId origin_thread_id_; | 374 base::PlatformThreadId origin_thread_id_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 return make_scoped_ptr(new BluetoothAdvertisementServiceProviderImpl( | 425 return make_scoped_ptr(new BluetoothAdvertisementServiceProviderImpl( |
402 bus, object_path, delegate, type, service_uuids.Pass(), | 426 bus, object_path, delegate, type, service_uuids.Pass(), |
403 manufacturer_data.Pass(), solicit_uuids.Pass(), service_data.Pass())); | 427 manufacturer_data.Pass(), solicit_uuids.Pass(), service_data.Pass())); |
404 } else { | 428 } else { |
405 return make_scoped_ptr( | 429 return make_scoped_ptr( |
406 new FakeBluetoothLEAdvertisementServiceProvider(object_path, delegate)); | 430 new FakeBluetoothLEAdvertisementServiceProvider(object_path, delegate)); |
407 } | 431 } |
408 } | 432 } |
409 | 433 |
410 } // namespace chromeos | 434 } // namespace chromeos |
OLD | NEW |