class gdbus_util.DBusObject(connection: DBusConnection)

Bases: object

DBusObject is an abstract class which facilitates registering D-Bus objects.

You have to define the D-Bus interfaces in the dbus_info property and the D-Bus object path in the dbus_path property. The interfaces are automatically registered on the D-Bus connection when the object is initialized.

Methods defined in the D-Bus interfaces must be implemented as methods of DBusObject and properties must be implemented as attributes or properties.

See hello-service.py for an example of how to use this class.

Parameters:

connection (Gio.DBusConnection) – The D-Bus connection to register the object on, as returned by Gio.bus_get_sync().

Variables:

exit_on_idle_service (Optional[ExitOnIdleService]) – Set this to an instance of ExitOnIdleService if you want to use this object in an exit-on-idle service. If set, the ExitOnIdleService.reset_idle_timer() method is called when a method call is received.

check_idle() bool

Check if the object is currently handling any method calls.

This method is useful for overriding the ExitOnIdleService.check_idle() method.

Returns:

True if the object is idle (i.e. not handling any method calls), False otherwise.

abstract property dbus_info: str

The D-Bus introspection XML for this object. The format is specified in the D-Bus specification.

Subclasses must implement this property.

Example:

dbus_info = """
<node>
    <interface name='org.example.Foo'>
        <method name='Bar'/>
        <property name='Baz' type='i' access='readwrite'/>
    </interface>
</node>
"""
abstract property dbus_path: str

The D-Bus object path for this object.

Subclasses must implement this property.

Example:

dbus_path = '/org/example/Foo'
emit_properties_changed_signal(interface_name: str, changed_properties: dict[str, Any], invalidated_properties: list[str] | None = None) None

Emit the PropertiesChanged signal for a D-Bus interface.

Parameters:
  • interface_name (str) – The name of the D-Bus interface.

  • changed_properties (dict[str, Any]) – A dictionary of the changed properties and their new values. The values must be of the correct type for the properties. They are automatically converted to GLib.Variant objects.

  • invalidated_properties (Optional[list[str]]) – A list of the names of properties that have been invalidated. This is an optional parameter.

emit_signal(signal_name: str, parameters: dict[str, Any]) None

Emit a D-Bus signal.

Parameters:
  • signal_name (str) – The name of the signal to emit.

  • parameters (dict[str, Any]) – A dictionary of the signal’s parameters. The values must be of the correct type for the signal. They are automatically converted to GLib.Variant objects.

unregister() None

Unregister the D-Bus interfaces of this object.