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" | 9 #include "base/basictypes.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 // nonzero. | 35 // nonzero. |
36 void AppendUint32Header(const std::string& header_name, | 36 void AppendUint32Header(const std::string& header_name, |
37 uint32 header_value, | 37 uint32 header_value, |
38 std::string* output) { | 38 std::string* output) { |
39 if (header_value != 0) { | 39 if (header_value != 0) { |
40 *output += (header_name + ": " + base::StringPrintf("%u", header_value) + | 40 *output += (header_name + ": " + base::StringPrintf("%u", header_value) + |
41 "\n"); | 41 "\n"); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 struct DBusFreeDeleter { | |
46 inline void operator()(void* ptr) const { | |
47 dbus_free(ptr); | |
48 } | |
49 }; | |
50 | |
45 } // namespace | 51 } // namespace |
46 | 52 |
47 namespace dbus { | 53 namespace dbus { |
48 | 54 |
49 bool IsDBusTypeUnixFdSupported() { | 55 bool IsDBusTypeUnixFdSupported() { |
50 int major = 0, minor = 0, micro = 0; | 56 int major = 0, minor = 0, micro = 0; |
51 dbus_get_version(&major, &minor, µ); | 57 dbus_get_version(&major, &minor, µ); |
52 return major >= 1 && minor >= 4; | 58 return major >= 1 && minor >= 4; |
53 } | 59 } |
54 | 60 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 | 261 |
256 // Generate headers first. | 262 // Generate headers first. |
257 std::string headers; | 263 std::string headers; |
258 AppendStringHeader("message_type", GetMessageTypeAsString(), &headers); | 264 AppendStringHeader("message_type", GetMessageTypeAsString(), &headers); |
259 AppendStringHeader("destination", GetDestination(), &headers); | 265 AppendStringHeader("destination", GetDestination(), &headers); |
260 AppendStringHeader("path", GetPath().value(), &headers); | 266 AppendStringHeader("path", GetPath().value(), &headers); |
261 AppendStringHeader("interface", GetInterface(), &headers); | 267 AppendStringHeader("interface", GetInterface(), &headers); |
262 AppendStringHeader("member", GetMember(), &headers); | 268 AppendStringHeader("member", GetMember(), &headers); |
263 AppendStringHeader("error_name", GetErrorName(), &headers); | 269 AppendStringHeader("error_name", GetErrorName(), &headers); |
264 AppendStringHeader("sender", GetSender(), &headers); | 270 AppendStringHeader("sender", GetSender(), &headers); |
265 AppendStringHeader("signature", GetSignature(), &headers); | 271 AppendStringHeader("signature", GetDataSignature(), &headers); |
266 AppendUint32Header("serial", GetSerial(), &headers); | 272 AppendUint32Header("serial", GetSerial(), &headers); |
267 AppendUint32Header("reply_serial", GetReplySerial(), &headers); | 273 AppendUint32Header("reply_serial", GetReplySerial(), &headers); |
268 | 274 |
269 // Generate the payload. | 275 // Generate the payload. |
270 MessageReader reader(this); | 276 MessageReader reader(this); |
271 return headers + "\n" + ToStringInternal(std::string(), &reader); | 277 return headers + "\n" + ToStringInternal(std::string(), &reader); |
272 } | 278 } |
273 | 279 |
274 bool Message::SetDestination(const std::string& destination) { | 280 bool Message::SetDestination(const std::string& destination) { |
275 return dbus_message_set_destination(raw_message_, destination.c_str()); | 281 return dbus_message_set_destination(raw_message_, destination.c_str()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 std::string Message::GetErrorName() { | 332 std::string Message::GetErrorName() { |
327 const char* error_name = dbus_message_get_error_name(raw_message_); | 333 const char* error_name = dbus_message_get_error_name(raw_message_); |
328 return error_name ? error_name : ""; | 334 return error_name ? error_name : ""; |
329 } | 335 } |
330 | 336 |
331 std::string Message::GetSender() { | 337 std::string Message::GetSender() { |
332 const char* sender = dbus_message_get_sender(raw_message_); | 338 const char* sender = dbus_message_get_sender(raw_message_); |
333 return sender ? sender : ""; | 339 return sender ? sender : ""; |
334 } | 340 } |
335 | 341 |
336 std::string Message::GetSignature() { | 342 std::string Message::GetDataSignature() { |
337 const char* signature = dbus_message_get_signature(raw_message_); | 343 const char* signature = dbus_message_get_signature(raw_message_); |
338 return signature ? signature : ""; | 344 return signature ? signature : ""; |
339 } | 345 } |
340 | 346 |
341 uint32 Message::GetSerial() { | 347 uint32 Message::GetSerial() { |
342 return dbus_message_get_serial(raw_message_); | 348 return dbus_message_get_serial(raw_message_); |
343 } | 349 } |
344 | 350 |
345 uint32 Message::GetReplySerial() { | 351 uint32 Message::GetReplySerial() { |
346 return dbus_message_get_reply_serial(raw_message_); | 352 return dbus_message_get_reply_serial(raw_message_); |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 if (success) | 934 if (success) |
929 *value = ObjectPath(tmp_value); | 935 *value = ObjectPath(tmp_value); |
930 return success; | 936 return success; |
931 } | 937 } |
932 | 938 |
933 Message::DataType MessageReader::GetDataType() { | 939 Message::DataType MessageReader::GetDataType() { |
934 const int dbus_type = dbus_message_iter_get_arg_type(&raw_message_iter_); | 940 const int dbus_type = dbus_message_iter_get_arg_type(&raw_message_iter_); |
935 return static_cast<Message::DataType>(dbus_type); | 941 return static_cast<Message::DataType>(dbus_type); |
936 } | 942 } |
937 | 943 |
944 std::string MessageReader::GetDataSignature() { | |
945 scoped_ptr<char, DBusFreeDeleter> signature( | |
946 dbus_message_iter_get_signature(&raw_message_iter_)); | |
satorux1
2014/08/25 05:33:27
I understand the intention, but I guess calling db
Ben Chan
2014/08/25 05:43:07
Done.
| |
947 return signature ? signature.get() : ""; | |
948 } | |
949 | |
938 bool MessageReader::CheckDataType(int dbus_type) { | 950 bool MessageReader::CheckDataType(int dbus_type) { |
939 const int actual_type = dbus_message_iter_get_arg_type(&raw_message_iter_); | 951 const int actual_type = dbus_message_iter_get_arg_type(&raw_message_iter_); |
940 if (actual_type != dbus_type) { | 952 if (actual_type != dbus_type) { |
941 VLOG(1) << "Type " << dbus_type << " is expected but got " | 953 VLOG(1) << "Type " << dbus_type << " is expected but got " |
942 << actual_type; | 954 << actual_type; |
943 return false; | 955 return false; |
944 } | 956 } |
945 return true; | 957 return true; |
946 } | 958 } |
947 | 959 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); | 994 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); |
983 if (!success) | 995 if (!success) |
984 return false; | 996 return false; |
985 | 997 |
986 value->PutValue(fd); | 998 value->PutValue(fd); |
987 // NB: the caller must check validity before using the value | 999 // NB: the caller must check validity before using the value |
988 return true; | 1000 return true; |
989 } | 1001 } |
990 | 1002 |
991 } // namespace dbus | 1003 } // namespace dbus |
OLD | NEW |