OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message.h" | 5 #include "dbus/message.h" |
6 | 6 |
7 #include <string> | |
8 | |
7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
8 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 // Appends the header name and the value to |output|, if the value is | 16 // Appends the header name and the value to |output|, if the value is |
15 // not empty. | 17 // not empty. |
16 static void AppendStringHeader(const std::string& header_name, | 18 static void AppendStringHeader(const std::string& header_name, |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 const std::vector<std::string>& object_paths) { | 587 const std::vector<std::string>& object_paths) { |
586 DCHECK(!container_is_open_); | 588 DCHECK(!container_is_open_); |
587 MessageWriter array_writer(message_); | 589 MessageWriter array_writer(message_); |
588 OpenArray("o", &array_writer); | 590 OpenArray("o", &array_writer); |
589 for (size_t i = 0; i < object_paths.size(); ++i) { | 591 for (size_t i = 0; i < object_paths.size(); ++i) { |
590 array_writer.AppendObjectPath(object_paths[i]); | 592 array_writer.AppendObjectPath(object_paths[i]); |
591 } | 593 } |
592 CloseContainer(&array_writer); | 594 CloseContainer(&array_writer); |
593 } | 595 } |
594 | 596 |
597 bool MessageWriter::AppendProtocolBuffer( | |
598 const google::protobuf::MessageLite& protobuf) { | |
599 std::string serialized_proto; | |
600 if (!protobuf.SerializeToString(&serialized_proto)) { | |
601 LOG(ERROR) << "Unable to serialize supplied protocol buffer"; | |
602 return false; | |
603 } | |
604 AppendArrayOfBytes(reinterpret_cast<const uint8*>(serialized_proto.data()), | |
605 serialized_proto.size()); | |
606 return true; | |
607 } | |
608 | |
595 void MessageWriter::AppendVariantOfByte(uint8 value) { | 609 void MessageWriter::AppendVariantOfByte(uint8 value) { |
596 AppendVariantOfBasic(DBUS_TYPE_BYTE, &value); | 610 AppendVariantOfBasic(DBUS_TYPE_BYTE, &value); |
597 } | 611 } |
598 | 612 |
599 void MessageWriter::AppendVariantOfBool(bool value) { | 613 void MessageWriter::AppendVariantOfBool(bool value) { |
600 // See the comment at MessageWriter::AppendBool(). | 614 // See the comment at MessageWriter::AppendBool(). |
601 dbus_bool_t dbus_value = value; | 615 dbus_bool_t dbus_value = value; |
602 AppendVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); | 616 AppendVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); |
603 } | 617 } |
604 | 618 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 return false; | 806 return false; |
793 while (array_reader.HasMoreData()) { | 807 while (array_reader.HasMoreData()) { |
794 std::string object_path; | 808 std::string object_path; |
795 if (!array_reader.PopObjectPath(&object_path)) | 809 if (!array_reader.PopObjectPath(&object_path)) |
796 return false; | 810 return false; |
797 object_paths->push_back(object_path); | 811 object_paths->push_back(object_path); |
798 } | 812 } |
799 return true; | 813 return true; |
800 } | 814 } |
801 | 815 |
816 bool MessageReader::PopProtocolBuffer(google::protobuf::MessageLite* protobuf) { | |
817 DCHECK(protobuf != NULL); | |
818 char* serialized_buf; | |
819 size_t buf_size; | |
satorux1
2012/01/31 21:42:31
Please initialize them.
char* serialized_buf = NU
rharrison
2012/02/01 19:03:20
Done.
| |
820 if (!PopArrayOfBytes(reinterpret_cast<uint8**>(&serialized_buf), &buf_size)) { | |
821 LOG(ERROR) << "Error reading array of bytes"; | |
822 return false; | |
823 } | |
824 if (!protobuf->ParseFromArray(serialized_buf, buf_size)) { | |
825 LOG(ERROR) << "Failed to parse protocol buffer from array"; | |
826 return false; | |
827 } | |
828 return true; | |
829 } | |
830 | |
802 bool MessageReader::PopVariantOfByte(uint8* value) { | 831 bool MessageReader::PopVariantOfByte(uint8* value) { |
803 return PopVariantOfBasic(DBUS_TYPE_BYTE, value); | 832 return PopVariantOfBasic(DBUS_TYPE_BYTE, value); |
804 } | 833 } |
805 | 834 |
806 bool MessageReader::PopVariantOfBool(bool* value) { | 835 bool MessageReader::PopVariantOfBool(bool* value) { |
807 // See the comment at MessageReader::PopBool(). | 836 // See the comment at MessageReader::PopBool(). |
808 dbus_bool_t dbus_value = FALSE; | 837 dbus_bool_t dbus_value = FALSE; |
809 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); | 838 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); |
810 *value = static_cast<bool>(dbus_value); | 839 *value = static_cast<bool>(dbus_value); |
811 return success; | 840 return success; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
894 } | 923 } |
895 | 924 |
896 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { | 925 bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { |
897 dbus::MessageReader variant_reader(message_); | 926 dbus::MessageReader variant_reader(message_); |
898 if (!PopVariant(&variant_reader)) | 927 if (!PopVariant(&variant_reader)) |
899 return false; | 928 return false; |
900 return variant_reader.PopBasic(dbus_type, value); | 929 return variant_reader.PopBasic(dbus_type, value); |
901 } | 930 } |
902 | 931 |
903 } // namespace dbus | 932 } // namespace dbus |
OLD | NEW |