DBusProxy class

Namespace Runic.Platform.Linux.DBus in Runic.Platform.Linux.DBus 0.23.0

public class DBusProxy

Calls one remote object: its methods, properties and signals.

Remarks

Use a proxy directly with interface and member names, or derive a typed proxy for one interface whose methods call the public call, property and signal methods of this class. A proxy holds no state on the bus and costs nothing to create; it fails only when used.

Constructors

DBusProxy

public DBusProxy(DBusConnection connection, string? destination, DBusObjectPath path)

Creates a proxy for the object at path of the service destination.

Parameters

connection

The connection that carries the calls.

destination

The service's bus name, such as org.freedesktop.UDisks2, or null on a peer-to-peer connection.

path

The object.

Exceptions

ArgumentException

destination is not a bus name.

Properties

Connection

public DBusConnection Connection { get; }

The connection that carries the calls.

Destination

public string? Destination { get; }

The service's bus name.

Path

public DBusObjectPath Path { get; }

The object.

Timeout

public TimeSpan? Timeout { get; init; }

How long each call through this proxy waits for its reply, including property reads and writes; null, the default, waits until the bus or the service replies or the call is cancelled.

Exceptions

ArgumentOutOfRangeException

The value is zero, negative other than Timeout.InfiniteTimeSpan, or longer than Task.WaitAsync accepts.

Remarks

Set it when creating the proxy, such as new DBusProxy(bus, name, path) { Timeout = TimeSpan.FromSeconds(5) }. A call that times out throws DBusException with DBusException.NoReply; see DBusMethodCall.Timeout.

Methods

CallAsync

public ValueTask<ImmutableArray<DBusValue>> CallAsync(string interfaceName, string member, ImmutableArray<DBusValue> arguments = default, DBusCallOptions options = DBusCallOptions.None, CancellationToken cancellationToken = default)

Calls a method of the object and returns its reply's values.

Exceptions

DBusException

The object replied with an error, or the connection closed.

GetAllPropertiesAsync

public ValueTask<ImmutableDictionary<string, DBusValue>> GetAllPropertiesAsync(string interfaceName, CancellationToken cancellationToken = default)

Reads every property of an interface, each unwrapped from its variant.

GetPropertyAsync

public ValueTask<DBusValue> GetPropertyAsync(string interfaceName, string name, CancellationToken cancellationToken = default)

Reads one property, unwrapped from its variant.

Exceptions

DBusException

The object has no such property, or replied with another error.

ReadPropertyChanges

public static DBusPropertyChanges? ReadPropertyChanges(DBusSignal signal)

Reads a PropertiesChanged signal, or returns null for any other signal.

SetPropertyAsync

public ValueTask SetPropertyAsync(string interfaceName, string name, DBusValue value, CancellationToken cancellationToken = default)

Writes one property; the method wraps the value in a variant.

SubscribePropertiesAsync

public ValueTask<DBusSignalSubscription> SubscribePropertiesAsync(string interfaceName, CancellationToken cancellationToken = default)

Starts receiving PropertiesChanged for one interface of the object.

Returns

A subscription that is active when this completes; read each signal with DBusProxy.ReadPropertyChanges.

SubscribeSignalAsync

public ValueTask<DBusSignalSubscription> SubscribeSignalAsync(string interfaceName, string member, CancellationToken cancellationToken = default)

Starts receiving one signal of the object.

Returns

A subscription that is active when this completes.

WatchPropertiesAsync

public IAsyncEnumerable<DBusPropertyChanges> WatchPropertiesAsync(string interfaceName, CancellationToken cancellationToken = default)

Reports the property changes of one interface of the object as they arrive.

Remarks

The subscription starts when enumeration starts. To read the current values without missing a change, call DBusProxy.SubscribePropertiesAsync first, then DBusProxy.GetAllPropertiesAsync, then enumerate the subscription.

WatchSignalAsync

public IAsyncEnumerable<ImmutableArray<DBusValue>> WatchSignalAsync(string interfaceName, string member, CancellationToken cancellationToken = default)

Reports the arguments of one signal of the object as it arrives; the subscription starts when enumeration starts.