diff options
author | Peter Qiu <zqiu@chromium.org> | 2015-08-06 21:28:03 -0700 |
---|---|---|
committer | Bertrand SIMONNET <bsimonnet@google.com> | 2015-08-12 10:56:27 -0700 |
commit | 667cf9b0bb9604c1e057a833f33583f2a437fc0a (patch) | |
tree | 9529a11010da5af9cd9bbaa27c51b47627e6f242 | |
parent | 3dbcfa4ec55edbf275d47b1fbc74c7587de0ff8b (diff) | |
download | libbrillo-667cf9b0bb9604c1e057a833f33583f2a437fc0a.tar.gz |
libchromeos: dbus: synchronous dbus object registration
This allows shill to maintain its current behavior regarding to
DBus object registration.
BUG=chromium:517721
TEST=emerge-$BOARD libchromeos shill
TEST=Verify with shill using chromeos dbus
Reviewed-on: https://chromium-review.googlesource.com/291432
Commit-Ready: Zeping Qiu <zqiu@chromium.org>
Tested-by: Zeping Qiu <zqiu@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
(cherry-picked from
https://chromium.googlesource.com/chromiumos/platform2 at
2962f062990d2b04646c84def2284e607f9d1113)
Change-Id: Id1379008e82a34c1ccf8e21d4c1d3393aa207081
-rw-r--r-- | chromeos/dbus/dbus_object.cc | 59 | ||||
-rw-r--r-- | chromeos/dbus/dbus_object.h | 16 |
2 files changed, 75 insertions, 0 deletions
diff --git a/chromeos/dbus/dbus_object.cc b/chromeos/dbus/dbus_object.cc index fbad428..eaed1b9 100644 --- a/chromeos/dbus/dbus_object.cc +++ b/chromeos/dbus/dbus_object.cc @@ -65,6 +65,34 @@ void DBusInterface::ExportAsync( sequencer->OnAllTasksCompletedCall(actions); } +void DBusInterface::ExportAndBlock( + ExportedObjectManager* object_manager, + dbus::Bus* bus, + dbus::ExportedObject* exported_object, + const dbus::ObjectPath& object_path) { + VLOG(1) << "Registering D-Bus interface '" << interface_name_ << "' for '" + << object_path.value() << "'"; + for (const auto& pair : handlers_) { + std::string method_name = pair.first; + VLOG(1) << "Exporting method: " << interface_name_ << "." << method_name; + auto method_handler = + base::Bind(&DBusInterface::HandleMethodCall, base::Unretained(this)); + if (!exported_object->ExportMethodAndBlock( + interface_name_, method_name, method_handler)) { + LOG(FATAL) << "Failed exporting " << method_name << " method"; + } + } + + if (object_manager) { + auto property_writer_callback = + dbus_object_->property_set_.GetPropertyWriter(interface_name_); + ClaimInterface(object_manager->AsWeakPtr(), + object_path, + property_writer_callback, + true); + } +} + void DBusInterface::ClaimInterface( base::WeakPtr<ExportedObjectManager> object_manager, const dbus::ObjectPath& object_path, @@ -192,6 +220,37 @@ void DBusObject::RegisterAsync( sequencer->OnAllTasksCompletedCall({completion_callback}); } +void DBusObject::RegisterAndBlock() { + VLOG(1) << "Registering D-Bus object '" << object_path_.value() << "'."; + CHECK(exported_object_ == nullptr) << "Object already registered."; + exported_object_ = bus_->GetExportedObject(object_path_); + + // Add the org.freedesktop.DBus.Properties interface to the object. + DBusInterface* prop_interface = AddOrGetInterface(dbus::kPropertiesInterface); + prop_interface->AddSimpleMethodHandler( + dbus::kPropertiesGetAll, + base::Unretained(&property_set_), + &ExportedPropertySet::HandleGetAll); + prop_interface->AddSimpleMethodHandlerWithError( + dbus::kPropertiesGet, + base::Unretained(&property_set_), + &ExportedPropertySet::HandleGet); + prop_interface->AddSimpleMethodHandlerWithError( + dbus::kPropertiesSet, + base::Unretained(&property_set_), + &ExportedPropertySet::HandleSet); + property_set_.OnPropertiesInterfaceExported(prop_interface); + + // Export interface methods + for (const auto& pair : interfaces_) { + pair.second->ExportAndBlock( + object_manager_.get(), + bus_.get(), + exported_object_, + object_path_); + } +} + bool DBusObject::SendSignal(dbus::Signal* signal) { if (exported_object_) { exported_object_->SendSignal(signal); diff --git a/chromeos/dbus/dbus_object.h b/chromeos/dbus/dbus_object.h index 16fe59b..441df5b 100644 --- a/chromeos/dbus/dbus_object.h +++ b/chromeos/dbus/dbus_object.h @@ -468,6 +468,18 @@ class CHROMEOS_EXPORT DBusInterface final { dbus::ExportedObject* exported_object, const dbus::ObjectPath& object_path, const AsyncEventSequencer::CompletionAction& completion_callback); + // Exports all the methods and properties of this interface and claims the + // D-Bus interface synchronously. + // object_manager - ExportedObjectManager instance that notifies D-Bus + // listeners of a new interface being claimed. + // exported_object - instance of D-Bus object the interface is being added to. + // object_path - D-Bus object path for the object instance. + // interface_name - name of interface being registered. + CHROMEOS_PRIVATE void ExportAndBlock( + ExportedObjectManager* object_manager, + dbus::Bus* bus, + dbus::ExportedObject* exported_object, + const dbus::ObjectPath& object_path); CHROMEOS_PRIVATE void ClaimInterface( base::WeakPtr<ExportedObjectManager> object_manager, @@ -518,6 +530,10 @@ class CHROMEOS_EXPORT DBusObject { virtual void RegisterAsync( const AsyncEventSequencer::CompletionAction& completion_callback); + // Registers the object instance with D-Bus. This is call is synchronous and + // will block until the object and all of its interfaces are registered. + virtual void RegisterAndBlock(); + // Returns the ExportedObjectManager proxy, if any. If DBusObject has been // constructed without an object manager, this method returns an empty // smart pointer (containing nullptr). |