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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include <dbus/dbus.h> | 10 #include <dbus/dbus.h> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" |
13 #include "dbus/dbus_export.h" | 14 #include "dbus/dbus_export.h" |
14 #include "dbus/file_descriptor.h" | 15 #include "dbus/file_descriptor.h" |
15 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
16 | 17 |
17 namespace google { | 18 namespace google { |
18 namespace protobuf { | 19 namespace protobuf { |
19 | 20 |
20 class MessageLite; | 21 class MessageLite; |
21 | 22 |
22 } // namespace protobuf | 23 } // namespace protobuf |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 Signal(); | 194 Signal(); |
194 | 195 |
195 DISALLOW_COPY_AND_ASSIGN(Signal); | 196 DISALLOW_COPY_AND_ASSIGN(Signal); |
196 }; | 197 }; |
197 | 198 |
198 // Response is a type of message used for receiving a response from a | 199 // Response is a type of message used for receiving a response from a |
199 // method via D-Bus. | 200 // method via D-Bus. |
200 class CHROME_DBUS_EXPORT Response : public Message { | 201 class CHROME_DBUS_EXPORT Response : public Message { |
201 public: | 202 public: |
202 // Returns a newly created Response from the given raw message of the | 203 // Returns a newly created Response from the given raw message of the |
203 // type DBUS_MESSAGE_TYPE_METHOD_RETURN. The caller must delete the | 204 // type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|. |
204 // returned object. Takes the ownership of |raw_message|. | 205 static scoped_ptr<Response> FromRawMessage(DBusMessage* raw_message); |
205 static Response* FromRawMessage(DBusMessage* raw_message); | |
206 | 206 |
207 // Returns a newly created Response from the given method call. The | 207 // Returns a newly created Response from the given method call. |
208 // caller must delete the returned object. Used for implementing | 208 // Used for implementing exported methods. Does NOT take the ownership of |
209 // exported methods. | 209 // |method_call|. |
210 static Response* FromMethodCall(MethodCall* method_call); | 210 static scoped_ptr<Response> FromMethodCall(MethodCall* method_call); |
211 | 211 |
212 // Returns a newly created Response with an empty payload. The caller | 212 // Returns a newly created Response with an empty payload. |
213 // must delete the returned object. Useful for testing. | 213 // Useful for testing. |
214 static Response* CreateEmpty(); | 214 static scoped_ptr<Response> CreateEmpty(); |
215 | 215 |
216 protected: | 216 protected: |
217 // Creates a Response message. The internal raw message is NULL. | 217 // Creates a Response message. The internal raw message is NULL. |
218 Response(); | 218 Response(); |
219 | 219 |
220 private: | 220 private: |
221 DISALLOW_COPY_AND_ASSIGN(Response); | 221 DISALLOW_COPY_AND_ASSIGN(Response); |
222 }; | 222 }; |
223 | 223 |
224 // ErrorResponse is a type of message used to return an error to the | 224 // ErrorResponse is a type of message used to return an error to the |
225 // caller of a method. | 225 // caller of a method. |
226 class CHROME_DBUS_EXPORT ErrorResponse: public Response { | 226 class CHROME_DBUS_EXPORT ErrorResponse: public Response { |
227 public: | 227 public: |
228 // Returns a newly created Response from the given raw message of the | 228 // Returns a newly created Response from the given raw message of the |
229 // type DBUS_MESSAGE_TYPE_METHOD_RETURN. The caller must delete the | 229 // type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|. |
230 // returned object. Takes the ownership of |raw_message|. | 230 static scoped_ptr<ErrorResponse> FromRawMessage(DBusMessage* raw_message); |
231 static ErrorResponse* FromRawMessage(DBusMessage* raw_message); | |
232 | 231 |
233 // Returns a newly created ErrorResponse from the given method call, the | 232 // Returns a newly created ErrorResponse from the given method call, the |
234 // error name, and the error message. The error name looks like | 233 // error name, and the error message. The error name looks like |
235 // "org.freedesktop.DBus.Error.Failed". Used for returning an error to a | 234 // "org.freedesktop.DBus.Error.Failed". Used for returning an error to a |
236 // failed method call. | 235 // failed method call. Does NOT take the ownership of |method_call|. |
237 static ErrorResponse* FromMethodCall(MethodCall* method_call, | 236 static scoped_ptr<ErrorResponse> FromMethodCall( |
238 const std::string& error_name, | 237 MethodCall* method_call, |
239 const std::string& error_message); | 238 const std::string& error_name, |
| 239 const std::string& error_message); |
240 | 240 |
241 private: | 241 private: |
242 // Creates an ErrorResponse message. The internal raw message is NULL. | 242 // Creates an ErrorResponse message. The internal raw message is NULL. |
243 ErrorResponse(); | 243 ErrorResponse(); |
244 | 244 |
245 DISALLOW_COPY_AND_ASSIGN(ErrorResponse); | 245 DISALLOW_COPY_AND_ASSIGN(ErrorResponse); |
246 }; | 246 }; |
247 | 247 |
248 // MessageWriter is used to write outgoing messages for calling methods | 248 // MessageWriter is used to write outgoing messages for calling methods |
249 // and sending signals. | 249 // and sending signals. |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 476 |
477 Message* message_; | 477 Message* message_; |
478 DBusMessageIter raw_message_iter_; | 478 DBusMessageIter raw_message_iter_; |
479 | 479 |
480 DISALLOW_COPY_AND_ASSIGN(MessageReader); | 480 DISALLOW_COPY_AND_ASSIGN(MessageReader); |
481 }; | 481 }; |
482 | 482 |
483 } // namespace dbus | 483 } // namespace dbus |
484 | 484 |
485 #endif // DBUS_MESSAGE_H_ | 485 #endif // DBUS_MESSAGE_H_ |
OLD | NEW |