public abstract class DBusObject An object that answers D-Bus calls once DBusConnection.Export exports it at a path.
Remarks
Override DBusObject.HandleMethodAsync for the object's methods and the property methods for its properties. The base class answers org.freedesktop.DBus.Introspectable from DBusObject.IntrospectionXml and org.freedesktop.DBus.Properties from the property methods; the connection answers org.freedesktop.DBus.Peer.
Calls run on the thread pool and may run concurrently, also with each other; an object that keeps state guards it, or moves work to its model context. Throw DBusException to reply with an error name. Any other exception replies DBusException.Failed without its message, which can contain internal details.
Any program on the bus can call an exported object, so the calls one object answers are bounded: at most DBusObject.MaxConcurrentCalls run at once, and up to 64 more wait for a turn. Calls start in the order they arrive. A call beyond both is refused with DBusException.LimitsExceeded.
Constructors
DBusObject
protected DBusObject() No documentation.
Properties
IntrospectionXml
protected virtual string IntrospectionXml { get; } The object's interfaces as introspection XML <interface> elements, without the standard interfaces.
Remarks
Tools such as busctl introspect and generic clients read it. The default lists no interfaces.
MaxConcurrentCalls
protected virtual int MaxConcurrentCalls { get; } The most calls the object answers at once; 16 unless overridden.
Remarks
Calls start in the order they arrive. With 1, the object answers one call at a time, in that order, so a call sees what an earlier call changed. Raise the limit for an object whose calls wait a long time, such as for a user.
While this many calls run, up to 64 more wait; the connection refuses further calls with DBusException.LimitsExceeded until one finishes. Introspection and calls whose arguments cannot be read are answered at once and do not count. The value is read when the object is exported.
Path
public DBusObjectPath? Path { get; } The path the object is exported at, or null while it is not exported.
Methods
EmitPropertiesChanged
protected bool EmitPropertiesChanged(string interfaceName, IReadOnlyDictionary<string, DBusValue> changed, IEnumerable<string>? invalidated = null) Emits org.freedesktop.DBus.Properties.PropertiesChanged for properties of one interface.
Parameters
interfaceNameThe interface whose properties changed.
changedThe new values; the method wraps each in a variant.
invalidatedProperties that changed without sending their new value.
Returns
Whether the signal was sent.
EmitSignal
protected bool EmitSignal(string interfaceName, string member, params ReadOnlySpan<DBusValue> arguments) Emits a signal from the object.
Returns
Whether the signal was sent: false while the object is not exported or after its connection closed.
GetAllPropertiesAsync
protected virtual ValueTask<ImmutableDictionary<string, DBusValue>> GetAllPropertiesAsync(string interfaceName, DBusMethodContext context) Gets every readable property of an interface for org.freedesktop.DBus.Properties.GetAll.
Remarks
The default returns none.
GetPropertyAsync
protected virtual ValueTask<DBusValue> GetPropertyAsync(string interfaceName, string name, DBusMethodContext context) Gets one property for org.freedesktop.DBus.Properties.Get.
Remarks
The default reports DBusException.UnknownProperty.
HandleMethodAsync
protected abstract ValueTask<ImmutableArray<DBusValue>> HandleMethodAsync(DBusMethodContext context) Answers a call of one of the object's methods with the reply's values, each carrying its signature.
Remarks
Check DBusMethodContext.Arguments against the method's signature and throw DBusException with DBusException.InvalidArgs when it does not match; throw it with DBusException.UnknownMethod for a method the object does not have.
SetPropertyAsync
protected virtual ValueTask SetPropertyAsync(string interfaceName, string name, DBusValue value, DBusMethodContext context) Sets one property for org.freedesktop.DBus.Properties.Set.
Remarks
The default reports DBusException.UnknownProperty. Report a read-only property with DBusException.PropertyReadOnly, and call DBusObject.EmitPropertiesChanged after a change.