DBusConnection

The gio.dbus_connection.DBusConnection 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 gio.iostream.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 gio.dbus_proxy.DBusProxy.newForBus APIs.

As an exception to the usual GLib rule that a particular object must not be used by two threads at the same time, gio.dbus_connection.DBusConnections 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 gio.dbus_connection.DBusConnection when called from any thread.

Most of the ways to obtain a gio.dbus_connection.DBusConnection automatically initialize it (i.e. connect to D-Bus): for instance, gio.dbus_connection.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 gio.initable.Initable.new_ or gio.async_initable.AsyncInitable.newAsync, which also initialize the connection.

If you construct an uninitialized gio.dbus_connection.DBusConnection, such as via gobject.object.ObjectG.new_, you must initialize it via gio.initable.Initable.init_ or gio.async_initable.AsyncInitable.initAsync before using its methods or properties. Calling methods or accessing properties on a gio.dbus_connection.DBusConnection that has not completed initialization successfully is considered to be invalid, and leads to undefined behaviour. In particular, if initialization fails with a glib.error.ErrorG, the only valid thing you can do with that gio.dbus_connection.DBusConnection is to free it with gobject.object.ObjectG.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

class DBusConnection : ObjectG , AsyncInitable , Initable {}

Members

Functions

addFilter
uint addFilter(gio.types.DBusMessageFilterFunction filterFunction)

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.

call
void call(string busName, string objectPath, string interfaceName, string methodName, glib.variant.VariantG parameters, glib.variant_type.VariantType replyType, gio.types.DBusCallFlags flags, int timeoutMsec, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Asynchronously invokes the method_name method on the interface_name D-Bus interface on the remote object at object_path owned by bus_name.

callFinish
glib.variant.VariantG callFinish(gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.call.

callSync
glib.variant.VariantG callSync(string busName, string objectPath, string interfaceName, string methodName, glib.variant.VariantG parameters, glib.variant_type.VariantType replyType, gio.types.DBusCallFlags flags, int timeoutMsec, gio.cancellable.Cancellable cancellable)

Synchronously invokes the method_name method on the interface_name D-Bus interface on the remote object at object_path owned by bus_name.

callWithUnixFdList
void callWithUnixFdList(string busName, string objectPath, string interfaceName, string methodName, glib.variant.VariantG parameters, glib.variant_type.VariantType replyType, gio.types.DBusCallFlags flags, int timeoutMsec, gio.unix_fdlist.UnixFDList fdList, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Like gio.dbus_connection.DBusConnection.call but also takes a #GUnixFDList object.

callWithUnixFdListFinish
glib.variant.VariantG callWithUnixFdListFinish(gio.unix_fdlist.UnixFDList outFdList, gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.callWithUnixFdList.

callWithUnixFdListSync
glib.variant.VariantG callWithUnixFdListSync(string busName, string objectPath, string interfaceName, string methodName, glib.variant.VariantG parameters, glib.variant_type.VariantType replyType, gio.types.DBusCallFlags flags, int timeoutMsec, gio.unix_fdlist.UnixFDList fdList, gio.unix_fdlist.UnixFDList outFdList, gio.cancellable.Cancellable cancellable)

Like gio.dbus_connection.DBusConnection.callSync but also takes and returns #GUnixFDList objects. See gio.dbus_connection.DBusConnection.callWithUnixFdList and gio.dbus_connection.DBusConnection.callWithUnixFdListFinish for more details.

close
void close(gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

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).

closeFinish
bool closeFinish(gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.close.

closeSync
bool closeSync(gio.cancellable.Cancellable cancellable)

Synchronously closes connection. The calling thread is blocked until this is done. See gio.dbus_connection.DBusConnection.close for the asynchronous version of this method and more details about what it does.

connectClosed
ulong connectClosed(T callback, Flag!"After" after)

Connect to Closed signal.

emitSignal
bool emitSignal(string destinationBusName, string objectPath, string interfaceName, string signalName, glib.variant.VariantG parameters)

Emits a signal.

exportActionGroup
uint exportActionGroup(string objectPath, gio.action_group.ActionGroup actionGroup)

Exports action_group on connection at object_path.

exportMenuModel
uint exportMenuModel(string objectPath, gio.menu_model.MenuModel menu)

Exports menu on connection at object_path.

flush
void flush(gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Asynchronously flushes connection, that is, writes all queued outgoing message to the transport and then flushes the transport (using gio.output_stream.OutputStream.flushAsync). 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.

flushFinish
bool flushFinish(gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.flush.

flushSync
bool flushSync(gio.cancellable.Cancellable cancellable)

Synchronously flushes connection. The calling thread is blocked until this is done. See gio.dbus_connection.DBusConnection.flush for the asynchronous version of this method and more details about what it does.

getCapabilities
gio.types.DBusCapabilityFlags getCapabilities()

Gets the capabilities negotiated with the remote peer

getExitOnClose
bool getExitOnClose()

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

getFlags
gio.types.DBusConnectionFlags getFlags()

Gets the flags used to construct this connection

getGuid
string getGuid()

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

getLastSerial
uint getLastSerial()

Retrieves the last serial number assigned to a #GDBusMessage on the current thread. This includes messages sent via both low-level API such as gio.dbus_connection.DBusConnection.sendMessage as well as high-level API such as gio.dbus_connection.DBusConnection.emitSignal, gio.dbus_connection.DBusConnection.call or gio.dbus_proxy.DBusProxy.call.

getPeerCredentials
gio.credentials.Credentials getPeerCredentials()

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

getStream
gio.iostream.IOStream getStream()

Gets the underlying stream used for IO.

getUniqueName
string getUniqueName()

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.

isClosed
bool isClosed()

Gets whether connection is closed.

registerObject
uint registerObject(string objectPath, gio.dbus_interface_info.DBusInterfaceInfo interfaceInfo, gobject.closure.Closure methodCallClosure, gobject.closure.Closure getPropertyClosure, gobject.closure.Closure setPropertyClosure)

Version of gio.dbus_connection.DBusConnection.registerObject using closures instead of a #GDBusInterfaceVTable for easier binding in other languages.

registerSubtree
uint registerSubtree(string objectPath, gio.types.DBusSubtreeVTable vtable, gio.types.DBusSubtreeFlags flags, void* userData, glib.types.DestroyNotify userDataFreeFunc)

Registers a whole subtree of dynamic objects.

removeFilter
void removeFilter(uint filterId)

Removes a filter.

sendMessage
bool sendMessage(gio.dbus_message.DBusMessage message, gio.types.DBusSendMessageFlags flags, uint outSerial)

Asynchronously sends message to the peer represented by connection.

sendMessageWithReply
void sendMessageWithReply(gio.dbus_message.DBusMessage message, gio.types.DBusSendMessageFlags flags, int timeoutMsec, uint outSerial, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Asynchronously sends message to the peer represented by connection.

sendMessageWithReplyFinish
gio.dbus_message.DBusMessage sendMessageWithReplyFinish(gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.sendMessageWithReply.

sendMessageWithReplySync
gio.dbus_message.DBusMessage sendMessageWithReplySync(gio.dbus_message.DBusMessage message, gio.types.DBusSendMessageFlags flags, int timeoutMsec, uint outSerial, gio.cancellable.Cancellable cancellable)

Synchronously sends message to the peer represented by connection and blocks the calling thread until a reply is received or the timeout is reached. See gio.dbus_connection.DBusConnection.sendMessageWithReply for the asynchronous version of this method.

setExitOnClose
void setExitOnClose(bool exitOnClose)

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

signalSubscribe
uint signalSubscribe(string sender, string interfaceName, string member, string objectPath, string arg0, gio.types.DBusSignalFlags flags, gio.types.DBusSignalCallback callback)

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

signalUnsubscribe
void signalUnsubscribe(uint subscriptionId)

Unsubscribes from signals.

startMessageProcessing
void startMessageProcessing()

If connection was created with gio.types.DBusConnectionFlags.DelayMessageProcessing, this method starts processing messages. Does nothing on if connection wasn't created with this flag or if the method has already been called.

unexportActionGroup
void unexportActionGroup(uint exportId)

Reverses the effect of a previous call to gio.dbus_connection.DBusConnection.exportActionGroup.

unexportMenuModel
void unexportMenuModel(uint exportId)

Reverses the effect of a previous call to gio.dbus_connection.DBusConnection.exportMenuModel.

unregisterObject
bool unregisterObject(uint registrationId)

Unregisters an object.

unregisterSubtree
bool unregisterSubtree(uint registrationId)

Unregisters a subtree.

Static functions

newFinish
gio.dbus_connection.DBusConnection newFinish(gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.new_.

newForAddress
void newForAddress(string address, gio.types.DBusConnectionFlags flags, gio.dbus_auth_observer.DBusAuthObserver observer, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Asynchronously 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.

newForAddressFinish
gio.dbus_connection.DBusConnection newForAddressFinish(gio.async_result.AsyncResult res)

Finishes an operation started with gio.dbus_connection.DBusConnection.newForAddress.

newForAddressSync
gio.dbus_connection.DBusConnection newForAddressSync(string address, gio.types.DBusConnectionFlags flags, gio.dbus_auth_observer.DBusAuthObserver observer, gio.cancellable.Cancellable cancellable)

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.

newSync
gio.dbus_connection.DBusConnection newSync(gio.iostream.IOStream stream, string guid, gio.types.DBusConnectionFlags flags, gio.dbus_auth_observer.DBusAuthObserver observer, gio.cancellable.Cancellable cancellable)

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

new_
void new_(gio.iostream.IOStream stream, string guid, gio.types.DBusConnectionFlags flags, gio.dbus_auth_observer.DBusAuthObserver observer, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

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

Mixed In Members

From mixin AsyncInitableT!()

initAsync
void initAsync(int ioPriority, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

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 gio.initable.Initable.init_ instead.

initFinish
bool initFinish(gio.async_result.AsyncResult res)

Finishes asynchronous initialization and returns the result. See gio.async_initable.AsyncInitable.initAsync.

newFinish
gobject.object.ObjectG newFinish(gio.async_result.AsyncResult res)

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

From mixin InitableT!()

init_
bool init_(gio.cancellable.Cancellable cancellable)

Initializes the object implementing the interface.

Inherited Members

From ObjectG

setGObject
void setGObject(void* cObj, Flag!"Take" take)

Set the GObject of a D ObjectG wrapper.

cPtr
void* cPtr(Flag!"Dup" dup)

Get a pointer to the underlying C object.

ref_
void* ref_(void* gObj)

Calls g_object_ref() on a GObject.

unref
unref(void* gObj)

Calls g_object_unref() on a GObject.

getType
GType getType()

Get the GType of an object.

gType
GType gType [@property getter]

GObject GType property.

self
ObjectG self()

Convenience method to return this cast to a type. For use in D with statements.

getDObject
T getDObject(void* cptr, Flag!"Take" take)

Template to get the D object from a C GObject and cast it to the given D object type.

connectSignalClosure
ulong connectSignalClosure(string signalDetail, DClosure closure, Flag!"After" after)

Connect a D closure to an object signal.

setProperty
void setProperty(string propertyName, T val)

Template for setting a GObject property.

getProperty
T getProperty(string propertyName)

Template for getting a GObject property.

compatControl
size_t compatControl(size_t what, void* data)
bindProperty
gobject.binding.Binding bindProperty(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags)

Creates a binding between source_property on source and target_property on target.

bindPropertyFull
gobject.binding.Binding bindPropertyFull(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags, gobject.closure.Closure transformTo, gobject.closure.Closure transformFrom)

Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

forceFloating
void forceFloating()

This function is intended for #GObject implementations to re-enforce a floating[floating-ref] object reference. Doing this is seldom required: all #GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling gobject.object.ObjectG.refSink.

freezeNotify
void freezeNotify()

Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

getData
void* getData(string key)

Gets a named field from the objects table of associations (see gobject.object.ObjectG.setData).

getProperty
void getProperty(string propertyName, gobject.value.Value value)

Gets a property of an object.

getQdata
void* getQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata.

getv
void getv(string[] names, gobject.value.Value[] values)

Gets n_properties properties for an object. Obtained properties will be set to values. All properties must be valid. Warnings will be emitted and undefined behaviour may result if invalid properties are passed in.

isFloating
bool isFloating()

Checks whether object has a floating[floating-ref] reference.

notify
void notify(string propertyName)

Emits a "notify" signal for the property property_name on object.

notifyByPspec
void notifyByPspec(gobject.param_spec.ParamSpec pspec)

Emits a "notify" signal for the property specified by pspec on object.

refSink
gobject.object.ObjectG refSink()

Increase the reference count of object, and possibly remove the floating[floating-ref] reference, if object has a floating reference.

runDispose
void runDispose()

Releases all references to other objects. This can be used to break reference cycles.

setData
void setData(string key, void* data)

Each object carries around a table of associations from strings to pointers. This function lets you set an association.

setProperty
void setProperty(string propertyName, gobject.value.Value value)

Sets a property on an object.

stealData
void* stealData(string key)

Remove a specified datum from the object's data associations, without invoking the association's destroy handler.

stealQdata
void* stealQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update user data pointers with a destroy notifier, for example:

thawNotify
void thawNotify()

Reverts the effect of a previous call to gobject.object.ObjectG.freezeNotify. The freeze count is decreased on object and when it reaches zero, queued "notify" signals are emitted.

watchClosure
void watchClosure(gobject.closure.Closure closure)

This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling gobject.closure.Closure.invalidate on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, gobject.object.ObjectG.ref_ and gobject.object.ObjectG.unref are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.

connectNotify
ulong connectNotify(string detail, T callback, Flag!"After" after)

Connect to Notify signal.

From AsyncInitable

newvAsync
void newvAsync(gobject.types.GType objectType, uint nParameters, gobject.parameter.Parameter parameters, int ioPriority, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Helper function for constructing #GAsyncInitable object. This is similar to gobject.object.ObjectG.newv but also initializes the object asynchronously.

initAsync
void initAsync(int ioPriority, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

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 gio.initable.Initable.init_ instead.

initFinish
bool initFinish(gio.async_result.AsyncResult res)

Finishes asynchronous initialization and returns the result. See gio.async_initable.AsyncInitable.initAsync.

newFinish
gobject.object.ObjectG newFinish(gio.async_result.AsyncResult res)

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

From Initable

init_
bool init_(gio.cancellable.Cancellable cancellable)

Initializes the object implementing the interface.