[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DBUS_OBJECT_PROXY_H_ |
| 6 | #define DBUS_OBJECT_PROXY_H_ |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 7 | |
[email protected] | 320eff4 | 2011-11-15 00:29:48 | [diff] [blame] | 8 | #include <dbus/dbus.h> |
| 9 | |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 10 | #include <map> |
dcheng | 2a19328 | 2016-04-08 22:55:04 | [diff] [blame] | 11 | #include <memory> |
[email protected] | 0ad9ef8 | 2011-11-23 22:08:38 | [diff] [blame] | 12 | #include <set> |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 13 | #include <string> |
[email protected] | 012e781dc | 2013-04-24 00:12:35 | [diff] [blame] | 14 | #include <vector> |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 15 | |
| 16 | #include "base/callback.h" |
avi | 22437c69 | 2015-12-22 18:12:45 | [diff] [blame] | 17 | #include "base/macros.h" |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 19 | #include "base/sequenced_task_runner.h" |
[email protected] | daf079a | 2013-04-17 21:42:40 | [diff] [blame] | 20 | #include "base/strings/string_piece.h" |
[email protected] | b43e556 | 2013-06-28 15:20:02 | [diff] [blame] | 21 | #include "base/time/time.h" |
[email protected] | e302446 | 2012-11-05 01:56:14 | [diff] [blame] | 22 | #include "dbus/dbus_export.h" |
[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 23 | #include "dbus/object_path.h" |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 24 | |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 25 | namespace dbus { |
| 26 | |
| 27 | class Bus; |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 28 | class ErrorResponse; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 29 | class MethodCall; |
| 30 | class Response; |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 31 | class ScopedDBusError; |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 32 | class Signal; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 33 | |
| 34 | // ObjectProxy is used to communicate with remote objects, mainly for |
| 35 | // calling methods of these objects. |
| 36 | // |
| 37 | // ObjectProxy is a ref counted object, to ensure that |this| of the |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 38 | // object is alive when callbacks referencing |this| are called; the |
[email protected] | 3b6205c | 2012-03-21 23:39:17 | [diff] [blame] | 39 | // bus always holds at least one of those references so object proxies |
| 40 | // always last as long as the bus that created them. |
[email protected] | e302446 | 2012-11-05 01:56:14 | [diff] [blame] | 41 | class CHROME_DBUS_EXPORT ObjectProxy |
| 42 | : public base::RefCountedThreadSafe<ObjectProxy> { |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 43 | public: |
[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 44 | // Client code should use Bus::GetObjectProxy() or |
| 45 | // Bus::GetObjectProxyWithOptions() instead of this constructor. |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 46 | ObjectProxy(Bus* bus, |
| 47 | const std::string& service_name, |
[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 48 | const ObjectPath& object_path, |
[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 49 | int options); |
| 50 | |
| 51 | // Options to be OR-ed together when calling Bus::GetObjectProxyWithOptions(). |
| 52 | // Set the IGNORE_SERVICE_UNKNOWN_ERRORS option to silence logging of |
[email protected] | 57051da | 2014-08-08 21:57:19 | [diff] [blame] | 53 | // org.freedesktop.DBus.Error.ServiceUnknown errors and |
| 54 | // org.freedesktop.DBus.Error.ObjectUnknown errors. |
[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 55 | enum Options { |
| 56 | DEFAULT_OPTIONS = 0, |
| 57 | IGNORE_SERVICE_UNKNOWN_ERRORS = 1 << 0 |
| 58 | }; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 59 | |
| 60 | // Special timeout constants. |
| 61 | // |
| 62 | // The constants correspond to DBUS_TIMEOUT_USE_DEFAULT and |
| 63 | // DBUS_TIMEOUT_INFINITE. Here we use literal numbers instead of these |
| 64 | // macros as these aren't defined with D-Bus earlier than 1.4.12. |
| 65 | enum { |
| 66 | TIMEOUT_USE_DEFAULT = -1, |
| 67 | TIMEOUT_INFINITE = 0x7fffffff, |
| 68 | }; |
| 69 | |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 70 | // Called when an error response is returned or no response is returned. |
| 71 | // Used for CallMethodWithErrorCallback(). |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 72 | using ErrorCallback = base::OnceCallback<void(ErrorResponse*)>; |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 73 | |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 74 | // Called when the response is returned. Used for CallMethod(). |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 75 | using ResponseCallback = base::OnceCallback<void(Response*)>; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 76 | |
Hidehiko Abe | fe6246c6 | 2017-10-19 19:54:56 | [diff] [blame] | 77 | // Called when the response is returned or an error occurs. Used for |
| 78 | // CallMethodWithErrorResponse(). |
| 79 | // Note that even in error case, ErrorResponse* may be nullptr. |
| 80 | // E.g. out-of-memory error is found in libdbus, or the connection of |
| 81 | // |bus_| is not yet established. |
| 82 | using ResponseOrErrorCallback = |
| 83 | base::OnceCallback<void(Response*, ErrorResponse*)>; |
| 84 | |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 85 | // Called when a signal is received. Signal* is the incoming signal. |
Reilly Grant | d4e6613 | 2019-11-22 17:14:50 | [diff] [blame] | 86 | using SignalCallback = base::RepeatingCallback<void(Signal*)>; |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 87 | |
[email protected] | db817802e | 2013-09-27 07:12:03 | [diff] [blame] | 88 | // Called when NameOwnerChanged signal is received. |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 89 | using NameOwnerChangedCallback = |
Reilly Grant | d4e6613 | 2019-11-22 17:14:50 | [diff] [blame] | 90 | base::RepeatingCallback<void(const std::string& old_owner, |
| 91 | const std::string& new_owner)>; |
[email protected] | db817802e | 2013-09-27 07:12:03 | [diff] [blame] | 92 | |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 93 | // Called when the service becomes available. |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 94 | using WaitForServiceToBeAvailableCallback = |
Ryo Hashimoto | 0fc9c71 | 2017-09-12 04:53:50 | [diff] [blame] | 95 | base::OnceCallback<void(bool service_is_available)>; |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 96 | |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 97 | // Called when the object proxy is connected to the signal. |
| 98 | // Parameters: |
| 99 | // - the interface name. |
| 100 | // - the signal name. |
| 101 | // - whether it was successful or not. |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 102 | using OnConnectedCallback = |
Ryo Hashimoto | 0fc9c71 | 2017-09-12 04:53:50 | [diff] [blame] | 103 | base::OnceCallback<void(const std::string&, const std::string&, bool)>; |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 104 | |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 105 | // Calls the method of the remote object and blocks until the response |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 106 | // is returned. Returns NULL on error with the error details specified |
| 107 | // in the |error| object. |
| 108 | // |
| 109 | // BLOCKING CALL. |
dcheng | 2a19328 | 2016-04-08 22:55:04 | [diff] [blame] | 110 | virtual std::unique_ptr<Response> CallMethodAndBlockWithErrorDetails( |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 111 | MethodCall* method_call, |
| 112 | int timeout_ms, |
| 113 | ScopedDBusError* error); |
| 114 | |
| 115 | // Calls the method of the remote object and blocks until the response |
[email protected] | 06ead87 | 2011-08-24 03:32:06 | [diff] [blame] | 116 | // is returned. Returns NULL on error. |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 117 | // |
| 118 | // BLOCKING CALL. |
dcheng | 2a19328 | 2016-04-08 22:55:04 | [diff] [blame] | 119 | virtual std::unique_ptr<Response> CallMethodAndBlock(MethodCall* method_call, |
| 120 | int timeout_ms); |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 121 | |
| 122 | // Requests to call the method of the remote object. |
| 123 | // |
| 124 | // |callback| will be called in the origin thread, once the method call |
| 125 | // is complete. As it's called in the origin thread, |callback| can |
| 126 | // safely reference objects in the origin thread (i.e. UI thread in most |
Peter Kasting | 341e1fb | 2018-02-24 00:03:01 | [diff] [blame] | 127 | // cases). |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 128 | // |
| 129 | // If the method call is successful, a pointer to Response object will |
Ben Chan | 14d50037 | 2017-11-09 20:20:16 | [diff] [blame] | 130 | // be passed to the callback. If unsuccessful, nullptr will be passed to |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 131 | // the callback. |
| 132 | // |
| 133 | // Must be called in the origin thread. |
| 134 | virtual void CallMethod(MethodCall* method_call, |
| 135 | int timeout_ms, |
| 136 | ResponseCallback callback); |
| 137 | |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 138 | // Requests to call the method of the remote object. |
| 139 | // |
Hidehiko Abe | fe6246c6 | 2017-10-19 19:54:56 | [diff] [blame] | 140 | // This is almost as same as CallMethod() defined above. |
| 141 | // The difference is that, the |callback| can take ErrorResponse. |
| 142 | // In case of error, ErrorResponse object is passed to the |callback| |
| 143 | // if the remote object returned an error, or nullptr if a response was not |
| 144 | // received at all (e.g., D-Bus connection is not established). In either |
| 145 | // error case, Response* should be nullptr. |
| 146 | virtual void CallMethodWithErrorResponse(MethodCall* method_call, |
| 147 | int timeout_ms, |
| 148 | ResponseOrErrorCallback callback); |
| 149 | |
| 150 | // DEPRECATED. Please use CallMethodWithErrorResponse() instead. |
| 151 | // TODO(hidehiko): Remove this when migration is done. |
| 152 | // Requests to call the method of the remote object. |
| 153 | // |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 154 | // |callback| and |error_callback| will be called in the origin thread, once |
| 155 | // the method call is complete. As it's called in the origin thread, |
| 156 | // |callback| can safely reference objects in the origin thread (i.e. |
Peter Kasting | 341e1fb | 2018-02-24 00:03:01 | [diff] [blame] | 157 | // UI thread in most cases). |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 158 | // |
hashimoto | fd6b551 | 2016-09-01 05:18:38 | [diff] [blame] | 159 | // If the method call is successful, |callback| will be invoked with a |
| 160 | // Response object. If unsuccessful, |error_callback| will be invoked with an |
| 161 | // ErrorResponse object (if the remote object returned an error) or nullptr |
| 162 | // (if a response was not received at all). |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 163 | // |
| 164 | // Must be called in the origin thread. |
| 165 | virtual void CallMethodWithErrorCallback(MethodCall* method_call, |
| 166 | int timeout_ms, |
| 167 | ResponseCallback callback, |
| 168 | ErrorCallback error_callback); |
| 169 | |
quiche | b270236 | 2015-10-23 15:06:03 | [diff] [blame] | 170 | // Requests to connect to the signal from the remote object. |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 171 | // |
| 172 | // |signal_callback| will be called in the origin thread, when the |
| 173 | // signal is received from the remote object. As it's called in the |
| 174 | // origin thread, |signal_callback| can safely reference objects in the |
| 175 | // origin thread (i.e. UI thread in most cases). |
| 176 | // |
| 177 | // |on_connected_callback| is called when the object proxy is connected |
| 178 | // to the signal, or failed to be connected, in the origin thread. |
| 179 | // |
quiche | b270236 | 2015-10-23 15:06:03 | [diff] [blame] | 180 | // If a SignalCallback has already been registered for the given |
| 181 | // |interface_name| and |signal_name|, |signal_callback| will be |
| 182 | // added to the list of callbacks for |interface_name| and |
| 183 | // |signal_name|. |
| 184 | // |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 185 | // Must be called in the origin thread. |
| 186 | virtual void ConnectToSignal(const std::string& interface_name, |
| 187 | const std::string& signal_name, |
| 188 | SignalCallback signal_callback, |
| 189 | OnConnectedCallback on_connected_callback); |
| 190 | |
[email protected] | 6d36c0c | 2012-11-14 11:02:59 | [diff] [blame] | 191 | // Sets a callback for "NameOwnerChanged" signal. The callback is called on |
| 192 | // the origin thread when D-Bus system sends "NameOwnerChanged" for the name |
| 193 | // represented by |service_name_|. |
[email protected] | db817802e | 2013-09-27 07:12:03 | [diff] [blame] | 194 | virtual void SetNameOwnerChangedCallback(NameOwnerChangedCallback callback); |
[email protected] | 6d36c0c | 2012-11-14 11:02:59 | [diff] [blame] | 195 | |
derat | 77fb818 | 2016-08-12 01:41:06 | [diff] [blame] | 196 | // Registers |callback| to run when the service becomes available. If the |
| 197 | // service is already available, or if connecting to the name-owner-changed |
| 198 | // signal fails, |callback| will be run once asynchronously. Otherwise, |
| 199 | // |callback| will be run once in the future after the service becomes |
| 200 | // available. |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 201 | virtual void WaitForServiceToBeAvailable( |
| 202 | WaitForServiceToBeAvailableCallback callback); |
| 203 | |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 204 | // Detaches from the remote object. The Bus object will take care of |
| 205 | // detaching so you don't have to do this manually. |
| 206 | // |
| 207 | // BLOCKING CALL. |
| 208 | virtual void Detach(); |
| 209 | |
[email protected] | ee994138 | 2013-10-07 22:56:57 | [diff] [blame] | 210 | const ObjectPath& object_path() const { return object_path_; } |
| 211 | |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 212 | protected: |
| 213 | // This is protected, so we can define sub classes. |
| 214 | virtual ~ObjectProxy(); |
| 215 | |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 216 | private: |
| 217 | friend class base::RefCountedThreadSafe<ObjectProxy>; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 218 | |
Hidehiko Abe | 7f05f78 | 2017-11-21 06:01:39 | [diff] [blame] | 219 | // Callback passed to CallMethod and its family should be deleted on the |
| 220 | // origin thread in any cases. This class manages the work. |
| 221 | class ReplyCallbackHolder { |
| 222 | public: |
| 223 | // Designed to be created on the origin thread. |
| 224 | // Both |origin_task_runner| and |callback| must not be null. |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 225 | ReplyCallbackHolder( |
| 226 | scoped_refptr<base::SequencedTaskRunner> origin_task_runner, |
| 227 | ResponseOrErrorCallback callback); |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 228 | |
Hidehiko Abe | 7f05f78 | 2017-11-21 06:01:39 | [diff] [blame] | 229 | // This is movable to be bound to an OnceCallback. |
| 230 | ReplyCallbackHolder(ReplyCallbackHolder&& other); |
| 231 | |
| 232 | // |callback_| needs to be destroyed on the origin thread. |
| 233 | // If this is not destroyed on non-origin thread, it PostTask()s the |
| 234 | // callback to the origin thread for destroying. |
| 235 | ~ReplyCallbackHolder(); |
| 236 | |
| 237 | // Returns |callback_| with releasing its ownership. |
| 238 | // This must be called on the origin thread. |
| 239 | ResponseOrErrorCallback ReleaseCallback(); |
| 240 | |
| 241 | private: |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 242 | scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
Hidehiko Abe | 7f05f78 | 2017-11-21 06:01:39 | [diff] [blame] | 243 | ResponseOrErrorCallback callback_; |
| 244 | DISALLOW_COPY_AND_ASSIGN(ReplyCallbackHolder); |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | // Starts the async method call. This is a helper function to implement |
| 248 | // CallMethod(). |
| 249 | void StartAsyncMethodCall(int timeout_ms, |
[email protected] | 1d887b27 | 2011-10-04 13:47:21 | [diff] [blame] | 250 | DBusMessage* request_message, |
Hidehiko Abe | 7f05f78 | 2017-11-21 06:01:39 | [diff] [blame] | 251 | ReplyCallbackHolder callback_holder, |
[email protected] | a7338989 | 2011-09-06 20:53:30 | [diff] [blame] | 252 | base::TimeTicks start_time); |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 253 | |
| 254 | // Called when the pending call is complete. |
Hidehiko Abe | 7f05f78 | 2017-11-21 06:01:39 | [diff] [blame] | 255 | void OnPendingCallIsComplete(ReplyCallbackHolder callback_holder, |
| 256 | base::TimeTicks start_time, |
| 257 | DBusPendingCall* pending_call); |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 258 | |
Hidehiko Abe | fe6246c6 | 2017-10-19 19:54:56 | [diff] [blame] | 259 | // Runs the ResponseOrErrorCallback with the given response object. |
Hidehiko Abe | 7f05f78 | 2017-11-21 06:01:39 | [diff] [blame] | 260 | void RunResponseOrErrorCallback(ReplyCallbackHolder callback_holderk, |
Hidehiko Abe | fe6246c6 | 2017-10-19 19:54:56 | [diff] [blame] | 261 | base::TimeTicks start_time, |
| 262 | Response* response, |
| 263 | ErrorResponse* error_response); |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 264 | |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 265 | // Connects to NameOwnerChanged signal. |
| 266 | bool ConnectToNameOwnerChangedSignal(); |
| 267 | |
Bing Xue | 55502d8b | 2019-08-06 17:12:11 | [diff] [blame] | 268 | // Tries to connect to NameOwnerChanged signal, ignores any error. |
| 269 | void TryConnectToNameOwnerChangedSignal(); |
| 270 | |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 271 | // Helper function for ConnectToSignal(). |
[email protected] | 9261675 | 2013-09-26 06:40:04 | [diff] [blame] | 272 | bool ConnectToSignalInternal(const std::string& interface_name, |
| 273 | const std::string& signal_name, |
| 274 | SignalCallback signal_callback); |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 275 | |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 276 | // Helper function for WaitForServiceToBeAvailable(). |
| 277 | void WaitForServiceToBeAvailableInternal(); |
| 278 | |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 279 | // Handles the incoming request messages and dispatches to the signal |
| 280 | // callbacks. |
| 281 | DBusHandlerResult HandleMessage(DBusConnection* connection, |
| 282 | DBusMessage* raw_message); |
| 283 | |
| 284 | // Runs the method. Helper function for HandleMessage(). |
[email protected] | a7338989 | 2011-09-06 20:53:30 | [diff] [blame] | 285 | void RunMethod(base::TimeTicks start_time, |
[email protected] | 012e781dc | 2013-04-24 00:12:35 | [diff] [blame] | 286 | std::vector<SignalCallback> signal_callbacks, |
[email protected] | a7338989 | 2011-09-06 20:53:30 | [diff] [blame] | 287 | Signal* signal); |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 288 | |
| 289 | // Redirects the function call to HandleMessage(). |
| 290 | static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
| 291 | DBusMessage* raw_message, |
| 292 | void* user_data); |
| 293 | |
[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 294 | // Helper method for logging response errors appropriately. |
[email protected] | 6b0f9738 | 2012-05-31 06:12:11 | [diff] [blame] | 295 | void LogMethodCallFailure(const base::StringPiece& interface_name, |
| 296 | const base::StringPiece& method_name, |
| 297 | const base::StringPiece& error_name, |
[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 298 | const base::StringPiece& error_message) const; |
| 299 | |
Hidehiko Abe | fe6246c6 | 2017-10-19 19:54:56 | [diff] [blame] | 300 | // Used as ResponseOrErrorCallback by CallMethod(). |
| 301 | // Logs error message, and drops |error_response| from the arguments to pass |
| 302 | // |response_callback|. |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 303 | void OnCallMethod(const std::string& interface_name, |
| 304 | const std::string& method_name, |
| 305 | ResponseCallback response_callback, |
| 306 | Response* response, |
| 307 | ErrorResponse* error_response); |
[email protected] | 91fe7ea | 2012-04-20 03:18:27 | [diff] [blame] | 308 | |
[email protected] | 8bbe31e | 2012-10-29 06:27:33 | [diff] [blame] | 309 | // Adds the match rule to the bus and associate the callback with the signal. |
| 310 | bool AddMatchRuleWithCallback(const std::string& match_rule, |
| 311 | const std::string& absolute_signal_name, |
| 312 | SignalCallback signal_callback); |
| 313 | |
| 314 | // Adds the match rule to the bus so that HandleMessage can see the signal. |
| 315 | bool AddMatchRuleWithoutCallback(const std::string& match_rule, |
| 316 | const std::string& absolute_signal_name); |
| 317 | |
| 318 | // Calls D-Bus's GetNameOwner method synchronously to update |
| 319 | // |service_name_owner_| with the current owner of |service_name_|. |
| 320 | // |
| 321 | // BLOCKING CALL. |
| 322 | void UpdateNameOwnerAndBlock(); |
| 323 | |
| 324 | // Handles NameOwnerChanged signal from D-Bus's special message bus. |
dcheng | 2a19328 | 2016-04-08 22:55:04 | [diff] [blame] | 325 | DBusHandlerResult HandleNameOwnerChanged( |
| 326 | std::unique_ptr<dbus::Signal> signal); |
[email protected] | 8bbe31e | 2012-10-29 06:27:33 | [diff] [blame] | 327 | |
[email protected] | db817802e | 2013-09-27 07:12:03 | [diff] [blame] | 328 | // Runs |name_owner_changed_callback_|. |
| 329 | void RunNameOwnerChangedCallback(const std::string& old_owner, |
| 330 | const std::string& new_owner); |
| 331 | |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 332 | // Runs |wait_for_service_to_be_available_callbacks_|. |
| 333 | void RunWaitForServiceToBeAvailableCallbacks(bool service_is_available); |
| 334 | |
[email protected] | 6477a41 | 2011-10-13 00:45:26 | [diff] [blame] | 335 | scoped_refptr<Bus> bus_; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 336 | std::string service_name_; |
[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 337 | ObjectPath object_path_; |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 338 | |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 339 | // The method table where keys are absolute signal names (i.e. interface |
[email protected] | 012e781dc | 2013-04-24 00:12:35 | [diff] [blame] | 340 | // name + signal name), and values are lists of the corresponding callbacks. |
Ryo Hashimoto | 2a363a8 | 2017-07-21 08:11:14 | [diff] [blame] | 341 | using MethodTable = std::map<std::string, std::vector<SignalCallback>>; |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 342 | MethodTable method_table_; |
| 343 | |
[email protected] | 6d36c0c | 2012-11-14 11:02:59 | [diff] [blame] | 344 | // The callback called when NameOwnerChanged signal is received. |
[email protected] | db817802e | 2013-09-27 07:12:03 | [diff] [blame] | 345 | NameOwnerChangedCallback name_owner_changed_callback_; |
[email protected] | 6d36c0c | 2012-11-14 11:02:59 | [diff] [blame] | 346 | |
[email protected] | 118090c5 | 2013-10-02 07:53:09 | [diff] [blame] | 347 | // Called when the service becomes available. |
| 348 | std::vector<WaitForServiceToBeAvailableCallback> |
| 349 | wait_for_service_to_be_available_callbacks_; |
| 350 | |
[email protected] | 0ad9ef8 | 2011-11-23 22:08:38 | [diff] [blame] | 351 | std::set<std::string> match_rules_; |
[email protected] | 3beaaa4e | 2011-08-23 07:29:21 | [diff] [blame] | 352 | |
[email protected] | 20bed01 | 2012-02-10 21:45:23 | [diff] [blame] | 353 | const bool ignore_service_unknown_errors_; |
| 354 | |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 355 | // Known name owner of the well-known bus name represented by |service_name_|. |
[email protected] | 8bbe31e | 2012-10-29 06:27:33 | [diff] [blame] | 356 | std::string service_name_owner_; |
| 357 | |
hashimoto | 41ece52 | 2015-03-30 07:01:39 | [diff] [blame] | 358 | std::set<DBusPendingCall*> pending_calls_; |
| 359 | |
[email protected] | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 360 | DISALLOW_COPY_AND_ASSIGN(ObjectProxy); |
| 361 | }; |
| 362 | |
| 363 | } // namespace dbus |
| 364 | |
| 365 | #endif // DBUS_OBJECT_PROXY_H_ |