DBusConnection

open class DBusConnection(pointer: <Error class: unknown class><<Error class: unknown class>>) : AsyncInitable, Initable

The GDBusConnection type is used for D-Bus connections to remote peers such as a message buses.

It is a low-level API that offers a lot of flexibility. For instance, it lets you establish a connection over any transport that can by represented as a class@Gio.IOStream.

This class is rarely used directly in D-Bus clients. If you are writing a D-Bus client, it is often easier to use the func@Gio.bus_own_name, func@Gio.bus_watch_name or func@Gio.DBusProxy.new_for_bus APIs.

As an exception to the usual GLib rule that a particular object must not be used by two threads at the same time, GDBusConnections methods may be called from any thread. This is so that func@Gio.bus_get and func@Gio.bus_get_sync can safely return the same GDBusConnection when called from any thread.

Most of the ways to obtain a GDBusConnection automatically initialize it (i.e. connect to D-Bus): for instance, func@Gio.DBusConnection.new and func@Gio.bus_get, and the synchronous versions of those methods, give you an initialized connection. Language bindings for GIO should use func@Gio.Initable.new or func@Gio.AsyncInitable.new_async, which also initialize the connection.

If you construct an uninitialized GDBusConnection, such as via ctor@GObject.Object.new, you must initialize it via method@Gio.Initable.init or method@Gio.AsyncInitable.init_async before using its methods or properties. Calling methods or accessing properties on a GDBusConnection that has not completed initialization successfully is considered to be invalid, and leads to undefined behaviour. In particular, if initialization fails with a GError, the only valid thing you can do with that GDBusConnection is to free it with method@GObject.Object.unref.

An example D-Bus server

Here is an example for a D-Bus server: gdbus-example-server.c

An example for exporting a subtree

Here is an example for exporting a subtree: gdbus-example-subtree.c

An example for file descriptor passing

Here is an example for passing UNIX file descriptors: gdbus-unix-fd-client.c

An example for exporting a GObject

Here is an example for exporting a #GObject: gdbus-example-export.c

Skipped during bindings generation

  • parameter out_fd_list: out_fd_list: Out parameter is not supported

  • parameter out_fd_list: out_fd_list: Out parameter is not supported

  • method register_object: g_dbus_connection_register_object is shadowedBy register_object_with_closures

  • parameter user_data: gpointer

  • parameter out_serial: out_serial: Out parameter is not supported

  • parameter out_serial: out_serial: Out parameter is not supported

  • parameter out_serial: out_serial: Out parameter is not supported

  • method address: Property has no getter nor setter

  • method authentication-observer: Property has no getter nor setter

  • method closed: Property has no getter nor setter

Since

2.26

Constructors

Link copied to clipboard
constructor(res: AsyncResult)

Finishes an operation started with g_dbus_connection_new().

constructor(address: String, flags: DBusConnectionFlags, observer: DBusAuthObserver? = null, cancellable: Cancellable? = null)

Synchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified by @address which must be in the D-Bus address format.

constructor(stream: IOStream, guid: String? = null, flags: DBusConnectionFlags, observer: DBusAuthObserver? = null, cancellable: Cancellable? = null)

Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented by @stream.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Flags from the #GDBusCapabilityFlags enumeration representing connection features negotiated with the other peer.

Link copied to clipboard

A boolean specifying whether the process will be terminated (by calling raise(SIGTERM)) if the connection is closed by the remote peer.

Link copied to clipboard

Flags from the #GDBusConnectionFlags enumeration.

Link copied to clipboard
open override val gioAsyncInitablePointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
val gioDBusConnectionPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val gioInitablePointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open val guid: String

The GUID of the peer performing the role of server when authenticating.

Link copied to clipboard
open val stream: IOStream

The underlying #GIOStream used for I/O.

Link copied to clipboard
open val uniqueName: String?

The unique name as assigned by the message bus or null if the connection is not open or not a message bus connection.

Functions

Link copied to clipboard
open fun addFilter(filterFunction: DBusMessageFilterFunction): <Error class: unknown class>

Adds a message filter. Filters are handlers that are run on all incoming and outgoing messages, prior to standard dispatch. Filters are run in the order that they were added. The same handler can be added as a filter more than once, in which case it will be run more than once. Filters added during a filter callback won't be run on the message being processed. Filter functions are allowed to modify and even drop messages.

Link copied to clipboard
open fun call(busName: String? = null, objectPath: String, interfaceName: String, methodName: String, parameters: <Error class: unknown class>? = null, replyType: <Error class: unknown class>? = null, flags: DBusCallFlags, timeoutMsec: Int, cancellable: Cancellable? = null, callback: AsyncReadyCallback)

Asynchronously invokes the @method_name method on the

Link copied to clipboard
open fun callFinish(res: AsyncResult): <Error class: unknown class><<Error class: unknown class>>

Finishes an operation started with g_dbus_connection_call().

Link copied to clipboard
open fun callSync(busName: String? = null, objectPath: String, interfaceName: String, methodName: String, parameters: <Error class: unknown class>? = null, replyType: <Error class: unknown class>? = null, flags: DBusCallFlags, timeoutMsec: Int, cancellable: Cancellable? = null): <Error class: unknown class><<Error class: unknown class>>

Synchronously invokes the @method_name method on the

Link copied to clipboard
open fun callWithUnixFdList(busName: String? = null, objectPath: String, interfaceName: String, methodName: String, parameters: <Error class: unknown class>? = null, replyType: <Error class: unknown class>? = null, flags: DBusCallFlags, timeoutMsec: Int, fdList: UnixFDList? = null, cancellable: Cancellable? = null, callback: AsyncReadyCallback)

Like g_dbus_connection_call() but also takes a #GUnixFDList object.

Link copied to clipboard
open fun close(cancellable: Cancellable? = null, callback: AsyncReadyCallback)

Closes @connection. Note that this never causes the process to exit (this might only happen if the other end of a shared message bus connection disconnects, see #GDBusConnection:exit-on-close).

Link copied to clipboard
open fun closeFinish(res: AsyncResult): <Error class: unknown class><Boolean>

Finishes an operation started with g_dbus_connection_close().

Link copied to clipboard
open fun closeSync(cancellable: Cancellable? = null): <Error class: unknown class><Boolean>

Synchronously closes @connection. The calling thread is blocked until this is done. See g_dbus_connection_close() for the asynchronous version of this method and more details about what it does.

Link copied to clipboard
fun connectClosed(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (remotePeerVanished: Boolean, <Error class: unknown class>?) -> Unit): <Error class: unknown class>

Emitted when the connection is closed.

Link copied to clipboard
open fun emitSignal(destinationBusName: String? = null, objectPath: String, interfaceName: String, signalName: String, parameters: <Error class: unknown class>? = null): <Error class: unknown class><Boolean>

Emits a signal.

Link copied to clipboard
open fun exportActionGroup(objectPath: String, actionGroup: ActionGroup): <Error class: unknown class><<Error class: unknown class>>

Exports @action_group on @connection at @object_path.

Link copied to clipboard
open fun exportMenuModel(objectPath: String, menu: MenuModel): <Error class: unknown class><<Error class: unknown class>>

Exports @menu on @connection at @object_path.

Link copied to clipboard
open fun flush(cancellable: Cancellable? = null, callback: AsyncReadyCallback)

Asynchronously flushes @connection, that is, writes all queued outgoing message to the transport and then flushes the transport (using g_output_stream_flush_async()). This is useful in programs that wants to emit a D-Bus signal and then exit immediately. Without flushing the connection, there is no guaranteed that the message has been sent to the networking buffers in the OS kernel.

Link copied to clipboard
open fun flushFinish(res: AsyncResult): <Error class: unknown class><Boolean>

Finishes an operation started with g_dbus_connection_flush().

Link copied to clipboard
open fun flushSync(cancellable: Cancellable? = null): <Error class: unknown class><Boolean>

Synchronously flushes @connection. The calling thread is blocked until this is done. See g_dbus_connection_flush() for the asynchronous version of this method and more details about what it does.

Link copied to clipboard

Gets the capabilities negotiated with the remote peer

Link copied to clipboard

Gets whether the process is terminated when @connection is closed by the remote peer. See #GDBusConnection:exit-on-close for more details.

Link copied to clipboard

Gets the flags used to construct this connection

Link copied to clipboard
open fun getGuid(): String

The GUID of the peer performing the role of server when authenticating. See #GDBusConnection:guid for more details.

Link copied to clipboard
open fun getLastSerial(): <Error class: unknown class>

Retrieves the last serial number assigned to a #GDBusMessage on the current thread. This includes messages sent via both low-level API such as g_dbus_connection_send_message() as well as high-level API such as g_dbus_connection_emit_signal(), g_dbus_connection_call() or g_dbus_proxy_call().

Link copied to clipboard

Gets the credentials of the authenticated peer. This will always return null unless @connection acted as a server (e.g. %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER was passed) when set up and the client passed credentials as part of the authentication process.

Link copied to clipboard
open fun getStream(): IOStream

Gets the underlying stream used for IO.

Link copied to clipboard
open fun getUniqueName(): String?

Gets the unique name of @connection as assigned by the message bus. This can also be used to figure out if @connection is a message bus connection.

Link copied to clipboard
open fun init(cancellable: Cancellable? = null): <Error class: unknown class><Boolean>

Initializes the object implementing the interface.

Link copied to clipboard
open fun initAsync(ioPriority: Int, cancellable: Cancellable? = null, callback: AsyncReadyCallback)

Starts asynchronous initialization of the object implementing the interface. This must be done before any real use of the object after initial construction. If the object also implements #GInitable you can optionally call g_initable_init() instead.

Link copied to clipboard
open fun initFinish(res: AsyncResult): <Error class: unknown class><Boolean>

Finishes asynchronous initialization and returns the result. See g_async_initable_init_async().

Link copied to clipboard
open fun isClosed(): Boolean

Gets whether @connection is closed.

Link copied to clipboard
open fun newFinish(res: AsyncResult): <Error class: unknown class><<Error class: unknown class>>

Finishes the async construction for the various g_async_initable_new calls, returning the created object or null on error.

Link copied to clipboard
open fun registerObject(objectPath: String, interfaceInfo: DBusInterfaceInfo, methodCallClosure: <Error class: unknown class>? = null, getPropertyClosure: <Error class: unknown class>? = null, setPropertyClosure: <Error class: unknown class>? = null): <Error class: unknown class><<Error class: unknown class>>

Version of g_dbus_connection_register_object() using closures instead of a #GDBusInterfaceVTable for easier binding in other languages.

Link copied to clipboard
open fun removeFilter(filterId: <Error class: unknown class>)

Removes a filter.

Link copied to clipboard
open fun sendMessageWithReplyFinish(res: AsyncResult): <Error class: unknown class><DBusMessage>

Finishes an operation started with g_dbus_connection_send_message_with_reply().

Link copied to clipboard
open fun setExitOnClose(exitOnClose: Boolean)

Sets whether the process should be terminated when @connection is closed by the remote peer. See #GDBusConnection:exit-on-close for more details.

Link copied to clipboard
open fun signalSubscribe(sender: String? = null, interfaceName: String? = null, member: String? = null, objectPath: String? = null, arg0: String? = null, flags: DBusSignalFlags, callback: DBusSignalCallback): <Error class: unknown class>

Subscribes to signals on @connection and invokes @callback whenever the signal is received. Note that @callback will be invoked in the g-main-context-push-thread-default of the thread you are calling this method from.

Link copied to clipboard
open fun signalUnsubscribe(subscriptionId: <Error class: unknown class>)

Unsubscribes from signals.

Link copied to clipboard

If @connection was created with %G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING, this method starts processing messages. Does nothing on if @connection wasn't created with this flag or if the method has already been called.

Link copied to clipboard
open fun unexportActionGroup(exportId: <Error class: unknown class>)

Reverses the effect of a previous call to method@Gio.DBusConnection.export_action_group.

Link copied to clipboard
open fun unexportMenuModel(exportId: <Error class: unknown class>)

Reverses the effect of a previous call to g_dbus_connection_export_menu_model().

Link copied to clipboard
open fun unregisterObject(registrationId: <Error class: unknown class>): Boolean

Unregisters an object.

Link copied to clipboard
open fun unregisterSubtree(registrationId: <Error class: unknown class>): Boolean

Unregisters a subtree.