OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "dbus/test_service.h" | 5 #include "dbus/test_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" |
8 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
9 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
10 #include "dbus/bus.h" | 11 #include "dbus/bus.h" |
11 #include "dbus/exported_object.h" | 12 #include "dbus/exported_object.h" |
12 #include "dbus/message.h" | 13 #include "dbus/message.h" |
13 #include "dbus/object_manager.h" | 14 #include "dbus/object_manager.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "dbus/property.h" | 16 #include "dbus/property.h" |
16 | 17 |
17 namespace { | 18 namespace { |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 MessageWriter writer(response.get()); | 424 MessageWriter writer(response.get()); |
424 MessageWriter variant_writer(NULL); | 425 MessageWriter variant_writer(NULL); |
425 MessageWriter variant_array_writer(NULL); | 426 MessageWriter variant_array_writer(NULL); |
426 | 427 |
427 writer.OpenVariant("ay", &variant_writer); | 428 writer.OpenVariant("ay", &variant_writer); |
428 const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 }; | 429 const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 }; |
429 variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes)); | 430 variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes)); |
430 writer.CloseContainer(&variant_writer); | 431 writer.CloseContainer(&variant_writer); |
431 | 432 |
432 response_sender.Run(response.Pass()); | 433 response_sender.Run(response.Pass()); |
| 434 } else if (name == "StringMap") { |
| 435 // Return the previous value for the "StringMap" property: |
| 436 // Variant<[{"One": "1"}, {"Two": "2"}, {"Three": "3"}, {"Four": "4"}]> |
| 437 scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
| 438 MessageWriter writer(response.get()); |
| 439 MessageWriter variant_writer(NULL); |
| 440 MessageWriter variant_array_writer(NULL); |
| 441 MessageWriter struct_entry_writer(NULL); |
| 442 |
| 443 writer.OpenVariant("a{ss}", &variant_writer); |
| 444 variant_writer.OpenArray("{ss}", &variant_array_writer); |
| 445 const char* items[] = {"One", "Two", "Three", "Four"}; |
| 446 for (unsigned i = 0; i < arraysize(items); ++i) { |
| 447 variant_array_writer.OpenDictEntry(&struct_entry_writer); |
| 448 struct_entry_writer.AppendString(items[i]); |
| 449 struct_entry_writer.AppendString(base::UintToString(i + 1)); |
| 450 variant_array_writer.CloseContainer(&struct_entry_writer); |
| 451 } |
| 452 variant_writer.CloseContainer(&variant_array_writer); |
| 453 writer.CloseContainer(&variant_writer); |
| 454 } else if (name == "IPList") { |
| 455 // Return the previous value for the "IPList" property: |
| 456 // "IPList": Variant<[([0x54, 0x65, 0x73, 0x74, 0x30], 0), |
| 457 // ([0x54, 0x65, 0x73, 0x74, 0x31], 1), |
| 458 // ([0x54, 0x65, 0x73, 0x74, 0x32], 2), |
| 459 // ([0x54, 0x65, 0x73, 0x74, 0x33], 3), |
| 460 // ([0x54, 0x65, 0x73, 0x74, 0x34], 4)]> |
| 461 scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
| 462 MessageWriter writer(response.get()); |
| 463 MessageWriter variant_writer(NULL); |
| 464 MessageWriter variant_array_writer(NULL); |
| 465 MessageWriter struct_entry_writer(NULL); |
| 466 |
| 467 writer.OpenVariant("a(ayq)", &variant_writer); |
| 468 variant_writer.OpenArray("(ayq)", &variant_array_writer); |
| 469 uint8 ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; |
| 470 for (uint16 i = 0; i < 5; ++i) { |
| 471 variant_array_writer.OpenStruct(&struct_entry_writer); |
| 472 ip_bytes[4] = 0x30 + i; |
| 473 struct_entry_writer.AppendArrayOfBytes(ip_bytes, arraysize(ip_bytes)); |
| 474 struct_entry_writer.AppendUint16(i); |
| 475 variant_array_writer.CloseContainer(&struct_entry_writer); |
| 476 } |
| 477 variant_writer.CloseContainer(&variant_array_writer); |
| 478 writer.CloseContainer(&variant_writer); |
| 479 |
433 } else { | 480 } else { |
434 // Return error. | 481 // Return error. |
435 response_sender.Run(scoped_ptr<Response>()); | 482 response_sender.Run(scoped_ptr<Response>()); |
436 return; | 483 return; |
437 } | 484 } |
438 } | 485 } |
439 | 486 |
440 void TestService::SetProperty(MethodCall* method_call, | 487 void TestService::SetProperty(MethodCall* method_call, |
441 ExportedObject::ResponseSender response_sender) { | 488 ExportedObject::ResponseSender response_sender) { |
442 MessageReader reader(method_call); | 489 MessageReader reader(method_call); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 // The properties response is a dictionary of strings identifying the | 622 // The properties response is a dictionary of strings identifying the |
576 // property and a variant containing the property value. We return all | 623 // property and a variant containing the property value. We return all |
577 // of the properties, thus the response is: | 624 // of the properties, thus the response is: |
578 // | 625 // |
579 // { | 626 // { |
580 // "Name": Variant<"TestService">, | 627 // "Name": Variant<"TestService">, |
581 // "Version": Variant<10>, | 628 // "Version": Variant<10>, |
582 // "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>, | 629 // "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>, |
583 // "Objects": Variant<[objectpath:"/TestObjectPath"]> | 630 // "Objects": Variant<[objectpath:"/TestObjectPath"]> |
584 // "Bytes": Variant<[0x54, 0x65, 0x73, 0x74]> | 631 // "Bytes": Variant<[0x54, 0x65, 0x73, 0x74]> |
| 632 // "StringMap": Variant<[{"One": "1"}, {"Two": "2"}, {"Three": "3"}, |
| 633 // {"Four": "4"}]> |
| 634 // "IPList": Variant<[([0x54, 0x65, 0x73, 0x74, 0x30], 0), |
| 635 // ([0x54, 0x65, 0x73, 0x74, 0x31], 1), |
| 636 // ([0x54, 0x65, 0x73, 0x74, 0x32], 2), |
| 637 // ([0x54, 0x65, 0x73, 0x74, 0x33], 3), |
| 638 // ([0x54, 0x65, 0x73, 0x74, 0x34], 4)]> |
585 // } | 639 // } |
586 | 640 |
587 MessageWriter array_writer(NULL); | 641 MessageWriter array_writer(NULL); |
588 MessageWriter dict_entry_writer(NULL); | 642 MessageWriter dict_entry_writer(NULL); |
589 MessageWriter variant_writer(NULL); | 643 MessageWriter variant_writer(NULL); |
590 MessageWriter variant_array_writer(NULL); | 644 MessageWriter variant_array_writer(NULL); |
| 645 MessageWriter struct_entry_writer(NULL); |
591 | 646 |
592 writer->OpenArray("{sv}", &array_writer); | 647 writer->OpenArray("{sv}", &array_writer); |
593 | 648 |
594 array_writer.OpenDictEntry(&dict_entry_writer); | 649 array_writer.OpenDictEntry(&dict_entry_writer); |
595 dict_entry_writer.AppendString("Name"); | 650 dict_entry_writer.AppendString("Name"); |
596 dict_entry_writer.AppendVariantOfString("TestService"); | 651 dict_entry_writer.AppendVariantOfString("TestService"); |
597 array_writer.CloseContainer(&dict_entry_writer); | 652 array_writer.CloseContainer(&dict_entry_writer); |
598 | 653 |
599 array_writer.OpenDictEntry(&dict_entry_writer); | 654 array_writer.OpenDictEntry(&dict_entry_writer); |
600 dict_entry_writer.AppendString("Version"); | 655 dict_entry_writer.AppendString("Version"); |
(...skipping 22 matching lines...) Expand all Loading... |
623 array_writer.CloseContainer(&dict_entry_writer); | 678 array_writer.CloseContainer(&dict_entry_writer); |
624 | 679 |
625 array_writer.OpenDictEntry(&dict_entry_writer); | 680 array_writer.OpenDictEntry(&dict_entry_writer); |
626 dict_entry_writer.AppendString("Bytes"); | 681 dict_entry_writer.AppendString("Bytes"); |
627 dict_entry_writer.OpenVariant("ay", &variant_writer); | 682 dict_entry_writer.OpenVariant("ay", &variant_writer); |
628 const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 }; | 683 const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 }; |
629 variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes)); | 684 variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes)); |
630 dict_entry_writer.CloseContainer(&variant_writer); | 685 dict_entry_writer.CloseContainer(&variant_writer); |
631 array_writer.CloseContainer(&dict_entry_writer); | 686 array_writer.CloseContainer(&dict_entry_writer); |
632 | 687 |
| 688 array_writer.OpenDictEntry(&dict_entry_writer); |
| 689 dict_entry_writer.AppendString("StringMap"); |
| 690 dict_entry_writer.OpenVariant("a{ss}", &variant_writer); |
| 691 variant_writer.OpenArray("{ss}", &variant_array_writer); |
| 692 const char* items[] = {"One", "Two", "Three", "Four"}; |
| 693 for (unsigned i = 0; i < arraysize(items); ++i) { |
| 694 variant_array_writer.OpenDictEntry(&struct_entry_writer); |
| 695 struct_entry_writer.AppendString(items[i]); |
| 696 struct_entry_writer.AppendString(base::UintToString(i + 1)); |
| 697 variant_array_writer.CloseContainer(&struct_entry_writer); |
| 698 } |
| 699 variant_writer.CloseContainer(&variant_array_writer); |
| 700 dict_entry_writer.CloseContainer(&variant_writer); |
| 701 array_writer.CloseContainer(&dict_entry_writer); |
| 702 |
| 703 array_writer.OpenDictEntry(&dict_entry_writer); |
| 704 dict_entry_writer.AppendString("IPList"); |
| 705 dict_entry_writer.OpenVariant("a(ayq)", &variant_writer); |
| 706 variant_writer.OpenArray("(ayq)", &variant_array_writer); |
| 707 uint8 ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; |
| 708 for (uint16 i = 0; i < 5; ++i) { |
| 709 variant_array_writer.OpenStruct(&struct_entry_writer); |
| 710 ip_bytes[4] = 0x30 + i; |
| 711 struct_entry_writer.AppendArrayOfBytes(ip_bytes, arraysize(ip_bytes)); |
| 712 struct_entry_writer.AppendUint16(i); |
| 713 variant_array_writer.CloseContainer(&struct_entry_writer); |
| 714 } |
| 715 variant_writer.CloseContainer(&variant_array_writer); |
| 716 dict_entry_writer.CloseContainer(&variant_writer); |
| 717 array_writer.CloseContainer(&dict_entry_writer); |
| 718 |
633 writer->CloseContainer(&array_writer); | 719 writer->CloseContainer(&array_writer); |
634 } | 720 } |
635 | 721 |
636 void TestService::AddObject(const ObjectPath& object_path) { | 722 void TestService::AddObject(const ObjectPath& object_path) { |
637 message_loop()->PostTask( | 723 message_loop()->PostTask( |
638 FROM_HERE, | 724 FROM_HERE, |
639 base::Bind(&TestService::AddObjectInternal, | 725 base::Bind(&TestService::AddObjectInternal, |
640 base::Unretained(this), | 726 base::Unretained(this), |
641 object_path)); | 727 object_path)); |
642 } | 728 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 array_writer.OpenDictEntry(&dict_entry_writer); | 785 array_writer.OpenDictEntry(&dict_entry_writer); |
700 dict_entry_writer.AppendString("Name"); | 786 dict_entry_writer.AppendString("Name"); |
701 dict_entry_writer.AppendVariantOfString(name); | 787 dict_entry_writer.AppendVariantOfString(name); |
702 array_writer.CloseContainer(&dict_entry_writer); | 788 array_writer.CloseContainer(&dict_entry_writer); |
703 writer.CloseContainer(&array_writer); | 789 writer.CloseContainer(&array_writer); |
704 | 790 |
705 exported_object_->SendSignal(&signal); | 791 exported_object_->SendSignal(&signal); |
706 } | 792 } |
707 | 793 |
708 } // namespace dbus | 794 } // namespace dbus |
OLD | NEW |