diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-10 22:34:02 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-10 22:34:02 +0000 |
commit | 9cce2d32f708024bb24d0036e98a2ded583a9552 (patch) | |
tree | fb80fe7896ce20361a777ae429bc74475f039f11 /dbus/message.h | |
parent | db6d774d0055bc4d1f79ced2b93dd2ea2a56fe9b (diff) | |
download | chromium_src-9cce2d32f708024bb24d0036e98a2ded583a9552.zip chromium_src-9cce2d32f708024bb24d0036e98a2ded583a9552.tar.gz chromium_src-9cce2d32f708024bb24d0036e98a2ded583a9552.tar.bz2 |
Add utility functions to Message classes.
The new functions will be used to implement other classes
that will be added in a separate patch.
BUG=90036
TEST=run unit tests
Review URL: http://codereview.chromium.org/7569020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96231 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/message.h')
-rw-r--r-- | dbus/message.h | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/dbus/message.h b/dbus/message.h index 501f99a..31887a1 100644 --- a/dbus/message.h +++ b/dbus/message.h @@ -74,6 +74,30 @@ class Message { // of raw_message. raw_message_ will be unref'ed in the destructor. void reset_raw_message(DBusMessage* raw_message); + // Sets the destination, the path, the interface, the member, etc. + void SetDestination(const std::string& destination); + void SetPath(const std::string& path); + void SetInterface(const std::string& interface); + void SetMember(const std::string& member); + void SetErrorName(const std::string& error_name); + void SetSender(const std::string& sender); + void SetSerial(uint32 serial); + void SetReplySerial(uint32 reply_serial); + // SetSignature() does not exist as we cannot do it. + + // Gets the destination, the path, the interface, the member, etc. + // If not set, an empty string is returned. + std::string GetDestination(); + std::string GetPath(); + std::string GetInterface(); + std::string GetMember(); + std::string GetErrorName(); + std::string GetSender(); + std::string GetSignature(); + // Gets the serial and reply serial numbers. Returns 0 if not set. + uint32 GetSerial(); + uint32 GetReplySerial(); + // Returns the string representation of this message. Useful for // debugging. std::string ToString(); @@ -104,16 +128,10 @@ class MethodCall : public Message { MethodCall(const std::string& interface_name, const std::string& method_name); - const std::string& interface_name() { return interface_name_; } - const std::string& method_name() { return method_name_; } - - // Sets the service name. This will be handled by the object proxy. - void SetServiceName(const std::string& service_name); - // Sets the object path. This will be handled by the object proxy. - void SetObjectPath(const std::string& object_path); - - std::string interface_name_; - std::string method_name_; + // Returns a newly created MethodCall from the given raw message of the + // type DBUS_MESSAGE_TYPE_METHOD_CALL. The caller must delete the + // returned object. Takes the ownership of |raw_message|. + static MethodCall* FromRawMessage(DBusMessage* raw_message); DISALLOW_COPY_AND_ASSIGN(MethodCall); }; @@ -127,10 +145,36 @@ class Response : public Message { // response is received from the server. See object_proxy.h. Response(); + // Returns a newly created Response from the given method call. The + // caller must delete the returned object. Used for implementing + // exported methods. + static Response* FromMethodCall(MethodCall* method_call); + private: DISALLOW_COPY_AND_ASSIGN(Response); }; +// ErrorResponse is a type of message used to return an error to the +// caller of a method. +class ErrorResponse: public Message { + public: + // Creates a ErrorResponse message. The internal raw message is NULL. + // Classes that implment method calls need to set the raw message once a + // response is received from the server. See object_proxy.h. + ErrorResponse(); + + // Returns a newly created ErrorResponse from the given method call, the + // error name, and the error message. The error name looks like + // "org.freedesktop.DBus.Error.Failed". Used for returning an error to a + // failed method call. + static ErrorResponse* FromMethodCall(MethodCall* method_call, + const std::string& error_name, + const std::string& error_message); + + private: + DISALLOW_COPY_AND_ASSIGN(ErrorResponse); +}; + // MessageWriter is used to write outgoing messages for calling methods // and sending signals. // |