gi-gio-2.0.27: Gio bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellNone
LanguageHaskell2010

GI.Gio.Objects.DBusConnection

Description

The 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 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 g_bus_own_name(), g_bus_watch_name() or dBusProxyNewForBus APIs.

As an exception to the usual GLib rule that a particular object must not be used by two threads at the same time, DBusConnection's methods may be called from any thread. This is so that busGet and busGetSync can safely return the same DBusConnection when called from any thread.

Most of the ways to obtain a DBusConnection automatically initialize it (i.e. connect to D-Bus): for instance, dBusConnectionNew and busGet, and the synchronous versions of those methods, give you an initialized connection. Language bindings for GIO should use g_initable_new() or g_async_initable_new_async(), which also initialize the connection.

If you construct an uninitialized DBusConnection, such as via g_object_new(), you must initialize it via initableInit or asyncInitableInitAsync before using its methods or properties. Calling methods or accessing properties on a DBusConnection 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 DBusConnection is to free it with objectUnref.

# {gdbus-server}

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

# {gdbus-subtree-server}

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

# {gdbus-unix-fd-client}

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

# {gdbus-export}

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

Since: 2.26

Synopsis

Exported types

class (GObject o, IsDescendantOf DBusConnection o) => IsDBusConnection o Source #

Type class for types which can be safely cast to DBusConnection, for instance with toDBusConnection.

Instances

Instances details
(GObject o, IsDescendantOf DBusConnection o) => IsDBusConnection o Source # 
Instance details

Defined in GI.Gio.Objects.DBusConnection

toDBusConnection :: (MonadIO m, IsDBusConnection o) => o -> m DBusConnection Source #

Cast to DBusConnection, for types for which this is known to be safe. For general casts, use castTo.

Methods

Overloaded methods

addFilter

dBusConnectionAddFilter Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> DBusMessageFilterFunction

filterFunction: a filter function

-> m Word32

Returns: a filter identifier that can be used with dBusConnectionRemoveFilter

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.

Note that filters are run in a dedicated message handling thread so they can't block and, generally, can't do anything but signal a worker thread. Also note that filters are rarely needed - use API such as dBusConnectionSendMessageWithReply, dBusConnectionSignalSubscribe or dBusConnectionCall instead.

If a filter consumes an incoming message the message is not dispatched anywhere else - not even the standard dispatch machinery (that API such as dBusConnectionSignalSubscribe and dBusConnectionSendMessageWithReply relies on) will see the message. Similarly, if a filter consumes an outgoing message, the message will not be sent to the other peer.

If userDataFreeFunc is non-Nothing, it will be called (in the thread-default main context of the thread you are calling this method from) at some point after userData is no longer needed. (It is not guaranteed to be called synchronously when the filter is removed, and may be called after connection has been destroyed.)

Since: 2.26

call

dBusConnectionCall Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsCancellable b) 
=> a

connection: a DBusConnection

-> Maybe Text

busName: a unique or well-known bus name or Nothing if connection is not a message bus connection

-> Text

objectPath: path of remote object

-> Text

interfaceName: D-Bus interface to invoke method on

-> Text

methodName: the name of the method to invoke

-> Maybe GVariant

parameters: a GVariant tuple with parameters for the method or Nothing if not passing parameters

-> Maybe VariantType

replyType: the expected type of the reply (which will be a tuple), or Nothing

-> [DBusCallFlags]

flags: flags from the DBusCallFlags enumeration

-> Int32

timeoutMsec: the timeout in milliseconds, -1 to use the default timeout or G_MAXINT for no timeout

-> Maybe b

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied or Nothing if you don't care about the result of the method invocation

-> m () 

Asynchronously invokes the methodName method on the interfaceName D-Bus interface on the remote object at objectPath owned by busName.

If connection is closed then the operation will fail with IOErrorEnumClosed. If cancellable is canceled, the operation will fail with IOErrorEnumCancelled. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with IOErrorEnumInvalidArgument.

If replyType is non-Nothing then the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give a replyType then any non-Nothing return value will be of this type. Unless it’s G_VARIANT_TYPE_UNIT, the replyType will be a tuple containing one or more values.

If the parameters GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:

C code

g_dbus_connection_call (connection,
                        "org.freedesktop.StringThings",
                        "/org/freedesktop/StringThings",
                        "org.freedesktop.StringThings",
                        "TwoStrings",
                        g_variant_new ("(ss)",
                                       "Thing One",
                                       "Thing Two"),
                        NULL,
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
                        (GAsyncReadyCallback) two_strings_done,
                        NULL);

This is an asynchronous method. When the operation is finished, 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. You can then call dBusConnectionCallFinish to get the result of the operation. See dBusConnectionCallSync for the synchronous version of this function.

If callback is Nothing then the D-Bus method call message will be sent with the DBusMessageFlagsNoReplyExpected flag set.

Since: 2.26

callFinish

dBusConnectionCallFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsAsyncResult b) 
=> a

connection: a DBusConnection

-> b

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionCall

-> m GVariant

Returns: Nothing if error is set. Otherwise a GVariant tuple with return values. Free with variantUnref. (Can throw GError)

Finishes an operation started with dBusConnectionCall.

Since: 2.26

callSync

dBusConnectionCallSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsCancellable b) 
=> a

connection: a DBusConnection

-> Maybe Text

busName: a unique or well-known bus name or Nothing if connection is not a message bus connection

-> Text

objectPath: path of remote object

-> Text

interfaceName: D-Bus interface to invoke method on

-> Text

methodName: the name of the method to invoke

-> Maybe GVariant

parameters: a GVariant tuple with parameters for the method or Nothing if not passing parameters

-> Maybe VariantType

replyType: the expected type of the reply, or Nothing

-> [DBusCallFlags]

flags: flags from the DBusCallFlags enumeration

-> Int32

timeoutMsec: the timeout in milliseconds, -1 to use the default timeout or G_MAXINT for no timeout

-> Maybe b

cancellable: a Cancellable or Nothing

-> m GVariant

Returns: Nothing if error is set. Otherwise a GVariant tuple with return values. Free with variantUnref. (Can throw GError)

Synchronously invokes the methodName method on the interfaceName D-Bus interface on the remote object at objectPath owned by busName.

If connection is closed then the operation will fail with IOErrorEnumClosed. If cancellable is canceled, the operation will fail with IOErrorEnumCancelled. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with IOErrorEnumInvalidArgument.

If replyType is non-Nothing then the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give a replyType then any non-Nothing return value will be of this type.

If the parameters GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:

C code

g_dbus_connection_call_sync (connection,
                             "org.freedesktop.StringThings",
                             "/org/freedesktop/StringThings",
                             "org.freedesktop.StringThings",
                             "TwoStrings",
                             g_variant_new ("(ss)",
                                            "Thing One",
                                            "Thing Two"),
                             NULL,
                             G_DBUS_CALL_FLAGS_NONE,
                             -1,
                             NULL,
                             &error);

The calling thread is blocked until a reply is received. See dBusConnectionCall for the asynchronous version of this method.

Since: 2.26

callWithUnixFdList

dBusConnectionCallWithUnixFdList Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsUnixFDList b, IsCancellable c) 
=> a

connection: a DBusConnection

-> Maybe Text

busName: a unique or well-known bus name or Nothing if connection is not a message bus connection

-> Text

objectPath: path of remote object

-> Text

interfaceName: D-Bus interface to invoke method on

-> Text

methodName: the name of the method to invoke

-> Maybe GVariant

parameters: a GVariant tuple with parameters for the method or Nothing if not passing parameters

-> Maybe VariantType

replyType: the expected type of the reply, or Nothing

-> [DBusCallFlags]

flags: flags from the DBusCallFlags enumeration

-> Int32

timeoutMsec: the timeout in milliseconds, -1 to use the default timeout or G_MAXINT for no timeout

-> Maybe b

fdList: a UnixFDList or Nothing

-> Maybe c

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied or Nothing if you don't * care about the result of the method invocation

-> m () 

Like dBusConnectionCall but also takes a UnixFDList object.

This method is only available on UNIX.

Since: 2.30

callWithUnixFdListFinish

dBusConnectionCallWithUnixFdListFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsAsyncResult b) 
=> a

connection: a DBusConnection

-> b

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionCallWithUnixFdList

-> m (GVariant, UnixFDList)

Returns: Nothing if error is set. Otherwise a GVariant tuple with return values. Free with variantUnref. (Can throw GError)

Finishes an operation started with dBusConnectionCallWithUnixFdList.

Since: 2.30

callWithUnixFdListSync

dBusConnectionCallWithUnixFdListSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsUnixFDList b, IsCancellable c) 
=> a

connection: a DBusConnection

-> Maybe Text

busName: a unique or well-known bus name or Nothing if connection is not a message bus connection

-> Text

objectPath: path of remote object

-> Text

interfaceName: D-Bus interface to invoke method on

-> Text

methodName: the name of the method to invoke

-> Maybe GVariant

parameters: a GVariant tuple with parameters for the method or Nothing if not passing parameters

-> Maybe VariantType

replyType: the expected type of the reply, or Nothing

-> [DBusCallFlags]

flags: flags from the DBusCallFlags enumeration

-> Int32

timeoutMsec: the timeout in milliseconds, -1 to use the default timeout or G_MAXINT for no timeout

-> Maybe b

fdList: a UnixFDList or Nothing

-> Maybe c

cancellable: a Cancellable or Nothing

-> m (GVariant, UnixFDList)

Returns: Nothing if error is set. Otherwise a GVariant tuple with return values. Free with variantUnref. (Can throw GError)

Like dBusConnectionCallSync but also takes and returns UnixFDList objects.

This method is only available on UNIX.

Since: 2.30

close

dBusConnectionClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsCancellable b) 
=> a

connection: a DBusConnection

-> Maybe b

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied or Nothing if you don't care about the result

-> m () 

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 DBusConnection:exit-on-close).

Once the connection is closed, operations such as sending a message will return with the error IOErrorEnumClosed. Closing a connection will not automatically flush the connection so queued messages may be lost. Use dBusConnectionFlush if you need such guarantees.

If connection is already closed, this method fails with IOErrorEnumClosed.

When connection has been closed, the closed signal is emitted in the [thread-default main context][g-main-context-push-thread-default] of the thread that connection was constructed in.

This is an asynchronous method. When the operation is finished, 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. You can then call dBusConnectionCloseFinish to get the result of the operation. See dBusConnectionCloseSync for the synchronous version.

Since: 2.26

closeFinish

dBusConnectionCloseFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsAsyncResult b) 
=> a

connection: a DBusConnection

-> b

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionClose

-> m ()

(Can throw GError)

Finishes an operation started with dBusConnectionClose.

Since: 2.26

closeSync

dBusConnectionCloseSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsCancellable b) 
=> a

connection: a DBusConnection

-> Maybe b

cancellable: a Cancellable or Nothing

-> m ()

(Can throw GError)

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

Since: 2.26

emitSignal

dBusConnectionEmitSignal Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Maybe Text

destinationBusName: the unique bus name for the destination for the signal or Nothing to emit to all listeners

-> Text

objectPath: path of remote object

-> Text

interfaceName: D-Bus interface to emit a signal on

-> Text

signalName: the name of the signal to emit

-> Maybe GVariant

parameters: a GVariant tuple with parameters for the signal or Nothing if not passing parameters

-> m ()

(Can throw GError)

Emits a signal.

If the parameters GVariant is floating, it is consumed.

This can only fail if parameters is not compatible with the D-Bus protocol (IOErrorEnumInvalidArgument), or if connection has been closed (IOErrorEnumClosed).

Since: 2.26

exportActionGroup

dBusConnectionExportActionGroup Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsActionGroup b) 
=> a

connection: a DBusConnection

-> Text

objectPath: a D-Bus object path

-> b

actionGroup: a ActionGroup

-> m Word32

Returns: the ID of the export (never zero), or 0 in case of failure (Can throw GError)

Exports actionGroup on connection at objectPath.

The implemented D-Bus API should be considered private. It is subject to change in the future.

A given object path can only have one action group exported on it. If this constraint is violated, the export will fail and 0 will be returned (with error set accordingly).

You can unexport the action group using dBusConnectionUnexportActionGroup with the return value of this function.

The thread default main context is taken at the time of this call. All incoming action activations and state change requests are reported from this context. Any changes on the action group that cause it to emit signals must also come from this same context. Since incoming action activations and state change requests are rather likely to cause changes on the action group, this effectively limits a given action group to being exported from only one main context.

Since: 2.32

exportMenuModel

dBusConnectionExportMenuModel Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsMenuModel b) 
=> a

connection: a DBusConnection

-> Text

objectPath: a D-Bus object path

-> b

menu: a MenuModel

-> m Word32

Returns: the ID of the export (never zero), or 0 in case of failure (Can throw GError)

Exports menu on connection at objectPath.

The implemented D-Bus API should be considered private. It is subject to change in the future.

An object path can only have one menu model exported on it. If this constraint is violated, the export will fail and 0 will be returned (with error set accordingly).

You can unexport the menu model using dBusConnectionUnexportMenuModel with the return value of this function.

Since: 2.32

flush

dBusConnectionFlush Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsCancellable b) 
=> a

connection: a DBusConnection

-> Maybe b

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied or Nothing if you don't care about the result

-> m () 

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

This is an asynchronous method. When the operation is finished, 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. You can then call dBusConnectionFlushFinish to get the result of the operation. See dBusConnectionFlushSync for the synchronous version.

Since: 2.26

flushFinish

dBusConnectionFlushFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsAsyncResult b) 
=> a

connection: a DBusConnection

-> b

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionFlush

-> m ()

(Can throw GError)

Finishes an operation started with dBusConnectionFlush.

Since: 2.26

flushSync

dBusConnectionFlushSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsCancellable b) 
=> a

connection: a DBusConnection

-> Maybe b

cancellable: a Cancellable or Nothing

-> m ()

(Can throw GError)

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

Since: 2.26

getCapabilities

dBusConnectionGetCapabilities Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m [DBusCapabilityFlags]

Returns: zero or more flags from the DBusCapabilityFlags enumeration

Gets the capabilities negotiated with the remote peer

Since: 2.26

getExitOnClose

dBusConnectionGetExitOnClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m Bool

Returns: whether the process is terminated when connection is closed by the remote peer

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

Since: 2.26

getFlags

dBusConnectionGetFlags Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m [DBusConnectionFlags]

Returns: zero or more flags from the DBusConnectionFlags enumeration

Gets the flags used to construct this connection

Since: 2.60

getGuid

dBusConnectionGetGuid Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m Text

Returns: The GUID. Do not free this string, it is owned by connection.

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

Since: 2.26

getLastSerial

dBusConnectionGetLastSerial Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m Word32

Returns: the last used serial or zero when no message has been sent within the current thread

Retrieves the last serial number assigned to a DBusMessage on the current thread. This includes messages sent via both low-level API such as dBusConnectionSendMessage as well as high-level API such as dBusConnectionEmitSignal, dBusConnectionCall or dBusProxyCall.

Since: 2.34

getPeerCredentials

dBusConnectionGetPeerCredentials Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m (Maybe Credentials)

Returns: a Credentials or Nothing if not available. Do not free this object, it is owned by connection.

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

In a message bus setup, the message bus is always the server and each application is a client. So this method will always return Nothing for message bus clients.

Since: 2.26

getStream

dBusConnectionGetStream Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m IOStream

Returns: the stream used for IO

Gets the underlying stream used for IO.

While the DBusConnection is active, it will interact with this stream from a worker thread, so it is not safe to interact with the stream directly.

Since: 2.26

getUniqueName

dBusConnectionGetUniqueName Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m (Maybe Text)

Returns: the unique name or Nothing if connection is not a message bus connection. Do not free this string, it is owned by connection.

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.

Since: 2.26

isClosed

dBusConnectionIsClosed Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m Bool

Returns: True if the connection is closed, False otherwise

Gets whether connection is closed.

Since: 2.26

new

dBusConnectionNew Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a, IsDBusAuthObserver b, IsCancellable c) 
=> a

stream: a IOStream

-> Maybe Text

guid: the GUID to use if authenticating as a server or Nothing

-> [DBusConnectionFlags]

flags: flags describing how to make the connection

-> Maybe b

observer: a DBusAuthObserver or Nothing

-> Maybe c

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied

-> m () 

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

If stream is a SocketConnection, then the corresponding Socket will be put into non-blocking mode.

The D-Bus connection will interact with stream from a worker thread. As a result, the caller should not interact with stream after this method has been called, except by calling objectUnref on it.

If observer is not Nothing it may be used to control the authentication process.

When the operation is finished, callback will be invoked. You can then call dBusConnectionNewFinish to get the result of the operation.

This is an asynchronous failable constructor. See dBusConnectionNewSync for the synchronous version.

Since: 2.26

newFinish

dBusConnectionNewFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsAsyncResult a) 
=> a

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionNew.

-> m DBusConnection

Returns: a DBusConnection or Nothing if error is set. Free with objectUnref. (Can throw GError)

Finishes an operation started with dBusConnectionNew.

Since: 2.26

newForAddress

dBusConnectionNewForAddress Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusAuthObserver a, IsCancellable b) 
=> Text

address: a D-Bus address

-> [DBusConnectionFlags]

flags: flags describing how to make the connection

-> Maybe a

observer: a DBusAuthObserver or Nothing

-> Maybe b

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied

-> m () 

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.

This constructor can only be used to initiate client-side connections - use dBusConnectionNew if you need to act as the server. In particular, flags cannot contain the DBusConnectionFlagsAuthenticationServer or DBusConnectionFlagsAuthenticationAllowAnonymous flags.

When the operation is finished, callback will be invoked. You can then call dBusConnectionNewForAddressFinish to get the result of the operation.

If observer is not Nothing it may be used to control the authentication process.

This is an asynchronous failable constructor. See dBusConnectionNewForAddressSync for the synchronous version.

Since: 2.26

newForAddressFinish

dBusConnectionNewForAddressFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsAsyncResult a) 
=> a

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionNew

-> m DBusConnection

Returns: a DBusConnection or Nothing if error is set. Free with objectUnref. (Can throw GError)

Finishes an operation started with dBusConnectionNewForAddress.

Since: 2.26

newForAddressSync

dBusConnectionNewForAddressSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusAuthObserver a, IsCancellable b) 
=> Text

address: a D-Bus address

-> [DBusConnectionFlags]

flags: flags describing how to make the connection

-> Maybe a

observer: a DBusAuthObserver or Nothing

-> Maybe b

cancellable: a Cancellable or Nothing

-> m DBusConnection

Returns: a DBusConnection or Nothing if error is set. Free with objectUnref. (Can throw GError)

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.

This constructor can only be used to initiate client-side connections - use dBusConnectionNewSync if you need to act as the server. In particular, flags cannot contain the DBusConnectionFlagsAuthenticationServer or DBusConnectionFlagsAuthenticationAllowAnonymous flags.

This is a synchronous failable constructor. See dBusConnectionNewForAddress for the asynchronous version.

If observer is not Nothing it may be used to control the authentication process.

Since: 2.26

newSync

dBusConnectionNewSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsIOStream a, IsDBusAuthObserver b, IsCancellable c) 
=> a

stream: a IOStream

-> Maybe Text

guid: the GUID to use if authenticating as a server or Nothing

-> [DBusConnectionFlags]

flags: flags describing how to make the connection

-> Maybe b

observer: a DBusAuthObserver or Nothing

-> Maybe c

cancellable: a Cancellable or Nothing

-> m DBusConnection

Returns: a DBusConnection or Nothing if error is set. Free with objectUnref. (Can throw GError)

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

If stream is a SocketConnection, then the corresponding Socket will be put into non-blocking mode.

The D-Bus connection will interact with stream from a worker thread. As a result, the caller should not interact with stream after this method has been called, except by calling objectUnref on it.

If observer is not Nothing it may be used to control the authentication process.

This is a synchronous failable constructor. See dBusConnectionNew for the asynchronous version.

Since: 2.26

registerObject

dBusConnectionRegisterObject Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: A DBusConnection.

-> Text

objectPath: The object path to register at.

-> DBusInterfaceInfo

interfaceInfo: Introspection data for the interface.

-> Maybe (GClosure b)

methodCallClosure: Closure for handling incoming method calls.

-> Maybe (GClosure c)

getPropertyClosure: Closure for getting a property.

-> Maybe (GClosure d)

setPropertyClosure: Closure for setting a property.

-> m Word32

Returns: 0 if error is set, otherwise a registration id (never 0) that can be used with dBusConnectionUnregisterObject . (Can throw GError)

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

Since: 2.46

registerSubtree

dBusConnectionRegisterSubtree Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Text

objectPath: the object path to register the subtree at

-> DBusSubtreeVTable

vtable: a DBusSubtreeVTable to enumerate, introspect and dispatch nodes in the subtree

-> [DBusSubtreeFlags]

flags: flags used to fine tune the behavior of the subtree

-> Ptr ()

userData: data to pass to functions in vtable

-> DestroyNotify

userDataFreeFunc: function to call when the subtree is unregistered

-> m Word32

Returns: 0 if error is set, otherwise a subtree registration id (never 0) that can be used with dBusConnectionUnregisterSubtree . (Can throw GError)

Registers a whole subtree of dynamic objects.

The enumerate and introspection functions in vtable are used to convey, to remote callers, what nodes exist in the subtree rooted by objectPath.

When handling remote calls into any node in the subtree, first the enumerate function is used to check if the node exists. If the node exists or the G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is set the introspection function is used to check if the node supports the requested method. If so, the dispatch function is used to determine where to dispatch the call. The collected DBusInterfaceVTable and gpointer will be used to call into the interface vtable for processing the request.

All calls into user-provided code will be invoked in the [thread-default main context][g-main-context-push-thread-default] of the thread you are calling this method from.

If an existing subtree is already registered at objectPath or then error is set to G_IO_ERROR_EXISTS.

Note that it is valid to register regular objects (using g_dbus_connection_register_object()) in a subtree registered with dBusConnectionRegisterSubtree - if so, the subtree handler is tried as the last resort. One way to think about a subtree handler is to consider it a fallback handler for object paths not registered via g_dbus_connection_register_object() or other bindings.

Note that vtable will be copied so you cannot change it after registration.

See this [server][gdbus-subtree-server] for an example of how to use this method.

Since: 2.26

removeFilter

dBusConnectionRemoveFilter Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Word32

filterId: an identifier obtained from dBusConnectionAddFilter

-> m () 

Removes a filter.

Note that since filters run in a different thread, there is a race condition where it is possible that the filter will be running even after calling dBusConnectionRemoveFilter, so you cannot just free data that the filter might be using. Instead, you should pass a DestroyNotify to dBusConnectionAddFilter, which will be called when it is guaranteed that the data is no longer needed.

Since: 2.26

sendMessage

dBusConnectionSendMessage Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsDBusMessage b) 
=> a

connection: a DBusConnection

-> b

message: a DBusMessage

-> [DBusSendMessageFlags]

flags: flags affecting how the message is sent

-> m Word32

(Can throw GError)

Asynchronously sends message to the peer represented by connection.

Unless flags contain the DBusSendMessageFlagsPreserveSerial flag, the serial number will be assigned by connection and set on message via dBusMessageSetSerial. If outSerial is not Nothing, then the serial number used will be written to this location prior to submitting the message to the underlying transport.

If connection is closed then the operation will fail with IOErrorEnumClosed. If message is not well-formed, the operation fails with IOErrorEnumInvalidArgument.

See this [server][gdbus-server] and [client][gdbus-unix-fd-client] for an example of how to use this low-level API to send and receive UNIX file descriptors.

Note that message must be unlocked, unless flags contain the DBusSendMessageFlagsPreserveSerial flag.

Since: 2.26

sendMessageWithReply

dBusConnectionSendMessageWithReply Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsDBusMessage b, IsCancellable c) 
=> a

connection: a DBusConnection

-> b

message: a DBusMessage

-> [DBusSendMessageFlags]

flags: flags affecting how the message is sent

-> Int32

timeoutMsec: the timeout in milliseconds, -1 to use the default timeout or G_MAXINT for no timeout

-> Maybe c

cancellable: a Cancellable or Nothing

-> Maybe AsyncReadyCallback

callback: a AsyncReadyCallback to call when the request is satisfied or Nothing if you don't care about the result

-> m Word32 

Asynchronously sends message to the peer represented by connection.

Unless flags contain the DBusSendMessageFlagsPreserveSerial flag, the serial number will be assigned by connection and set on message via dBusMessageSetSerial. If outSerial is not Nothing, then the serial number used will be written to this location prior to submitting the message to the underlying transport.

If connection is closed then the operation will fail with IOErrorEnumClosed. If cancellable is canceled, the operation will fail with IOErrorEnumCancelled. If message is not well-formed, the operation fails with IOErrorEnumInvalidArgument.

This is an asynchronous method. When the operation is finished, 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. You can then call dBusConnectionSendMessageWithReplyFinish to get the result of the operation. See dBusConnectionSendMessageWithReplySync for the synchronous version.

Note that message must be unlocked, unless flags contain the DBusSendMessageFlagsPreserveSerial flag.

See this [server][gdbus-server] and [client][gdbus-unix-fd-client] for an example of how to use this low-level API to send and receive UNIX file descriptors.

Since: 2.26

sendMessageWithReplyFinish

dBusConnectionSendMessageWithReplyFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsAsyncResult b) 
=> a

connection: a DBusConnection

-> b

res: a AsyncResult obtained from the AsyncReadyCallback passed to dBusConnectionSendMessageWithReply

-> m DBusMessage

Returns: a locked DBusMessage or Nothing if error is set (Can throw GError)

Finishes an operation started with dBusConnectionSendMessageWithReply.

Note that error is only set if a local in-process error occurred. That is to say that the returned DBusMessage object may be of type DBusMessageTypeError. Use dBusMessageToGerror to transcode this to a GError.

See this [server][gdbus-server] and [client][gdbus-unix-fd-client] for an example of how to use this low-level API to send and receive UNIX file descriptors.

Since: 2.26

sendMessageWithReplySync

dBusConnectionSendMessageWithReplySync Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a, IsDBusMessage b, IsCancellable c) 
=> a

connection: a DBusConnection

-> b

message: a DBusMessage

-> [DBusSendMessageFlags]

flags: flags affecting how the message is sent.

-> Int32

timeoutMsec: the timeout in milliseconds, -1 to use the default timeout or G_MAXINT for no timeout

-> Maybe c

cancellable: a Cancellable or Nothing

-> m (DBusMessage, Word32)

Returns: a locked DBusMessage that is the reply to message or Nothing if error is set (Can throw GError)

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 dBusConnectionSendMessageWithReply for the asynchronous version of this method.

Unless flags contain the DBusSendMessageFlagsPreserveSerial flag, the serial number will be assigned by connection and set on message via dBusMessageSetSerial. If outSerial is not Nothing, then the serial number used will be written to this location prior to submitting the message to the underlying transport.

If connection is closed then the operation will fail with IOErrorEnumClosed. If cancellable is canceled, the operation will fail with IOErrorEnumCancelled. If message is not well-formed, the operation fails with IOErrorEnumInvalidArgument.

Note that error is only set if a local in-process error occurred. That is to say that the returned DBusMessage object may be of type DBusMessageTypeError. Use dBusMessageToGerror to transcode this to a GError.

See this [server][gdbus-server] and [client][gdbus-unix-fd-client] for an example of how to use this low-level API to send and receive UNIX file descriptors.

Note that message must be unlocked, unless flags contain the DBusSendMessageFlagsPreserveSerial flag.

Since: 2.26

setExitOnClose

dBusConnectionSetExitOnClose Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Bool

exitOnClose: whether the process should be terminated when connection is closed by the remote peer

-> m () 

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

Note that this function should be used with care. Most modern UNIX desktops tie the notion of a user session with the session bus, and expect all of a user's applications to quit when their bus connection goes away. If you are setting exitOnClose to False for the shared session bus connection, you should make sure that your application exits when the user session ends.

Since: 2.26

signalSubscribe

dBusConnectionSignalSubscribe Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Maybe Text

sender: sender name to match on (unique or well-known name) or Nothing to listen from all senders

-> Maybe Text

interfaceName: D-Bus interface name to match on or Nothing to match on all interfaces

-> Maybe Text

member: D-Bus signal name to match on or Nothing to match on all signals

-> Maybe Text

objectPath: object path to match on or Nothing to match on all object paths

-> Maybe Text

arg0: contents of first string argument to match on or Nothing to match on all kinds of arguments

-> [DBusSignalFlags]

flags: DBusSignalFlags describing how arg0 is used in subscribing to the signal

-> DBusSignalCallback

callback: callback to invoke when there is a signal matching the requested data

-> m Word32

Returns: a subscription identifier that can be used with dBusConnectionSignalUnsubscribe

Subscribes to signals on connection and invokes callback with a 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.

If connection is not a message bus connection, sender must be Nothing.

If sender is a well-known name note that callback is invoked with the unique name for the owner of sender, not the well-known name as one would expect. This is because the message bus rewrites the name. As such, to avoid certain race conditions, users should be tracking the name owner of the well-known name and use that when processing the received signal.

If one of DBusSignalFlagsMatchArg0Namespace or DBusSignalFlagsMatchArg0Path are given, arg0 is interpreted as part of a namespace or path. The first argument of a signal is matched against that part as specified by D-Bus.

If userDataFreeFunc is non-Nothing, it will be called (in the thread-default main context of the thread you are calling this method from) at some point after userData is no longer needed. (It is not guaranteed to be called synchronously when the signal is unsubscribed from, and may be called after connection has been destroyed.)

As callback is potentially invoked in a different thread from where it’s emitted, it’s possible for this to happen after dBusConnectionSignalUnsubscribe has been called in another thread. Due to this, userData should have a strong reference which is freed with userDataFreeFunc, rather than pointing to data whose lifecycle is tied to the signal subscription. For example, if a Object is used to store the subscription ID from dBusConnectionSignalSubscribe, a strong reference to that Object must be passed to userData, and objectUnref passed to userDataFreeFunc. You are responsible for breaking the resulting reference count cycle by explicitly unsubscribing from the signal when dropping the last external reference to the Object. Alternatively, a weak reference may be used.

It is guaranteed that if you unsubscribe from a signal using dBusConnectionSignalUnsubscribe from the same thread which made the corresponding dBusConnectionSignalSubscribe call, callback will not be invoked after dBusConnectionSignalUnsubscribe returns.

The returned subscription identifier is an opaque value which is guaranteed to never be zero.

This function can never fail.

Since: 2.26

signalUnsubscribe

dBusConnectionSignalUnsubscribe Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Word32

subscriptionId: a subscription id obtained from dBusConnectionSignalSubscribe

-> m () 

Unsubscribes from signals.

Note that there may still be D-Bus traffic to process (relating to this signal subscription) in the current thread-default MainContext after this function has returned. You should continue to iterate the MainContext until the DestroyNotify function passed to dBusConnectionSignalSubscribe is called, in order to avoid memory leaks through callbacks queued on the MainContext after it’s stopped being iterated.

Since: 2.26

startMessageProcessing

dBusConnectionStartMessageProcessing Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> m () 

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

Since: 2.26

unexportActionGroup

dBusConnectionUnexportActionGroup Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Word32

exportId: the ID from dBusConnectionExportActionGroup

-> m () 

Reverses the effect of a previous call to dBusConnectionExportActionGroup.

It is an error to call this function with an ID that wasn't returned from dBusConnectionExportActionGroup or to call it with the same ID more than once.

Since: 2.32

unexportMenuModel

dBusConnectionUnexportMenuModel Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Word32

exportId: the ID from dBusConnectionExportMenuModel

-> m () 

Reverses the effect of a previous call to dBusConnectionExportMenuModel.

It is an error to call this function with an ID that wasn't returned from dBusConnectionExportMenuModel or to call it with the same ID more than once.

Since: 2.32

unregisterObject

dBusConnectionUnregisterObject Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Word32

registrationId: a registration id obtained from g_dbus_connection_register_object()

-> m Bool

Returns: True if the object was unregistered, False otherwise

Unregisters an object.

Since: 2.26

unregisterSubtree

dBusConnectionUnregisterSubtree Source #

Arguments

:: (HasCallStack, MonadIO m, IsDBusConnection a) 
=> a

connection: a DBusConnection

-> Word32

registrationId: a subtree registration id obtained from dBusConnectionRegisterSubtree

-> m Bool

Returns: True if the subtree was unregistered, False otherwise

Unregisters a subtree.

Since: 2.26

Properties

address

A D-Bus address specifying potential endpoints that can be used when establishing the connection.

Since: 2.26

constructDBusConnectionAddress :: (IsDBusConnection o, MonadIO m) => Text -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “address” property. This is rarely needed directly, but it is used by new.

authenticationObserver

A DBusAuthObserver object to assist in the authentication process or Nothing.

Since: 2.26

constructDBusConnectionAuthenticationObserver :: (IsDBusConnection o, MonadIO m, IsDBusAuthObserver a) => a -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “authentication-observer” property. This is rarely needed directly, but it is used by new.

capabilities

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

Since: 2.26

getDBusConnectionCapabilities :: (MonadIO m, IsDBusConnection o) => o -> m [DBusCapabilityFlags] Source #

Get the value of the “capabilities” property. When overloading is enabled, this is equivalent to

get dBusConnection #capabilities

closed

A boolean specifying whether the connection has been closed.

Since: 2.26

getDBusConnectionClosed :: (MonadIO m, IsDBusConnection o) => o -> m Bool Source #

Get the value of the “closed” property. When overloading is enabled, this is equivalent to

get dBusConnection #closed

exitOnClose

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

Note that DBusConnection objects returned by busGetFinish and busGetSync will (usually) have this property set to True.

Since: 2.26

constructDBusConnectionExitOnClose :: (IsDBusConnection o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “exit-on-close” property. This is rarely needed directly, but it is used by new.

getDBusConnectionExitOnClose :: (MonadIO m, IsDBusConnection o) => o -> m Bool Source #

Get the value of the “exit-on-close” property. When overloading is enabled, this is equivalent to

get dBusConnection #exitOnClose

setDBusConnectionExitOnClose :: (MonadIO m, IsDBusConnection o) => o -> Bool -> m () Source #

Set the value of the “exit-on-close” property. When overloading is enabled, this is equivalent to

set dBusConnection [ #exitOnClose := value ]

flags

Flags from the DBusConnectionFlags enumeration.

Since: 2.26

constructDBusConnectionFlags :: (IsDBusConnection o, MonadIO m) => [DBusConnectionFlags] -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “flags” property. This is rarely needed directly, but it is used by new.

getDBusConnectionFlags :: (MonadIO m, IsDBusConnection o) => o -> m [DBusConnectionFlags] Source #

Get the value of the “flags” property. When overloading is enabled, this is equivalent to

get dBusConnection #flags

guid

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

If you are constructing a DBusConnection and pass DBusConnectionFlagsAuthenticationServer in the DBusConnection:flags property then you MUST also set this property to a valid guid.

If you are constructing a DBusConnection and pass DBusConnectionFlagsAuthenticationClient in the DBusConnection:flags property you will be able to read the GUID of the other peer here after the connection has been successfully initialized.

Since: 2.26

constructDBusConnectionGuid :: (IsDBusConnection o, MonadIO m) => Text -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “guid” property. This is rarely needed directly, but it is used by new.

getDBusConnectionGuid :: (MonadIO m, IsDBusConnection o) => o -> m Text Source #

Get the value of the “guid” property. When overloading is enabled, this is equivalent to

get dBusConnection #guid

stream

The underlying IOStream used for I/O.

If this is passed on construction and is a SocketConnection, then the corresponding Socket will be put into non-blocking mode.

While the DBusConnection is active, it will interact with this stream from a worker thread, so it is not safe to interact with the stream directly.

Since: 2.26

constructDBusConnectionStream :: (IsDBusConnection o, MonadIO m, IsIOStream a) => a -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “stream” property. This is rarely needed directly, but it is used by new.

getDBusConnectionStream :: (MonadIO m, IsDBusConnection o) => o -> m IOStream Source #

Get the value of the “stream” property. When overloading is enabled, this is equivalent to

get dBusConnection #stream

uniqueName

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

Since: 2.26

getDBusConnectionUniqueName :: (MonadIO m, IsDBusConnection o) => o -> m (Maybe Text) Source #

Get the value of the “unique-name” property. When overloading is enabled, this is equivalent to

get dBusConnection #uniqueName

Signals

closed

type C_DBusConnectionClosedCallback = Ptr () -> CInt -> Ptr GError -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type DBusConnectionClosedCallback Source #

Arguments

 = Bool

remotePeerVanished: True if connection is closed because the remote peer closed its end of the connection

-> Maybe GError

error: a GError with more details about the event or Nothing

-> IO () 

Emitted when the connection is closed.

The cause of this event can be

  • If dBusConnectionClose is called. In this case remotePeerVanished is set to False and error is Nothing.
  • If the remote peer closes the connection. In this case remotePeerVanished is set to True and error is set.
  • If the remote peer sends invalid or malformed data. In this case remotePeerVanished is set to False and error is set.

Upon receiving this signal, you should give up your reference to connection. You are guaranteed that this signal is emitted only once.

Since: 2.26

afterDBusConnectionClosed :: (IsDBusConnection a, MonadIO m) => a -> DBusConnectionClosedCallback -> m SignalHandlerId Source #

Connect a signal handler for the closed signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after dBusConnection #closed callback

onDBusConnectionClosed :: (IsDBusConnection a, MonadIO m) => a -> DBusConnectionClosedCallback -> m SignalHandlerId Source #

Connect a signal handler for the closed signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on dBusConnection #closed callback