Chromium Code Reviews| 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/message.h" | 5 #include "dbus/message.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 OpenArray("y", &array_writer); | 592 OpenArray("y", &array_writer); |
| 593 const bool success = dbus_message_iter_append_fixed_array( | 593 const bool success = dbus_message_iter_append_fixed_array( |
| 594 &(array_writer.raw_message_iter_), | 594 &(array_writer.raw_message_iter_), |
| 595 DBUS_TYPE_BYTE, | 595 DBUS_TYPE_BYTE, |
| 596 &values, | 596 &values, |
| 597 static_cast<int>(length)); | 597 static_cast<int>(length)); |
| 598 CHECK(success) << "Unable to allocate memory"; | 598 CHECK(success) << "Unable to allocate memory"; |
| 599 CloseContainer(&array_writer); | 599 CloseContainer(&array_writer); |
| 600 } | 600 } |
| 601 | 601 |
| 602 void MessageWriter::AppendArrayOfDoubles(const double* values, size_t length) { | |
| 603 DCHECK(!container_is_open_); | |
| 604 MessageWriter array_writer(message_); | |
| 605 OpenArray("d", &array_writer); | |
| 606 const bool success = dbus_message_iter_append_fixed_array( | |
| 607 &(array_writer.raw_message_iter_), | |
| 608 DBUS_TYPE_DOUBLE, | |
| 609 &values, | |
| 610 static_cast<int>(length)); | |
| 611 CHECK(success) << "Unable to allocate memory"; | |
| 612 CloseContainer(&array_writer); | |
| 613 } | |
| 614 | |
| 602 void MessageWriter::AppendArrayOfStrings( | 615 void MessageWriter::AppendArrayOfStrings( |
| 603 const std::vector<std::string>& strings) { | 616 const std::vector<std::string>& strings) { |
| 604 DCHECK(!container_is_open_); | 617 DCHECK(!container_is_open_); |
| 605 MessageWriter array_writer(message_); | 618 MessageWriter array_writer(message_); |
| 606 OpenArray("s", &array_writer); | 619 OpenArray("s", &array_writer); |
| 607 for (size_t i = 0; i < strings.size(); ++i) { | 620 for (size_t i = 0; i < strings.size(); ++i) { |
| 608 array_writer.AppendString(strings[i]); | 621 array_writer.AppendString(strings[i]); |
| 609 } | 622 } |
| 610 CloseContainer(&array_writer); | 623 CloseContainer(&array_writer); |
| 611 } | 624 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) | 832 if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) |
| 820 return false; | 833 return false; |
| 821 int int_length = 0; | 834 int int_length = 0; |
| 822 dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, | 835 dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, |
| 823 bytes, | 836 bytes, |
| 824 &int_length); | 837 &int_length); |
| 825 *length = static_cast<int>(int_length); | 838 *length = static_cast<int>(int_length); |
| 826 return true; | 839 return true; |
| 827 } | 840 } |
| 828 | 841 |
| 842 bool MessageReader::PopArrayOfDoubles(const double** doubles, size_t* length) { | |
| 843 MessageReader array_reader(message_); | |
| 844 if (!PopArray(&array_reader)) | |
| 845 return false; | |
| 846 if (!array_reader.HasMoreData()) { | |
| 847 *length = 0; | |
| 848 *doubles = nullptr; | |
| 849 return true; | |
| 850 } | |
| 851 if (!array_reader.CheckDataType(DBUS_TYPE_DOUBLE)) | |
| 852 return false; | |
| 853 int int_length = 0; | |
| 854 dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, | |
| 855 doubles, | |
| 856 &int_length); | |
| 857 *length = static_cast<int>(int_length); | |
|
stevenjb
2016/03/29 18:38:03
static_cast<size_t> ?
Qiang(Joe) Xu
2016/03/29 19:19:09
Done.
| |
| 858 return true; | |
| 859 } | |
| 860 | |
| 829 bool MessageReader::PopArrayOfStrings( | 861 bool MessageReader::PopArrayOfStrings( |
| 830 std::vector<std::string> *strings) { | 862 std::vector<std::string> *strings) { |
| 831 strings->clear(); | 863 strings->clear(); |
| 832 MessageReader array_reader(message_); | 864 MessageReader array_reader(message_); |
| 833 if (!PopArray(&array_reader)) | 865 if (!PopArray(&array_reader)) |
| 834 return false; | 866 return false; |
| 835 while (array_reader.HasMoreData()) { | 867 while (array_reader.HasMoreData()) { |
| 836 std::string string; | 868 std::string string; |
| 837 if (!array_reader.PopString(&string)) | 869 if (!array_reader.PopString(&string)) |
| 838 return false; | 870 return false; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); | 1023 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); |
| 992 if (!success) | 1024 if (!success) |
| 993 return false; | 1025 return false; |
| 994 | 1026 |
| 995 value->PutValue(fd); | 1027 value->PutValue(fd); |
| 996 // NB: the caller must check validity before using the value | 1028 // NB: the caller must check validity before using the value |
| 997 return true; | 1029 return true; |
| 998 } | 1030 } |
| 999 | 1031 |
| 1000 } // namespace dbus | 1032 } // namespace dbus |
| OLD | NEW |