| 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 | 7 |
| 8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 // Creates a Bus object. The actual connection will be established when | 205 // Creates a Bus object. The actual connection will be established when |
| 206 // Connect() is called. | 206 // Connect() is called. |
| 207 explicit Bus(const Options& options); | 207 explicit Bus(const Options& options); |
| 208 | 208 |
| 209 // Called when an ownership request is complete. | 209 // Called when an ownership request is complete. |
| 210 // Parameters: | 210 // Parameters: |
| 211 // - the requested service name. | 211 // - the requested service name. |
| 212 // - whether ownership has been obtained or not. | 212 // - whether ownership has been obtained or not. |
| 213 typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback; | 213 typedef base::Callback<void (const std::string&, bool)> OnOwnershipCallback; |
| 214 |
| 215 // Called when GetServiceOwner() completes. |
| 216 // |service_owner| is the return value from GetServiceOwnerAndBlock(). |
| 217 typedef base::Callback<void (const std::string& service_owner)> |
| 218 GetServiceOwnerCallback; |
| 219 |
| 214 // TODO(satorux): Remove the service name parameter as the caller of | 220 // TODO(satorux): Remove the service name parameter as the caller of |
| 215 // RequestOwnership() knows the service name. | 221 // RequestOwnership() knows the service name. |
| 216 | 222 |
| 217 // Gets the object proxy for the given service name and the object path. | 223 // Gets the object proxy for the given service name and the object path. |
| 218 // The caller must not delete the returned object. | 224 // The caller must not delete the returned object. |
| 219 // | 225 // |
| 220 // Returns an existing object proxy if the bus object already owns the | 226 // Returns an existing object proxy if the bus object already owns the |
| 221 // object proxy for the given service name and the object path. | 227 // object proxy for the given service name and the object path. |
| 222 // Never returns NULL. | 228 // Never returns NULL. |
| 223 // | 229 // |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 529 |
| 524 // Check whether the current thread is on the origin thread (the thread | 530 // Check whether the current thread is on the origin thread (the thread |
| 525 // that created the bus). If not, DCHECK will fail. | 531 // that created the bus). If not, DCHECK will fail. |
| 526 virtual void AssertOnOriginThread(); | 532 virtual void AssertOnOriginThread(); |
| 527 | 533 |
| 528 // Check whether the current thread is on the D-Bus thread. If not, | 534 // Check whether the current thread is on the D-Bus thread. If not, |
| 529 // DCHECK will fail. If the D-Bus thread is not supplied, it calls | 535 // DCHECK will fail. If the D-Bus thread is not supplied, it calls |
| 530 // AssertOnOriginThread(). | 536 // AssertOnOriginThread(). |
| 531 virtual void AssertOnDBusThread(); | 537 virtual void AssertOnDBusThread(); |
| 532 | 538 |
| 539 // Gets the owner for |service_name| via org.freedesktop.DBus.GetNameOwner. |
| 540 // Returns the owner name, if any, or an empty string on failure. |
| 541 // Set |suppress_errors| to true to avoid printing error messages. |
| 542 // |
| 543 // BLOCKING CALL. |
| 544 virtual std::string GetServiceOwnerAndBlock(const std::string& service_name, |
| 545 bool suppress_errors); |
| 546 |
| 547 // A non-blocking version of GetServiceOwnerAndBlock(). |
| 548 // Must be called in the origin thread. |
| 549 virtual void GetServiceOwner(const std::string& service_name, |
| 550 const GetServiceOwnerCallback& callback); |
| 551 |
| 533 // Returns true if the bus is connected to D-Bus. | 552 // Returns true if the bus is connected to D-Bus. |
| 534 bool is_connected() { return connection_ != NULL; } | 553 bool is_connected() { return connection_ != NULL; } |
| 535 | 554 |
| 536 protected: | 555 protected: |
| 537 // This is protected, so we can define sub classes. | 556 // This is protected, so we can define sub classes. |
| 538 virtual ~Bus(); | 557 virtual ~Bus(); |
| 539 | 558 |
| 540 private: | 559 private: |
| 541 friend class base::RefCountedThreadSafe<Bus>; | 560 friend class base::RefCountedThreadSafe<Bus>; |
| 542 | 561 |
| 543 // Helper function used for RemoveObjectProxy(). | 562 // Helper function used for RemoveObjectProxy(). |
| 544 void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy, | 563 void RemoveObjectProxyInternal(scoped_refptr<dbus::ObjectProxy> object_proxy, |
| 545 const base::Closure& callback); | 564 const base::Closure& callback); |
| 546 | 565 |
| 547 // Helper function used for UnregisterExportedObject(). | 566 // Helper function used for UnregisterExportedObject(). |
| 548 void UnregisterExportedObjectInternal( | 567 void UnregisterExportedObjectInternal( |
| 549 scoped_refptr<dbus::ExportedObject> exported_object); | 568 scoped_refptr<dbus::ExportedObject> exported_object); |
| 550 | 569 |
| 551 // Helper function used for ShutdownOnDBusThreadAndBlock(). | 570 // Helper function used for ShutdownOnDBusThreadAndBlock(). |
| 552 void ShutdownOnDBusThreadAndBlockInternal(); | 571 void ShutdownOnDBusThreadAndBlockInternal(); |
| 553 | 572 |
| 554 // Helper function used for RequestOwnership(). | 573 // Helper function used for RequestOwnership(). |
| 555 void RequestOwnershipInternal(const std::string& service_name, | 574 void RequestOwnershipInternal(const std::string& service_name, |
| 556 OnOwnershipCallback on_ownership_callback); | 575 OnOwnershipCallback on_ownership_callback); |
| 557 | 576 |
| 577 // Helper function used for GetServiceOwner(). |
| 578 void GetServiceOwnerInternal(const std::string& service_name, |
| 579 const GetServiceOwnerCallback& callback); |
| 580 |
| 558 // Processes the all incoming data to the connection, if any. | 581 // Processes the all incoming data to the connection, if any. |
| 559 // | 582 // |
| 560 // BLOCKING CALL. | 583 // BLOCKING CALL. |
| 561 void ProcessAllIncomingDataIfAny(); | 584 void ProcessAllIncomingDataIfAny(); |
| 562 | 585 |
| 563 // Called when a watch object is added. Used to start monitoring the | 586 // Called when a watch object is added. Used to start monitoring the |
| 564 // file descriptor used for D-Bus communication. | 587 // file descriptor used for D-Bus communication. |
| 565 dbus_bool_t OnAddWatch(DBusWatch* raw_watch); | 588 dbus_bool_t OnAddWatch(DBusWatch* raw_watch); |
| 566 | 589 |
| 567 // Called when a watch object is removed. | 590 // Called when a watch object is removed. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 680 |
| 658 std::string address_; | 681 std::string address_; |
| 659 base::Closure on_disconnected_closure_; | 682 base::Closure on_disconnected_closure_; |
| 660 | 683 |
| 661 DISALLOW_COPY_AND_ASSIGN(Bus); | 684 DISALLOW_COPY_AND_ASSIGN(Bus); |
| 662 }; | 685 }; |
| 663 | 686 |
| 664 } // namespace dbus | 687 } // namespace dbus |
| 665 | 688 |
| 666 #endif // DBUS_BUS_H_ | 689 #endif // DBUS_BUS_H_ |
| OLD | NEW |