Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 #ifndef DBUS_BUS_H_ | 6 #ifndef DBUS_BUS_H_ |
| 7 #define DBUS_BUS_H_ | 7 #define DBUS_BUS_H_ |
| 8 #pragma once | 8 #pragma once |
| 9 | 9 |
| 10 #include <map> | |
| 10 #include <set> | 11 #include <set> |
| 11 #include <string> | 12 #include <string> |
| 13 #include <utility> | |
| 12 #include <dbus/dbus.h> | 14 #include <dbus/dbus.h> |
| 13 | 15 |
| 14 #include "base/callback.h" | 16 #include "base/callback.h" |
| 15 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
| 18 | 20 |
| 19 class MessageLoop; | 21 class MessageLoop; |
| 20 | 22 |
| 21 namespace base { | 23 namespace base { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 48 // | 50 // |
| 49 // BLOCKING CALLS | 51 // BLOCKING CALLS |
| 50 // | 52 // |
| 51 // Functions that issue blocking calls are marked "BLOCKING CALL" and | 53 // Functions that issue blocking calls are marked "BLOCKING CALL" and |
| 52 // these functions should be called in the D-Bus thread (if | 54 // these functions should be called in the D-Bus thread (if |
| 53 // supplied). AssertOnDBusThread() is placed in these functions. | 55 // supplied). AssertOnDBusThread() is placed in these functions. |
| 54 // | 56 // |
| 55 // Note that it's hard to tell if a libdbus function is actually blocking | 57 // Note that it's hard to tell if a libdbus function is actually blocking |
| 56 // or not (ex. dbus_bus_request_name() internally calls | 58 // or not (ex. dbus_bus_request_name() internally calls |
| 57 // dbus_connection_send_with_reply_and_block(), which is a blocking | 59 // dbus_connection_send_with_reply_and_block(), which is a blocking |
| 58 // call). To err on the side, we consider all libdbus functions that deal | 60 // call). To err on the safe side, we consider all libdbus functions that |
| 59 // with the connection to dbus-damoen to be blocking. | 61 // deal with the connection to dbus-damoen to be blocking. |
| 60 // | 62 // |
| 61 // EXAMPLE USAGE: | 63 // EXAMPLE USAGE: |
| 62 // | 64 // |
| 63 // Synchronous method call: | 65 // Synchronous method call: |
| 64 // | 66 // |
| 65 // dbus::Bus::Options options; | 67 // dbus::Bus::Options options; |
| 66 // // Set up the bus options here. | 68 // // Set up the bus options here. |
| 67 // ... | 69 // ... |
| 68 // dbus::Bus bus(options); | 70 // dbus::Bus bus(options); |
| 69 // | 71 // |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 // Called when shutdown is done. Used for Shutdown(). | 161 // Called when shutdown is done. Used for Shutdown(). |
| 160 typedef base::Callback<void ()> OnShutdownCallback; | 162 typedef base::Callback<void ()> OnShutdownCallback; |
| 161 | 163 |
| 162 // Creates a Bus object. The actual connection will be established when | 164 // Creates a Bus object. The actual connection will be established when |
| 163 // Connect() is called. | 165 // Connect() is called. |
| 164 explicit Bus(const Options& options); | 166 explicit Bus(const Options& options); |
| 165 | 167 |
| 166 // Gets the object proxy for the given service name and the object path. | 168 // Gets the object proxy for the given service name and the object path. |
| 167 // The caller must not delete the returned object. The bus will own the | 169 // The caller must not delete the returned object. |
| 168 // object. Never returns NULL. | 170 // |
| 171 // Returns an existing object proxy if the bus object already owns the | |
| 172 // object proxy for the given the service name and the object path. | |
|
stevenjb
2011/08/22 17:46:22
s/the given the/the given/
satorux1
2011/08/22 19:01:58
Done.
| |
| 173 // Never returns NULL. | |
| 174 // | |
| 175 // The bus will own all object proxies created by the bus, to ensure | |
| 176 // that the object proxies are detached from remote objects at the | |
| 177 // shutdown time of the bus. | |
| 169 // | 178 // |
| 170 // The object proxy is used to call methods of remote objects, and | 179 // The object proxy is used to call methods of remote objects, and |
| 171 // receive signals from them. | 180 // receive signals from them. |
| 172 // | 181 // |
| 173 // |service_name| looks like "org.freedesktop.NetworkManager", and | 182 // |service_name| looks like "org.freedesktop.NetworkManager", and |
| 174 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". | 183 // |object_path| looks like "/org/freedesktop/NetworkManager/Devices/0". |
| 175 // | 184 // |
| 176 // Must be called in the origin thread. | 185 // Must be called in the origin thread. |
| 177 virtual ObjectProxy* GetObjectProxy(const std::string& service_name, | 186 virtual ObjectProxy* GetObjectProxy(const std::string& service_name, |
| 178 const std::string& object_path); | 187 const std::string& object_path); |
| 179 | 188 |
| 180 // Gets the exported object for the given service name and the object | 189 // Gets the exported object for the given service name and the object |
| 181 // path. The caller must not delete the returned object. The bus will | 190 // path. The caller must not delete the returned object. |
| 182 // own the object. Never returns NULL. | 191 // |
| 192 // Returns an existing exported object if the bus object already owns | |
| 193 // the exported object for the given the service name and the object path. | |
|
stevenjb
2011/08/22 17:46:22
s/the given the/the given/
satorux1
2011/08/22 19:01:58
Done.
| |
| 194 // Never returns NULL. | |
| 195 // | |
| 196 // The bus will own all exported objects created by the bus, to ensure | |
| 197 // that the exported objects are unregistered at the shutdown time of | |
| 198 // the bus. | |
| 183 // | 199 // |
| 184 // The exported object is used to export methods of local objects, and | 200 // The exported object is used to export methods of local objects, and |
| 185 // send signal from them. | 201 // send signal from them. |
| 186 // | 202 // |
| 187 // Must be called in the origin thread. | 203 // Must be called in the origin thread. |
| 188 virtual ExportedObject* GetExportedObject(const std::string& service_name, | 204 virtual ExportedObject* GetExportedObject(const std::string& service_name, |
| 189 const std::string& object_path); | 205 const std::string& object_path); |
| 190 | 206 |
| 191 // Shuts down the bus and blocks until it's done. More specifically, this | 207 // Shuts down the bus and blocks until it's done. More specifically, this |
| 192 // function does the following: | 208 // function does the following: |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 base::PlatformThreadId origin_thread_id_; | 425 base::PlatformThreadId origin_thread_id_; |
| 410 base::PlatformThreadId dbus_thread_id_; | 426 base::PlatformThreadId dbus_thread_id_; |
| 411 | 427 |
| 412 std::set<std::string> owned_service_names_; | 428 std::set<std::string> owned_service_names_; |
| 413 // The following sets are used to check if rules/object_paths/filters | 429 // The following sets are used to check if rules/object_paths/filters |
| 414 // are properly cleaned up before destruction of the bus object. | 430 // are properly cleaned up before destruction of the bus object. |
| 415 std::set<std::string> match_rules_added_; | 431 std::set<std::string> match_rules_added_; |
| 416 std::set<std::string> registered_object_paths_; | 432 std::set<std::string> registered_object_paths_; |
| 417 std::set<DBusHandleMessageFunction> filter_functions_added_; | 433 std::set<DBusHandleMessageFunction> filter_functions_added_; |
| 418 | 434 |
| 419 std::vector<scoped_refptr<dbus::ObjectProxy> > object_proxies_; | 435 // ObjectProxyTable is used to hold the object proxies created by the |
| 420 std::vector<scoped_refptr<dbus::ExportedObject> > exported_objects_; | 436 // bus object. Key is a pair of service name and object path. |
|
stevenjb
2011/08/22 17:46:22
nit: Does it make sense to concatnate service name
satorux1
2011/08/22 19:01:58
Good point. I thought about it but didn't go with
| |
| 437 typedef std::map<std::pair<std::string, std::string>, | |
| 438 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; | |
| 439 ObjectProxyTable object_proxy_table_; | |
| 440 | |
| 441 // ExportedObjectTable is used to hold the exported objects created by | |
| 442 // the bus object. Key is a pair of service name and object path. | |
| 443 typedef std::map<std::pair<std::string, std::string>, | |
| 444 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; | |
| 445 ExportedObjectTable exported_object_table_; | |
| 421 | 446 |
| 422 bool async_operations_are_set_up_; | 447 bool async_operations_are_set_up_; |
| 423 | 448 |
| 424 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and | 449 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and |
| 425 // OnAddTimeout()/OnRemoveTimeou() are balanced. | 450 // OnAddTimeout()/OnRemoveTimeou() are balanced. |
| 426 int num_pending_watches_; | 451 int num_pending_watches_; |
| 427 int num_pending_timeouts_; | 452 int num_pending_timeouts_; |
| 428 | 453 |
| 429 DISALLOW_COPY_AND_ASSIGN(Bus); | 454 DISALLOW_COPY_AND_ASSIGN(Bus); |
| 430 }; | 455 }; |
| 431 | 456 |
| 432 } // namespace dbus | 457 } // namespace dbus |
| 433 | 458 |
| 434 #endif // DBUS_BUS_H_ | 459 #endif // DBUS_BUS_H_ |
| OLD | NEW |