Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <dbus/dbus.h> | 12 #include <dbus/dbus.h> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/synchronization/waitable_event.h" | |
| 17 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 18 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
| 19 | 20 |
| 20 class MessageLoop; | 21 class MessageLoop; |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class Thread; | 24 class Thread; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace dbus { | 27 namespace dbus { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 // | 219 // |
| 219 // BLOCKING CALL. | 220 // BLOCKING CALL. |
| 220 virtual void ShutdownAndBlock(); | 221 virtual void ShutdownAndBlock(); |
| 221 | 222 |
| 222 // Shuts down the bus in the D-Bus thread. |callback| will be called in | 223 // Shuts down the bus in the D-Bus thread. |callback| will be called in |
| 223 // the origin thread. | 224 // the origin thread. |
| 224 // | 225 // |
| 225 // Must be called in the origin thread. | 226 // Must be called in the origin thread. |
| 226 virtual void Shutdown(OnShutdownCallback callback); | 227 virtual void Shutdown(OnShutdownCallback callback); |
| 227 | 228 |
| 229 // Similar to ShutdownAndBlock(), but this function is used to | |
| 230 // synchronously shut down the bus that uses the D-Bus thread. This | |
| 231 // function is intended to be used at the very end of the browser | |
| 232 // shutdown, where it makes more sense to shut down the bus | |
| 233 // synchronously, than trying to make it asynchronous. | |
| 234 // | |
| 235 // BLOCKING CALL, but must be called in the origin thread. | |
| 236 virtual void ShutdownAndBlockWithDBusThread(); | |
|
stevenjb
2011/09/01 17:53:44
Do we need to expose both ShutdownAndBlock and Shu
satorux1
2011/09/01 17:57:30
ShutdownAndBlock() is already used in wifi_data_pr
stevenjb
2011/09/01 18:19:33
OK. In that case I suggest we name this ShutdownOn
| |
| 237 | |
| 238 // Returns true if the shutdown has been completed. | |
| 239 bool shutdown_completed() { return shutdown_completed_; } | |
| 240 | |
| 228 // | 241 // |
| 229 // The public functions below are not intended to be used in client | 242 // The public functions below are not intended to be used in client |
| 230 // code. These are used to implement ObjectProxy and ExportedObject. | 243 // code. These are used to implement ObjectProxy and ExportedObject. |
| 231 // | 244 // |
| 232 | 245 |
| 233 // Connects the bus to the dbus-daemon. | 246 // Connects the bus to the dbus-daemon. |
| 234 // Returns true on success, or the bus is already connected. | 247 // Returns true on success, or the bus is already connected. |
| 235 // | 248 // |
| 236 // BLOCKING CALL. | 249 // BLOCKING CALL. |
| 237 virtual bool Connect(); | 250 virtual bool Connect(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 protected: | 390 protected: |
| 378 // This is protected, so we can define sub classes. | 391 // This is protected, so we can define sub classes. |
| 379 virtual ~Bus(); | 392 virtual ~Bus(); |
| 380 | 393 |
| 381 private: | 394 private: |
| 382 friend class base::RefCountedThreadSafe<Bus>; | 395 friend class base::RefCountedThreadSafe<Bus>; |
| 383 | 396 |
| 384 // Helper function used for Shutdown(). | 397 // Helper function used for Shutdown(). |
| 385 void ShutdownInternal(OnShutdownCallback callback); | 398 void ShutdownInternal(OnShutdownCallback callback); |
| 386 | 399 |
| 400 // Helper function used for ShutdownAndBlockWithDBusThread(). | |
| 401 void ShutdownAndBlockWithDBusThreadInternal(); | |
| 402 | |
| 387 // Processes the all incoming data to the connection, if any. | 403 // Processes the all incoming data to the connection, if any. |
| 388 // | 404 // |
| 389 // BLOCKING CALL. | 405 // BLOCKING CALL. |
| 390 void ProcessAllIncomingDataIfAny(); | 406 void ProcessAllIncomingDataIfAny(); |
| 391 | 407 |
| 392 // Called when a watch object is added. Used to start monitoring the | 408 // Called when a watch object is added. Used to start monitoring the |
| 393 // file descriptor used for D-Bus communication. | 409 // file descriptor used for D-Bus communication. |
| 394 dbus_bool_t OnAddWatch(DBusWatch* raw_watch); | 410 dbus_bool_t OnAddWatch(DBusWatch* raw_watch); |
| 395 | 411 |
| 396 // Called when a watch object is removed. | 412 // Called when a watch object is removed. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 420 static void OnToggleWatchThunk(DBusWatch* raw_watch, void* data); | 436 static void OnToggleWatchThunk(DBusWatch* raw_watch, void* data); |
| 421 static dbus_bool_t OnAddTimeoutThunk(DBusTimeout* raw_timeout, void* data); | 437 static dbus_bool_t OnAddTimeoutThunk(DBusTimeout* raw_timeout, void* data); |
| 422 static void OnRemoveTimeoutThunk(DBusTimeout* raw_timeout, void* data); | 438 static void OnRemoveTimeoutThunk(DBusTimeout* raw_timeout, void* data); |
| 423 static void OnToggleTimeoutThunk(DBusTimeout* raw_timeout, void* data); | 439 static void OnToggleTimeoutThunk(DBusTimeout* raw_timeout, void* data); |
| 424 static void OnDispatchStatusChangedThunk(DBusConnection* connection, | 440 static void OnDispatchStatusChangedThunk(DBusConnection* connection, |
| 425 DBusDispatchStatus status, | 441 DBusDispatchStatus status, |
| 426 void* data); | 442 void* data); |
| 427 const BusType bus_type_; | 443 const BusType bus_type_; |
| 428 const ConnectionType connection_type_; | 444 const ConnectionType connection_type_; |
| 429 base::Thread* dbus_thread_; | 445 base::Thread* dbus_thread_; |
| 446 base::WaitableEvent on_shutdown_; | |
| 430 DBusConnection* connection_; | 447 DBusConnection* connection_; |
| 431 | 448 |
| 432 MessageLoop* origin_loop_; | 449 MessageLoop* origin_loop_; |
| 433 base::PlatformThreadId origin_thread_id_; | 450 base::PlatformThreadId origin_thread_id_; |
| 434 base::PlatformThreadId dbus_thread_id_; | 451 base::PlatformThreadId dbus_thread_id_; |
| 435 | 452 |
| 436 std::set<std::string> owned_service_names_; | 453 std::set<std::string> owned_service_names_; |
| 437 // The following sets are used to check if rules/object_paths/filters | 454 // The following sets are used to check if rules/object_paths/filters |
| 438 // are properly cleaned up before destruction of the bus object. | 455 // are properly cleaned up before destruction of the bus object. |
| 439 std::set<std::string> match_rules_added_; | 456 std::set<std::string> match_rules_added_; |
| 440 std::set<std::string> registered_object_paths_; | 457 std::set<std::string> registered_object_paths_; |
| 441 std::set<DBusHandleMessageFunction> filter_functions_added_; | 458 std::set<DBusHandleMessageFunction> filter_functions_added_; |
| 442 | 459 |
| 443 // ObjectProxyTable is used to hold the object proxies created by the | 460 // ObjectProxyTable is used to hold the object proxies created by the |
| 444 // bus object. Key is a concatenated string of service name + object path, | 461 // bus object. Key is a concatenated string of service name + object path, |
| 445 // like "org.chromium.TestService/org/chromium/TestObject". | 462 // like "org.chromium.TestService/org/chromium/TestObject". |
| 446 typedef std::map<std::string, | 463 typedef std::map<std::string, |
| 447 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; | 464 scoped_refptr<dbus::ObjectProxy> > ObjectProxyTable; |
| 448 ObjectProxyTable object_proxy_table_; | 465 ObjectProxyTable object_proxy_table_; |
| 449 | 466 |
| 450 // ExportedObjectTable is used to hold the exported objects created by | 467 // ExportedObjectTable is used to hold the exported objects created by |
| 451 // the bus object. Key is a concatenated string of service name + | 468 // the bus object. Key is a concatenated string of service name + |
| 452 // object path, like "org.chromium.TestService/org/chromium/TestObject". | 469 // object path, like "org.chromium.TestService/org/chromium/TestObject". |
| 453 typedef std::map<std::string, | 470 typedef std::map<std::string, |
| 454 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; | 471 scoped_refptr<dbus::ExportedObject> > ExportedObjectTable; |
| 455 ExportedObjectTable exported_object_table_; | 472 ExportedObjectTable exported_object_table_; |
| 456 | 473 |
| 457 bool async_operations_set_up_; | 474 bool async_operations_set_up_; |
| 475 bool shutdown_completed_; | |
| 458 | 476 |
| 459 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and | 477 // Counters to make sure that OnAddWatch()/OnRemoveWatch() and |
| 460 // OnAddTimeout()/OnRemoveTimeou() are balanced. | 478 // OnAddTimeout()/OnRemoveTimeou() are balanced. |
| 461 int num_pending_watches_; | 479 int num_pending_watches_; |
| 462 int num_pending_timeouts_; | 480 int num_pending_timeouts_; |
| 463 | 481 |
| 464 DISALLOW_COPY_AND_ASSIGN(Bus); | 482 DISALLOW_COPY_AND_ASSIGN(Bus); |
| 465 }; | 483 }; |
| 466 | 484 |
| 467 } // namespace dbus | 485 } // namespace dbus |
| 468 | 486 |
| 469 #endif // DBUS_BUS_H_ | 487 #endif // DBUS_BUS_H_ |
| OLD | NEW |