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 | 7 |
| 8 #include <dbus/dbus.h> |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
8 #include <string> | 11 #include <string> |
9 #include <vector> | 12 #include <vector> |
10 #include <dbus/dbus.h> | |
11 | 13 |
12 #include "base/basictypes.h" | 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "dbus/dbus_export.h" | 16 #include "dbus/dbus_export.h" |
15 #include "dbus/file_descriptor.h" | 17 #include "dbus/file_descriptor.h" |
16 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
17 | 19 |
18 namespace google { | 20 namespace google { |
19 namespace protobuf { | 21 namespace protobuf { |
20 | 22 |
21 class MessageLite; | 23 class MessageLite; |
22 | 24 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 94 |
93 DBusMessage* raw_message() { return raw_message_; } | 95 DBusMessage* raw_message() { return raw_message_; } |
94 | 96 |
95 // Sets the destination, the path, the interface, the member, etc. | 97 // Sets the destination, the path, the interface, the member, etc. |
96 bool SetDestination(const std::string& destination); | 98 bool SetDestination(const std::string& destination); |
97 bool SetPath(const ObjectPath& path); | 99 bool SetPath(const ObjectPath& path); |
98 bool SetInterface(const std::string& interface); | 100 bool SetInterface(const std::string& interface); |
99 bool SetMember(const std::string& member); | 101 bool SetMember(const std::string& member); |
100 bool SetErrorName(const std::string& error_name); | 102 bool SetErrorName(const std::string& error_name); |
101 bool SetSender(const std::string& sender); | 103 bool SetSender(const std::string& sender); |
102 void SetSerial(uint32 serial); | 104 void SetSerial(uint32_t serial); |
103 void SetReplySerial(uint32 reply_serial); | 105 void SetReplySerial(uint32_t reply_serial); |
104 // SetSignature() does not exist as we cannot do it. | 106 // SetSignature() does not exist as we cannot do it. |
105 | 107 |
106 // Gets the destination, the path, the interface, the member, etc. | 108 // Gets the destination, the path, the interface, the member, etc. |
107 // If not set, an empty string is returned. | 109 // If not set, an empty string is returned. |
108 std::string GetDestination(); | 110 std::string GetDestination(); |
109 ObjectPath GetPath(); | 111 ObjectPath GetPath(); |
110 std::string GetInterface(); | 112 std::string GetInterface(); |
111 std::string GetMember(); | 113 std::string GetMember(); |
112 std::string GetErrorName(); | 114 std::string GetErrorName(); |
113 std::string GetSender(); | 115 std::string GetSender(); |
114 std::string GetSignature(); | 116 std::string GetSignature(); |
115 // Gets the serial and reply serial numbers. Returns 0 if not set. | 117 // Gets the serial and reply serial numbers. Returns 0 if not set. |
116 uint32 GetSerial(); | 118 uint32_t GetSerial(); |
117 uint32 GetReplySerial(); | 119 uint32_t GetReplySerial(); |
118 | 120 |
119 // Returns the string representation of this message. Useful for | 121 // Returns the string representation of this message. Useful for |
120 // debugging. The output is truncated as needed (ex. strings are truncated | 122 // debugging. The output is truncated as needed (ex. strings are truncated |
121 // if longer than a certain limit defined in the .cc file). | 123 // if longer than a certain limit defined in the .cc file). |
122 std::string ToString(); | 124 std::string ToString(); |
123 | 125 |
124 protected: | 126 protected: |
125 // This class cannot be instantiated. Use sub classes instead. | 127 // This class cannot be instantiated. Use sub classes instead. |
126 Message(); | 128 Message(); |
127 virtual ~Message(); | 129 virtual ~Message(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // writer.AppendString(str); | 265 // writer.AppendString(str); |
264 // | 266 // |
265 class CHROME_DBUS_EXPORT MessageWriter { | 267 class CHROME_DBUS_EXPORT MessageWriter { |
266 public: | 268 public: |
267 // Data added with Append* will be written to |message|, which may be NULL | 269 // Data added with Append* will be written to |message|, which may be NULL |
268 // to create a sub-writer for passing to OpenArray, etc. | 270 // to create a sub-writer for passing to OpenArray, etc. |
269 explicit MessageWriter(Message* message); | 271 explicit MessageWriter(Message* message); |
270 ~MessageWriter(); | 272 ~MessageWriter(); |
271 | 273 |
272 // Appends a byte to the message. | 274 // Appends a byte to the message. |
273 void AppendByte(uint8 value); | 275 void AppendByte(uint8_t value); |
274 void AppendBool(bool value); | 276 void AppendBool(bool value); |
275 void AppendInt16(int16 value); | 277 void AppendInt16(int16_t value); |
276 void AppendUint16(uint16 value); | 278 void AppendUint16(uint16_t value); |
277 void AppendInt32(int32 value); | 279 void AppendInt32(int32_t value); |
278 void AppendUint32(uint32 value); | 280 void AppendUint32(uint32_t value); |
279 void AppendInt64(int64 value); | 281 void AppendInt64(int64_t value); |
280 void AppendUint64(uint64 value); | 282 void AppendUint64(uint64_t value); |
281 void AppendDouble(double value); | 283 void AppendDouble(double value); |
282 void AppendString(const std::string& value); | 284 void AppendString(const std::string& value); |
283 void AppendObjectPath(const ObjectPath& value); | 285 void AppendObjectPath(const ObjectPath& value); |
284 void AppendFileDescriptor(const FileDescriptor& value); | 286 void AppendFileDescriptor(const FileDescriptor& value); |
285 | 287 |
286 // Opens an array. The array contents can be added to the array with | 288 // Opens an array. The array contents can be added to the array with |
287 // |sub_writer|. The client code must close the array with | 289 // |sub_writer|. The client code must close the array with |
288 // CloseContainer(), once all contents are added. | 290 // CloseContainer(), once all contents are added. |
289 // | 291 // |
290 // |signature| parameter is used to supply the D-Bus type signature of | 292 // |signature| parameter is used to supply the D-Bus type signature of |
(...skipping 10 matching lines...) Expand all Loading... |
301 // Do the same for Struct and dict entry. They don't need the signature. | 303 // Do the same for Struct and dict entry. They don't need the signature. |
302 void OpenStruct(MessageWriter* sub_writer); | 304 void OpenStruct(MessageWriter* sub_writer); |
303 void OpenDictEntry(MessageWriter* sub_writer); | 305 void OpenDictEntry(MessageWriter* sub_writer); |
304 | 306 |
305 // Close the container for a array/variant/struct/dict entry. | 307 // Close the container for a array/variant/struct/dict entry. |
306 void CloseContainer(MessageWriter* sub_writer); | 308 void CloseContainer(MessageWriter* sub_writer); |
307 | 309 |
308 // Appends the array of bytes. Arrays of bytes are often used for | 310 // Appends the array of bytes. Arrays of bytes are often used for |
309 // exchanging binary blobs hence it's worth having a specialized | 311 // exchanging binary blobs hence it's worth having a specialized |
310 // function. | 312 // function. |
311 void AppendArrayOfBytes(const uint8* values, size_t length); | 313 void AppendArrayOfBytes(const uint8_t* values, size_t length); |
312 | 314 |
313 // Appends the array of strings. Arrays of strings are often used for | 315 // Appends the array of strings. Arrays of strings are often used for |
314 // exchanging lists of names hence it's worth having a specialized | 316 // exchanging lists of names hence it's worth having a specialized |
315 // function. | 317 // function. |
316 void AppendArrayOfStrings(const std::vector<std::string>& strings); | 318 void AppendArrayOfStrings(const std::vector<std::string>& strings); |
317 | 319 |
318 // Appends the array of object paths. Arrays of object paths are often | 320 // Appends the array of object paths. Arrays of object paths are often |
319 // used when exchanging object paths, hence it's worth having a | 321 // used when exchanging object paths, hence it's worth having a |
320 // specialized function. | 322 // specialized function. |
321 void AppendArrayOfObjectPaths(const std::vector<ObjectPath>& object_paths); | 323 void AppendArrayOfObjectPaths(const std::vector<ObjectPath>& object_paths); |
322 | 324 |
323 // Appends the protocol buffer as an array of bytes. The buffer is serialized | 325 // Appends the protocol buffer as an array of bytes. The buffer is serialized |
324 // into an array of bytes before communication, since protocol buffers are not | 326 // into an array of bytes before communication, since protocol buffers are not |
325 // a native dbus type. On the receiving size the array of bytes needs to be | 327 // a native dbus type. On the receiving size the array of bytes needs to be |
326 // read and deserialized into a protocol buffer of the correct type. There are | 328 // read and deserialized into a protocol buffer of the correct type. There are |
327 // methods in MessageReader to assist in this. Return true on succes and fail | 329 // methods in MessageReader to assist in this. Return true on succes and fail |
328 // when serialization is not successful. | 330 // when serialization is not successful. |
329 bool AppendProtoAsArrayOfBytes(const google::protobuf::MessageLite& protobuf); | 331 bool AppendProtoAsArrayOfBytes(const google::protobuf::MessageLite& protobuf); |
330 | 332 |
331 // Appends the byte wrapped in a variant data container. Variants are | 333 // Appends the byte wrapped in a variant data container. Variants are |
332 // widely used in D-Bus services so it's worth having a specialized | 334 // widely used in D-Bus services so it's worth having a specialized |
333 // function. For instance, The third parameter of | 335 // function. For instance, The third parameter of |
334 // "org.freedesktop.DBus.Properties.Set" is a variant. | 336 // "org.freedesktop.DBus.Properties.Set" is a variant. |
335 void AppendVariantOfByte(uint8 value); | 337 void AppendVariantOfByte(uint8_t value); |
336 void AppendVariantOfBool(bool value); | 338 void AppendVariantOfBool(bool value); |
337 void AppendVariantOfInt16(int16 value); | 339 void AppendVariantOfInt16(int16_t value); |
338 void AppendVariantOfUint16(uint16 value); | 340 void AppendVariantOfUint16(uint16_t value); |
339 void AppendVariantOfInt32(int32 value); | 341 void AppendVariantOfInt32(int32_t value); |
340 void AppendVariantOfUint32(uint32 value); | 342 void AppendVariantOfUint32(uint32_t value); |
341 void AppendVariantOfInt64(int64 value); | 343 void AppendVariantOfInt64(int64_t value); |
342 void AppendVariantOfUint64(uint64 value); | 344 void AppendVariantOfUint64(uint64_t value); |
343 void AppendVariantOfDouble(double value); | 345 void AppendVariantOfDouble(double value); |
344 void AppendVariantOfString(const std::string& value); | 346 void AppendVariantOfString(const std::string& value); |
345 void AppendVariantOfObjectPath(const ObjectPath& value); | 347 void AppendVariantOfObjectPath(const ObjectPath& value); |
346 | 348 |
347 private: | 349 private: |
348 // Helper function used to implement AppendByte etc. | 350 // Helper function used to implement AppendByte etc. |
349 void AppendBasic(int dbus_type, const void* value); | 351 void AppendBasic(int dbus_type, const void* value); |
350 | 352 |
351 // Helper function used to implement AppendVariantOfByte() etc. | 353 // Helper function used to implement AppendVariantOfByte() etc. |
352 void AppendVariantOfBasic(int dbus_type, const void* value); | 354 void AppendVariantOfBasic(int dbus_type, const void* value); |
(...skipping 20 matching lines...) Expand all Loading... |
373 // Returns true if the reader has more data to read. The function is | 375 // Returns true if the reader has more data to read. The function is |
374 // used to iterate contents in a container like: | 376 // used to iterate contents in a container like: |
375 // | 377 // |
376 // while (reader.HasMoreData()) | 378 // while (reader.HasMoreData()) |
377 // reader.PopString(&value); | 379 // reader.PopString(&value); |
378 bool HasMoreData(); | 380 bool HasMoreData(); |
379 | 381 |
380 // Gets the byte at the current iterator position. | 382 // Gets the byte at the current iterator position. |
381 // Returns true and advances the iterator on success. | 383 // Returns true and advances the iterator on success. |
382 // Returns false if the data type is not a byte. | 384 // Returns false if the data type is not a byte. |
383 bool PopByte(uint8* value); | 385 bool PopByte(uint8_t* value); |
384 bool PopBool(bool* value); | 386 bool PopBool(bool* value); |
385 bool PopInt16(int16* value); | 387 bool PopInt16(int16_t* value); |
386 bool PopUint16(uint16* value); | 388 bool PopUint16(uint16_t* value); |
387 bool PopInt32(int32* value); | 389 bool PopInt32(int32_t* value); |
388 bool PopUint32(uint32* value); | 390 bool PopUint32(uint32_t* value); |
389 bool PopInt64(int64* value); | 391 bool PopInt64(int64_t* value); |
390 bool PopUint64(uint64* value); | 392 bool PopUint64(uint64_t* value); |
391 bool PopDouble(double* value); | 393 bool PopDouble(double* value); |
392 bool PopString(std::string* value); | 394 bool PopString(std::string* value); |
393 bool PopObjectPath(ObjectPath* value); | 395 bool PopObjectPath(ObjectPath* value); |
394 bool PopFileDescriptor(FileDescriptor* value); | 396 bool PopFileDescriptor(FileDescriptor* value); |
395 | 397 |
396 // Sets up the given message reader to read an array at the current | 398 // Sets up the given message reader to read an array at the current |
397 // iterator position. | 399 // iterator position. |
398 // Returns true and advances the iterator on success. | 400 // Returns true and advances the iterator on success. |
399 // Returns false if the data type is not an array | 401 // Returns false if the data type is not an array |
400 bool PopArray(MessageReader* sub_reader); | 402 bool PopArray(MessageReader* sub_reader); |
401 bool PopStruct(MessageReader* sub_reader); | 403 bool PopStruct(MessageReader* sub_reader); |
402 bool PopDictEntry(MessageReader* sub_reader); | 404 bool PopDictEntry(MessageReader* sub_reader); |
403 bool PopVariant(MessageReader* sub_reader); | 405 bool PopVariant(MessageReader* sub_reader); |
404 | 406 |
405 // Gets the array of bytes at the current iterator position. | 407 // Gets the array of bytes at the current iterator position. |
406 // Returns true and advances the iterator on success. | 408 // Returns true and advances the iterator on success. |
407 // | 409 // |
408 // Arrays of bytes are often used for exchanging binary blobs hence it's | 410 // Arrays of bytes are often used for exchanging binary blobs hence it's |
409 // worth having a specialized function. | 411 // worth having a specialized function. |
410 // | 412 // |
411 // Ownership of the memory pointed to by |bytes| remains with the | 413 // Ownership of the memory pointed to by |bytes| remains with the |
412 // MessageReader; |bytes| must be copied if the contents will be referenced | 414 // MessageReader; |bytes| must be copied if the contents will be referenced |
413 // after the MessageReader is destroyed. | 415 // after the MessageReader is destroyed. |
414 bool PopArrayOfBytes(const uint8** bytes, size_t* length); | 416 bool PopArrayOfBytes(const uint8_t** bytes, size_t* length); |
415 | 417 |
416 // Gets the array of strings at the current iterator position. |strings| is | 418 // Gets the array of strings at the current iterator position. |strings| is |
417 // cleared before being modified. Returns true and advances the iterator on | 419 // cleared before being modified. Returns true and advances the iterator on |
418 // success. | 420 // success. |
419 // | 421 // |
420 // Arrays of strings are often used to communicate with D-Bus | 422 // Arrays of strings are often used to communicate with D-Bus |
421 // services like KWallet, hence it's worth having a specialized | 423 // services like KWallet, hence it's worth having a specialized |
422 // function. | 424 // function. |
423 bool PopArrayOfStrings(std::vector<std::string>* strings); | 425 bool PopArrayOfStrings(std::vector<std::string>* strings); |
424 | 426 |
(...skipping 14 matching lines...) Expand all Loading... |
439 // the wrong type of protocol buffer is passed in and the parse fails. | 441 // the wrong type of protocol buffer is passed in and the parse fails. |
440 bool PopArrayOfBytesAsProto(google::protobuf::MessageLite* protobuf); | 442 bool PopArrayOfBytesAsProto(google::protobuf::MessageLite* protobuf); |
441 | 443 |
442 // Gets the byte from the variant data container at the current iterator | 444 // Gets the byte from the variant data container at the current iterator |
443 // position. | 445 // position. |
444 // Returns true and advances the iterator on success. | 446 // Returns true and advances the iterator on success. |
445 // | 447 // |
446 // Variants are widely used in D-Bus services so it's worth having a | 448 // Variants are widely used in D-Bus services so it's worth having a |
447 // specialized function. For instance, The return value type of | 449 // specialized function. For instance, The return value type of |
448 // "org.freedesktop.DBus.Properties.Get" is a variant. | 450 // "org.freedesktop.DBus.Properties.Get" is a variant. |
449 bool PopVariantOfByte(uint8* value); | 451 bool PopVariantOfByte(uint8_t* value); |
450 bool PopVariantOfBool(bool* value); | 452 bool PopVariantOfBool(bool* value); |
451 bool PopVariantOfInt16(int16* value); | 453 bool PopVariantOfInt16(int16_t* value); |
452 bool PopVariantOfUint16(uint16* value); | 454 bool PopVariantOfUint16(uint16_t* value); |
453 bool PopVariantOfInt32(int32* value); | 455 bool PopVariantOfInt32(int32_t* value); |
454 bool PopVariantOfUint32(uint32* value); | 456 bool PopVariantOfUint32(uint32_t* value); |
455 bool PopVariantOfInt64(int64* value); | 457 bool PopVariantOfInt64(int64_t* value); |
456 bool PopVariantOfUint64(uint64* value); | 458 bool PopVariantOfUint64(uint64_t* value); |
457 bool PopVariantOfDouble(double* value); | 459 bool PopVariantOfDouble(double* value); |
458 bool PopVariantOfString(std::string* value); | 460 bool PopVariantOfString(std::string* value); |
459 bool PopVariantOfObjectPath(ObjectPath* value); | 461 bool PopVariantOfObjectPath(ObjectPath* value); |
460 | 462 |
461 // Get the data type of the value at the current iterator | 463 // Get the data type of the value at the current iterator |
462 // position. INVALID_DATA will be returned if the iterator points to the | 464 // position. INVALID_DATA will be returned if the iterator points to the |
463 // end of the message. | 465 // end of the message. |
464 Message::DataType GetDataType(); | 466 Message::DataType GetDataType(); |
465 | 467 |
466 // Get the DBus signature of the value at the current iterator position. | 468 // Get the DBus signature of the value at the current iterator position. |
(...skipping 17 matching lines...) Expand all Loading... |
484 | 486 |
485 Message* message_; | 487 Message* message_; |
486 DBusMessageIter raw_message_iter_; | 488 DBusMessageIter raw_message_iter_; |
487 | 489 |
488 DISALLOW_COPY_AND_ASSIGN(MessageReader); | 490 DISALLOW_COPY_AND_ASSIGN(MessageReader); |
489 }; | 491 }; |
490 | 492 |
491 } // namespace dbus | 493 } // namespace dbus |
492 | 494 |
493 #endif // DBUS_MESSAGE_H_ | 495 #endif // DBUS_MESSAGE_H_ |
OLD | NEW |