| 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_BUS_H_ | 5 #ifndef DBUS_BUS_H_ |
| 6 #define DBUS_BUS_H_ | 6 #define DBUS_BUS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <dbus/dbus.h> | 13 #include <dbus/dbus.h> |
| 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/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
| 20 #include "dbus/object_path.h" |
| 20 | 21 |
| 21 class MessageLoop; | 22 class MessageLoop; |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class Thread; | 25 class Thread; |
| 25 class MessageLoopProxy; | 26 class MessageLoopProxy; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace dbus { | 29 namespace dbus { |
| 29 | 30 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // // Do something with method_call. | 106 // // Do something with method_call. |
| 106 // Response* response = Response::FromMethodCall(method_call); | 107 // Response* response = Response::FromMethodCall(method_call); |
| 107 // // Build response here. | 108 // // Build response here. |
| 108 // // Can send an immediate response here to implement a synchronous service | 109 // // Can send an immediate response here to implement a synchronous service |
| 109 // // or store the response_sender and send a response later to implement an | 110 // // or store the response_sender and send a response later to implement an |
| 110 // // asynchronous service. | 111 // // asynchronous service. |
| 111 // response_sender.Run(response); | 112 // response_sender.Run(response); |
| 112 // } | 113 // } |
| 113 // | 114 // |
| 114 // void OnExported(const std::string& interface_name, | 115 // void OnExported(const std::string& interface_name, |
| 115 // const std::string& object_path, | 116 // const ObjectPath& object_path, |
| 116 // bool success) { | 117 // bool success) { |
| 117 // // success is true if the method was exported successfully. | 118 // // success is true if the method was exported successfully. |
| 118 // } | 119 // } |
| 119 // | 120 // |
| 120 // ... | 121 // ... |
| 121 // dbus::ExportedObject* exported_object = | 122 // dbus::ExportedObject* exported_object = |
| 122 // bus.GetExportedObject(service_name, object_path); | 123 // bus.GetExportedObject(service_name, object_path); |
| 123 // exported_object.ExportMethod(interface_name, method_name, | 124 // exported_object.ExportMethod(interface_name, method_name, |
| 124 // base::Bind(&Echo), | 125 // base::Bind(&Echo), |
| 125 // base::Bind(&OnExported)); | 126 // base::Bind(&OnExported)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // shutdown time of the bus. | 188 // shutdown time of the bus. |
| 188 // | 189 // |
| 189 // The object proxy is used to call methods of remote objects, and | 190 // The object proxy is used to call methods of remote objects, and |
| 190 // receive signals from them. | 191 // receive signals from them. |
| 191 // | 192 // |
| 192 // |service_name| looks like "org.freedesktop.NetworkManager", and | 193 // |service_name| looks like "org.freedesktop.NetworkManager", and |
| 193 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". | 194 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". |
| 194 // | 195 // |
| 195 // Must be called in the origin thread. | 196 // Must be called in the origin thread. |
| 196 virtual ObjectProxy* GetObjectProxy(const std::string& service_name, | 197 virtual ObjectProxy* GetObjectProxy(const std::string& service_name, |
| 197 const std::string& object_path); | 198 const ObjectPath& object_path); |
| 198 | 199 |
| 199 // Same as above, but also takes a bitfield of ObjectProxy::Options. | 200 // Same as above, but also takes a bitfield of ObjectProxy::Options. |
| 200 // See object_proxy.h for available options. | 201 // See object_proxy.h for available options. |
| 201 virtual ObjectProxy* GetObjectProxyWithOptions( | 202 virtual ObjectProxy* GetObjectProxyWithOptions( |
| 202 const std::string& service_name, | 203 const std::string& service_name, |
| 203 const std::string& object_path, | 204 const ObjectPath& object_path, |
| 204 int options); | 205 int options); |
| 205 | 206 |
| 206 // Gets the exported object for the given service name and the object | 207 // Gets the exported object for the given service name and the object |
| 207 // path. The caller must not delete the returned object. | 208 // path. The caller must not delete the returned object. |
| 208 // | 209 // |
| 209 // Returns an existing exported object if the bus object already owns | 210 // Returns an existing exported object if the bus object already owns |
| 210 // the exported object for the given service name and the object path. | 211 // the exported object for the given service name and the object path. |
| 211 // Never returns NULL. | 212 // Never returns NULL. |
| 212 // | 213 // |
| 213 // The bus will own all exported objects created by the bus, to ensure | 214 // The bus will own all exported objects created by the bus, to ensure |
| 214 // that the exported objects are unregistered at the shutdown time of | 215 // that the exported objects are unregistered at the shutdown time of |
| 215 // the bus. | 216 // the bus. |
| 216 // | 217 // |
| 217 // The exported object is used to export methods of local objects, and | 218 // The exported object is used to export methods of local objects, and |
| 218 // send signal from them. | 219 // send signal from them. |
| 219 // | 220 // |
| 220 // Must be called in the origin thread. | 221 // Must be called in the origin thread. |
| 221 virtual ExportedObject* GetExportedObject(const std::string& service_name, | 222 virtual ExportedObject* GetExportedObject(const std::string& service_name, |
| 222 const std::string& object_path); | 223 const ObjectPath& object_path); |
| 223 | 224 |
| 224 // Shuts down the bus and blocks until it's done. More specifically, this | 225 // Shuts down the bus and blocks until it's done. More specifically, this |
| 225 // function does the following: | 226 // function does the following: |
| 226 // | 227 // |
| 227 // - Unregisters the object paths | 228 // - Unregisters the object paths |
| 228 // - Releases the service names | 229 // - Releases the service names |
| 229 // - Closes the connection to dbus-daemon. | 230 // - Closes the connection to dbus-daemon. |
| 230 // | 231 // |
| 231 // BLOCKING CALL. | 232 // BLOCKING CALL. |
| 232 virtual void ShutdownAndBlock(); | 233 virtual void ShutdownAndBlock(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // | 347 // |
| 347 // |message_function| in |vtable| will be called every time when a new | 348 // |message_function| in |vtable| will be called every time when a new |
| 348 // |message sent to the object path arrives. | 349 // |message sent to the object path arrives. |
| 349 // | 350 // |
| 350 // The same object path must not be added more than once. | 351 // The same object path must not be added more than once. |
| 351 // | 352 // |
| 352 // See also documentation of |dbus_connection_try_register_object_path| at | 353 // See also documentation of |dbus_connection_try_register_object_path| at |
| 353 // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html | 354 // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html |
| 354 // | 355 // |
| 355 // BLOCKING CALL. | 356 // BLOCKING CALL. |
| 356 virtual bool TryRegisterObjectPath(const std::string& object_path, | 357 virtual bool TryRegisterObjectPath(const ObjectPath& object_path, |
| 357 const DBusObjectPathVTable* vtable, | 358 const DBusObjectPathVTable* vtable, |
| 358 void* user_data, | 359 void* user_data, |
| 359 DBusError* error); | 360 DBusError* error); |
| 360 | 361 |
| 361 // Unregister the object path. | 362 // Unregister the object path. |
| 362 // | 363 // |
| 363 // BLOCKING CALL. | 364 // BLOCKING CALL. |
| 364 virtual void UnregisterObjectPath(const std::string& object_path); | 365 virtual void UnregisterObjectPath(const ObjectPath& object_path); |
| 365 | 366 |
| 366 // Posts the task to the message loop of the thread that created the bus. | 367 // Posts the task to the message loop of the thread that created the bus. |
| 367 virtual void PostTaskToOriginThread( | 368 virtual void PostTaskToOriginThread( |
| 368 const tracked_objects::Location& from_here, | 369 const tracked_objects::Location& from_here, |
| 369 const base::Closure& task); | 370 const base::Closure& task); |
| 370 | 371 |
| 371 // Posts the task to the message loop of the D-Bus thread. If D-Bus | 372 // Posts the task to the message loop of the D-Bus thread. If D-Bus |
| 372 // thread is not supplied, the message loop of the origin thread will be | 373 // thread is not supplied, the message loop of the origin thread will be |
| 373 // used. | 374 // used. |
| 374 virtual void PostTaskToDBusThread( | 375 virtual void PostTaskToDBusThread( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 base::WaitableEvent on_shutdown_; | 455 base::WaitableEvent on_shutdown_; |
| 455 DBusConnection* connection_; | 456 DBusConnection* connection_; |
| 456 | 457 |
| 457 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 458 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
| 458 base::PlatformThreadId origin_thread_id_; | 459 base::PlatformThreadId origin_thread_id_; |
| 459 | 460 |
| 460 std::set<std::string> owned_service_names_; | 461 std::set<std::string> owned_service_names_; |
| 461 // The following sets are used to check if rules/object_paths/filters | 462 // The following sets are used to check if rules/object_paths/filters |
| 462 // are properly cleaned up before destruction of the bus object. | 463 // are properly cleaned up before destruction of the bus object. |
| 463 std::set<std::string> match_rules_added_; | 464 std::set<std::string> match_rules_added_; |
| 464 std::set<std::string> registered_object_paths_; | 465 std::set<ObjectPath> registered_object_paths_; |
| 465 std::set<std::pair<DBusHandleMessageFunction, void*> > | 466 std::set<std::pair<DBusHandleMessageFunction, void*> > |
| 466 filter_functions_added_; | 467 filter_functions_added_; |
| 467 | 468 |
| 468 // ObjectProxyTable is used to hold the object proxies created by the | 469 // ObjectProxyTable is used to hold the object proxies created by the |
| 469 // bus object. Key is a pair; the first part is a concatenated string of | 470 // bus object. Key is a pair; the first part is a concatenated string of |
| 470 // service name + object path, like | 471 // service name + object path, like |
| 471 // "org.chromium.TestService/org/chromium/TestObject". | 472 // "org.chromium.TestService/org/chromium/TestObject". |
| 472 // The second part is the ObjectProxy::Options for the proxy. | 473 // The second part is the ObjectProxy::Options for the proxy. |
| 473 typedef std::map<std::pair<std::string, int>, | 474 typedef std::map<std::pair<std::string, int>, |
| 474 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; | 475 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 488 // OnAddTimeout()/OnRemoveTimeou() are balanced. | 489 // OnAddTimeout()/OnRemoveTimeou() are balanced. |
| 489 int num_pending_watches_; | 490 int num_pending_watches_; |
| 490 int num_pending_timeouts_; | 491 int num_pending_timeouts_; |
| 491 | 492 |
| 492 DISALLOW_COPY_AND_ASSIGN(Bus); | 493 DISALLOW_COPY_AND_ASSIGN(Bus); |
| 493 }; | 494 }; |
| 494 | 495 |
| 495 } // namespace dbus | 496 } // namespace dbus |
| 496 | 497 |
| 497 #endif // DBUS_BUS_H_ | 498 #endif // DBUS_BUS_H_ |
| OLD | NEW |