OLD | NEW |
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_OBJECT_PROXY_H_ | 5 #ifndef DBUS_OBJECT_PROXY_H_ |
6 #define DBUS_OBJECT_PROXY_H_ | 6 #define DBUS_OBJECT_PROXY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <dbus/dbus.h> | 9 #include <dbus/dbus.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/string_piece.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 | 19 |
19 namespace dbus { | 20 namespace dbus { |
20 | 21 |
21 class Bus; | 22 class Bus; |
22 class MethodCall; | 23 class MethodCall; |
23 class Response; | 24 class Response; |
24 class Signal; | 25 class Signal; |
25 | 26 |
26 // ObjectProxy is used to communicate with remote objects, mainly for | 27 // ObjectProxy is used to communicate with remote objects, mainly for |
27 // calling methods of these objects. | 28 // calling methods of these objects. |
28 // | 29 // |
29 // ObjectProxy is a ref counted object, to ensure that |this| of the | 30 // ObjectProxy is a ref counted object, to ensure that |this| of the |
30 // object is is alive when callbacks referencing |this| are called. | 31 // object is is alive when callbacks referencing |this| are called. |
31 class ObjectProxy : public base::RefCountedThreadSafe<ObjectProxy> { | 32 class ObjectProxy : public base::RefCountedThreadSafe<ObjectProxy> { |
32 public: | 33 public: |
33 // Client code should use Bus::GetObjectProxy() instead of this | 34 // Client code should use Bus::GetObjectProxy() or |
34 // constructor. | 35 // Bus::GetObjectProxyWithOptions() instead of this constructor. |
35 ObjectProxy(Bus* bus, | 36 ObjectProxy(Bus* bus, |
36 const std::string& service_name, | 37 const std::string& service_name, |
37 const std::string& object_path); | 38 const std::string& object_path, |
| 39 int options); |
| 40 |
| 41 // Options to be OR-ed together when calling Bus::GetObjectProxyWithOptions(). |
| 42 // Set the IGNORE_SERVICE_UNKNOWN_ERRORS option to silence logging of |
| 43 // org.freedesktop.DBus.Error.ServiceUnknown errors. |
| 44 enum Options { |
| 45 DEFAULT_OPTIONS = 0, |
| 46 IGNORE_SERVICE_UNKNOWN_ERRORS = 1 << 0 |
| 47 }; |
38 | 48 |
39 // Special timeout constants. | 49 // Special timeout constants. |
40 // | 50 // |
41 // The constants correspond to DBUS_TIMEOUT_USE_DEFAULT and | 51 // The constants correspond to DBUS_TIMEOUT_USE_DEFAULT and |
42 // DBUS_TIMEOUT_INFINITE. Here we use literal numbers instead of these | 52 // DBUS_TIMEOUT_INFINITE. Here we use literal numbers instead of these |
43 // macros as these aren't defined with D-Bus earlier than 1.4.12. | 53 // macros as these aren't defined with D-Bus earlier than 1.4.12. |
44 enum { | 54 enum { |
45 TIMEOUT_USE_DEFAULT = -1, | 55 TIMEOUT_USE_DEFAULT = -1, |
46 TIMEOUT_INFINITE = 0x7fffffff, | 56 TIMEOUT_INFINITE = 0x7fffffff, |
47 }; | 57 }; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Runs the method. Helper function for HandleMessage(). | 183 // Runs the method. Helper function for HandleMessage(). |
174 void RunMethod(base::TimeTicks start_time, | 184 void RunMethod(base::TimeTicks start_time, |
175 SignalCallback signal_callback, | 185 SignalCallback signal_callback, |
176 Signal* signal); | 186 Signal* signal); |
177 | 187 |
178 // Redirects the function call to HandleMessage(). | 188 // Redirects the function call to HandleMessage(). |
179 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, | 189 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
180 DBusMessage* raw_message, | 190 DBusMessage* raw_message, |
181 void* user_data); | 191 void* user_data); |
182 | 192 |
| 193 // Helper method for logging response errors appropriately. |
| 194 void LogMethodCallFailure(const base::StringPiece& error_name, |
| 195 const base::StringPiece& error_message) const; |
| 196 |
183 scoped_refptr<Bus> bus_; | 197 scoped_refptr<Bus> bus_; |
184 std::string service_name_; | 198 std::string service_name_; |
185 std::string object_path_; | 199 std::string object_path_; |
186 | 200 |
187 // True if the message filter was added. | 201 // True if the message filter was added. |
188 bool filter_added_; | 202 bool filter_added_; |
189 | 203 |
190 // The method table where keys are absolute signal names (i.e. interface | 204 // The method table where keys are absolute signal names (i.e. interface |
191 // name + signal name), and values are the corresponding callbacks. | 205 // name + signal name), and values are the corresponding callbacks. |
192 typedef std::map<std::string, SignalCallback> MethodTable; | 206 typedef std::map<std::string, SignalCallback> MethodTable; |
193 MethodTable method_table_; | 207 MethodTable method_table_; |
194 | 208 |
195 std::set<std::string> match_rules_; | 209 std::set<std::string> match_rules_; |
196 | 210 |
| 211 const bool ignore_service_unknown_errors_; |
| 212 |
197 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); | 213 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); |
198 }; | 214 }; |
199 | 215 |
200 } // namespace dbus | 216 } // namespace dbus |
201 | 217 |
202 #endif // DBUS_OBJECT_PROXY_H_ | 218 #endif // DBUS_OBJECT_PROXY_H_ |
OLD | NEW |