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 #ifndef DBUS_MESSAGE_H_ | 5 #ifndef DBUS_MESSAGE_H_ |
6 #define DBUS_MESSAGE_H_ | 6 #define DBUS_MESSAGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 #include <dbus/dbus.h> | 11 #include <dbus/dbus.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "dbus/object_path.h" |
14 | 15 |
15 namespace google { | 16 namespace google { |
16 namespace protobuf { | 17 namespace protobuf { |
17 | 18 |
18 class MessageLite; | 19 class MessageLite; |
19 | 20 |
20 } // namespace protobuf | 21 } // namespace protobuf |
21 } // namespace google | 22 } // namespace google |
22 | 23 |
23 | 24 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 MessageType GetMessageType(); | 74 MessageType GetMessageType(); |
74 | 75 |
75 // Returns the type of the message as string like "MESSAGE_METHOD_CALL" | 76 // Returns the type of the message as string like "MESSAGE_METHOD_CALL" |
76 // for instance. | 77 // for instance. |
77 std::string GetMessageTypeAsString(); | 78 std::string GetMessageTypeAsString(); |
78 | 79 |
79 DBusMessage* raw_message() { return raw_message_; } | 80 DBusMessage* raw_message() { return raw_message_; } |
80 | 81 |
81 // Sets the destination, the path, the interface, the member, etc. | 82 // Sets the destination, the path, the interface, the member, etc. |
82 void SetDestination(const std::string& destination); | 83 void SetDestination(const std::string& destination); |
83 void SetPath(const std::string& path); | 84 void SetPath(const ObjectPath& path); |
84 void SetInterface(const std::string& interface); | 85 void SetInterface(const std::string& interface); |
85 void SetMember(const std::string& member); | 86 void SetMember(const std::string& member); |
86 void SetErrorName(const std::string& error_name); | 87 void SetErrorName(const std::string& error_name); |
87 void SetSender(const std::string& sender); | 88 void SetSender(const std::string& sender); |
88 void SetSerial(uint32 serial); | 89 void SetSerial(uint32 serial); |
89 void SetReplySerial(uint32 reply_serial); | 90 void SetReplySerial(uint32 reply_serial); |
90 // SetSignature() does not exist as we cannot do it. | 91 // SetSignature() does not exist as we cannot do it. |
91 | 92 |
92 // Gets the destination, the path, the interface, the member, etc. | 93 // Gets the destination, the path, the interface, the member, etc. |
93 // If not set, an empty string is returned. | 94 // If not set, an empty string is returned. |
94 std::string GetDestination(); | 95 std::string GetDestination(); |
95 std::string GetPath(); | 96 ObjectPath GetPath(); |
96 std::string GetInterface(); | 97 std::string GetInterface(); |
97 std::string GetMember(); | 98 std::string GetMember(); |
98 std::string GetErrorName(); | 99 std::string GetErrorName(); |
99 std::string GetSender(); | 100 std::string GetSender(); |
100 std::string GetSignature(); | 101 std::string GetSignature(); |
101 // Gets the serial and reply serial numbers. Returns 0 if not set. | 102 // Gets the serial and reply serial numbers. Returns 0 if not set. |
102 uint32 GetSerial(); | 103 uint32 GetSerial(); |
103 uint32 GetReplySerial(); | 104 uint32 GetReplySerial(); |
104 | 105 |
105 // Returns the string representation of this message. Useful for | 106 // Returns the string representation of this message. Useful for |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void AppendByte(uint8 value); | 259 void AppendByte(uint8 value); |
259 void AppendBool(bool value); | 260 void AppendBool(bool value); |
260 void AppendInt16(int16 value); | 261 void AppendInt16(int16 value); |
261 void AppendUint16(uint16 value); | 262 void AppendUint16(uint16 value); |
262 void AppendInt32(int32 value); | 263 void AppendInt32(int32 value); |
263 void AppendUint32(uint32 value); | 264 void AppendUint32(uint32 value); |
264 void AppendInt64(int64 value); | 265 void AppendInt64(int64 value); |
265 void AppendUint64(uint64 value); | 266 void AppendUint64(uint64 value); |
266 void AppendDouble(double value); | 267 void AppendDouble(double value); |
267 void AppendString(const std::string& value); | 268 void AppendString(const std::string& value); |
268 void AppendObjectPath(const std::string& value); | 269 void AppendObjectPath(const ObjectPath& value); |
269 | 270 |
270 // Opens an array. The array contents can be added to the array with | 271 // Opens an array. The array contents can be added to the array with |
271 // |sub_writer|. The client code must close the array with | 272 // |sub_writer|. The client code must close the array with |
272 // CloseContainer(), once all contents are added. | 273 // CloseContainer(), once all contents are added. |
273 // | 274 // |
274 // |signature| parameter is used to supply the D-Bus type signature of | 275 // |signature| parameter is used to supply the D-Bus type signature of |
275 // the array contents. For instance, if you want an array of strings, | 276 // the array contents. For instance, if you want an array of strings, |
276 // then you pass "s" as the signature. | 277 // then you pass "s" as the signature. |
277 // | 278 // |
278 // See the spec for details about the type signatures. | 279 // See the spec for details about the type signatures. |
(...skipping 16 matching lines...) Expand all Loading... |
295 void AppendArrayOfBytes(const uint8* values, size_t length); | 296 void AppendArrayOfBytes(const uint8* values, size_t length); |
296 | 297 |
297 // Appends the array of strings. Arrays of strings are often used for | 298 // Appends the array of strings. Arrays of strings are often used for |
298 // exchanging lists of names hence it's worth having a specialized | 299 // exchanging lists of names hence it's worth having a specialized |
299 // function. | 300 // function. |
300 void AppendArrayOfStrings(const std::vector<std::string>& strings); | 301 void AppendArrayOfStrings(const std::vector<std::string>& strings); |
301 | 302 |
302 // Appends the array of object paths. Arrays of object paths are often | 303 // Appends the array of object paths. Arrays of object paths are often |
303 // used when exchanging object paths, hence it's worth having a | 304 // used when exchanging object paths, hence it's worth having a |
304 // specialized function. | 305 // specialized function. |
305 void AppendArrayOfObjectPaths(const std::vector<std::string>& object_paths); | 306 void AppendArrayOfObjectPaths(const std::vector<ObjectPath>& object_paths); |
306 | 307 |
307 // Appends the protocol buffer as an array of bytes. The buffer is serialized | 308 // Appends the protocol buffer as an array of bytes. The buffer is serialized |
308 // into an array of bytes before communication, since protocol buffers are not | 309 // into an array of bytes before communication, since protocol buffers are not |
309 // a native dbus type. On the receiving size the array of bytes needs to be | 310 // a native dbus type. On the receiving size the array of bytes needs to be |
310 // read and deserialized into a protocol buffer of the correct type. There are | 311 // read and deserialized into a protocol buffer of the correct type. There are |
311 // methods in MessageReader to assist in this. Return true on succes and fail | 312 // methods in MessageReader to assist in this. Return true on succes and fail |
312 // when serialization is not successful. | 313 // when serialization is not successful. |
313 bool AppendProtoAsArrayOfBytes(const google::protobuf::MessageLite& protobuf); | 314 bool AppendProtoAsArrayOfBytes(const google::protobuf::MessageLite& protobuf); |
314 | 315 |
315 // Appends the byte wrapped in a variant data container. Variants are | 316 // Appends the byte wrapped in a variant data container. Variants are |
316 // widely used in D-Bus services so it's worth having a specialized | 317 // widely used in D-Bus services so it's worth having a specialized |
317 // function. For instance, The third parameter of | 318 // function. For instance, The third parameter of |
318 // "org.freedesktop.DBus.Properties.Set" is a variant. | 319 // "org.freedesktop.DBus.Properties.Set" is a variant. |
319 void AppendVariantOfByte(uint8 value); | 320 void AppendVariantOfByte(uint8 value); |
320 void AppendVariantOfBool(bool value); | 321 void AppendVariantOfBool(bool value); |
321 void AppendVariantOfInt16(int16 value); | 322 void AppendVariantOfInt16(int16 value); |
322 void AppendVariantOfUint16(uint16 value); | 323 void AppendVariantOfUint16(uint16 value); |
323 void AppendVariantOfInt32(int32 value); | 324 void AppendVariantOfInt32(int32 value); |
324 void AppendVariantOfUint32(uint32 value); | 325 void AppendVariantOfUint32(uint32 value); |
325 void AppendVariantOfInt64(int64 value); | 326 void AppendVariantOfInt64(int64 value); |
326 void AppendVariantOfUint64(uint64 value); | 327 void AppendVariantOfUint64(uint64 value); |
327 void AppendVariantOfDouble(double value); | 328 void AppendVariantOfDouble(double value); |
328 void AppendVariantOfString(const std::string& value); | 329 void AppendVariantOfString(const std::string& value); |
329 void AppendVariantOfObjectPath(const std::string& value); | 330 void AppendVariantOfObjectPath(const ObjectPath& value); |
330 | 331 |
331 private: | 332 private: |
332 // Helper function used to implement AppendByte etc. | 333 // Helper function used to implement AppendByte etc. |
333 void AppendBasic(int dbus_type, const void* value); | 334 void AppendBasic(int dbus_type, const void* value); |
334 | 335 |
335 // Helper function used to implement AppendVariantOfByte() etc. | 336 // Helper function used to implement AppendVariantOfByte() etc. |
336 void AppendVariantOfBasic(int dbus_type, const void* value); | 337 void AppendVariantOfBasic(int dbus_type, const void* value); |
337 | 338 |
338 Message* message_; | 339 Message* message_; |
339 DBusMessageIter raw_message_iter_; | 340 DBusMessageIter raw_message_iter_; |
(...skipping 27 matching lines...) Expand all Loading... |
367 bool PopByte(uint8* value); | 368 bool PopByte(uint8* value); |
368 bool PopBool(bool* value); | 369 bool PopBool(bool* value); |
369 bool PopInt16(int16* value); | 370 bool PopInt16(int16* value); |
370 bool PopUint16(uint16* value); | 371 bool PopUint16(uint16* value); |
371 bool PopInt32(int32* value); | 372 bool PopInt32(int32* value); |
372 bool PopUint32(uint32* value); | 373 bool PopUint32(uint32* value); |
373 bool PopInt64(int64* value); | 374 bool PopInt64(int64* value); |
374 bool PopUint64(uint64* value); | 375 bool PopUint64(uint64* value); |
375 bool PopDouble(double* value); | 376 bool PopDouble(double* value); |
376 bool PopString(std::string* value); | 377 bool PopString(std::string* value); |
377 bool PopObjectPath(std::string* value); | 378 bool PopObjectPath(ObjectPath* value); |
378 | 379 |
379 // Sets up the given message reader to read an array at the current | 380 // Sets up the given message reader to read an array at the current |
380 // iterator position. | 381 // iterator position. |
381 // Returns true and advances the iterator on success. | 382 // Returns true and advances the iterator on success. |
382 // Returns false if the data type is not an array | 383 // Returns false if the data type is not an array |
383 bool PopArray(MessageReader* sub_reader); | 384 bool PopArray(MessageReader* sub_reader); |
384 bool PopStruct(MessageReader* sub_reader); | 385 bool PopStruct(MessageReader* sub_reader); |
385 bool PopDictEntry(MessageReader* sub_reader); | 386 bool PopDictEntry(MessageReader* sub_reader); |
386 bool PopVariant(MessageReader* sub_reader); | 387 bool PopVariant(MessageReader* sub_reader); |
387 | 388 |
(...skipping 14 matching lines...) Expand all Loading... |
402 // services like KWallet, hence it's worth having a specialized | 403 // services like KWallet, hence it's worth having a specialized |
403 // function. | 404 // function. |
404 bool PopArrayOfStrings(std::vector<std::string>* strings); | 405 bool PopArrayOfStrings(std::vector<std::string>* strings); |
405 | 406 |
406 // Gets the array of object paths at the current iterator position. | 407 // Gets the array of object paths at the current iterator position. |
407 // Returns true and advances the iterator on success. | 408 // Returns true and advances the iterator on success. |
408 // | 409 // |
409 // Arrays of object paths are often used to communicate with D-Bus | 410 // Arrays of object paths are often used to communicate with D-Bus |
410 // services like NetworkManager, hence it's worth having a specialized | 411 // services like NetworkManager, hence it's worth having a specialized |
411 // function. | 412 // function. |
412 bool PopArrayOfObjectPaths(std::vector<std::string>* object_paths); | 413 bool PopArrayOfObjectPaths(std::vector<ObjectPath>* object_paths); |
413 | 414 |
414 // Gets the array of bytes at the current iterator position. It then parses | 415 // Gets the array of bytes at the current iterator position. It then parses |
415 // this binary blob into the protocol buffer supplied. | 416 // this binary blob into the protocol buffer supplied. |
416 // Returns true and advances the iterator on success. On failure returns false | 417 // Returns true and advances the iterator on success. On failure returns false |
417 // and emits an error message on the source of the failure. The two most | 418 // and emits an error message on the source of the failure. The two most |
418 // common errors come from the iterator not currently being at a byte array or | 419 // common errors come from the iterator not currently being at a byte array or |
419 // the wrong type of protocol buffer is passed in and the parse fails. | 420 // the wrong type of protocol buffer is passed in and the parse fails. |
420 bool PopArrayOfBytesAsProto(google::protobuf::MessageLite* protobuf); | 421 bool PopArrayOfBytesAsProto(google::protobuf::MessageLite* protobuf); |
421 | 422 |
422 // Gets the byte from the variant data container at the current iterator | 423 // Gets the byte from the variant data container at the current iterator |
423 // position. | 424 // position. |
424 // Returns true and advances the iterator on success. | 425 // Returns true and advances the iterator on success. |
425 // | 426 // |
426 // Variants are widely used in D-Bus services so it's worth having a | 427 // Variants are widely used in D-Bus services so it's worth having a |
427 // specialized function. For instance, The return value type of | 428 // specialized function. For instance, The return value type of |
428 // "org.freedesktop.DBus.Properties.Get" is a variant. | 429 // "org.freedesktop.DBus.Properties.Get" is a variant. |
429 bool PopVariantOfByte(uint8* value); | 430 bool PopVariantOfByte(uint8* value); |
430 bool PopVariantOfBool(bool* value); | 431 bool PopVariantOfBool(bool* value); |
431 bool PopVariantOfInt16(int16* value); | 432 bool PopVariantOfInt16(int16* value); |
432 bool PopVariantOfUint16(uint16* value); | 433 bool PopVariantOfUint16(uint16* value); |
433 bool PopVariantOfInt32(int32* value); | 434 bool PopVariantOfInt32(int32* value); |
434 bool PopVariantOfUint32(uint32* value); | 435 bool PopVariantOfUint32(uint32* value); |
435 bool PopVariantOfInt64(int64* value); | 436 bool PopVariantOfInt64(int64* value); |
436 bool PopVariantOfUint64(uint64* value); | 437 bool PopVariantOfUint64(uint64* value); |
437 bool PopVariantOfDouble(double* value); | 438 bool PopVariantOfDouble(double* value); |
438 bool PopVariantOfString(std::string* value); | 439 bool PopVariantOfString(std::string* value); |
439 bool PopVariantOfObjectPath(std::string* value); | 440 bool PopVariantOfObjectPath(ObjectPath* value); |
440 | 441 |
441 // Get the data type of the value at the current iterator | 442 // Get the data type of the value at the current iterator |
442 // position. INVALID_DATA will be returned if the iterator points to the | 443 // position. INVALID_DATA will be returned if the iterator points to the |
443 // end of the message. | 444 // end of the message. |
444 Message::DataType GetDataType(); | 445 Message::DataType GetDataType(); |
445 | 446 |
446 private: | 447 private: |
447 // Returns true if the data type at the current iterator position | 448 // Returns true if the data type at the current iterator position |
448 // matches the given D-Bus type, such as DBUS_TYPE_BYTE. | 449 // matches the given D-Bus type, such as DBUS_TYPE_BYTE. |
449 bool CheckDataType(int dbus_type); | 450 bool CheckDataType(int dbus_type); |
450 | 451 |
451 // Helper function used to implement PopByte() etc. | 452 // Helper function used to implement PopByte() etc. |
452 bool PopBasic(int dbus_type, void *value); | 453 bool PopBasic(int dbus_type, void *value); |
453 | 454 |
454 // Helper function used to implement PopArray() etc. | 455 // Helper function used to implement PopArray() etc. |
455 bool PopContainer(int dbus_type, MessageReader* sub_reader); | 456 bool PopContainer(int dbus_type, MessageReader* sub_reader); |
456 | 457 |
457 // Helper function used to implement PopVariantOfByte() etc. | 458 // Helper function used to implement PopVariantOfByte() etc. |
458 bool PopVariantOfBasic(int dbus_type, void* value); | 459 bool PopVariantOfBasic(int dbus_type, void* value); |
459 | 460 |
460 Message* message_; | 461 Message* message_; |
461 DBusMessageIter raw_message_iter_; | 462 DBusMessageIter raw_message_iter_; |
462 | 463 |
463 DISALLOW_COPY_AND_ASSIGN(MessageReader); | 464 DISALLOW_COPY_AND_ASSIGN(MessageReader); |
464 }; | 465 }; |
465 | 466 |
466 } // namespace dbus | 467 } // namespace dbus |
467 | 468 |
468 #endif // DBUS_MESSAGE_H_ | 469 #endif // DBUS_MESSAGE_H_ |
OLD | NEW |