gi-gio-2.0.14: Gio bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.Gio.Objects.DBusProxy

Contents

Description

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

By default, DBusProxy will cache all properties (and listen to changes) of the remote object, and proxy all signals that gets emitted. This behaviour can be changed by passing suitable 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.

If a DBusProxy is used for a well-known name, the owner of the name is tracked and can be read from DBusProxy:g-name-owner. Connect to the 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 DBusProxyFlagsDoNotAutoStart is set).

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

A DBusProxy instance can be used from multiple threads but note that all signals (e.g. DBusProxy::g-signal, DBusProxy::g-properties-changed and Object::notify) are emitted in the [thread-default main context][g-main-context-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

Synopsis

Exported types

Methods

call

dBusProxyCall Source #

Arguments

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

proxy: A DBusProxy.

-> Text

methodName: Name of method to invoke.

-> Maybe GVariant

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

-> [DBusCallFlags]

flags: Flags from the DBusCallFlags enumeration.

-> Int32

timeoutMsec: The timeout in milliseconds (with G_MAXINT meaning "infinite") or -1 to use the proxy default 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 proxy.

If methodName contains any dots, then name is split into interface and method name parts. This allows using proxy for invoking methods on other interfaces.

If the DBusConnection associated with proxy 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 the parameters GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:

C code

g_dbus_proxy_call (proxy,
                   "TwoStrings",
                   g_variant_new ("(ss)",
                                  "Thing One",
                                  "Thing Two"),
                   G_DBUS_CALL_FLAGS_NONE,
                   -1,
                   NULL,
                   (GAsyncReadyCallback) two_strings_done,
                   &data);

If proxy has an expected interface (see DBusProxy:g-interface-info) and methodName is referenced by it, then the return value is checked against the return type.

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 dBusProxyCallFinish to get the result of the operation. See dBusProxyCallSync for the synchronous version of this method.

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

Since: 2.26

callFinish

dBusProxyCallFinish Source #

Arguments

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

proxy: A DBusProxy.

-> b

res: A AsyncResult obtained from the AsyncReadyCallback passed to dBusProxyCall.

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

Since: 2.26

callSync

dBusProxyCallSync Source #

Arguments

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

proxy: A DBusProxy.

-> Text

methodName: Name of method to invoke.

-> Maybe GVariant

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

-> [DBusCallFlags]

flags: Flags from the DBusCallFlags enumeration.

-> Int32

timeoutMsec: The timeout in milliseconds (with G_MAXINT meaning "infinite") or -1 to use the proxy default 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 proxy.

If methodName contains any dots, then name is split into interface and method name parts. This allows using proxy for invoking methods on other interfaces.

If the DBusConnection associated with proxy is disconnected 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 the parameters GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:

C code

g_dbus_proxy_call_sync (proxy,
                        "TwoStrings",
                        g_variant_new ("(ss)",
                                       "Thing One",
                                       "Thing Two"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
                        &error);

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

If proxy has an expected interface (see DBusProxy:g-interface-info) and methodName is referenced by it, then the return value is checked against the return type.

Since: 2.26

callWithUnixFdList

dBusProxyCallWithUnixFdList Source #

Arguments

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

proxy: A DBusProxy.

-> Text

methodName: Name of method to invoke.

-> Maybe GVariant

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

-> [DBusCallFlags]

flags: Flags from the DBusCallFlags enumeration.

-> Int32

timeoutMsec: The timeout in milliseconds (with G_MAXINT meaning "infinite") or -1 to use the proxy default 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 dBusProxyCall but also takes a UnixFDList object.

This method is only available on UNIX.

Since: 2.30

callWithUnixFdListFinish

dBusProxyCallWithUnixFdListFinish Source #

Arguments

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

proxy: A DBusProxy.

-> b

res: A AsyncResult obtained from the AsyncReadyCallback passed to dBusProxyCallWithUnixFdList.

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

Since: 2.30

callWithUnixFdListSync

dBusProxyCallWithUnixFdListSync Source #

Arguments

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

proxy: A DBusProxy.

-> Text

methodName: Name of method to invoke.

-> Maybe GVariant

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

-> [DBusCallFlags]

flags: Flags from the DBusCallFlags enumeration.

-> Int32

timeoutMsec: The timeout in milliseconds (with G_MAXINT meaning "infinite") or -1 to use the proxy default 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 dBusProxyCallSync but also takes and returns UnixFDList objects.

This method is only available on UNIX.

Since: 2.30

getCachedProperty

dBusProxyGetCachedProperty Source #

Arguments

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

proxy: A DBusProxy.

-> Text

propertyName: Property name.

-> m GVariant

Returns: A reference to the GVariant instance that holds the value for propertyName or Nothing if the value is not in the cache. The returned reference must be freed with variantUnref.

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

If proxy has an expected interface (see DBusProxy:g-interface-info) and propertyName is referenced by it, then value is checked against the type of the property.

Since: 2.26

getCachedPropertyNames

dBusProxyGetCachedPropertyNames Source #

Arguments

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

proxy: A DBusProxy.

-> m [Text]

Returns: A Nothing-terminated array of strings or Nothing if proxy has no cached properties. Free the returned array with strfreev.

Gets the names of all cached properties on proxy.

Since: 2.26

getConnection

dBusProxyGetConnection Source #

Arguments

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

proxy: A DBusProxy.

-> m DBusConnection

Returns: A DBusConnection owned by proxy. Do not free.

Gets the connection proxy is for.

Since: 2.26

getDefaultTimeout

dBusProxyGetDefaultTimeout Source #

Arguments

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

proxy: A DBusProxy.

-> m Int32

Returns: Timeout to use for proxy.

Gets the timeout to use if -1 (specifying default timeout) is passed as timeoutMsec in the dBusProxyCall and dBusProxyCallSync functions.

See the DBusProxy:g-default-timeout property for more details.

Since: 2.26

getFlags

dBusProxyGetFlags Source #

Arguments

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

proxy: A DBusProxy.

-> m [DBusProxyFlags]

Returns: Flags from the DBusProxyFlags enumeration.

Gets the flags that proxy was constructed with.

Since: 2.26

getInterfaceInfo

dBusProxyGetInterfaceInfo Source #

Arguments

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

proxy: A DBusProxy

-> m DBusInterfaceInfo

Returns: A DBusInterfaceInfo or Nothing. Do not unref the returned object, it is owned by proxy.

Returns the DBusInterfaceInfo, if any, specifying the interface that proxy conforms to. See the DBusProxy:g-interface-info property for more details.

Since: 2.26

getInterfaceName

dBusProxyGetInterfaceName Source #

Arguments

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

proxy: A DBusProxy.

-> m Text

Returns: A string owned by proxy. Do not free.

Gets the D-Bus interface name proxy is for.

Since: 2.26

getName

dBusProxyGetName Source #

Arguments

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

proxy: A DBusProxy.

-> m Text

Returns: A string owned by proxy. Do not free.

Gets the name that proxy was constructed for.

Since: 2.26

getNameOwner

dBusProxyGetNameOwner Source #

Arguments

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

proxy: A DBusProxy.

-> m Text

Returns: The name owner or Nothing if no name owner exists. Free with free.

The unique name that owns the name that proxy is for or Nothing if no-one currently owns that name. You may connect to the Object::notify signal to track changes to the DBusProxy:g-name-owner property.

Since: 2.26

getObjectPath

dBusProxyGetObjectPath Source #

Arguments

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

proxy: A DBusProxy.

-> m Text

Returns: A string owned by proxy. Do not free.

Gets the object path proxy is for.

Since: 2.26

new

dBusProxyNew Source #

Arguments

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

connection: A DBusConnection.

-> [DBusProxyFlags]

flags: Flags used when constructing the proxy.

-> Maybe DBusInterfaceInfo

info: A DBusInterfaceInfo specifying the minimal interface that proxy conforms to or Nothing.

-> Maybe Text

name: A bus name (well-known or unique) or Nothing if connection is not a message bus connection.

-> Text

objectPath: An object path.

-> Text

interfaceName: A D-Bus interface name.

-> Maybe b

cancellable: A Cancellable or Nothing.

-> Maybe AsyncReadyCallback

callback: Callback function to invoke when the proxy is ready.

-> m () 

Creates a proxy for accessing interfaceName on the remote object at objectPath owned by name at connection and asynchronously loads D-Bus properties unless the DBusProxyFlagsDoNotLoadProperties flag is used. Connect to the DBusProxy::g-properties-changed signal to get notified about property changes.

If the DBusProxyFlagsDoNotConnectSignals flag is not set, also sets up match rules for signals. Connect to the DBusProxy::g-signal signal to handle signals from the remote object.

If name is a well-known name and the DBusProxyFlagsDoNotAutoStart and DBusProxyFlagsDoNotAutoStartAtConstruction flags aren't set and no name owner currently exists, the message bus will be requested to launch a name owner for the name.

This is a failable asynchronous constructor - when the proxy is ready, callback will be invoked and you can use dBusProxyNewFinish to get the result.

See dBusProxyNewSync and for a synchronous version of this constructor.

DBusProxy is used in this [example][gdbus-wellknown-proxy].

Since: 2.26

newFinish

dBusProxyNewFinish Source #

Arguments

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

res: A AsyncResult obtained from the AsyncReadyCallback function passed to dBusProxyNew.

-> m DBusProxy

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

Finishes creating a DBusProxy.

Since: 2.26

newForBus

dBusProxyNewForBus Source #

Arguments

:: (HasCallStack, MonadIO m, IsCancellable a) 
=> BusType

busType: A BusType.

-> [DBusProxyFlags]

flags: Flags used when constructing the proxy.

-> Maybe DBusInterfaceInfo

info: A DBusInterfaceInfo specifying the minimal interface that proxy conforms to or Nothing.

-> Text

name: A bus name (well-known or unique).

-> Text

objectPath: An object path.

-> Text

interfaceName: A D-Bus interface name.

-> Maybe a

cancellable: A Cancellable or Nothing.

-> Maybe AsyncReadyCallback

callback: Callback function to invoke when the proxy is ready.

-> m () 

Like dBusProxyNew but takes a BusType instead of a DBusConnection.

DBusProxy is used in this [example][gdbus-wellknown-proxy].

Since: 2.26

newForBusFinish

dBusProxyNewForBusFinish Source #

Arguments

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

res: A AsyncResult obtained from the AsyncReadyCallback function passed to dBusProxyNewForBus.

-> m DBusProxy

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

Finishes creating a DBusProxy.

Since: 2.26

newForBusSync

dBusProxyNewForBusSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsCancellable a) 
=> BusType

busType: A BusType.

-> [DBusProxyFlags]

flags: Flags used when constructing the proxy.

-> Maybe DBusInterfaceInfo

info: A DBusInterfaceInfo specifying the minimal interface that proxy conforms to or Nothing.

-> Text

name: A bus name (well-known or unique).

-> Text

objectPath: An object path.

-> Text

interfaceName: A D-Bus interface name.

-> Maybe a

cancellable: A Cancellable or Nothing.

-> m DBusProxy

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

Like dBusProxyNewSync but takes a BusType instead of a DBusConnection.

DBusProxy is used in this [example][gdbus-wellknown-proxy].

Since: 2.26

newSync

dBusProxyNewSync Source #

Arguments

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

connection: A DBusConnection.

-> [DBusProxyFlags]

flags: Flags used when constructing the proxy.

-> Maybe DBusInterfaceInfo

info: A DBusInterfaceInfo specifying the minimal interface that proxy conforms to or Nothing.

-> Maybe Text

name: A bus name (well-known or unique) or Nothing if connection is not a message bus connection.

-> Text

objectPath: An object path.

-> Text

interfaceName: A D-Bus interface name.

-> Maybe b

cancellable: A Cancellable or Nothing.

-> m DBusProxy

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

Creates a proxy for accessing interfaceName on the remote object at objectPath owned by name at connection and synchronously loads D-Bus properties unless the DBusProxyFlagsDoNotLoadProperties flag is used.

If the DBusProxyFlagsDoNotConnectSignals flag is not set, also sets up match rules for signals. Connect to the DBusProxy::g-signal signal to handle signals from the remote object.

If name is a well-known name and the DBusProxyFlagsDoNotAutoStart and DBusProxyFlagsDoNotAutoStartAtConstruction flags aren't set and no name owner currently exists, the message bus will be requested to launch a name owner for the name.

This is a synchronous failable constructor. See dBusProxyNew and dBusProxyNewFinish for the asynchronous version.

DBusProxy is used in this [example][gdbus-wellknown-proxy].

Since: 2.26

setCachedProperty

dBusProxySetCachedProperty Source #

Arguments

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

proxy: A DBusProxy

-> Text

propertyName: Property name.

-> Maybe GVariant

value: Value for the property or Nothing to remove it from the cache.

-> m () 

If value is not Nothing, sets the cached value for the property with name propertyName to the value in value.

If value is Nothing, then the cached value is removed from the property cache.

If proxy has an expected interface (see DBusProxy:g-interface-info) and propertyName is referenced by it, then value is checked against the type of the property.

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

C code

g_dbus_proxy_set_cached_property (proxy,
                                  "SomeProperty",
                                  g_variant_new ("(si)",
                                                "A String",
                                                42));

Normally you will not need to use this method since proxy is tracking changes using the org.freedesktop.DBus.Properties.PropertiesChanged D-Bus signal. However, for performance reasons an object may decide to not use this signal for some properties and instead use a proprietary out-of-band mechanism to transmit changes.

As a concrete example, consider an object with a property ChatroomParticipants which is an array of strings. Instead of transmitting the same (long) array every time the property changes, it is more efficient to only transmit the delta using e.g. signals ChatroomParticipantJoined(String name) and ChatroomParticipantParted(String name).

Since: 2.26

setDefaultTimeout

dBusProxySetDefaultTimeout Source #

Arguments

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

proxy: A DBusProxy.

-> Int32

timeoutMsec: Timeout in milliseconds.

-> m () 

Sets the timeout to use if -1 (specifying default timeout) is passed as timeoutMsec in the dBusProxyCall and dBusProxyCallSync functions.

See the DBusProxy:g-default-timeout property for more details.

Since: 2.26

setInterfaceInfo

dBusProxySetInterfaceInfo Source #

Arguments

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

proxy: A DBusProxy

-> Maybe DBusInterfaceInfo

info: Minimum interface this proxy conforms to or Nothing to unset.

-> m () 

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

Since: 2.26

Properties

gBusType

gConnection

gDefaultTimeout

gFlags

gInterfaceInfo

gInterfaceName

gName

gNameOwner

gObjectPath

Signals

gPropertiesChanged

gSignal