ServiceInterface¶
- class dbus_fast.service.ServiceInterface¶
An abstract class that can be extended by the user to define DBus services.
Instances of
ServiceInterface
can be exported on a path of the bus with theexport
method of aMessageBus
.Use the
@method
,@dbus_property
, and@signal
decorators to mark class methods as DBus methods, properties, and signals respectively.- Variables:
name (str) – The name of this interface as it appears to clients. Must be a valid interface name.
- emit_properties_changed(changed_properties: dict[str, Any], invalidated_properties: list[str] = [])¶
Emit the
org.freedesktop.DBus.Properties.PropertiesChanged
signal.This signal is intended to be used to alert clients when a property of the interface has changed.
- Parameters:
changed_properties (dict(str, Any)) – The keys must be the names of properties exposed by this bus. The values must be valid for the signature of those properties.
invalidated_properties (list(str)) – A list of names of properties that are now invalid (presumably for clients who cache the value).
- introspect() Interface ¶
Get introspection information for this interface.
This might be useful for creating clients for the interface or examining the introspection output of an interface.
- Returns:
The introspection data for the interface.
- Return type:
- name¶
- @dbus_fast.service.dbus_property(access: PropertyAccess = PropertyAccess.READWRITE, name: str | None = None, disabled: bool = False)¶
A decorator to mark a class method of a
ServiceInterface
to be a DBus property.The class method must be a Python getter method with a return annotation that is a signature string of a single complete DBus type. When a client gets the property through the
org.freedesktop.DBus.Properties
interface, the getter will be called and the resulting value will be returned to the client.If the property is writable, it must have a setter method that takes a single parameter that is annotated with the same signature. When a client sets the property through the
org.freedesktop.DBus.Properties
interface, the setter will be called with the value from the calling client.The parameters of the getter and the setter must conform to the dbus-fast type system. The getter or the setter may raise a
DBusError
to return an error to the client.- Parameters:
name (str) – The name that DBus clients will use to interact with this property on the bus.
disabled (bool) – If set to true, the property will not be visible to clients.
- Example:
@dbus_property() def string_prop(self) -> 's': return self._string_prop @string_prop.setter def string_prop(self, val: 's'): self._string_prop = val
- @dbus_fast.service.method(name: str | None = None, disabled: bool = False)¶
A decorator to mark a class method of a
ServiceInterface
to be a DBus service method.The parameters and return value must each be annotated with a signature string of a single complete DBus type.
This class method will be called when a client calls the method on the DBus interface. The parameters given to the function come from the calling client and will conform to the dbus-fast type system. The parameters returned will be returned to the calling client and must conform to the dbus-fast type system. If multiple parameters are returned, they must be contained within a
list
.The decorated method may raise a
DBusError
to return an error to the client.- Parameters:
name (str) – The member name that DBus clients will use to call this method. Defaults to the name of the class method.
disabled (bool) – If set to true, the method will not be visible to clients.
- Example:
@method() def echo(self, val: 's') -> 's': return val @method() def echo_two(self, val1: 's', val2: 'u') -> 'su': return [val1, val2]
- @dbus_fast.service.signal(name: str | None = None, disabled: bool = False)¶
A decorator to mark a class method of a
ServiceInterface
to be a DBus signal.The signal is broadcast on the bus when the decorated class method is called by the user.
If the signal has an out argument, the class method must have a return type annotation with a signature string of a single complete DBus type and the return value of the class method must conform to the dbus-fast type system. If the signal has multiple out arguments, they must be returned within a
list
.- Parameters:
name (str) – The member name that will be used for this signal. Defaults to the name of the class method.
disabled (bool) – If set to true, the signal will not be visible to clients.
- Example:
@signal() def string_signal(self, val) -> 's': return val @signal() def two_strings_signal(self, val1, val2) -> 'ss': return [val1, val2]