| 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/property.h" | 5 #include "dbus/property.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 | 13 |
| 12 #include "dbus/message.h" | 14 #include "dbus/message.h" |
| 13 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 14 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
| 15 | 17 |
| 16 namespace dbus { | 18 namespace dbus { |
| 17 | 19 |
| 18 // | 20 // |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 array_writer.OpenStruct(&struct_writer); | 654 array_writer.OpenStruct(&struct_writer); |
| 653 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), | 655 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), |
| 654 std::get<0>(pair).size()); | 656 std::get<0>(pair).size()); |
| 655 struct_writer.AppendUint16(std::get<1>(pair)); | 657 struct_writer.AppendUint16(std::get<1>(pair)); |
| 656 array_writer.CloseContainer(&struct_writer); | 658 array_writer.CloseContainer(&struct_writer); |
| 657 } | 659 } |
| 658 variant_writer.CloseContainer(&array_writer); | 660 variant_writer.CloseContainer(&array_writer); |
| 659 writer->CloseContainer(&variant_writer); | 661 writer->CloseContainer(&variant_writer); |
| 660 } | 662 } |
| 661 | 663 |
| 664 // |
| 665 // Property<std::map<std::string, std::vector<uint8_t>>> |
| 666 // specialization. |
| 667 // |
| 668 |
| 669 template <> |
| 670 bool Property<std::unordered_map<std::string, std::vector<uint8_t>>>:: |
| 671 PopValueFromReader(MessageReader* reader) { |
| 672 MessageReader variant_reader(nullptr); |
| 673 MessageReader dict_reader(nullptr); |
| 674 if (!reader->PopVariant(&variant_reader) || |
| 675 !variant_reader.PopArray(&dict_reader)) |
| 676 return false; |
| 677 |
| 678 value_.clear(); |
| 679 while (dict_reader.HasMoreData()) { |
| 680 MessageReader entry_reader(nullptr); |
| 681 if (!dict_reader.PopDictEntry(&entry_reader)) |
| 682 return false; |
| 683 |
| 684 std::string key; |
| 685 MessageReader value_varient_reader(nullptr); |
| 686 if (!entry_reader.PopString(&key) || |
| 687 !entry_reader.PopVariant(&value_varient_reader)) |
| 688 return false; |
| 689 |
| 690 const uint8_t* bytes = nullptr; |
| 691 size_t length = 0; |
| 692 if (!value_varient_reader.PopArrayOfBytes(&bytes, &length)) |
| 693 return false; |
| 694 |
| 695 value_[key].assign(bytes, bytes + length); |
| 696 } |
| 697 return true; |
| 698 } |
| 699 |
| 700 template <> |
| 701 void Property<std::unordered_map<std::string, std::vector<uint8_t>>>:: |
| 702 AppendSetValueToWriter(MessageWriter* writer) { |
| 703 MessageWriter variant_writer(nullptr); |
| 704 MessageWriter dict_writer(nullptr); |
| 705 |
| 706 writer->OpenVariant("a{sv}", &variant_writer); |
| 707 variant_writer.OpenArray("{sv}", &dict_writer); |
| 708 |
| 709 for (const auto& pair : set_value_) { |
| 710 MessageWriter entry_writer(nullptr); |
| 711 dict_writer.OpenDictEntry(&entry_writer); |
| 712 |
| 713 entry_writer.AppendString(pair.first); |
| 714 |
| 715 MessageWriter value_varient_writer(nullptr); |
| 716 entry_writer.OpenVariant("ay", &value_varient_writer); |
| 717 value_varient_writer.AppendArrayOfBytes(pair.second.data(), |
| 718 pair.second.size()); |
| 719 entry_writer.CloseContainer(&value_varient_writer); |
| 720 |
| 721 dict_writer.CloseContainer(&entry_writer); |
| 722 } |
| 723 |
| 724 variant_writer.CloseContainer(&dict_writer); |
| 725 writer->CloseContainer(&variant_writer); |
| 726 } |
| 727 |
| 662 template class Property<uint8_t>; | 728 template class Property<uint8_t>; |
| 663 template class Property<bool>; | 729 template class Property<bool>; |
| 664 template class Property<int16_t>; | 730 template class Property<int16_t>; |
| 665 template class Property<uint16_t>; | 731 template class Property<uint16_t>; |
| 666 template class Property<int32_t>; | 732 template class Property<int32_t>; |
| 667 template class Property<uint32_t>; | 733 template class Property<uint32_t>; |
| 668 template class Property<int64_t>; | 734 template class Property<int64_t>; |
| 669 template class Property<uint64_t>; | 735 template class Property<uint64_t>; |
| 670 template class Property<double>; | 736 template class Property<double>; |
| 671 template class Property<std::string>; | 737 template class Property<std::string>; |
| 672 template class Property<ObjectPath>; | 738 template class Property<ObjectPath>; |
| 673 template class Property<std::vector<std::string> >; | 739 template class Property<std::vector<std::string> >; |
| 674 template class Property<std::vector<ObjectPath> >; | 740 template class Property<std::vector<ObjectPath> >; |
| 675 template class Property<std::vector<uint8_t>>; | 741 template class Property<std::vector<uint8_t>>; |
| 676 template class Property<std::map<std::string, std::string>>; | 742 template class Property<std::map<std::string, std::string>>; |
| 677 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; | 743 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; |
| 744 template class Property<std::unordered_map<std::string, std::vector<uint8_t>>>; |
| 678 | 745 |
| 679 } // namespace dbus | 746 } // namespace dbus |
| OLD | NEW |