Class Connection
Represents a client connection to a D-Bus message bus or peer.
[Obsolete("Use DBusConnection instead.")]
public class Connection : IDisposable
- Inheritance
-
Connection
- Implements
- Inherited Members
Constructors
Connection(string)
Initializes a new instance of the Connection class.
public Connection(string address)
Parameters
addressstringThe D-Bus address to connect to.
Connection(ConnectionOptions)
Initializes a new instance of the Connection class.
public Connection(ConnectionOptions connectionOptions)
Parameters
connectionOptionsConnectionOptionsThe connection options.
Fields
DBusInterface
The D-Bus daemon interface name.
public const string DBusInterface = "org.freedesktop.DBus"
Field Value
DBusObjectPath
The D-Bus daemon object path.
public const string DBusObjectPath = "/org/freedesktop/DBus"
Field Value
DBusServiceName
The D-Bus daemon service name.
public const string DBusServiceName = "org.freedesktop.DBus"
Field Value
Properties
Session
Gets a shared connection to the session bus.
public static Connection Session { get; }
Property Value
System
Gets a shared connection to the system bus.
public static Connection System { get; }
Property Value
UniqueName
Gets the unique name assigned to this connection by the bus.
public string? UniqueName { get; }
Property Value
Methods
AddMatchAsync<T>(MatchRule, MessageValueReader<T>, Action<Exception?, T, object?, object?>, object?, object?, bool, ObserverFlags)
Adds an observer to receive D-Bus messages matching the specified criteria.
public ValueTask<IDisposable> AddMatchAsync<T>(MatchRule rule, MessageValueReader<T> reader, Action<Exception?, T, object?, object?> handler, object? readerState, object? handlerState, bool emitOnCapturedContext, ObserverFlags flags)
Parameters
ruleMatchRuleThe match rule defining which messages to receive.
readerMessageValueReader<T>Delegate to read values from matched messages.
handlerAction<Exception, T, object, object>Callback invoked for each matched message.
readerStateobjectOptional state passed to the reader delegate.
handlerStateobjectOptional state passed to the handler delegate.
emitOnCapturedContextboolWhether to invoke the handler on the captured synchronization context.
flagsObserverFlagsObserver behavior flags.
Returns
- ValueTask<IDisposable>
IDisposable that removes the observer when disposed.
Type Parameters
TThe type of value read from matched messages.
AddMatchAsync<T>(MatchRule, MessageValueReader<T>, Action<Exception?, T, object?, object?>, object?, object?, SynchronizationContext?, ObserverFlags)
Adds an observer to receive D-Bus messages matching the specified criteria.
public ValueTask<IDisposable> AddMatchAsync<T>(MatchRule rule, MessageValueReader<T> reader, Action<Exception?, T, object?, object?> handler, object? readerState, object? handlerState, SynchronizationContext? synchronizationContext, ObserverFlags flags)
Parameters
ruleMatchRuleThe match rule defining which messages to receive.
readerMessageValueReader<T>Delegate to read values from matched messages.
handlerAction<Exception, T, object, object>Callback invoked for each matched message.
readerStateobjectOptional state passed to the reader delegate.
handlerStateobjectOptional state passed to the handler delegate.
synchronizationContextSynchronizationContextThe synchronization context to invoke the handler on.
flagsObserverFlagsObserver behavior flags.
Returns
- ValueTask<IDisposable>
IDisposable that removes the observer when disposed.
Type Parameters
TThe type of value read from matched messages.
AddMatchAsync<T>(MatchRule, MessageValueReader<T>, Action<Exception?, T, object?, object?>, ObserverFlags, object?, object?, bool)
Adds an observer to receive D-Bus messages matching the specified criteria.
public ValueTask<IDisposable> AddMatchAsync<T>(MatchRule rule, MessageValueReader<T> reader, Action<Exception?, T, object?, object?> handler, ObserverFlags flags, object? readerState = null, object? handlerState = null, bool emitOnCapturedContext = true)
Parameters
ruleMatchRuleThe match rule defining which messages to receive.
readerMessageValueReader<T>Delegate to read values from matched messages.
handlerAction<Exception, T, object, object>Callback invoked for each matched message.
flagsObserverFlagsObserver behavior flags.
readerStateobjectOptional state passed to the reader delegate.
handlerStateobjectOptional state passed to the handler delegate.
emitOnCapturedContextboolWhether to invoke the handler on the captured synchronization context.
Returns
- ValueTask<IDisposable>
IDisposable that removes the observer when disposed.
Type Parameters
TThe type of value read from matched messages.
AddMethodHandler(IMethodHandler)
Adds an IMethodHandler to handle incoming method calls.
public void AddMethodHandler(IMethodHandler methodHandler)
Parameters
methodHandlerIMethodHandlerThe method handler to add.
AddMethodHandler(IPathMethodHandler)
Adds an IPathMethodHandler to handle incoming method calls.
public void AddMethodHandler(IPathMethodHandler methodHandler)
Parameters
methodHandlerIPathMethodHandlerThe method handler to add.
AddMethodHandlers(IReadOnlyList<IMethodHandler>)
Adds multiple IMethodHandler instances to handle incoming method calls.
public void AddMethodHandlers(IReadOnlyList<IMethodHandler> methodHandlers)
Parameters
methodHandlersIReadOnlyList<IMethodHandler>The method handlers to add.
AddMethodHandlers(IReadOnlyList<IPathMethodHandler>)
Adds multiple IPathMethodHandler instances to handle incoming method calls.
public void AddMethodHandlers(IReadOnlyList<IPathMethodHandler> methodHandlers)
Parameters
methodHandlersIReadOnlyList<IPathMethodHandler>The method handlers to add.
BecomeMonitorAsync(Action<Exception?, DisposableMessage>, IEnumerable<MatchRule>?)
Becomes a monitor that receives all messages on the bus.
public Task BecomeMonitorAsync(Action<Exception?, DisposableMessage> handler, IEnumerable<MatchRule>? rules = null)
Parameters
handlerAction<Exception, DisposableMessage>The handler invoked for each message received.
rulesIEnumerable<MatchRule>Optional match rules to filter which messages to receive.
Returns
CallMethodAsync(MessageBuffer)
Calls a D-Bus method asynchronously without returning a response value.
public Task CallMethodAsync(MessageBuffer message)
Parameters
messageMessageBufferThe method call message.
Returns
CallMethodAsync<T>(MessageBuffer, MessageValueReader<T>, object?)
Calls a D-Bus method asynchronously and returns a response value.
public Task<T> CallMethodAsync<T>(MessageBuffer message, MessageValueReader<T> reader, object? readerState = null)
Parameters
messageMessageBufferThe method call message.
readerMessageValueReader<T>The delegate to read the return value from the reply.
readerStateobjectOptional state passed to the reader delegate.
Returns
- Task<T>
Value read from the reply.
Type Parameters
TThe type of the return value.
ConnectAsync()
Establishes the connection.
public ValueTask ConnectAsync()
Returns
DisconnectedAsync()
Returns a task that completes when the connection has disconnected.
public Task<Exception?> DisconnectedAsync()
Returns
Dispose()
Disposes the connection and releases all resources.
public void Dispose()
GetMessageWriter()
Gets a message writer for creating D-Bus messages.
public MessageWriter GetMessageWriter()
Returns
- MessageWriter
A new MessageWriter instance.
ListActivatableServicesAsync()
Gets all service names that can be activated on the bus.
public Task<string[]> ListActivatableServicesAsync()
Returns
ListServicesAsync()
Lists all currently registered service names on the bus.
public Task<string[]> ListServicesAsync()
Returns
MonitorBusAsync(string, IEnumerable<MatchRule>?, CancellationToken)
Monitors a D-Bus bus and returns an IAsyncEnumerable<T> for the observed messages.
public static IAsyncEnumerable<DisposableMessage> MonitorBusAsync(string address, IEnumerable<MatchRule>? rules = null, CancellationToken ct = default)
Parameters
addressstringThe D-Bus address to connect to.
rulesIEnumerable<MatchRule>Optional match rules to filter which messages to receive.
ctCancellationTokenCancellation token to stop monitoring.
Returns
QueueNameRequestAsync(string, RequestNameOptions)
Enqueues for ownership of a name.
public Task QueueNameRequestAsync(string name, RequestNameOptions options)
Parameters
namestringThe name to request.
optionsRequestNameOptionsOptions for requesting the name.
Returns
QueueNameRequestAsync(string, RequestNameOptions, Action<string, object?>?, Action<string, object?>?, object?, bool)
Enqueues for ownership of a name with callbacks for acquisition and loss notifications.
public Task QueueNameRequestAsync(string name, RequestNameOptions options = RequestNameOptions.Default, Action<string, object?>? onAcquired = null, Action<string, object?>? onLost = null, object? actionState = null, bool emitOnCapturedContext = true)
Parameters
namestringThe well-known name to request.
optionsRequestNameOptionsOptions for requesting the name.
onAcquiredAction<string, object>Callback invoked when the name is acquired.
onLostAction<string, object>Callback invoked when the name is lost to another bus user.
actionStateobjectState object passed to the callbacks.
emitOnCapturedContextboolWhether to invoke callbacks on the captured synchronization context.
Returns
ReleaseNameAsync(string)
Releases ownership of a name.
public Task<bool> ReleaseNameAsync(string serviceName)
Parameters
serviceNamestringThe well-known name to release.
Returns
- Task<bool>
A Task containing true if the name was released/dequeued; false if the name was not requested by this connection.
RemoveMethodHandler(string)
Removes a method handler for the specified path.
public void RemoveMethodHandler(string path)
Parameters
pathstringThe object path of the handler to remove.
RemoveMethodHandlers(IEnumerable<string>)
Removes multiple method handlers for the specified paths.
public void RemoveMethodHandlers(IEnumerable<string> paths)
Parameters
pathsIEnumerable<string>The object paths of the handlers to remove.
RequestNameAsync(string, RequestNameOptions)
Requests ownership of a name.
public Task RequestNameAsync(string name, RequestNameOptions options)
Parameters
namestringThe name to request.
optionsRequestNameOptionsOptions for requesting the name.
Returns
RequestNameAsync(string, RequestNameOptions, Action<string, object?>?, object?, bool)
Requests ownership of a name with callback for name loss notification.
public Task RequestNameAsync(string name, RequestNameOptions options = RequestNameOptions.Default, Action<string, object?>? onLost = null, object? actionState = null, bool emitOnCapturedContext = true)
Parameters
namestringThe name to request.
optionsRequestNameOptionsOptions for requesting the name.
onLostAction<string, object>Callback invoked when the name is lost to another connection.
actionStateobjectState object passed to the callback.
emitOnCapturedContextboolWhether to invoke the callback on the captured synchronization context.
Returns
TryRequestNameAsync(string, RequestNameOptions)
Tries to request ownership of a name.
public Task<bool> TryRequestNameAsync(string name, RequestNameOptions options)
Parameters
namestringThe name to request.
optionsRequestNameOptionsOptions for requesting the name.
Returns
TryRequestNameAsync(string, RequestNameOptions, Action<string, object?>?, object?, bool)
Tries to request ownership of a name with callback for name loss notification.
public Task<bool> TryRequestNameAsync(string name, RequestNameOptions options = RequestNameOptions.Default, Action<string, object?>? onLost = null, object? actionState = null, bool emitOnCapturedContext = true)
Parameters
namestringThe name to request.
optionsRequestNameOptionsOptions for requesting the name.
onLostAction<string, object>Callback invoked when the name is lost to another connection.
actionStateobjectState object passed to the callback.
emitOnCapturedContextboolWhether to invoke the callback on the captured synchronization context.
Returns
TrySendMessage(MessageBuffer)
Sends a D-Bus message.
public bool TrySendMessage(MessageBuffer message)
Parameters
messageMessageBufferThe message to send.