adamk@chromium.org | 35c0eef | 2012-02-11 06:45:23 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [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_BUS_H_ |
| 6 | #define DBUS_BUS_H_ |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 7 | |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 8 | #include <dbus/dbus.h> |
| 9 | |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 10 | #include <map> |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 11 | #include <set> |
| 12 | #include <string> |
satorux@chromium.org | 66bc4c2 | 2011-10-06 09:20:53 +0900 | [diff] [blame] | 13 | #include <utility> |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 14 | #include <vector> |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 15 | |
| 16 | #include "base/callback.h" |
| 17 | #include "base/memory/ref_counted.h" |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 18 | #include "base/synchronization/waitable_event.h" |
satorux@chromium.org | c6ac757 | 2011-09-01 03:02:43 +0900 | [diff] [blame] | 19 | #include "base/threading/platform_thread.h" |
tfarina@chromium.org | 7928ea2 | 2012-11-05 10:56:14 +0900 | [diff] [blame] | 20 | #include "dbus/dbus_export.h" |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 21 | #include "dbus/object_path.h" |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 22 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 23 | namespace base { |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 24 | class SequencedTaskRunner; |
| 25 | class SingleThreadTaskRunner; |
hashimoto@chromium.org | 955f648 | 2013-09-26 13:32:29 +0900 | [diff] [blame] | 26 | class TaskRunner; |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | namespace tracked_objects { |
| 30 | class Location; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | namespace dbus { |
| 34 | |
| 35 | class ExportedObject; |
keybuk@chromium.org | 0971501 | 2013-03-26 03:20:08 +0900 | [diff] [blame] | 36 | class ObjectManager; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 37 | class ObjectProxy; |
| 38 | |
| 39 | // Bus is used to establish a connection with D-Bus, create object |
| 40 | // proxies, and export objects. |
| 41 | // |
| 42 | // For asynchronous operations such as an asynchronous method call, the |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 43 | // bus object will use a task runner to monitor the underlying file |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 44 | // descriptor used for D-Bus communication. By default, the bus will use |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 45 | // the current thread's task runner. If |dbus_task_runner| option is |
| 46 | // specified, the bus will use that task runner instead. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 47 | // |
| 48 | // THREADING |
| 49 | // |
| 50 | // In the D-Bus library, we use the two threads: |
| 51 | // |
| 52 | // - The origin thread: the thread that created the Bus object. |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 53 | // - The D-Bus thread: the thread servicing |dbus_task_runner|. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 54 | // |
| 55 | // The origin thread is usually Chrome's UI thread. The D-Bus thread is |
| 56 | // usually a dedicated thread for the D-Bus library. |
| 57 | // |
| 58 | // BLOCKING CALLS |
| 59 | // |
| 60 | // Functions that issue blocking calls are marked "BLOCKING CALL" and |
| 61 | // these functions should be called in the D-Bus thread (if |
| 62 | // supplied). AssertOnDBusThread() is placed in these functions. |
| 63 | // |
| 64 | // Note that it's hard to tell if a libdbus function is actually blocking |
| 65 | // or not (ex. dbus_bus_request_name() internally calls |
| 66 | // dbus_connection_send_with_reply_and_block(), which is a blocking |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 67 | // call). To err on the safe side, we consider all libdbus functions that |
satorux@chromium.org | c6ac757 | 2011-09-01 03:02:43 +0900 | [diff] [blame] | 68 | // deal with the connection to dbus-daemon to be blocking. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 69 | // |
satorux@chromium.org | 326a6f8 | 2011-08-27 16:26:34 +0900 | [diff] [blame] | 70 | // SHUTDOWN |
| 71 | // |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 72 | // The Bus object must be shut down manually by ShutdownAndBlock() and |
| 73 | // friends. We require the manual shutdown to make the operation explicit |
| 74 | // rather than doing it silently in the destructor. |
satorux@chromium.org | 326a6f8 | 2011-08-27 16:26:34 +0900 | [diff] [blame] | 75 | // |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 76 | // EXAMPLE USAGE: |
| 77 | // |
| 78 | // Synchronous method call: |
| 79 | // |
| 80 | // dbus::Bus::Options options; |
| 81 | // // Set up the bus options here. |
| 82 | // ... |
| 83 | // dbus::Bus bus(options); |
| 84 | // |
| 85 | // dbus::ObjectProxy* object_proxy = |
| 86 | // bus.GetObjectProxy(service_name, object_path); |
| 87 | // |
| 88 | // dbus::MethodCall method_call(interface_name, method_name); |
mdm@chromium.org | 45f2c6a | 2011-09-07 05:03:24 +0900 | [diff] [blame] | 89 | // scoped_ptr<dbus::Response> response( |
| 90 | // object_proxy.CallMethodAndBlock(&method_call, timeout_ms)); |
| 91 | // if (response.get() != NULL) { // Success. |
| 92 | // ... |
| 93 | // } |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 94 | // |
| 95 | // Asynchronous method call: |
| 96 | // |
| 97 | // void OnResponse(dbus::Response* response) { |
| 98 | // // response is NULL if the method call failed. |
| 99 | // if (!response) |
| 100 | // return; |
| 101 | // } |
| 102 | // |
| 103 | // ... |
| 104 | // object_proxy.CallMethod(&method_call, timeout_ms, |
| 105 | // base::Bind(&OnResponse)); |
| 106 | // |
| 107 | // Exporting a method: |
| 108 | // |
vlaviano@chromium.org | 241215d | 2011-11-30 13:57:42 +0900 | [diff] [blame] | 109 | // void Echo(dbus::MethodCall* method_call, |
| 110 | // dbus::ExportedObject::ResponseSender response_sender) { |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 111 | // // Do something with method_call. |
| 112 | // Response* response = Response::FromMethodCall(method_call); |
| 113 | // // Build response here. |
vlaviano@chromium.org | 241215d | 2011-11-30 13:57:42 +0900 | [diff] [blame] | 114 | // // Can send an immediate response here to implement a synchronous service |
| 115 | // // or store the response_sender and send a response later to implement an |
| 116 | // // asynchronous service. |
| 117 | // response_sender.Run(response); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 118 | // } |
| 119 | // |
| 120 | // void OnExported(const std::string& interface_name, |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 121 | // const ObjectPath& object_path, |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 122 | // bool success) { |
| 123 | // // success is true if the method was exported successfully. |
| 124 | // } |
| 125 | // |
| 126 | // ... |
| 127 | // dbus::ExportedObject* exported_object = |
| 128 | // bus.GetExportedObject(service_name, object_path); |
| 129 | // exported_object.ExportMethod(interface_name, method_name, |
| 130 | // base::Bind(&Echo), |
| 131 | // base::Bind(&OnExported)); |
| 132 | // |
| 133 | // WHY IS THIS A REF COUNTED OBJECT? |
| 134 | // |
| 135 | // Bus is a ref counted object, to ensure that |this| of the object is |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 136 | // alive when callbacks referencing |this| are called. However, after the |
| 137 | // bus is shut down, |connection_| can be NULL. Hence, callbacks should |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 138 | // not rely on that |connection_| is alive. |
tfarina@chromium.org | 7928ea2 | 2012-11-05 10:56:14 +0900 | [diff] [blame] | 139 | class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> { |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 140 | public: |
| 141 | // Specifies the bus type. SESSION is used to communicate with per-user |
| 142 | // services like GNOME applications. SYSTEM is used to communicate with |
nona@chromium.org | 9f638e0 | 2012-04-19 12:20:03 +0900 | [diff] [blame] | 143 | // system-wide services like NetworkManager. CUSTOM_ADDRESS is used to |
| 144 | // communicate with an user specified address. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 145 | enum BusType { |
| 146 | SESSION = DBUS_BUS_SESSION, |
nona@chromium.org | 9f638e0 | 2012-04-19 12:20:03 +0900 | [diff] [blame] | 147 | SYSTEM = DBUS_BUS_SYSTEM, |
| 148 | CUSTOM_ADDRESS, |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | // Specifies the connection type. PRIVATE should usually be used unless |
| 152 | // you are sure that SHARED is safe for you, which is unlikely the case |
| 153 | // in Chrome. |
| 154 | // |
| 155 | // PRIVATE gives you a private connection, that won't be shared with |
| 156 | // other Bus objects. |
| 157 | // |
| 158 | // SHARED gives you a connection shared among other Bus objects, which |
| 159 | // is unsafe if the connection is shared with multiple threads. |
| 160 | enum ConnectionType { |
| 161 | PRIVATE, |
| 162 | SHARED, |
| 163 | }; |
| 164 | |
thestig@chromium.org | 56057f2 | 2013-05-05 00:48:37 +0900 | [diff] [blame] | 165 | // Specifies whether the GetServiceOwnerAndBlock call should report or |
| 166 | // suppress errors. |
| 167 | enum GetServiceOwnerOption { |
| 168 | REPORT_ERRORS, |
| 169 | SUPPRESS_ERRORS, |
| 170 | }; |
| 171 | |
cmasone@chromium.org | 989857e | 2013-07-31 15:34:59 +0900 | [diff] [blame] | 172 | // Specifies service ownership options. |
| 173 | // |
| 174 | // REQUIRE_PRIMARY indicates that you require primary ownership of the |
| 175 | // service name. |
| 176 | // |
| 177 | // ALLOW_REPLACEMENT indicates that you'll allow another connection to |
| 178 | // steal ownership of this service name from you. |
| 179 | // |
| 180 | // REQUIRE_PRIMARY_ALLOW_REPLACEMENT does the obvious. |
| 181 | enum ServiceOwnershipOptions { |
| 182 | REQUIRE_PRIMARY = (DBUS_NAME_FLAG_DO_NOT_QUEUE | |
| 183 | DBUS_NAME_FLAG_REPLACE_EXISTING), |
| 184 | REQUIRE_PRIMARY_ALLOW_REPLACEMENT = (REQUIRE_PRIMARY | |
| 185 | DBUS_NAME_FLAG_ALLOW_REPLACEMENT), |
| 186 | }; |
| 187 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 188 | // Options used to create a Bus object. |
tfarina@chromium.org | 7928ea2 | 2012-11-05 10:56:14 +0900 | [diff] [blame] | 189 | struct CHROME_DBUS_EXPORT Options { |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 190 | Options(); |
| 191 | ~Options(); |
| 192 | |
| 193 | BusType bus_type; // SESSION by default. |
| 194 | ConnectionType connection_type; // PRIVATE by default. |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 195 | // If dbus_task_runner is set, the bus object will use that |
| 196 | // task runner to process asynchronous operations. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 197 | // |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 198 | // The thread servicing the task runner should meet the following |
mdm@chromium.org | 45f2c6a | 2011-09-07 05:03:24 +0900 | [diff] [blame] | 199 | // requirements: |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 200 | // 1) Already running. |
| 201 | // 2) Has a MessageLoopForIO. |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 202 | scoped_refptr<base::SequencedTaskRunner> dbus_task_runner; |
nona@chromium.org | 9f638e0 | 2012-04-19 12:20:03 +0900 | [diff] [blame] | 203 | |
| 204 | // Specifies the server addresses to be connected. If you want to |
| 205 | // communicate with non dbus-daemon such as ibus-daemon, set |bus_type| to |
| 206 | // CUSTOM_ADDRESS, and |address| to the D-Bus server address you want to |
| 207 | // connect to. The format of this address value is the dbus address style |
| 208 | // which is described in |
| 209 | // http://dbus.freedesktop.org/doc/dbus-specification.html#addresses |
| 210 | // |
| 211 | // EXAMPLE USAGE: |
| 212 | // dbus::Bus::Options options; |
| 213 | // options.bus_type = CUSTOM_ADDRESS; |
| 214 | // options.address.assign("unix:path=/tmp/dbus-XXXXXXX"); |
| 215 | // // Set up other options |
| 216 | // dbus::Bus bus(options); |
| 217 | // |
| 218 | // // Do something. |
| 219 | // |
| 220 | std::string address; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 221 | }; |
| 222 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 223 | // Creates a Bus object. The actual connection will be established when |
| 224 | // Connect() is called. |
| 225 | explicit Bus(const Options& options); |
| 226 | |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 227 | // Called when an ownership request is complete. |
| 228 | // Parameters: |
| 229 | // - the requested service name. |
| 230 | // - whether ownership has been obtained or not. |
| 231 | typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback; |
thestig@chromium.org | 56057f2 | 2013-05-05 00:48:37 +0900 | [diff] [blame] | 232 | |
| 233 | // Called when GetServiceOwner() completes. |
| 234 | // |service_owner| is the return value from GetServiceOwnerAndBlock(). |
| 235 | typedef base::Callback<void (const std::string& service_owner)> |
| 236 | GetServiceOwnerCallback; |
| 237 | |
deymo@chromium.org | 6d168a7 | 2013-01-30 05:29:12 +0900 | [diff] [blame] | 238 | // TODO(satorux): Remove the service name parameter as the caller of |
| 239 | // RequestOwnership() knows the service name. |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 240 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 241 | // Gets the object proxy for the given service name and the object path. |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 242 | // The caller must not delete the returned object. |
| 243 | // |
| 244 | // Returns an existing object proxy if the bus object already owns the |
| 245 | // object proxy for the given service name and the object path. |
| 246 | // Never returns NULL. |
| 247 | // |
| 248 | // The bus will own all object proxies created by the bus, to ensure |
| 249 | // that the object proxies are detached from remote objects at the |
| 250 | // shutdown time of the bus. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 251 | // |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 252 | // The object proxy is used to call methods of remote objects, and |
| 253 | // receive signals from them. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 254 | // |
| 255 | // |service_name| looks like "org.freedesktop.NetworkManager", and |
| 256 | // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". |
| 257 | // |
| 258 | // Must be called in the origin thread. |
| 259 | virtual ObjectProxy* GetObjectProxy(const std::string& service_name, |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 260 | const ObjectPath& object_path); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 261 | |
adamk@chromium.org | 35c0eef | 2012-02-11 06:45:23 +0900 | [diff] [blame] | 262 | // Same as above, but also takes a bitfield of ObjectProxy::Options. |
| 263 | // See object_proxy.h for available options. |
| 264 | virtual ObjectProxy* GetObjectProxyWithOptions( |
| 265 | const std::string& service_name, |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 266 | const ObjectPath& object_path, |
adamk@chromium.org | 35c0eef | 2012-02-11 06:45:23 +0900 | [diff] [blame] | 267 | int options); |
| 268 | |
deymo@chromium.org | 6d168a7 | 2013-01-30 05:29:12 +0900 | [diff] [blame] | 269 | // Removes the previously created object proxy for the given service |
| 270 | // name and the object path and releases its memory. |
| 271 | // |
| 272 | // If and object proxy for the given service name and object was |
| 273 | // created with GetObjectProxy, this function removes it from the |
| 274 | // bus object and detaches the ObjectProxy, invalidating any pointer |
| 275 | // previously acquired for it with GetObjectProxy. A subsequent call |
| 276 | // to GetObjectProxy will return a new object. |
| 277 | // |
| 278 | // All the object proxies are detached from remote objects at the |
| 279 | // shutdown time of the bus, but they can be detached early to reduce |
| 280 | // memory footprint and used match rules for the bus connection. |
| 281 | // |
| 282 | // |service_name| looks like "org.freedesktop.NetworkManager", and |
| 283 | // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". |
| 284 | // |callback| is called when the object proxy is successfully removed and |
| 285 | // detached. |
| 286 | // |
| 287 | // The function returns true when there is an object proxy matching the |
| 288 | // |service_name| and |object_path| to remove, and calls |callback| when it |
| 289 | // is removed. Otherwise, it returns false and the |callback| function is |
| 290 | // never called. The |callback| argument must not be null. |
| 291 | // |
| 292 | // Must be called in the origin thread. |
| 293 | virtual bool RemoveObjectProxy(const std::string& service_name, |
| 294 | const ObjectPath& object_path, |
| 295 | const base::Closure& callback); |
| 296 | |
| 297 | // Same as above, but also takes a bitfield of ObjectProxy::Options. |
| 298 | // See object_proxy.h for available options. |
| 299 | virtual bool RemoveObjectProxyWithOptions( |
| 300 | const std::string& service_name, |
| 301 | const ObjectPath& object_path, |
| 302 | int options, |
| 303 | const base::Closure& callback); |
| 304 | |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 305 | // Gets the exported object for the given object path. |
| 306 | // The caller must not delete the returned object. |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 307 | // |
| 308 | // Returns an existing exported object if the bus object already owns |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 309 | // the exported object for the given object path. Never returns NULL. |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 310 | // |
| 311 | // The bus will own all exported objects created by the bus, to ensure |
| 312 | // that the exported objects are unregistered at the shutdown time of |
| 313 | // the bus. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 314 | // |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 315 | // The exported object is used to export methods of local objects, and |
| 316 | // send signal from them. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 317 | // |
| 318 | // Must be called in the origin thread. |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 319 | virtual ExportedObject* GetExportedObject(const ObjectPath& object_path); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 320 | |
keybuk@chromium.org | d2ca8f3 | 2012-03-14 10:18:35 +0900 | [diff] [blame] | 321 | // Unregisters the exported object for the given object path |object_path|. |
| 322 | // |
| 323 | // Getting an exported object for the same object path after this call |
| 324 | // will return a new object, method calls on any remaining copies of the |
| 325 | // previous object will not be called. |
| 326 | // |
| 327 | // Must be called in the origin thread. |
| 328 | virtual void UnregisterExportedObject(const ObjectPath& object_path); |
| 329 | |
keybuk@chromium.org | 0971501 | 2013-03-26 03:20:08 +0900 | [diff] [blame] | 330 | |
| 331 | // Gets an object manager for the given remote object path |object_path| |
| 332 | // exported by the service |service_name|. |
| 333 | // |
| 334 | // Returns an existing object manager if the bus object already owns a |
| 335 | // matching object manager, never returns NULL. |
| 336 | // |
| 337 | // The caller must not delete the returned object, the bus retains ownership |
| 338 | // of all object managers. |
| 339 | // |
| 340 | // Must be called in the origin thread. |
| 341 | virtual ObjectManager* GetObjectManager(const std::string& service_name, |
| 342 | const ObjectPath& object_path); |
| 343 | |
| 344 | // Unregisters the object manager for the given remote object path |
| 345 | // |object_path| exported by the srevice |service_name|. |
| 346 | // |
| 347 | // Getting an object manager for the same remote object after this call |
| 348 | // will return a new object, method calls on any remaining copies of the |
| 349 | // previous object are not permitted. |
| 350 | // |
armansito | f436464 | 2014-09-06 02:49:34 +0900 | [diff] [blame] | 351 | // This method will asynchronously clean up any match rules that have been |
| 352 | // added for the object manager and invoke |callback| when the operation is |
| 353 | // complete. If this method returns false, then |callback| is never called. |
| 354 | // The |callback| argument must not be null. |
| 355 | // |
keybuk@chromium.org | 0971501 | 2013-03-26 03:20:08 +0900 | [diff] [blame] | 356 | // Must be called in the origin thread. |
armansito | f436464 | 2014-09-06 02:49:34 +0900 | [diff] [blame] | 357 | virtual bool RemoveObjectManager(const std::string& service_name, |
| 358 | const ObjectPath& object_path, |
| 359 | const base::Closure& callback); |
keybuk@chromium.org | 0971501 | 2013-03-26 03:20:08 +0900 | [diff] [blame] | 360 | |
| 361 | // Instructs all registered object managers to retrieve their set of managed |
| 362 | // objects from their respective remote objects. There is no need to call this |
| 363 | // manually, this is called automatically by the D-Bus thread manager once |
| 364 | // implementation classes are registered. |
| 365 | virtual void GetManagedObjects(); |
| 366 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 367 | // Shuts down the bus and blocks until it's done. More specifically, this |
| 368 | // function does the following: |
| 369 | // |
| 370 | // - Unregisters the object paths |
| 371 | // - Releases the service names |
| 372 | // - Closes the connection to dbus-daemon. |
| 373 | // |
nona@chromium.org | 5a44d2b | 2013-02-08 19:53:39 +0900 | [diff] [blame] | 374 | // This function can be called multiple times and it is no-op for the 2nd time |
| 375 | // calling. |
| 376 | // |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 377 | // BLOCKING CALL. |
| 378 | virtual void ShutdownAndBlock(); |
| 379 | |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 380 | // Similar to ShutdownAndBlock(), but this function is used to |
| 381 | // synchronously shut down the bus that uses the D-Bus thread. This |
| 382 | // function is intended to be used at the very end of the browser |
| 383 | // shutdown, where it makes more sense to shut down the bus |
| 384 | // synchronously, than trying to make it asynchronous. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 385 | // |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 386 | // BLOCKING CALL, but must be called in the origin thread. |
| 387 | virtual void ShutdownOnDBusThreadAndBlock(); |
| 388 | |
| 389 | // Returns true if the shutdown has been completed. |
| 390 | bool shutdown_completed() { return shutdown_completed_; } |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 391 | |
| 392 | // |
| 393 | // The public functions below are not intended to be used in client |
| 394 | // code. These are used to implement ObjectProxy and ExportedObject. |
| 395 | // |
| 396 | |
| 397 | // Connects the bus to the dbus-daemon. |
| 398 | // Returns true on success, or the bus is already connected. |
| 399 | // |
| 400 | // BLOCKING CALL. |
| 401 | virtual bool Connect(); |
| 402 | |
nona@chromium.org | 1de76fd | 2013-02-16 01:44:40 +0900 | [diff] [blame] | 403 | // Disconnects the bus from the dbus-daemon. |
| 404 | // Safe to call multiple times and no operation after the first call. |
| 405 | // Do not call for shared connection it will be released by libdbus. |
| 406 | // |
| 407 | // BLOCKING CALL. |
| 408 | virtual void ClosePrivateConnection(); |
| 409 | |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 410 | // Requests the ownership of the service name given by |service_name|. |
| 411 | // See also RequestOwnershipAndBlock(). |
| 412 | // |
| 413 | // |on_ownership_callback| is called when the service name is obtained |
| 414 | // or failed to be obtained, in the origin thread. |
| 415 | // |
| 416 | // Must be called in the origin thread. |
| 417 | virtual void RequestOwnership(const std::string& service_name, |
cmasone@chromium.org | 989857e | 2013-07-31 15:34:59 +0900 | [diff] [blame] | 418 | ServiceOwnershipOptions options, |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 419 | OnOwnershipCallback on_ownership_callback); |
| 420 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 421 | // Requests the ownership of the given service name. |
| 422 | // Returns true on success, or the the service name is already obtained. |
| 423 | // |
satorux@chromium.org | 49e0bc7 | 2014-01-09 13:39:17 +0900 | [diff] [blame] | 424 | // Note that it's important to expose methods before requesting a service |
| 425 | // name with this method. See also ExportedObject::ExportMethodAndBlock() |
| 426 | // for details. |
| 427 | // |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 428 | // BLOCKING CALL. |
cmasone@chromium.org | 989857e | 2013-07-31 15:34:59 +0900 | [diff] [blame] | 429 | virtual bool RequestOwnershipAndBlock(const std::string& service_name, |
| 430 | ServiceOwnershipOptions options); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 431 | |
| 432 | // Releases the ownership of the given service name. |
| 433 | // Returns true on success. |
| 434 | // |
| 435 | // BLOCKING CALL. |
| 436 | virtual bool ReleaseOwnership(const std::string& service_name); |
| 437 | |
| 438 | // Sets up async operations. |
| 439 | // Returns true on success, or it's already set up. |
| 440 | // This function needs to be called before starting async operations. |
| 441 | // |
| 442 | // BLOCKING CALL. |
| 443 | virtual bool SetUpAsyncOperations(); |
| 444 | |
| 445 | // Sends a message to the bus and blocks until the response is |
| 446 | // received. Used to implement synchronous method calls. |
| 447 | // |
| 448 | // BLOCKING CALL. |
| 449 | virtual DBusMessage* SendWithReplyAndBlock(DBusMessage* request, |
| 450 | int timeout_ms, |
| 451 | DBusError* error); |
| 452 | |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 453 | // Requests to send a message to the bus. The reply is handled with |
| 454 | // |pending_call| at a later time. |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 455 | // |
| 456 | // BLOCKING CALL. |
| 457 | virtual void SendWithReply(DBusMessage* request, |
| 458 | DBusPendingCall** pending_call, |
| 459 | int timeout_ms); |
| 460 | |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 461 | // Requests to send a message to the bus. The message serial number will |
| 462 | // be stored in |serial|. |
| 463 | // |
| 464 | // BLOCKING CALL. |
| 465 | virtual void Send(DBusMessage* request, uint32* serial); |
| 466 | |
| 467 | // Adds the message filter function. |filter_function| will be called |
hashimoto | 46be6e9 | 2014-12-04 16:41:55 +0900 | [diff] [blame] | 468 | // when incoming messages are received. |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 469 | // |
| 470 | // When a new incoming message arrives, filter functions are called in |
| 471 | // the order that they were added until the the incoming message is |
| 472 | // handled by a filter function. |
| 473 | // |
satorux@chromium.org | 66bc4c2 | 2011-10-06 09:20:53 +0900 | [diff] [blame] | 474 | // The same filter function associated with the same user data cannot be |
hashimoto | 46be6e9 | 2014-12-04 16:41:55 +0900 | [diff] [blame] | 475 | // added more than once. |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 476 | // |
| 477 | // BLOCKING CALL. |
hashimoto | 46be6e9 | 2014-12-04 16:41:55 +0900 | [diff] [blame] | 478 | virtual void AddFilterFunction(DBusHandleMessageFunction filter_function, |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 479 | void* user_data); |
| 480 | |
| 481 | // Removes the message filter previously added by AddFilterFunction(). |
| 482 | // |
| 483 | // BLOCKING CALL. |
hashimoto | 46be6e9 | 2014-12-04 16:41:55 +0900 | [diff] [blame] | 484 | virtual void RemoveFilterFunction(DBusHandleMessageFunction filter_function, |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 485 | void* user_data); |
| 486 | |
| 487 | // Adds the match rule. Messages that match the rule will be processed |
| 488 | // by the filter functions added by AddFilterFunction(). |
| 489 | // |
| 490 | // You cannot specify which filter function to use for a match rule. |
| 491 | // Instead, you should check if an incoming message is what you are |
| 492 | // interested in, in the filter functions. |
| 493 | // |
deymo@chromium.org | 7894ebf | 2013-01-31 15:08:02 +0900 | [diff] [blame] | 494 | // The same match rule can be added more than once and should be removed |
| 495 | // as many times as it was added. |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 496 | // |
| 497 | // The match rule looks like: |
| 498 | // "type='signal', interface='org.chromium.SomeInterface'". |
| 499 | // |
| 500 | // See "Message Bus Message Routing" section in the D-Bus specification |
| 501 | // for details about match rules: |
| 502 | // http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing |
| 503 | // |
| 504 | // BLOCKING CALL. |
| 505 | virtual void AddMatch(const std::string& match_rule, DBusError* error); |
| 506 | |
| 507 | // Removes the match rule previously added by AddMatch(). |
deymo@chromium.org | 7894ebf | 2013-01-31 15:08:02 +0900 | [diff] [blame] | 508 | // Returns false if the requested match rule is unknown or has already been |
| 509 | // removed. Otherwise, returns true and sets |error| accordingly. |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 510 | // |
| 511 | // BLOCKING CALL. |
deymo@chromium.org | 7894ebf | 2013-01-31 15:08:02 +0900 | [diff] [blame] | 512 | virtual bool RemoveMatch(const std::string& match_rule, DBusError* error); |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 513 | |
| 514 | // Tries to register the object path. Returns true on success. |
| 515 | // Returns false if the object path is already registered. |
| 516 | // |
| 517 | // |message_function| in |vtable| will be called every time when a new |
| 518 | // |message sent to the object path arrives. |
| 519 | // |
| 520 | // The same object path must not be added more than once. |
| 521 | // |
| 522 | // See also documentation of |dbus_connection_try_register_object_path| at |
| 523 | // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 524 | // |
| 525 | // BLOCKING CALL. |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 526 | virtual bool TryRegisterObjectPath(const ObjectPath& object_path, |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 527 | const DBusObjectPathVTable* vtable, |
| 528 | void* user_data, |
| 529 | DBusError* error); |
| 530 | |
| 531 | // Unregister the object path. |
| 532 | // |
| 533 | // BLOCKING CALL. |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 534 | virtual void UnregisterObjectPath(const ObjectPath& object_path); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 535 | |
hashimoto@chromium.org | 955f648 | 2013-09-26 13:32:29 +0900 | [diff] [blame] | 536 | // Returns the task runner of the D-Bus thread. |
| 537 | virtual base::TaskRunner* GetDBusTaskRunner(); |
haruki@chromium.org | 4a1f956 | 2013-05-08 20:57:14 +0900 | [diff] [blame] | 538 | |
hashimoto@chromium.org | 955f648 | 2013-09-26 13:32:29 +0900 | [diff] [blame] | 539 | // Returns the task runner of the thread that created the bus. |
| 540 | virtual base::TaskRunner* GetOriginTaskRunner(); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 541 | |
| 542 | // Returns true if the bus has the D-Bus thread. |
| 543 | virtual bool HasDBusThread(); |
| 544 | |
| 545 | // Check whether the current thread is on the origin thread (the thread |
| 546 | // that created the bus). If not, DCHECK will fail. |
| 547 | virtual void AssertOnOriginThread(); |
| 548 | |
| 549 | // Check whether the current thread is on the D-Bus thread. If not, |
| 550 | // DCHECK will fail. If the D-Bus thread is not supplied, it calls |
| 551 | // AssertOnOriginThread(). |
| 552 | virtual void AssertOnDBusThread(); |
| 553 | |
thestig@chromium.org | 56057f2 | 2013-05-05 00:48:37 +0900 | [diff] [blame] | 554 | // Gets the owner for |service_name| via org.freedesktop.DBus.GetNameOwner. |
| 555 | // Returns the owner name, if any, or an empty string on failure. |
| 556 | // |options| specifies where to printing error messages or not. |
| 557 | // |
| 558 | // BLOCKING CALL. |
| 559 | virtual std::string GetServiceOwnerAndBlock(const std::string& service_name, |
| 560 | GetServiceOwnerOption options); |
| 561 | |
| 562 | // A non-blocking version of GetServiceOwnerAndBlock(). |
| 563 | // Must be called in the origin thread. |
| 564 | virtual void GetServiceOwner(const std::string& service_name, |
| 565 | const GetServiceOwnerCallback& callback); |
| 566 | |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 567 | // Whenever the owner for |service_name| changes, run |callback| with the |
| 568 | // name of the new owner. If the owner goes away, then |callback| receives |
| 569 | // an empty string. |
| 570 | // |
| 571 | // Any unique (service_name, callback) can be used. Duplicate are ignored. |
| 572 | // |service_name| must not be empty and |callback| must not be null. |
| 573 | // |
| 574 | // Must be called in the origin thread. |
| 575 | virtual void ListenForServiceOwnerChange( |
| 576 | const std::string& service_name, |
| 577 | const GetServiceOwnerCallback& callback); |
| 578 | |
| 579 | // Stop listening for |service_name| owner changes for |callback|. |
| 580 | // Any unique (service_name, callback) can be used. Non-registered callbacks |
| 581 | // for a given service name are ignored. |
| 582 | // |service_name| must not be empty and |callback| must not be null. |
| 583 | // |
| 584 | // Must be called in the origin thread. |
| 585 | virtual void UnlistenForServiceOwnerChange( |
| 586 | const std::string& service_name, |
| 587 | const GetServiceOwnerCallback& callback); |
| 588 | |
zqiu | a84d25f | 2015-07-08 11:08:30 +0900 | [diff] [blame] | 589 | // Return the unique name of the bus connnection if it is connected to |
| 590 | // D-BUS. Otherwise, return an empty string. |
| 591 | std::string GetConnectionName(); |
| 592 | |
satorux@chromium.org | c9ebea2 | 2011-10-08 01:26:30 +0900 | [diff] [blame] | 593 | // Returns true if the bus is connected to D-Bus. |
| 594 | bool is_connected() { return connection_ != NULL; } |
| 595 | |
satorux@chromium.org | f77861f | 2011-08-25 14:18:29 +0900 | [diff] [blame] | 596 | protected: |
| 597 | // This is protected, so we can define sub classes. |
| 598 | virtual ~Bus(); |
| 599 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 600 | private: |
| 601 | friend class base::RefCountedThreadSafe<Bus>; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 602 | |
deymo@chromium.org | 6d168a7 | 2013-01-30 05:29:12 +0900 | [diff] [blame] | 603 | // Helper function used for RemoveObjectProxy(). |
| 604 | void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy, |
| 605 | const base::Closure& callback); |
| 606 | |
armansito | f436464 | 2014-09-06 02:49:34 +0900 | [diff] [blame] | 607 | // Helper functions used for RemoveObjectManager(). |
| 608 | void RemoveObjectManagerInternal( |
| 609 | scoped_refptr<dbus::ObjectManager> object_manager, |
| 610 | const base::Closure& callback); |
| 611 | void RemoveObjectManagerInternalHelper( |
| 612 | scoped_refptr<dbus::ObjectManager> object_manager, |
| 613 | const base::Closure& callback); |
| 614 | |
keybuk@chromium.org | d2ca8f3 | 2012-03-14 10:18:35 +0900 | [diff] [blame] | 615 | // Helper function used for UnregisterExportedObject(). |
| 616 | void UnregisterExportedObjectInternal( |
| 617 | scoped_refptr<dbus::ExportedObject> exported_object); |
| 618 | |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 619 | // Helper function used for ShutdownOnDBusThreadAndBlock(). |
| 620 | void ShutdownOnDBusThreadAndBlockInternal(); |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 621 | |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 622 | // Helper function used for RequestOwnership(). |
| 623 | void RequestOwnershipInternal(const std::string& service_name, |
cmasone@chromium.org | 989857e | 2013-07-31 15:34:59 +0900 | [diff] [blame] | 624 | ServiceOwnershipOptions options, |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 625 | OnOwnershipCallback on_ownership_callback); |
| 626 | |
thestig@chromium.org | 56057f2 | 2013-05-05 00:48:37 +0900 | [diff] [blame] | 627 | // Helper function used for GetServiceOwner(). |
| 628 | void GetServiceOwnerInternal(const std::string& service_name, |
| 629 | const GetServiceOwnerCallback& callback); |
| 630 | |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 631 | // Helper function used for ListenForServiceOwnerChange(). |
| 632 | void ListenForServiceOwnerChangeInternal( |
| 633 | const std::string& service_name, |
| 634 | const GetServiceOwnerCallback& callback); |
| 635 | |
| 636 | // Helper function used for UnListenForServiceOwnerChange(). |
| 637 | void UnlistenForServiceOwnerChangeInternal( |
| 638 | const std::string& service_name, |
| 639 | const GetServiceOwnerCallback& callback); |
| 640 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 641 | // Processes the all incoming data to the connection, if any. |
| 642 | // |
| 643 | // BLOCKING CALL. |
| 644 | void ProcessAllIncomingDataIfAny(); |
| 645 | |
| 646 | // Called when a watch object is added. Used to start monitoring the |
| 647 | // file descriptor used for D-Bus communication. |
| 648 | dbus_bool_t OnAddWatch(DBusWatch* raw_watch); |
| 649 | |
| 650 | // Called when a watch object is removed. |
| 651 | void OnRemoveWatch(DBusWatch* raw_watch); |
| 652 | |
| 653 | // Called when the "enabled" status of |raw_watch| is toggled. |
| 654 | void OnToggleWatch(DBusWatch* raw_watch); |
| 655 | |
| 656 | // Called when a timeout object is added. Used to start monitoring |
| 657 | // timeout for method calls. |
| 658 | dbus_bool_t OnAddTimeout(DBusTimeout* raw_timeout); |
| 659 | |
| 660 | // Called when a timeout object is removed. |
| 661 | void OnRemoveTimeout(DBusTimeout* raw_timeout); |
| 662 | |
| 663 | // Called when the "enabled" status of |raw_timeout| is toggled. |
| 664 | void OnToggleTimeout(DBusTimeout* raw_timeout); |
| 665 | |
| 666 | // Called when the dispatch status (i.e. if any incoming data is |
| 667 | // available) is changed. |
| 668 | void OnDispatchStatusChanged(DBusConnection* connection, |
| 669 | DBusDispatchStatus status); |
| 670 | |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 671 | // Called when a service owner change occurs. |
| 672 | void OnServiceOwnerChanged(DBusMessage* message); |
| 673 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 674 | // Callback helper functions. Redirects to the corresponding member function. |
| 675 | static dbus_bool_t OnAddWatchThunk(DBusWatch* raw_watch, void* data); |
| 676 | static void OnRemoveWatchThunk(DBusWatch* raw_watch, void* data); |
| 677 | static void OnToggleWatchThunk(DBusWatch* raw_watch, void* data); |
| 678 | static dbus_bool_t OnAddTimeoutThunk(DBusTimeout* raw_timeout, void* data); |
| 679 | static void OnRemoveTimeoutThunk(DBusTimeout* raw_timeout, void* data); |
| 680 | static void OnToggleTimeoutThunk(DBusTimeout* raw_timeout, void* data); |
| 681 | static void OnDispatchStatusChangedThunk(DBusConnection* connection, |
| 682 | DBusDispatchStatus status, |
| 683 | void* data); |
nona@chromium.org | 5a44d2b | 2013-02-08 19:53:39 +0900 | [diff] [blame] | 684 | |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 685 | // Calls OnConnectionDisconnected if the Disconnected signal is received. |
nona@chromium.org | 5a44d2b | 2013-02-08 19:53:39 +0900 | [diff] [blame] | 686 | static DBusHandlerResult OnConnectionDisconnectedFilter( |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 687 | DBusConnection* connection, |
| 688 | DBusMessage* message, |
| 689 | void* user_data); |
nona@chromium.org | 5a44d2b | 2013-02-08 19:53:39 +0900 | [diff] [blame] | 690 | |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 691 | // Calls OnServiceOwnerChanged for a NameOwnerChanged signal. |
| 692 | static DBusHandlerResult OnServiceOwnerChangedFilter( |
| 693 | DBusConnection* connection, |
| 694 | DBusMessage* message, |
| 695 | void* user_data); |
| 696 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 697 | const BusType bus_type_; |
| 698 | const ConnectionType connection_type_; |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 699 | scoped_refptr<base::SequencedTaskRunner> dbus_task_runner_; |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 700 | base::WaitableEvent on_shutdown_; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 701 | DBusConnection* connection_; |
| 702 | |
thestig@chromium.org | 074b1db | 2013-02-20 10:36:53 +0900 | [diff] [blame] | 703 | scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 704 | base::PlatformThreadId origin_thread_id_; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 705 | |
| 706 | std::set<std::string> owned_service_names_; |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 707 | // The following sets are used to check if rules/object_paths/filters |
| 708 | // are properly cleaned up before destruction of the bus object. |
deymo@chromium.org | 7894ebf | 2013-01-31 15:08:02 +0900 | [diff] [blame] | 709 | // Since it's not an error to add the same match rule twice, the repeated |
| 710 | // match rules are counted in a map. |
| 711 | std::map<std::string, int> match_rules_added_; |
keybuk@google.com | bf4649a | 2012-02-15 06:29:06 +0900 | [diff] [blame] | 712 | std::set<ObjectPath> registered_object_paths_; |
satorux@chromium.org | 66bc4c2 | 2011-10-06 09:20:53 +0900 | [diff] [blame] | 713 | std::set<std::pair<DBusHandleMessageFunction, void*> > |
| 714 | filter_functions_added_; |
satorux@chromium.org | 7f0c451 | 2011-08-23 16:29:21 +0900 | [diff] [blame] | 715 | |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 716 | // ObjectProxyTable is used to hold the object proxies created by the |
adamk@chromium.org | 35c0eef | 2012-02-11 06:45:23 +0900 | [diff] [blame] | 717 | // bus object. Key is a pair; the first part is a concatenated string of |
| 718 | // service name + object path, like |
| 719 | // "org.chromium.TestService/org/chromium/TestObject". |
| 720 | // The second part is the ObjectProxy::Options for the proxy. |
| 721 | typedef std::map<std::pair<std::string, int>, |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 722 | scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; |
| 723 | ObjectProxyTable object_proxy_table_; |
| 724 | |
| 725 | // ExportedObjectTable is used to hold the exported objects created by |
| 726 | // the bus object. Key is a concatenated string of service name + |
| 727 | // object path, like "org.chromium.TestService/org/chromium/TestObject". |
keybuk@chromium.org | 9cb73f0 | 2012-03-10 10:12:52 +0900 | [diff] [blame] | 728 | typedef std::map<const dbus::ObjectPath, |
satorux@chromium.org | dccbb7b | 2011-08-24 04:25:20 +0900 | [diff] [blame] | 729 | scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; |
| 730 | ExportedObjectTable exported_object_table_; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 731 | |
keybuk@chromium.org | 0971501 | 2013-03-26 03:20:08 +0900 | [diff] [blame] | 732 | // ObjectManagerTable is used to hold the object managers created by the |
| 733 | // bus object. Key is a concatenated string of service name + object path, |
| 734 | // like "org.chromium.TestService/org/chromium/TestObject". |
| 735 | typedef std::map<std::string, |
| 736 | scoped_refptr<dbus::ObjectManager> > ObjectManagerTable; |
| 737 | ObjectManagerTable object_manager_table_; |
| 738 | |
thestig@chromium.org | c2482f1 | 2013-06-11 07:52:34 +0900 | [diff] [blame] | 739 | // A map of NameOwnerChanged signals to listen for and the callbacks to run |
| 740 | // on the origin thread when the owner changes. |
| 741 | // Only accessed on the DBus thread. |
| 742 | // Key: Service name |
| 743 | // Value: Vector of callbacks. Unique and expected to be small. Not using |
| 744 | // std::set here because base::Callbacks don't have a '<' operator. |
| 745 | typedef std::map<std::string, std::vector<GetServiceOwnerCallback> > |
| 746 | ServiceOwnerChangedListenerMap; |
| 747 | ServiceOwnerChangedListenerMap service_owner_changed_listener_map_; |
| 748 | |
satorux@chromium.org | 326a6f8 | 2011-08-27 16:26:34 +0900 | [diff] [blame] | 749 | bool async_operations_set_up_; |
satorux@chromium.org | d336d45 | 2011-09-02 15:56:23 +0900 | [diff] [blame] | 750 | bool shutdown_completed_; |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 751 | |
| 752 | // Counters to make sure that OnAddWatch()/OnRemoveWatch() and |
| 753 | // OnAddTimeout()/OnRemoveTimeou() are balanced. |
| 754 | int num_pending_watches_; |
| 755 | int num_pending_timeouts_; |
| 756 | |
nona@chromium.org | 9f638e0 | 2012-04-19 12:20:03 +0900 | [diff] [blame] | 757 | std::string address_; |
| 758 | |
satorux@chromium.org | 163f1cb | 2011-08-18 05:58:12 +0900 | [diff] [blame] | 759 | DISALLOW_COPY_AND_ASSIGN(Bus); |
| 760 | }; |
| 761 | |
| 762 | } // namespace dbus |
| 763 | |
| 764 | #endif // DBUS_BUS_H_ |