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