Module: DBus::ObjectManager
- Defined in:
- lib/dbus/object_manager.rb
Overview
A mixin for Object implementing org.freedesktop.DBus.ObjectManager.
DBus::ObjectServer#export and DBus::ObjectServer#unexport will look for an ObjectManager parent in the path hierarchy. If found, it will emit InterfacesAdded or InterfacesRemoved, as appropriate.
Constant Summary collapse
- OBJECT_MANAGER_INTERFACE =
"org.freedesktop.DBus.ObjectManager"
Class Method Summary collapse
-
.included(base) ⇒ Object
Module#included, a hook for ‘include ObjectManager`, declares its dbus_interface.
Instance Method Summary collapse
-
#managed_objects ⇒ Hash{ObjectPath => Hash{String => Hash{String => Data::Base}}}
Implements ‘the GetManagedObjects` method.
-
#object_added(object) ⇒ void
DBus::ObjectServer#export will call this for you to emit the ‘InterfacesAdded` signal.
-
#object_removed(object) ⇒ void
DBus::ObjectServer#unexport will call this for you to emit the ‘InterfacesRemoved` signal.
Class Method Details
.included(base) ⇒ Object
Module#included, a hook for ‘include ObjectManager`, declares its dbus_interface.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dbus/object_manager.rb', line 48 def self.included(base) base.class_eval do dbus_interface OBJECT_MANAGER_INTERFACE do dbus_method :GetManagedObjects, "out res:a{oa{sa{sv}}}" do [managed_objects] end dbus_signal :InterfacesAdded, "object:o, interfaces_and_properties:a{sa{sv}}" dbus_signal :InterfacesRemoved, "object:o, interfaces:as" end end end |
Instance Method Details
#managed_objects ⇒ Hash{ObjectPath => Hash{String => Hash{String => Data::Base}}}
Implements ‘the GetManagedObjects` method.
26 27 28 29 30 31 |
# File 'lib/dbus/object_manager.rb', line 26 def managed_objects descendant_objects = object_server.descendants_for(path) descendant_objects.each_with_object({}) do |obj, hash| hash[obj.path] = obj.interfaces_and_properties end end |
#object_added(object) ⇒ void
This method returns an undefined value.
DBus::ObjectServer#export will call this for you to emit the ‘InterfacesAdded` signal.
36 37 38 |
# File 'lib/dbus/object_manager.rb', line 36 def object_added(object) InterfacesAdded(object.path, object.interfaces_and_properties) end |
#object_removed(object) ⇒ void
This method returns an undefined value.
DBus::ObjectServer#unexport will call this for you to emit the ‘InterfacesRemoved` signal.
43 44 45 |
# File 'lib/dbus/object_manager.rb', line 43 def object_removed(object) InterfacesRemoved(object.path, object.intfs.keys) end |