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/basictypes.h" | |
10 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
16 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
17 | 16 |
18 #if defined(USE_SYSTEM_PROTOBUF) | 17 #if defined(USE_SYSTEM_PROTOBUF) |
19 #include <google/protobuf/message_lite.h> | 18 #include <google/protobuf/message_lite.h> |
20 #else | 19 #else |
21 #include "third_party/protobuf/src/google/protobuf/message_lite.h" | 20 #include "third_party/protobuf/src/google/protobuf/message_lite.h" |
22 #endif | 21 #endif |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 // Appends the header name and the value to |output|, if the value is | 25 // Appends the header name and the value to |output|, if the value is |
27 // not empty. | 26 // not empty. |
28 void AppendStringHeader(const std::string& header_name, | 27 void AppendStringHeader(const std::string& header_name, |
29 const std::string& header_value, | 28 const std::string& header_value, |
30 std::string* output) { | 29 std::string* output) { |
31 if (!header_value.empty()) { | 30 if (!header_value.empty()) { |
32 *output += header_name + ": " + header_value + "\n"; | 31 *output += header_name + ": " + header_value + "\n"; |
33 } | 32 } |
34 } | 33 } |
35 | 34 |
36 // Appends the header name and the value to |output|, if the value is | 35 // Appends the header name and the value to |output|, if the value is |
37 // nonzero. | 36 // nonzero. |
38 void AppendUint32Header(const std::string& header_name, | 37 void AppendUint32Header(const std::string& header_name, |
39 uint32 header_value, | 38 uint32_t header_value, |
40 std::string* output) { | 39 std::string* output) { |
41 if (header_value != 0) { | 40 if (header_value != 0) { |
42 *output += (header_name + ": " + base::UintToString(header_value) + "\n"); | 41 *output += (header_name + ": " + base::UintToString(header_value) + "\n"); |
43 } | 42 } |
44 } | 43 } |
45 | 44 |
46 } // namespace | 45 } // namespace |
47 | 46 |
48 namespace dbus { | 47 namespace dbus { |
49 | 48 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 91 } |
93 | 92 |
94 std::string Message::ToStringInternal(const std::string& indent, | 93 std::string Message::ToStringInternal(const std::string& indent, |
95 MessageReader* reader) { | 94 MessageReader* reader) { |
96 const char* kBrokenMessage = "[broken message]"; | 95 const char* kBrokenMessage = "[broken message]"; |
97 std::string output; | 96 std::string output; |
98 while (reader->HasMoreData()) { | 97 while (reader->HasMoreData()) { |
99 const DataType type = reader->GetDataType(); | 98 const DataType type = reader->GetDataType(); |
100 switch (type) { | 99 switch (type) { |
101 case BYTE: { | 100 case BYTE: { |
102 uint8 value = 0; | 101 uint8_t value = 0; |
103 if (!reader->PopByte(&value)) | 102 if (!reader->PopByte(&value)) |
104 return kBrokenMessage; | 103 return kBrokenMessage; |
105 output += indent + "byte " + base::UintToString(value) + "\n"; | 104 output += indent + "byte " + base::UintToString(value) + "\n"; |
106 break; | 105 break; |
107 } | 106 } |
108 case BOOL: { | 107 case BOOL: { |
109 bool value = false; | 108 bool value = false; |
110 if (!reader->PopBool(&value)) | 109 if (!reader->PopBool(&value)) |
111 return kBrokenMessage; | 110 return kBrokenMessage; |
112 output += indent + "bool " + (value ? "true" : "false") + "\n"; | 111 output += indent + "bool " + (value ? "true" : "false") + "\n"; |
113 break; | 112 break; |
114 } | 113 } |
115 case INT16: { | 114 case INT16: { |
116 int16 value = 0; | 115 int16_t value = 0; |
117 if (!reader->PopInt16(&value)) | 116 if (!reader->PopInt16(&value)) |
118 return kBrokenMessage; | 117 return kBrokenMessage; |
119 output += indent + "int16 " + base::IntToString(value) + "\n"; | 118 output += indent + "int16_t " + base::IntToString(value) + "\n"; |
120 break; | 119 break; |
121 } | 120 } |
122 case UINT16: { | 121 case UINT16: { |
123 uint16 value = 0; | 122 uint16_t value = 0; |
124 if (!reader->PopUint16(&value)) | 123 if (!reader->PopUint16(&value)) |
125 return kBrokenMessage; | 124 return kBrokenMessage; |
126 output += indent + "uint16 " + base::UintToString(value) + "\n"; | 125 output += indent + "uint16_t " + base::UintToString(value) + "\n"; |
127 break; | 126 break; |
128 } | 127 } |
129 case INT32: { | 128 case INT32: { |
130 int32 value = 0; | 129 int32_t value = 0; |
131 if (!reader->PopInt32(&value)) | 130 if (!reader->PopInt32(&value)) |
132 return kBrokenMessage; | 131 return kBrokenMessage; |
133 output += indent + "int32 " + base::IntToString(value) + "\n"; | 132 output += indent + "int32_t " + base::IntToString(value) + "\n"; |
134 break; | 133 break; |
135 } | 134 } |
136 case UINT32: { | 135 case UINT32: { |
137 uint32 value = 0; | 136 uint32_t value = 0; |
138 if (!reader->PopUint32(&value)) | 137 if (!reader->PopUint32(&value)) |
139 return kBrokenMessage; | 138 return kBrokenMessage; |
140 output += indent + "uint32 " + base::UintToString(value) + "\n"; | 139 output += indent + "uint32_t " + base::UintToString(value) + "\n"; |
141 break; | 140 break; |
142 } | 141 } |
143 case INT64: { | 142 case INT64: { |
144 int64 value = 0; | 143 int64_t value = 0; |
145 if (!reader->PopInt64(&value)) | 144 if (!reader->PopInt64(&value)) |
146 return kBrokenMessage; | 145 return kBrokenMessage; |
147 output += (indent + "int64 " + base::Int64ToString(value) + "\n"); | 146 output += (indent + "int64_t " + base::Int64ToString(value) + "\n"); |
148 break; | 147 break; |
149 } | 148 } |
150 case UINT64: { | 149 case UINT64: { |
151 uint64 value = 0; | 150 uint64_t value = 0; |
152 if (!reader->PopUint64(&value)) | 151 if (!reader->PopUint64(&value)) |
153 return kBrokenMessage; | 152 return kBrokenMessage; |
154 output += (indent + "uint64 " + base::Uint64ToString(value) + "\n"); | 153 output += (indent + "uint64_t " + base::Uint64ToString(value) + "\n"); |
155 break; | 154 break; |
156 } | 155 } |
157 case DOUBLE: { | 156 case DOUBLE: { |
158 double value = 0; | 157 double value = 0; |
159 if (!reader->PopDouble(&value)) | 158 if (!reader->PopDouble(&value)) |
160 return kBrokenMessage; | 159 return kBrokenMessage; |
161 output += indent + "double " + base::DoubleToString(value) + "\n"; | 160 output += indent + "double " + base::DoubleToString(value) + "\n"; |
162 break; | 161 break; |
163 } | 162 } |
164 case STRING: { | 163 case STRING: { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 286 } |
288 | 287 |
289 bool Message::SetErrorName(const std::string& error_name) { | 288 bool Message::SetErrorName(const std::string& error_name) { |
290 return dbus_message_set_error_name(raw_message_, error_name.c_str()); | 289 return dbus_message_set_error_name(raw_message_, error_name.c_str()); |
291 } | 290 } |
292 | 291 |
293 bool Message::SetSender(const std::string& sender) { | 292 bool Message::SetSender(const std::string& sender) { |
294 return dbus_message_set_sender(raw_message_, sender.c_str()); | 293 return dbus_message_set_sender(raw_message_, sender.c_str()); |
295 } | 294 } |
296 | 295 |
297 void Message::SetSerial(uint32 serial) { | 296 void Message::SetSerial(uint32_t serial) { |
298 dbus_message_set_serial(raw_message_, serial); | 297 dbus_message_set_serial(raw_message_, serial); |
299 } | 298 } |
300 | 299 |
301 void Message::SetReplySerial(uint32 reply_serial) { | 300 void Message::SetReplySerial(uint32_t reply_serial) { |
302 dbus_message_set_reply_serial(raw_message_, reply_serial); | 301 dbus_message_set_reply_serial(raw_message_, reply_serial); |
303 } | 302 } |
304 | 303 |
305 std::string Message::GetDestination() { | 304 std::string Message::GetDestination() { |
306 const char* destination = dbus_message_get_destination(raw_message_); | 305 const char* destination = dbus_message_get_destination(raw_message_); |
307 return destination ? destination : ""; | 306 return destination ? destination : ""; |
308 } | 307 } |
309 | 308 |
310 ObjectPath Message::GetPath() { | 309 ObjectPath Message::GetPath() { |
311 const char* path = dbus_message_get_path(raw_message_); | 310 const char* path = dbus_message_get_path(raw_message_); |
(...skipping 18 matching lines...) Expand all Loading... |
330 std::string Message::GetSender() { | 329 std::string Message::GetSender() { |
331 const char* sender = dbus_message_get_sender(raw_message_); | 330 const char* sender = dbus_message_get_sender(raw_message_); |
332 return sender ? sender : ""; | 331 return sender ? sender : ""; |
333 } | 332 } |
334 | 333 |
335 std::string Message::GetSignature() { | 334 std::string Message::GetSignature() { |
336 const char* signature = dbus_message_get_signature(raw_message_); | 335 const char* signature = dbus_message_get_signature(raw_message_); |
337 return signature ? signature : ""; | 336 return signature ? signature : ""; |
338 } | 337 } |
339 | 338 |
340 uint32 Message::GetSerial() { | 339 uint32_t Message::GetSerial() { |
341 return dbus_message_get_serial(raw_message_); | 340 return dbus_message_get_serial(raw_message_); |
342 } | 341 } |
343 | 342 |
344 uint32 Message::GetReplySerial() { | 343 uint32_t Message::GetReplySerial() { |
345 return dbus_message_get_reply_serial(raw_message_); | 344 return dbus_message_get_reply_serial(raw_message_); |
346 } | 345 } |
347 | 346 |
348 // | 347 // |
349 // MethodCall implementation. | 348 // MethodCall implementation. |
350 // | 349 // |
351 | 350 |
352 MethodCall::MethodCall(const std::string& interface_name, | 351 MethodCall::MethodCall(const std::string& interface_name, |
353 const std::string& method_name) | 352 const std::string& method_name) |
354 : Message() { | 353 : Message() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 : message_(message), | 454 : message_(message), |
456 container_is_open_(false) { | 455 container_is_open_(false) { |
457 memset(&raw_message_iter_, 0, sizeof(raw_message_iter_)); | 456 memset(&raw_message_iter_, 0, sizeof(raw_message_iter_)); |
458 if (message) | 457 if (message) |
459 dbus_message_iter_init_append(message_->raw_message(), &raw_message_iter_); | 458 dbus_message_iter_init_append(message_->raw_message(), &raw_message_iter_); |
460 } | 459 } |
461 | 460 |
462 MessageWriter::~MessageWriter() { | 461 MessageWriter::~MessageWriter() { |
463 } | 462 } |
464 | 463 |
465 void MessageWriter::AppendByte(uint8 value) { | 464 void MessageWriter::AppendByte(uint8_t value) { |
466 AppendBasic(DBUS_TYPE_BYTE, &value); | 465 AppendBasic(DBUS_TYPE_BYTE, &value); |
467 } | 466 } |
468 | 467 |
469 void MessageWriter::AppendBool(bool value) { | 468 void MessageWriter::AppendBool(bool value) { |
470 // The size of dbus_bool_t and the size of bool are different. The | 469 // The size of dbus_bool_t and the size of bool are different. The |
471 // former is always 4 per dbus-types.h, whereas the latter is usually 1. | 470 // former is always 4 per dbus-types.h, whereas the latter is usually 1. |
472 // dbus_message_iter_append_basic() used in AppendBasic() expects four | 471 // dbus_message_iter_append_basic() used in AppendBasic() expects four |
473 // bytes for DBUS_TYPE_BOOLEAN, so we must pass a dbus_bool_t, instead | 472 // bytes for DBUS_TYPE_BOOLEAN, so we must pass a dbus_bool_t, instead |
474 // of a bool, to AppendBasic(). | 473 // of a bool, to AppendBasic(). |
475 dbus_bool_t dbus_value = value; | 474 dbus_bool_t dbus_value = value; |
476 AppendBasic(DBUS_TYPE_BOOLEAN, &dbus_value); | 475 AppendBasic(DBUS_TYPE_BOOLEAN, &dbus_value); |
477 } | 476 } |
478 | 477 |
479 void MessageWriter::AppendInt16(int16 value) { | 478 void MessageWriter::AppendInt16(int16_t value) { |
480 AppendBasic(DBUS_TYPE_INT16, &value); | 479 AppendBasic(DBUS_TYPE_INT16, &value); |
481 } | 480 } |
482 | 481 |
483 void MessageWriter::AppendUint16(uint16 value) { | 482 void MessageWriter::AppendUint16(uint16_t value) { |
484 AppendBasic(DBUS_TYPE_UINT16, &value); | 483 AppendBasic(DBUS_TYPE_UINT16, &value); |
485 } | 484 } |
486 | 485 |
487 void MessageWriter::AppendInt32(int32 value) { | 486 void MessageWriter::AppendInt32(int32_t value) { |
488 AppendBasic(DBUS_TYPE_INT32, &value); | 487 AppendBasic(DBUS_TYPE_INT32, &value); |
489 } | 488 } |
490 | 489 |
491 void MessageWriter::AppendUint32(uint32 value) { | 490 void MessageWriter::AppendUint32(uint32_t value) { |
492 AppendBasic(DBUS_TYPE_UINT32, &value); | 491 AppendBasic(DBUS_TYPE_UINT32, &value); |
493 } | 492 } |
494 | 493 |
495 void MessageWriter::AppendInt64(int64 value) { | 494 void MessageWriter::AppendInt64(int64_t value) { |
496 AppendBasic(DBUS_TYPE_INT64, &value); | 495 AppendBasic(DBUS_TYPE_INT64, &value); |
497 } | 496 } |
498 | 497 |
499 void MessageWriter::AppendUint64(uint64 value) { | 498 void MessageWriter::AppendUint64(uint64_t value) { |
500 AppendBasic(DBUS_TYPE_UINT64, &value); | 499 AppendBasic(DBUS_TYPE_UINT64, &value); |
501 } | 500 } |
502 | 501 |
503 void MessageWriter::AppendDouble(double value) { | 502 void MessageWriter::AppendDouble(double value) { |
504 AppendBasic(DBUS_TYPE_DOUBLE, &value); | 503 AppendBasic(DBUS_TYPE_DOUBLE, &value); |
505 } | 504 } |
506 | 505 |
507 void MessageWriter::AppendString(const std::string& value) { | 506 void MessageWriter::AppendString(const std::string& value) { |
508 // D-Bus Specification (0.19) says a string "must be valid UTF-8". | 507 // D-Bus Specification (0.19) says a string "must be valid UTF-8". |
509 CHECK(base::IsStringUTF8(value)); | 508 CHECK(base::IsStringUTF8(value)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 579 |
581 void MessageWriter::CloseContainer(MessageWriter* writer) { | 580 void MessageWriter::CloseContainer(MessageWriter* writer) { |
582 DCHECK(container_is_open_); | 581 DCHECK(container_is_open_); |
583 | 582 |
584 const bool success = dbus_message_iter_close_container( | 583 const bool success = dbus_message_iter_close_container( |
585 &raw_message_iter_, &writer->raw_message_iter_); | 584 &raw_message_iter_, &writer->raw_message_iter_); |
586 CHECK(success) << "Unable to allocate memory"; | 585 CHECK(success) << "Unable to allocate memory"; |
587 container_is_open_ = false; | 586 container_is_open_ = false; |
588 } | 587 } |
589 | 588 |
590 void MessageWriter::AppendArrayOfBytes(const uint8* values, size_t length) { | 589 void MessageWriter::AppendArrayOfBytes(const uint8_t* values, size_t length) { |
591 DCHECK(!container_is_open_); | 590 DCHECK(!container_is_open_); |
592 MessageWriter array_writer(message_); | 591 MessageWriter array_writer(message_); |
593 OpenArray("y", &array_writer); | 592 OpenArray("y", &array_writer); |
594 const bool success = dbus_message_iter_append_fixed_array( | 593 const bool success = dbus_message_iter_append_fixed_array( |
595 &(array_writer.raw_message_iter_), | 594 &(array_writer.raw_message_iter_), |
596 DBUS_TYPE_BYTE, | 595 DBUS_TYPE_BYTE, |
597 &values, | 596 &values, |
598 static_cast<int>(length)); | 597 static_cast<int>(length)); |
599 CHECK(success) << "Unable to allocate memory"; | 598 CHECK(success) << "Unable to allocate memory"; |
600 CloseContainer(&array_writer); | 599 CloseContainer(&array_writer); |
(...skipping 21 matching lines...) Expand all Loading... |
622 CloseContainer(&array_writer); | 621 CloseContainer(&array_writer); |
623 } | 622 } |
624 | 623 |
625 bool MessageWriter::AppendProtoAsArrayOfBytes( | 624 bool MessageWriter::AppendProtoAsArrayOfBytes( |
626 const google::protobuf::MessageLite& protobuf) { | 625 const google::protobuf::MessageLite& protobuf) { |
627 std::string serialized_proto; | 626 std::string serialized_proto; |
628 if (!protobuf.SerializeToString(&serialized_proto)) { | 627 if (!protobuf.SerializeToString(&serialized_proto)) { |
629 LOG(ERROR) << "Unable to serialize supplied protocol buffer"; | 628 LOG(ERROR) << "Unable to serialize supplied protocol buffer"; |
630 return false; | 629 return false; |
631 } | 630 } |
632 AppendArrayOfBytes(reinterpret_cast<const uint8*>(serialized_proto.data()), | 631 AppendArrayOfBytes(reinterpret_cast<const uint8_t*>(serialized_proto.data()), |
633 serialized_proto.size()); | 632 serialized_proto.size()); |
634 return true; | 633 return true; |
635 } | 634 } |
636 | 635 |
637 void MessageWriter::AppendVariantOfByte(uint8 value) { | 636 void MessageWriter::AppendVariantOfByte(uint8_t value) { |
638 AppendVariantOfBasic(DBUS_TYPE_BYTE, &value); | 637 AppendVariantOfBasic(DBUS_TYPE_BYTE, &value); |
639 } | 638 } |
640 | 639 |
641 void MessageWriter::AppendVariantOfBool(bool value) { | 640 void MessageWriter::AppendVariantOfBool(bool value) { |
642 // See the comment at MessageWriter::AppendBool(). | 641 // See the comment at MessageWriter::AppendBool(). |
643 dbus_bool_t dbus_value = value; | 642 dbus_bool_t dbus_value = value; |
644 AppendVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); | 643 AppendVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); |
645 } | 644 } |
646 | 645 |
647 void MessageWriter::AppendVariantOfInt16(int16 value) { | 646 void MessageWriter::AppendVariantOfInt16(int16_t value) { |
648 AppendVariantOfBasic(DBUS_TYPE_INT16, &value); | 647 AppendVariantOfBasic(DBUS_TYPE_INT16, &value); |
649 } | 648 } |
650 | 649 |
651 void MessageWriter::AppendVariantOfUint16(uint16 value) { | 650 void MessageWriter::AppendVariantOfUint16(uint16_t value) { |
652 AppendVariantOfBasic(DBUS_TYPE_UINT16, &value); | 651 AppendVariantOfBasic(DBUS_TYPE_UINT16, &value); |
653 } | 652 } |
654 | 653 |
655 void MessageWriter::AppendVariantOfInt32(int32 value) { | 654 void MessageWriter::AppendVariantOfInt32(int32_t value) { |
656 AppendVariantOfBasic(DBUS_TYPE_INT32, &value); | 655 AppendVariantOfBasic(DBUS_TYPE_INT32, &value); |
657 } | 656 } |
658 | 657 |
659 void MessageWriter::AppendVariantOfUint32(uint32 value) { | 658 void MessageWriter::AppendVariantOfUint32(uint32_t value) { |
660 AppendVariantOfBasic(DBUS_TYPE_UINT32, &value); | 659 AppendVariantOfBasic(DBUS_TYPE_UINT32, &value); |
661 } | 660 } |
662 | 661 |
663 void MessageWriter::AppendVariantOfInt64(int64 value) { | 662 void MessageWriter::AppendVariantOfInt64(int64_t value) { |
664 AppendVariantOfBasic(DBUS_TYPE_INT64, &value); | 663 AppendVariantOfBasic(DBUS_TYPE_INT64, &value); |
665 } | 664 } |
666 | 665 |
667 void MessageWriter::AppendVariantOfUint64(uint64 value) { | 666 void MessageWriter::AppendVariantOfUint64(uint64_t value) { |
668 AppendVariantOfBasic(DBUS_TYPE_UINT64, &value); | 667 AppendVariantOfBasic(DBUS_TYPE_UINT64, &value); |
669 } | 668 } |
670 | 669 |
671 void MessageWriter::AppendVariantOfDouble(double value) { | 670 void MessageWriter::AppendVariantOfDouble(double value) { |
672 AppendVariantOfBasic(DBUS_TYPE_DOUBLE, &value); | 671 AppendVariantOfBasic(DBUS_TYPE_DOUBLE, &value); |
673 } | 672 } |
674 | 673 |
675 void MessageWriter::AppendVariantOfString(const std::string& value) { | 674 void MessageWriter::AppendVariantOfString(const std::string& value) { |
676 const char* pointer = value.c_str(); | 675 const char* pointer = value.c_str(); |
677 AppendVariantOfBasic(DBUS_TYPE_STRING, &pointer); | 676 AppendVariantOfBasic(DBUS_TYPE_STRING, &pointer); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 | 725 |
727 | 726 |
728 MessageReader::~MessageReader() { | 727 MessageReader::~MessageReader() { |
729 } | 728 } |
730 | 729 |
731 bool MessageReader::HasMoreData() { | 730 bool MessageReader::HasMoreData() { |
732 const int dbus_type = dbus_message_iter_get_arg_type(&raw_message_iter_); | 731 const int dbus_type = dbus_message_iter_get_arg_type(&raw_message_iter_); |
733 return dbus_type != DBUS_TYPE_INVALID; | 732 return dbus_type != DBUS_TYPE_INVALID; |
734 } | 733 } |
735 | 734 |
736 bool MessageReader::PopByte(uint8* value) { | 735 bool MessageReader::PopByte(uint8_t* value) { |
737 return PopBasic(DBUS_TYPE_BYTE, value); | 736 return PopBasic(DBUS_TYPE_BYTE, value); |
738 } | 737 } |
739 | 738 |
740 bool MessageReader::PopBool(bool* value) { | 739 bool MessageReader::PopBool(bool* value) { |
741 // Like MessageWriter::AppendBool(), we should copy |value| to | 740 // Like MessageWriter::AppendBool(), we should copy |value| to |
742 // dbus_bool_t, as dbus_message_iter_get_basic() used in PopBasic() | 741 // dbus_bool_t, as dbus_message_iter_get_basic() used in PopBasic() |
743 // expects four bytes for DBUS_TYPE_BOOLEAN. | 742 // expects four bytes for DBUS_TYPE_BOOLEAN. |
744 dbus_bool_t dbus_value = FALSE; | 743 dbus_bool_t dbus_value = FALSE; |
745 const bool success = PopBasic(DBUS_TYPE_BOOLEAN, &dbus_value); | 744 const bool success = PopBasic(DBUS_TYPE_BOOLEAN, &dbus_value); |
746 *value = static_cast<bool>(dbus_value); | 745 *value = static_cast<bool>(dbus_value); |
747 return success; | 746 return success; |
748 } | 747 } |
749 | 748 |
750 bool MessageReader::PopInt16(int16* value) { | 749 bool MessageReader::PopInt16(int16_t* value) { |
751 return PopBasic(DBUS_TYPE_INT16, value); | 750 return PopBasic(DBUS_TYPE_INT16, value); |
752 } | 751 } |
753 | 752 |
754 bool MessageReader::PopUint16(uint16* value) { | 753 bool MessageReader::PopUint16(uint16_t* value) { |
755 return PopBasic(DBUS_TYPE_UINT16, value); | 754 return PopBasic(DBUS_TYPE_UINT16, value); |
756 } | 755 } |
757 | 756 |
758 bool MessageReader::PopInt32(int32* value) { | 757 bool MessageReader::PopInt32(int32_t* value) { |
759 return PopBasic(DBUS_TYPE_INT32, value); | 758 return PopBasic(DBUS_TYPE_INT32, value); |
760 } | 759 } |
761 | 760 |
762 bool MessageReader::PopUint32(uint32* value) { | 761 bool MessageReader::PopUint32(uint32_t* value) { |
763 return PopBasic(DBUS_TYPE_UINT32, value); | 762 return PopBasic(DBUS_TYPE_UINT32, value); |
764 } | 763 } |
765 | 764 |
766 bool MessageReader::PopInt64(int64* value) { | 765 bool MessageReader::PopInt64(int64_t* value) { |
767 return PopBasic(DBUS_TYPE_INT64, value); | 766 return PopBasic(DBUS_TYPE_INT64, value); |
768 } | 767 } |
769 | 768 |
770 bool MessageReader::PopUint64(uint64* value) { | 769 bool MessageReader::PopUint64(uint64_t* value) { |
771 return PopBasic(DBUS_TYPE_UINT64, value); | 770 return PopBasic(DBUS_TYPE_UINT64, value); |
772 } | 771 } |
773 | 772 |
774 bool MessageReader::PopDouble(double* value) { | 773 bool MessageReader::PopDouble(double* value) { |
775 return PopBasic(DBUS_TYPE_DOUBLE, value); | 774 return PopBasic(DBUS_TYPE_DOUBLE, value); |
776 } | 775 } |
777 | 776 |
778 bool MessageReader::PopString(std::string* value) { | 777 bool MessageReader::PopString(std::string* value) { |
779 char* tmp_value = NULL; | 778 char* tmp_value = NULL; |
780 const bool success = PopBasic(DBUS_TYPE_STRING, &tmp_value); | 779 const bool success = PopBasic(DBUS_TYPE_STRING, &tmp_value); |
(...skipping 19 matching lines...) Expand all Loading... |
800 } | 799 } |
801 | 800 |
802 bool MessageReader::PopDictEntry(MessageReader* sub_reader) { | 801 bool MessageReader::PopDictEntry(MessageReader* sub_reader) { |
803 return PopContainer(DBUS_TYPE_DICT_ENTRY, sub_reader); | 802 return PopContainer(DBUS_TYPE_DICT_ENTRY, sub_reader); |
804 } | 803 } |
805 | 804 |
806 bool MessageReader::PopVariant(MessageReader* sub_reader) { | 805 bool MessageReader::PopVariant(MessageReader* sub_reader) { |
807 return PopContainer(DBUS_TYPE_VARIANT, sub_reader); | 806 return PopContainer(DBUS_TYPE_VARIANT, sub_reader); |
808 } | 807 } |
809 | 808 |
810 bool MessageReader::PopArrayOfBytes(const uint8** bytes, size_t* length) { | 809 bool MessageReader::PopArrayOfBytes(const uint8_t** bytes, size_t* length) { |
811 MessageReader array_reader(message_); | 810 MessageReader array_reader(message_); |
812 if (!PopArray(&array_reader)) | 811 if (!PopArray(&array_reader)) |
813 return false; | 812 return false; |
814 // An empty array is allowed. | 813 // An empty array is allowed. |
815 if (!array_reader.HasMoreData()) { | 814 if (!array_reader.HasMoreData()) { |
816 *length = 0; | 815 *length = 0; |
817 *bytes = NULL; | 816 *bytes = NULL; |
818 return true; | 817 return true; |
819 } | 818 } |
820 if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) | 819 if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 object_paths->push_back(object_path); | 854 object_paths->push_back(object_path); |
856 } | 855 } |
857 return true; | 856 return true; |
858 } | 857 } |
859 | 858 |
860 bool MessageReader::PopArrayOfBytesAsProto( | 859 bool MessageReader::PopArrayOfBytesAsProto( |
861 google::protobuf::MessageLite* protobuf) { | 860 google::protobuf::MessageLite* protobuf) { |
862 DCHECK(protobuf != NULL); | 861 DCHECK(protobuf != NULL); |
863 const char* serialized_buf = NULL; | 862 const char* serialized_buf = NULL; |
864 size_t buf_size = 0; | 863 size_t buf_size = 0; |
865 if (!PopArrayOfBytes( | 864 if (!PopArrayOfBytes(reinterpret_cast<const uint8_t**>(&serialized_buf), |
866 reinterpret_cast<const uint8**>(&serialized_buf), &buf_size)) { | 865 &buf_size)) { |
867 LOG(ERROR) << "Error reading array of bytes"; | 866 LOG(ERROR) << "Error reading array of bytes"; |
868 return false; | 867 return false; |
869 } | 868 } |
870 if (!protobuf->ParseFromArray(serialized_buf, buf_size)) { | 869 if (!protobuf->ParseFromArray(serialized_buf, buf_size)) { |
871 LOG(ERROR) << "Failed to parse protocol buffer from array"; | 870 LOG(ERROR) << "Failed to parse protocol buffer from array"; |
872 return false; | 871 return false; |
873 } | 872 } |
874 return true; | 873 return true; |
875 } | 874 } |
876 | 875 |
877 bool MessageReader::PopVariantOfByte(uint8* value) { | 876 bool MessageReader::PopVariantOfByte(uint8_t* value) { |
878 return PopVariantOfBasic(DBUS_TYPE_BYTE, value); | 877 return PopVariantOfBasic(DBUS_TYPE_BYTE, value); |
879 } | 878 } |
880 | 879 |
881 bool MessageReader::PopVariantOfBool(bool* value) { | 880 bool MessageReader::PopVariantOfBool(bool* value) { |
882 // See the comment at MessageReader::PopBool(). | 881 // See the comment at MessageReader::PopBool(). |
883 dbus_bool_t dbus_value = FALSE; | 882 dbus_bool_t dbus_value = FALSE; |
884 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); | 883 const bool success = PopVariantOfBasic(DBUS_TYPE_BOOLEAN, &dbus_value); |
885 *value = static_cast<bool>(dbus_value); | 884 *value = static_cast<bool>(dbus_value); |
886 return success; | 885 return success; |
887 } | 886 } |
888 | 887 |
889 bool MessageReader::PopVariantOfInt16(int16* value) { | 888 bool MessageReader::PopVariantOfInt16(int16_t* value) { |
890 return PopVariantOfBasic(DBUS_TYPE_INT16, value); | 889 return PopVariantOfBasic(DBUS_TYPE_INT16, value); |
891 } | 890 } |
892 | 891 |
893 bool MessageReader::PopVariantOfUint16(uint16* value) { | 892 bool MessageReader::PopVariantOfUint16(uint16_t* value) { |
894 return PopVariantOfBasic(DBUS_TYPE_UINT16, value); | 893 return PopVariantOfBasic(DBUS_TYPE_UINT16, value); |
895 } | 894 } |
896 | 895 |
897 bool MessageReader::PopVariantOfInt32(int32* value) { | 896 bool MessageReader::PopVariantOfInt32(int32_t* value) { |
898 return PopVariantOfBasic(DBUS_TYPE_INT32, value); | 897 return PopVariantOfBasic(DBUS_TYPE_INT32, value); |
899 } | 898 } |
900 | 899 |
901 bool MessageReader::PopVariantOfUint32(uint32* value) { | 900 bool MessageReader::PopVariantOfUint32(uint32_t* value) { |
902 return PopVariantOfBasic(DBUS_TYPE_UINT32, value); | 901 return PopVariantOfBasic(DBUS_TYPE_UINT32, value); |
903 } | 902 } |
904 | 903 |
905 bool MessageReader::PopVariantOfInt64(int64* value) { | 904 bool MessageReader::PopVariantOfInt64(int64_t* value) { |
906 return PopVariantOfBasic(DBUS_TYPE_INT64, value); | 905 return PopVariantOfBasic(DBUS_TYPE_INT64, value); |
907 } | 906 } |
908 | 907 |
909 bool MessageReader::PopVariantOfUint64(uint64* value) { | 908 bool MessageReader::PopVariantOfUint64(uint64_t* value) { |
910 return PopVariantOfBasic(DBUS_TYPE_UINT64, value); | 909 return PopVariantOfBasic(DBUS_TYPE_UINT64, value); |
911 } | 910 } |
912 | 911 |
913 bool MessageReader::PopVariantOfDouble(double* value) { | 912 bool MessageReader::PopVariantOfDouble(double* value) { |
914 return PopVariantOfBasic(DBUS_TYPE_DOUBLE, value); | 913 return PopVariantOfBasic(DBUS_TYPE_DOUBLE, value); |
915 } | 914 } |
916 | 915 |
917 bool MessageReader::PopVariantOfString(std::string* value) { | 916 bool MessageReader::PopVariantOfString(std::string* value) { |
918 char* tmp_value = NULL; | 917 char* tmp_value = NULL; |
919 const bool success = PopVariantOfBasic(DBUS_TYPE_STRING, &tmp_value); | 918 const bool success = PopVariantOfBasic(DBUS_TYPE_STRING, &tmp_value); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); | 991 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); |
993 if (!success) | 992 if (!success) |
994 return false; | 993 return false; |
995 | 994 |
996 value->PutValue(fd); | 995 value->PutValue(fd); |
997 // NB: the caller must check validity before using the value | 996 // NB: the caller must check validity before using the value |
998 return true; | 997 return true; |
999 } | 998 } |
1000 | 999 |
1001 } // namespace dbus | 1000 } // namespace dbus |
OLD | NEW |