Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: dbus/message.h

Issue 7491029: Implement Bus and ObjectProxy classes for our D-Bus library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor change Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Returns the type of the message. Returns MESSAGE_INVALID if 67 // Returns the type of the message. Returns MESSAGE_INVALID if
68 // raw_message_ is NULL. 68 // raw_message_ is NULL.
69 MessageType GetMessageType(); 69 MessageType GetMessageType();
70 70
71 DBusMessage* raw_message() { return raw_message_; } 71 DBusMessage* raw_message() { return raw_message_; }
72 72
73 // Resets raw_message_ with the given raw message. Takes the ownership 73 // Resets raw_message_ with the given raw message. Takes the ownership
74 // of raw_message. raw_message_ will be unref'ed in the destructor. 74 // of raw_message. raw_message_ will be unref'ed in the destructor.
75 void reset_raw_message(DBusMessage* raw_message); 75 void reset_raw_message(DBusMessage* raw_message);
76 76
77 // Sets the destination, the path, the interface, the member, etc.
78 void SetDestination(const std::string& destination);
79 void SetPath(const std::string& path);
80 void SetInterface(const std::string& interface);
81 void SetMember(const std::string& member);
82 void SetErrorName(const std::string& error_name);
83 void SetSender(const std::string& sender);
84 void SetSerial(uint32 serial);
85 void SetReplySerial(uint32 reply_serial);
86 // SetSignature() does not exist as we cannot do it.
87
88 // Gets the destination, the path, the interface, the member, etc.
89 // If not set, an empty string is returned.
90 std::string GetDestination();
91 std::string GetPath();
92 std::string GetInterface();
93 std::string GetMember();
94 std::string GetErrorName();
95 std::string GetSender();
96 std::string GetSignature();
97 // Gets the serial and reply serial numbers. Returns 0 if not set.
98 uint32 GetSerial();
99 uint32 GetReplySerial();
100
77 // Returns the string representation of this message. Useful for 101 // Returns the string representation of this message. Useful for
78 // debugging. 102 // debugging.
79 std::string ToString(); 103 std::string ToString();
80 104
81 private: 105 private:
82 // Helper function used in ToString(). 106 // Helper function used in ToString().
83 std::string ToStringInternal(const std::string& indent, 107 std::string ToStringInternal(const std::string& indent,
84 MessageReader* reader); 108 MessageReader* reader);
85 109
86 DBusMessage* raw_message_; 110 DBusMessage* raw_message_;
(...skipping 10 matching lines...) Expand all
97 // interface ("org.freedesktop.DBus.Introspectable"), create a method 121 // interface ("org.freedesktop.DBus.Introspectable"), create a method
98 // call like this: 122 // call like this:
99 // 123 //
100 // MethodCall method_call(DBUS_INTERFACE_INTROSPECTABLE, "Get"); 124 // MethodCall method_call(DBUS_INTERFACE_INTROSPECTABLE, "Get");
101 // 125 //
102 // The constructor creates the internal raw_message_, so the client 126 // The constructor creates the internal raw_message_, so the client
103 // doesn't need to set this with reset_raw_message(). 127 // doesn't need to set this with reset_raw_message().
104 MethodCall(const std::string& interface_name, 128 MethodCall(const std::string& interface_name,
105 const std::string& method_name); 129 const std::string& method_name);
106 130
107 const std::string& interface_name() { return interface_name_; } 131 // Returns a newly created MethodCall from the given raw message of the
108 const std::string& method_name() { return method_name_; } 132 // type DBUS_MESSAGE_TYPE_METHOD_CALL. The caller must delete the
109 133 // returned object. Takes the ownership of |raw_message|.
110 // Sets the service name. This will be handled by the object proxy. 134 static MethodCall* FromRawMessage(DBusMessage* raw_message);
111 void SetServiceName(const std::string& service_name);
112 // Sets the object path. This will be handled by the object proxy.
113 void SetObjectPath(const std::string& object_path);
114
115 std::string interface_name_;
116 std::string method_name_;
117 135
118 DISALLOW_COPY_AND_ASSIGN(MethodCall); 136 DISALLOW_COPY_AND_ASSIGN(MethodCall);
119 }; 137 };
120 138
121 // Response is a type of message used for receiving a response from a 139 // Response is a type of message used for receiving a response from a
122 // method via D-Bus. 140 // method via D-Bus.
123 class Response : public Message { 141 class Response : public Message {
124 public: 142 public:
125 // Creates a Response message. The internal raw message is NULL. 143 // Creates a Response message. The internal raw message is NULL.
126 // Classes that implment method calls need to set the raw message once a 144 // Classes that implment method calls need to set the raw message once a
127 // response is received from the server. See object_proxy.h. 145 // response is received from the server. See object_proxy.h.
128 Response(); 146 Response();
129 147
148 // Returns a newly created Response from the given method call. The
149 // caller must delete the returned object. Used for implementing
150 // exported methods.
151 static Response* FromMethodCall(MethodCall* method_call);
152
130 private: 153 private:
131 DISALLOW_COPY_AND_ASSIGN(Response); 154 DISALLOW_COPY_AND_ASSIGN(Response);
132 }; 155 };
133 156
157 // ErrorResponse is a type of message used to return an error to the
158 // caller of a method.
159 class ErrorResponse: public Message {
160 public:
161 // Creates a ErrorResponse message. The internal raw message is NULL.
162 // Classes that implment method calls need to set the raw message once a
163 // response is received from the server. See object_proxy.h.
164 ErrorResponse();
165
166 // Returns a newly created ErrorResponse from the given method call, the
167 // error name, and the error message. The error name looks like
168 // "org.freedesktop.DBus.Error.Failed". Used for returning an error to a
169 // failed method call.
170 static ErrorResponse* FromMethodCall(MethodCall* method_call,
171 const std::string& error_name,
172 const std::string& error_message);
173
174 private:
175 DISALLOW_COPY_AND_ASSIGN(ErrorResponse);
176 };
177
134 // MessageWriter is used to write outgoing messages for calling methods 178 // MessageWriter is used to write outgoing messages for calling methods
135 // and sending signals. 179 // and sending signals.
136 // 180 //
137 // The main design goal of MessageReader and MessageWriter classes is to 181 // The main design goal of MessageReader and MessageWriter classes is to
138 // provide a type safe API. In the past, there was a Chrome OS blocker 182 // provide a type safe API. In the past, there was a Chrome OS blocker
139 // bug, that took days to fix, that would have been prevented if the API 183 // bug, that took days to fix, that would have been prevented if the API
140 // was type-safe. 184 // was type-safe.
141 // 185 //
142 // For instance, instead of doing something like: 186 // For instance, instead of doing something like:
143 // 187 //
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 368
325 Message* message_; 369 Message* message_;
326 DBusMessageIter raw_message_iter_; 370 DBusMessageIter raw_message_iter_;
327 371
328 DISALLOW_COPY_AND_ASSIGN(MessageReader); 372 DISALLOW_COPY_AND_ASSIGN(MessageReader);
329 }; 373 };
330 374
331 } // namespace dbus 375 } // namespace dbus
332 376
333 #endif // DBUS_MESSAGE_H_ 377 #endif // DBUS_MESSAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698