DBusProxy

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

GDBusProxy is a base class used for proxies to access a D-Bus interface on a remote object. A GDBusProxy can be constructed for both well-known and unique names.

By default, GDBusProxy will cache all properties (and listen to changes) of the remote object, and proxy all signals that get emitted. This behaviour can be changed by passing suitable flags@Gio.DBusProxyFlags when the proxy is created. If the proxy is for a well-known name, the property cache is flushed when the name owner vanishes and reloaded when a name owner appears.

The unique name owner of the proxy’s name is tracked and can be read from property@Gio.DBusProxy:g-name-owner. Connect to the signal@GObject.Object::notify signal to get notified of changes. Additionally, only signals and property changes emitted from the current name owner are considered and calls are always sent to the current name owner. This avoids a number of race conditions when the name is lost by one owner and claimed by another. However, if no name owner currently exists, then calls will be sent to the well-known name which may result in the message bus launching an owner (unless G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set).

If the proxy is for a stateless D-Bus service, where the name owner may be started and stopped between calls, the property@Gio.DBusProxy:g-name-owner tracking of GDBusProxy will cause the proxy to drop signal and property changes from the service after it has restarted for the first time. When interacting with a stateless D-Bus service, do not use GDBusProxy — use direct D-Bus method calls and signal connections.

The generic signal@Gio.DBusProxy::g-properties-changed and signal@Gio.DBusProxy::g-signal signals are not very convenient to work with. Therefore, the recommended way of working with proxies is to subclass GDBusProxy, and have more natural properties and signals in your derived class. This migrating-gdbus.html#using-gdbus-codegen shows how this can easily be done using the gdbus-codegen.html tool.

A GDBusProxy instance can be used from multiple threads but note that all signals (e.g. signal@Gio.DBusProxy::g-signal, signal@Gio.DBusProxy::g-properties-changed and signal@GObject.Object::notify) are emitted in the thread-default main context (see method@GLib.MainContext.push_thread_default) of the thread where the instance was constructed.

An example using a proxy for a well-known name can be found in gdbus-example-watch-proxy.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 g-bus-type: Property has no getter nor setter

  • method g-connection: Property has no getter nor setter

  • method g-default-timeout: Property has no getter nor setter

  • method g-flags: Property has no getter nor setter

  • method g-interface-info: Property has no getter nor setter

  • method g-interface-name: Property has no getter nor setter

  • method g-name: Property has no getter nor setter

  • method g-name-owner: Property has no getter nor setter

  • method g-object-path: Property has no getter nor setter

Since

2.26

Constructors

Link copied to clipboard
constructor(res: AsyncResult)

Finishes creating a #GDBusProxy.

constructor(busType: BusType, flags: DBusProxyFlags, info: DBusInterfaceInfo? = null, name: String, objectPath: String, interfaceName: String, cancellable: Cancellable? = null)

Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.

constructor(connection: DBusConnection, flags: DBusProxyFlags, info: DBusInterfaceInfo? = null, name: String? = null, objectPath: String, interfaceName: String, cancellable: Cancellable? = null)

Creates a proxy for accessing @interface_name on the remote object at @object_path owned by @name at @connection and synchronously loads D-Bus properties unless the %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.

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

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val gioAsyncInitablePointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val gioDBusInterfacePointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
val gioDBusProxyPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val gioInitablePointer: <Error class: unknown class><<Error class: unknown class>>

Functions

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

Asynchronously invokes the @method_name method on @proxy.

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

Finishes an operation started with g_dbus_proxy_call().

Link copied to clipboard
open fun callSync(methodName: String, parameters: <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 @proxy.

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

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

Link copied to clipboard
fun connectGPropertiesChanged(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>, invalidatedProperties: List<String>) -> Unit): <Error class: unknown class>

Emitted when one or more D-Bus properties on @proxy changes. The local cache has already been updated when this signal fires. Note that both @changed_properties and @invalidated_properties are guaranteed to never be null (either may be empty though).

Link copied to clipboard
fun connectGSignal(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (senderName: String, signalName: String, <Error class: unknown class>) -> Unit): <Error class: unknown class>

Emitted when a signal from the remote object and interface that @proxy is for, has been received.

Link copied to clipboard
open fun getCachedProperty(propertyName: String): <Error class: unknown class>?

Looks up the value for a property from the cache. This call does no blocking IO.

Link copied to clipboard

Gets the names of all cached properties on @proxy.

Link copied to clipboard

Gets the connection @proxy is for.

Link copied to clipboard

Gets the timeout to use if -1 (specifying default timeout) is passed as @timeout_msec in the g_dbus_proxy_call() and g_dbus_proxy_call_sync() functions.

Link copied to clipboard

Gets the flags that @proxy was constructed with.

Link copied to clipboard

Gets D-Bus introspection information for the D-Bus interface implemented by @interface_.

Link copied to clipboard

Returns the #GDBusInterfaceInfo, if any, specifying the interface that @proxy conforms to. See the #GDBusProxy:g-interface-info property for more details.

Link copied to clipboard

Gets the D-Bus interface name @proxy is for.

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

Gets the name that @proxy was constructed for.

Link copied to clipboard
open fun getNameOwner(): String

The unique name that owns the name that @proxy is for or null if no-one currently owns that name. You may connect to the #GObject::notify signal to track changes to the #GDBusProxy:g-name-owner property.

Link copied to clipboard
open fun getObject(): DBusObject?

Gets the #GDBusObject that @interface_ belongs to, if any.

Link copied to clipboard
open fun getObjectPath(): String

Gets the object path @proxy is for.

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 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 setCachedProperty(propertyName: String, value: <Error class: unknown class>? = null)

If @value is not null, sets the cached value for the property with name @property_name to the value in @value.

Link copied to clipboard
open fun setDefaultTimeout(timeoutMsec: Int)

Sets the timeout to use if -1 (specifying default timeout) is passed as @timeout_msec in the g_dbus_proxy_call() and g_dbus_proxy_call_sync() functions.

Link copied to clipboard
open fun setInterfaceInfo(info: DBusInterfaceInfo? = null)

Ensure that interactions with @proxy conform to the given interface. See the #GDBusProxy:g-interface-info property for more details.

Link copied to clipboard
open fun setObject(object: DBusObject? = null)

Sets the #GDBusObject for @interface_ to @object.