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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 AppendStringHeader("sender", GetSender(), &headers); | 242 AppendStringHeader("sender", GetSender(), &headers); |
243 AppendStringHeader("signature", GetSignature(), &headers); | 243 AppendStringHeader("signature", GetSignature(), &headers); |
244 AppendUint32Header("serial", GetSerial(), &headers); | 244 AppendUint32Header("serial", GetSerial(), &headers); |
245 AppendUint32Header("reply_serial", GetReplySerial(), &headers); | 245 AppendUint32Header("reply_serial", GetReplySerial(), &headers); |
246 | 246 |
247 // Generate the payload. | 247 // Generate the payload. |
248 MessageReader reader(this); | 248 MessageReader reader(this); |
249 return headers + "\n" + ToStringInternal("", &reader); | 249 return headers + "\n" + ToStringInternal("", &reader); |
250 } | 250 } |
251 | 251 |
252 void Message::SetDestination(const std::string& destination) { | 252 bool Message::SetDestination(const std::string& destination) { |
253 const bool success = dbus_message_set_destination(raw_message_, | 253 return dbus_message_set_destination(raw_message_, destination.c_str()); |
254 destination.c_str()); | |
255 CHECK(success) << "Unable to allocate memory"; | |
256 } | 254 } |
257 | 255 |
258 void Message::SetPath(const ObjectPath& path) { | 256 bool Message::SetPath(const ObjectPath& path) { |
259 const bool success = dbus_message_set_path(raw_message_, | 257 return dbus_message_set_path(raw_message_, path.value().c_str()); |
260 path.value().c_str()); | |
261 CHECK(success) << "Unable to allocate memory"; | |
262 } | 258 } |
263 | 259 |
264 void Message::SetInterface(const std::string& interface) { | 260 bool Message::SetInterface(const std::string& interface) { |
265 const bool success = dbus_message_set_interface(raw_message_, | 261 return dbus_message_set_interface(raw_message_, interface.c_str()); |
266 interface.c_str()); | |
267 CHECK(success) << "Unable to allocate memory"; | |
268 } | 262 } |
269 | 263 |
270 void Message::SetMember(const std::string& member) { | 264 bool Message::SetMember(const std::string& member) { |
271 const bool success = dbus_message_set_member(raw_message_, | 265 return dbus_message_set_member(raw_message_, member.c_str()); |
272 member.c_str()); | |
273 CHECK(success) << "Unable to allocate memory"; | |
274 } | 266 } |
275 | 267 |
276 void Message::SetErrorName(const std::string& error_name) { | 268 bool Message::SetErrorName(const std::string& error_name) { |
277 const bool success = dbus_message_set_error_name(raw_message_, | 269 return dbus_message_set_error_name(raw_message_, error_name.c_str()); |
278 error_name.c_str()); | |
279 CHECK(success) << "Unable to allocate memory"; | |
280 } | 270 } |
281 | 271 |
282 void Message::SetSender(const std::string& sender) { | 272 bool Message::SetSender(const std::string& sender) { |
283 const bool success = dbus_message_set_sender(raw_message_, | 273 return dbus_message_set_sender(raw_message_, sender.c_str()); |
284 sender.c_str()); | |
285 CHECK(success) << "Unable to allocate memory"; | |
286 } | 274 } |
287 | 275 |
288 void Message::SetSerial(uint32 serial) { | 276 void Message::SetSerial(uint32 serial) { |
289 dbus_message_set_serial(raw_message_, serial); | 277 dbus_message_set_serial(raw_message_, serial); |
290 } | 278 } |
291 | 279 |
292 void Message::SetReplySerial(uint32 reply_serial) { | 280 void Message::SetReplySerial(uint32 reply_serial) { |
293 dbus_message_set_reply_serial(raw_message_, reply_serial); | 281 dbus_message_set_reply_serial(raw_message_, reply_serial); |
294 } | 282 } |
295 | 283 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 326 |
339 // | 327 // |
340 // MethodCall implementation. | 328 // MethodCall implementation. |
341 // | 329 // |
342 | 330 |
343 MethodCall::MethodCall(const std::string& interface_name, | 331 MethodCall::MethodCall(const std::string& interface_name, |
344 const std::string& method_name) | 332 const std::string& method_name) |
345 : Message() { | 333 : Message() { |
346 Init(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)); | 334 Init(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)); |
347 | 335 |
348 SetInterface(interface_name); | 336 CHECK(SetInterface(interface_name)); |
349 SetMember(method_name); | 337 CHECK(SetMember(method_name)); |
350 } | 338 } |
351 | 339 |
352 MethodCall::MethodCall() : Message() { | 340 MethodCall::MethodCall() : Message() { |
353 } | 341 } |
354 | 342 |
355 MethodCall* MethodCall::FromRawMessage(DBusMessage* raw_message) { | 343 MethodCall* MethodCall::FromRawMessage(DBusMessage* raw_message) { |
356 DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_CALL, dbus_message_get_type(raw_message)); | 344 DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_CALL, dbus_message_get_type(raw_message)); |
357 | 345 |
358 MethodCall* method_call = new MethodCall; | 346 MethodCall* method_call = new MethodCall; |
359 method_call->Init(raw_message); | 347 method_call->Init(raw_message); |
360 return method_call; | 348 return method_call; |
361 } | 349 } |
362 | 350 |
363 // | 351 // |
364 // Signal implementation. | 352 // Signal implementation. |
365 // | 353 // |
366 Signal::Signal(const std::string& interface_name, | 354 Signal::Signal(const std::string& interface_name, |
367 const std::string& method_name) | 355 const std::string& method_name) |
368 : Message() { | 356 : Message() { |
369 Init(dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL)); | 357 Init(dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL)); |
370 | 358 |
371 SetInterface(interface_name); | 359 CHECK(SetInterface(interface_name)); |
372 SetMember(method_name); | 360 CHECK(SetMember(method_name)); |
373 } | 361 } |
374 | 362 |
375 Signal::Signal() : Message() { | 363 Signal::Signal() : Message() { |
376 } | 364 } |
377 | 365 |
378 Signal* Signal::FromRawMessage(DBusMessage* raw_message) { | 366 Signal* Signal::FromRawMessage(DBusMessage* raw_message) { |
379 DCHECK_EQ(DBUS_MESSAGE_TYPE_SIGNAL, dbus_message_get_type(raw_message)); | 367 DCHECK_EQ(DBUS_MESSAGE_TYPE_SIGNAL, dbus_message_get_type(raw_message)); |
380 | 368 |
381 Signal* signal = new Signal; | 369 Signal* signal = new Signal; |
382 signal->Init(raw_message); | 370 signal->Init(raw_message); |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); | 952 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); |
965 if (!success) | 953 if (!success) |
966 return false; | 954 return false; |
967 | 955 |
968 value->PutValue(fd); | 956 value->PutValue(fd); |
969 // NB: the caller must check validity before using the value | 957 // NB: the caller must check validity before using the value |
970 return true; | 958 return true; |
971 } | 959 } |
972 | 960 |
973 } // namespace dbus | 961 } // namespace dbus |
OLD | NEW |