diff options
-rw-r--r-- | brillo/dbus/dbus_object.cc | 46 | ||||
-rw-r--r-- | brillo/dbus/dbus_object.h | 16 |
2 files changed, 49 insertions, 13 deletions
diff --git a/brillo/dbus/dbus_object.cc b/brillo/dbus/dbus_object.cc index 5172dc6..15bcddd 100644 --- a/brillo/dbus/dbus_object.cc +++ b/brillo/dbus/dbus_object.cc @@ -16,6 +16,23 @@ namespace brillo { namespace dbus_utils { +namespace { + +void SetupDefaultPropertyHandlers(DBusInterface* prop_interface, + ExportedPropertySet* property_set) { + 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); +} + +} // namespace + ////////////////////////////////////////////////////////////////////////////// DBusInterface::DBusInterface(DBusObject* dbus_object, @@ -152,7 +169,21 @@ void DBusInterface::AddSignalImpl( DBusObject::DBusObject(ExportedObjectManager* object_manager, const scoped_refptr<dbus::Bus>& bus, const dbus::ObjectPath& object_path) - : property_set_(bus.get()), bus_(bus), object_path_(object_path) { + : DBusObject::DBusObject(object_manager, + bus, + object_path, + base::Bind(&SetupDefaultPropertyHandlers)) {} + +DBusObject::DBusObject( + ExportedObjectManager* object_manager, + const scoped_refptr<dbus::Bus>& bus, + const dbus::ObjectPath& object_path, + PropertyHandlerSetupCallback property_handler_setup_callback) + : property_set_(bus.get()), + bus_(bus), + object_path_(object_path), + property_handler_setup_callback_( + std::move(property_handler_setup_callback)) { if (object_manager) object_manager_ = object_manager->AsWeakPtr(); } @@ -249,18 +280,7 @@ bool DBusObject::SendSignal(dbus::Signal* signal) { void DBusObject::RegisterPropertiesInterface() { 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_handler_setup_callback_.Run(prop_interface, &property_set_); property_set_.OnPropertiesInterfaceExported(prop_interface); } diff --git a/brillo/dbus/dbus_object.h b/brillo/dbus/dbus_object.h index e7c59e3..48f09ff 100644 --- a/brillo/dbus/dbus_object.h +++ b/brillo/dbus/dbus_object.h @@ -507,6 +507,9 @@ class BRILLO_EXPORT DBusInterface final { // by this object. class BRILLO_EXPORT DBusObject { public: + using PropertyHandlerSetupCallback = base::Callback<void( + DBusInterface* prop_interface, ExportedPropertySet* property_set)>; + // object_manager - ExportedObjectManager instance that notifies D-Bus // listeners of a new interface being claimed and property // changes on those interfaces. @@ -514,6 +517,17 @@ class BRILLO_EXPORT DBusObject { DBusObject(ExportedObjectManager* object_manager, const scoped_refptr<dbus::Bus>& bus, const dbus::ObjectPath& object_path); + + // property_handler_setup_callback - To be called when setting up property + // method handlers. Clients can register + // their own custom property method handlers + // (GetAll/Get/Set) by passing in this + // callback. + DBusObject(ExportedObjectManager* object_manager, + const scoped_refptr<dbus::Bus>& bus, + const dbus::ObjectPath& object_path, + PropertyHandlerSetupCallback property_handler_setup_callback); + virtual ~DBusObject(); // Returns an proxy handler for the interface |interface_name|. If the @@ -571,6 +585,8 @@ class BRILLO_EXPORT DBusObject { dbus::ObjectPath object_path_; // D-Bus object instance once this object is successfully exported. dbus::ExportedObject* exported_object_ = nullptr; // weak; owned by |bus_|. + // Sets up property method handlers. + PropertyHandlerSetupCallback property_handler_setup_callback_; friend class DBusInterface; DISALLOW_COPY_AND_ASSIGN(DBusObject); |