[]Struct gio::DBusConnection

pub struct DBusConnection(_, _);

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 DBusProxy::new_for_bus APIs.

As an exception to the usual GLib rule that a particular object must not be used by two threads at the same time, DBusConnection's methods may be called from any thread. This is so that g_bus_get and g_bus_get_sync 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, DBusConnection::new and g_bus_get, and the synchronous versions of those methods, give you an initialized connection. Language bindings for GIO should use Initable::new or AsyncInitable::new_async, which also initialize the connection.

If you construct an uninitialized DBusConnection, such as via gobject::Object::new, you must initialize it via Initable::init or AsyncInitable::init_async 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 glib::Error, the only valid thing you can do with that DBusConnection is to free it with gobject::ObjectExt::unref.

An example D-Bus server # {gdbus-server}

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

An example for exporting a subtree # {gdbus-subtree-server}

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

An example for file descriptor passing # {gdbus-unix-fd-client}

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

An example for exporting a GObject # {gdbus-export}

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

Implements

glib::object::ObjectExt

Implementations

impl DBusConnection[src]

pub fn register_object<MethodCall, SetProperty, GetProperty>(
    &self,
    object_path: &str,
    interface_info: &DBusInterfaceInfo,
    method_call: MethodCall,
    get_property: GetProperty,
    set_property: SetProperty
) -> Result<RegistrationId, Error> where
    MethodCall: Fn(DBusConnection, &str, &str, &str, &str, Variant, DBusMethodInvocation) + Send + Sync + 'static,
    GetProperty: Fn(DBusConnection, &str, &str, &str, &str) -> Variant + Send + Sync + 'static,
    SetProperty: Fn(DBusConnection, &str, &str, &str, &str, Variant) -> bool + Send + Sync + 'static, 
[src]

Registers callbacks for exported objects at object_path with the D-Bus interface that is described in interface_info.

Calls to functions in vtable (and user_data_free_func) will happen in the [thread-default main context][g-main-context-push-thread-default] of the thread you are calling this method from.

Note that all glib::Variant values passed to functions in vtable will match the signature given in interface_info - if a remote caller passes incorrect values, the org.freedesktop.DBus.Error.InvalidArgs is returned to the remote caller.

Additionally, if the remote caller attempts to invoke methods or access properties not mentioned in interface_info the org.freedesktop.DBus.Error.UnknownMethod resp. org.freedesktop.DBus.Error.InvalidArgs errors are returned to the caller.

It is considered a programming error if the GDBusInterfaceGetPropertyFunc function in vtable returns a glib::Variant of incorrect type.

If an existing callback is already registered at object_path and interface_name, then error is set to IOErrorEnum::Exists.

GDBus automatically implements the standard D-Bus interfaces org.freedesktop.DBus.Properties, org.freedesktop.DBus.Introspectable and org.freedesktop.Peer, so you don't have to implement those for the objects you export. You can implement org.freedesktop.DBus.Properties yourself, e.g. to handle getting and setting of properties asynchronously.

Note that the reference count on interface_info will be incremented by 1 (unless allocated statically, e.g. if the reference count is -1, see DBusInterfaceInfo::ref) for as long as the object is exported. Also note that vtable will be copied.

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

object_path

the object path to register at

interface_info

introspection data for the interface

vtable

a DBusInterfaceVTable to call into or None

user_data

data to pass to functions in vtable

user_data_free_func

function to call when the object path is unregistered

Returns

0 if error is set, otherwise a registration id (never 0) that can be used with DBusConnection::unregister_object

pub fn unregister_object(
    &self,
    registration_id: RegistrationId
) -> Result<(), BoolError>
[src]

Unregisters an object.

registration_id

a registration id obtained from DBusConnection::register_object

Returns

true if the object was unregistered, false otherwise

pub fn export_action_group<P: IsA<ActionGroup>>(
    &self,
    object_path: &str,
    action_group: &P
) -> Result<ActionGroupExportId, Error>
[src]

Exports action_group on self at object_path.

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 DBusConnection::unexport_action_group 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.

object_path

a D-Bus object path

action_group

a ActionGroup

Returns

the ID of the export (never zero), or 0 in case of failure

pub fn unexport_action_group(&self, export_id: ActionGroupExportId)[src]

Reverses the effect of a previous call to DBusConnection::export_action_group.

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

export_id

the ID from DBusConnection::export_action_group

pub fn export_menu_model<P: IsA<MenuModel>>(
    &self,
    object_path: &str,
    menu: &P
) -> Result<MenuModelExportId, Error>
[src]

Exports menu on self at object_path.

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 DBusConnection::unexport_menu_model with the return value of this function.

object_path

a D-Bus object path

a MenuModel

Returns

the ID of the export (never zero), or 0 in case of failure

pub fn unexport_menu_model(&self, export_id: MenuModelExportId)[src]

Reverses the effect of a previous call to DBusConnection::export_menu_model.

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

export_id

the ID from DBusConnection::export_menu_model

pub fn add_filter<P: Fn(&DBusConnection, &DBusMessage, bool) -> Option<DBusMessage> + 'static>(
    &self,
    filter_function: P
) -> FilterId
[src]

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 DBusConnection::send_message_with_reply, DBusConnection::signal_subscribe or DBusConnection::call 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 DBusConnection::signal_subscribe and DBusConnection::send_message_with_reply 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 user_data_free_func is non-None, it will be called (in the thread-default main context of the thread you are calling this method from) at some point after user_data is no longer needed. (It is not guaranteed to be called synchronously when the filter is removed, and may be called after self has been destroyed.)

filter_function

a filter function

user_data

user data to pass to filter_function

user_data_free_func

function to free user_data with when filter is removed or None

Returns

a filter identifier that can be used with DBusConnection::remove_filter

pub fn remove_filter(&self, filter_id: FilterId)[src]

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 DBusConnection::remove_filter, so you cannot just free data that the filter might be using. Instead, you should pass a GDestroyNotify to DBusConnection::add_filter, which will be called when it is guaranteed that the data is no longer needed.

filter_id

an identifier obtained from DBusConnection::add_filter

pub fn signal_subscribe<P: Fn(&DBusConnection, &str, &str, &str, &str, &Variant) + 'static>(
    &self,
    sender: Option<&str>,
    interface_name: Option<&str>,
    member: Option<&str>,
    object_path: Option<&str>,
    arg0: Option<&str>,
    flags: DBusSignalFlags,
    callback: P
) -> SignalSubscriptionId
[src]

Subscribes to signals on self 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 self is not a message bus connection, sender must be None.

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 DBusSignalFlags::MatchArg0Namespace or DBusSignalFlags::MatchArg0Path 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 user_data_free_func is non-None, it will be called (in the thread-default main context of the thread you are calling this method from) at some point after user_data is no longer needed. (It is not guaranteed to be called synchronously when the signal is unsubscribed from, and may be called after self 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 DBusConnection::signal_unsubscribe has been called in another thread. Due to this, user_data should have a strong reference which is freed with user_data_free_func, rather than pointing to data whose lifecycle is tied to the signal subscription. For example, if a gobject::Object is used to store the subscription ID from DBusConnection::signal_subscribe, a strong reference to that gobject::Object must be passed to user_data, and gobject::ObjectExt::unref passed to user_data_free_func. You are responsible for breaking the resulting reference count cycle by explicitly unsubscribing from the signal when dropping the last external reference to the gobject::Object. Alternatively, a weak reference may be used.

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

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

This function can never fail.

sender

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

interface_name

D-Bus interface name to match on or None to match on all interfaces

member

D-Bus signal name to match on or None to match on all signals

object_path

object path to match on or None to match on all object paths

arg0

contents of first string argument to match on or None to match on all kinds of arguments

flags

DBusSignalFlags describing how arg0 is used in subscribing to the signal

callback

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

user_data

user data to pass to callback

user_data_free_func

function to free user_data with when subscription is removed or None

Returns

a subscription identifier that can be used with DBusConnection::signal_unsubscribe

pub fn signal_unsubscribe(&self, subscription_id: SignalSubscriptionId)[src]

Unsubscribes from signals.

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

subscription_id

a subscription id obtained from DBusConnection::signal_subscribe

impl DBusConnection[src]

pub fn new_for_address_sync<P: IsA<Cancellable>>(
    address: &str,
    flags: DBusConnectionFlags,
    observer: Option<&DBusAuthObserver>,
    cancellable: Option<&P>
) -> Result<DBusConnection, Error>
[src]

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 DBusConnection::new_sync if you need to act as the server. In particular, flags cannot contain the DBusConnectionFlags::AuthenticationServer or DBusConnectionFlags::AuthenticationAllowAnonymous flags.

This is a synchronous failable constructor. See DBusConnection::new_for_address for the asynchronous version.

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

address

a D-Bus address

flags

flags describing how to make the connection

observer

a DBusAuthObserver or None

cancellable

a Cancellable or None

Returns

a DBusConnection or None if error is set. Free with gobject::ObjectExt::unref.

pub fn new_sync<P: IsA<IOStream>, Q: IsA<Cancellable>>(
    stream: &P,
    guid: Option<&str>,
    flags: DBusConnectionFlags,
    observer: Option<&DBusAuthObserver>,
    cancellable: Option<&Q>
) -> Result<DBusConnection, Error>
[src]

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 gobject::ObjectExt::unref on it.

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

This is a synchronous failable constructor. See DBusConnection::new for the asynchronous version.

stream

a IOStream

guid

the GUID to use if authenticating as a server or None

flags

flags describing how to make the connection

observer

a DBusAuthObserver or None

cancellable

a Cancellable or None

Returns

a DBusConnection or None if error is set. Free with gobject::ObjectExt::unref.

pub fn call<P: IsA<Cancellable>, Q: FnOnce(Result<Variant, Error>) + Send + 'static>(
    &self,
    bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    method_name: &str,
    parameters: Option<&Variant>,
    reply_type: Option<&VariantTy>,
    flags: DBusCallFlags,
    timeout_msec: i32,
    cancellable: Option<&P>,
    callback: Q
)
[src]

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

If self is closed then the operation will fail with IOErrorEnum::Closed. If cancellable is canceled, the operation will fail with IOErrorEnum::Cancelled. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with IOErrorEnum::InvalidArgument.

If reply_type is non-None 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 reply_type then any non-None return value will be of this type. Unless it’s G_VARIANT_TYPE_UNIT, the reply_type will be a tuple containing one or more values.

If the parameters glib::Variant is floating, it is consumed. This allows convenient 'inline' use of glib::Variant::new, e.g.:

 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 DBusConnection::call_finish to get the result of the operation. See DBusConnection::call_sync for the synchronous version of this function.

If callback is None then the D-Bus method call message will be sent with the DBusMessageFlags::NoReplyExpected flag set.

bus_name

a unique or well-known bus name or None if self is not a message bus connection

object_path

path of remote object

interface_name

D-Bus interface to invoke method on

method_name

the name of the method to invoke

parameters

a glib::Variant tuple with parameters for the method or None if not passing parameters

reply_type

the expected type of the reply (which will be a tuple), or None

flags

flags from the DBusCallFlags enumeration

timeout_msec

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

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied or None if you don't care about the result of the method invocation

user_data

the data to pass to callback

pub fn call_future(
    &self,
    bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    method_name: &str,
    parameters: Option<&Variant>,
    reply_type: Option<&VariantTy>,
    flags: DBusCallFlags,
    timeout_msec: i32
) -> Pin<Box_<dyn Future<Output = Result<Variant, Error>> + 'static>>
[src]

pub fn call_sync<P: IsA<Cancellable>>(
    &self,
    bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    method_name: &str,
    parameters: Option<&Variant>,
    reply_type: Option<&VariantTy>,
    flags: DBusCallFlags,
    timeout_msec: i32,
    cancellable: Option<&P>
) -> Result<Variant, Error>
[src]

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

If self is closed then the operation will fail with IOErrorEnum::Closed. If cancellable is canceled, the operation will fail with IOErrorEnum::Cancelled. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with IOErrorEnum::InvalidArgument.

If reply_type is non-None 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 reply_type then any non-None return value will be of this type.

If the parameters glib::Variant is floating, it is consumed. This allows convenient 'inline' use of glib::Variant::new, e.g.:

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

bus_name

a unique or well-known bus name or None if self is not a message bus connection

object_path

path of remote object

interface_name

D-Bus interface to invoke method on

method_name

the name of the method to invoke

parameters

a glib::Variant tuple with parameters for the method or None if not passing parameters

reply_type

the expected type of the reply, or None

flags

flags from the DBusCallFlags enumeration

timeout_msec

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

cancellable

a Cancellable or None

Returns

None if error is set. Otherwise a glib::Variant tuple with return values. Free with glib::Variant::unref.

pub fn call_with_unix_fd_list<P: IsA<UnixFDList>, Q: IsA<Cancellable>, R: FnOnce(Result<(Variant, UnixFDList), Error>) + Send + 'static>(
    &self,
    bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    method_name: &str,
    parameters: Option<&Variant>,
    reply_type: Option<&VariantTy>,
    flags: DBusCallFlags,
    timeout_msec: i32,
    fd_list: Option<&P>,
    cancellable: Option<&Q>,
    callback: R
)
[src]

Like DBusConnection::call but also takes a UnixFDList object.

This method is only available on UNIX.

bus_name

a unique or well-known bus name or None if self is not a message bus connection

object_path

path of remote object

interface_name

D-Bus interface to invoke method on

method_name

the name of the method to invoke

parameters

a glib::Variant tuple with parameters for the method or None if not passing parameters

reply_type

the expected type of the reply, or None

flags

flags from the DBusCallFlags enumeration

timeout_msec

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

fd_list

a UnixFDList or None

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied or None if you don't * care about the result of the method invocation

user_data

The data to pass to callback.

pub fn call_with_unix_fd_list_future<P: IsA<UnixFDList> + Clone + 'static>(
    &self,
    bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    method_name: &str,
    parameters: Option<&Variant>,
    reply_type: Option<&VariantTy>,
    flags: DBusCallFlags,
    timeout_msec: i32,
    fd_list: Option<&P>
) -> Pin<Box_<dyn Future<Output = Result<(Variant, UnixFDList), Error>> + 'static>>
[src]

pub fn call_with_unix_fd_list_sync<P: IsA<UnixFDList>, Q: IsA<Cancellable>>(
    &self,
    bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    method_name: &str,
    parameters: Option<&Variant>,
    reply_type: Option<&VariantTy>,
    flags: DBusCallFlags,
    timeout_msec: i32,
    fd_list: Option<&P>,
    cancellable: Option<&Q>
) -> Result<(Variant, UnixFDList), Error>
[src]

Like DBusConnection::call_sync but also takes and returns UnixFDList objects.

This method is only available on UNIX.

bus_name

a unique or well-known bus name or None if self is not a message bus connection

object_path

path of remote object

interface_name

D-Bus interface to invoke method on

method_name

the name of the method to invoke

parameters

a glib::Variant tuple with parameters for the method or None if not passing parameters

reply_type

the expected type of the reply, or None

flags

flags from the DBusCallFlags enumeration

timeout_msec

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

fd_list

a UnixFDList or None

out_fd_list

return location for a UnixFDList or None

cancellable

a Cancellable or None

Returns

None if error is set. Otherwise a glib::Variant tuple with return values. Free with glib::Variant::unref.

pub fn close<P: IsA<Cancellable>, Q: FnOnce(Result<(), Error>) + Send + 'static>(
    &self,
    cancellable: Option<&P>,
    callback: Q
)
[src]

Closes self. 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 IOErrorEnum::Closed. Closing a connection will not automatically flush the connection so queued messages may be lost. Use DBusConnection::flush if you need such guarantees.

If self is already closed, this method fails with IOErrorEnum::Closed.

When self has been closed, the DBusConnection::closed signal is emitted in the [thread-default main context][g-main-context-push-thread-default] of the thread that self 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 DBusConnection::close_finish to get the result of the operation. See DBusConnection::close_sync for the synchronous version.

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied or None if you don't care about the result

user_data

The data to pass to callback

pub fn close_future(
    &self
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>
[src]

pub fn close_sync<P: IsA<Cancellable>>(
    &self,
    cancellable: Option<&P>
) -> Result<(), Error>
[src]

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

cancellable

a Cancellable or None

Returns

true if the operation succeeded, false if error is set

pub fn emit_signal(
    &self,
    destination_bus_name: Option<&str>,
    object_path: &str,
    interface_name: &str,
    signal_name: &str,
    parameters: Option<&Variant>
) -> Result<(), Error>
[src]

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 (IOErrorEnum::InvalidArgument), or if self has been closed (IOErrorEnum::Closed).

destination_bus_name

the unique bus name for the destination for the signal or None to emit to all listeners

object_path

path of remote object

interface_name

D-Bus interface to emit a signal on

signal_name

the name of the signal to emit

parameters

a glib::Variant tuple with parameters for the signal or None if not passing parameters

Returns

true unless error is set

pub fn flush<P: IsA<Cancellable>, Q: FnOnce(Result<(), Error>) + Send + 'static>(
    &self,
    cancellable: Option<&P>,
    callback: Q
)
[src]

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

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 DBusConnection::flush_finish to get the result of the operation. See DBusConnection::flush_sync for the synchronous version.

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied or None if you don't care about the result

user_data

The data to pass to callback

pub fn flush_future(
    &self
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>
[src]

pub fn flush_sync<P: IsA<Cancellable>>(
    &self,
    cancellable: Option<&P>
) -> Result<(), Error>
[src]

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

cancellable

a Cancellable or None

Returns

true if the operation succeeded, false if error is set

pub fn get_capabilities(&self) -> DBusCapabilityFlags[src]

Gets the capabilities negotiated with the remote peer

Returns

zero or more flags from the DBusCapabilityFlags enumeration

pub fn get_exit_on_close(&self) -> bool[src]

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

Returns

whether the process is terminated when self is closed by the remote peer

pub fn get_flags(&self) -> DBusConnectionFlags[src]

Gets the flags used to construct this connection

Feature: v2_60

Returns

zero or more flags from the DBusConnectionFlags enumeration

pub fn get_guid(&self) -> Option<GString>[src]

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

Returns

The GUID. Do not free this string, it is owned by self.

pub fn get_last_serial(&self) -> u32[src]

Retrieves the last serial number assigned to a DBusMessage on the current thread. This includes messages sent via both low-level API such as DBusConnection::send_message as well as high-level API such as DBusConnection::emit_signal, DBusConnection::call or DBusProxyExt::call.

Returns

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

pub fn get_peer_credentials(&self) -> Option<Credentials>[src]

Gets the credentials of the authenticated peer. This will always return None unless self acted as a server (e.g. DBusConnectionFlags::AuthenticationServer 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 None for message bus clients.

Returns

a Credentials or None if not available. Do not free this object, it is owned by self.

pub fn get_stream(&self) -> Option<IOStream>[src]

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.

Returns

the stream used for IO

pub fn get_unique_name(&self) -> Option<GString>[src]

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

Returns

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

pub fn is_closed(&self) -> bool[src]

Gets whether self is closed.

Returns

true if the connection is closed, false otherwise

pub fn send_message(
    &self,
    message: &DBusMessage,
    flags: DBusSendMessageFlags
) -> Result<u32, Error>
[src]

Asynchronously sends message to the peer represented by self.

Unless flags contain the DBusSendMessageFlags::PreserveSerial flag, the serial number will be assigned by self and set on message via DBusMessage::set_serial. If out_serial is not None, then the serial number used will be written to this location prior to submitting the message to the underlying transport.

If self is closed then the operation will fail with IOErrorEnum::Closed. If message is not well-formed, the operation fails with IOErrorEnum::InvalidArgument.

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 DBusSendMessageFlags::PreserveSerial flag.

message

a DBusMessage

flags

flags affecting how the message is sent

out_serial

return location for serial number assigned to message when sending it or None

Returns

true if the message was well-formed and queued for transmission, false if error is set

pub fn send_message_with_reply<P: IsA<Cancellable>, Q: FnOnce(Result<DBusMessage, Error>) + Send + 'static>(
    &self,
    message: &DBusMessage,
    flags: DBusSendMessageFlags,
    timeout_msec: i32,
    cancellable: Option<&P>,
    callback: Q
) -> u32
[src]

Asynchronously sends message to the peer represented by self.

Unless flags contain the DBusSendMessageFlags::PreserveSerial flag, the serial number will be assigned by self and set on message via DBusMessage::set_serial. If out_serial is not None, then the serial number used will be written to this location prior to submitting the message to the underlying transport.

If self is closed then the operation will fail with IOErrorEnum::Closed. If cancellable is canceled, the operation will fail with IOErrorEnum::Cancelled. If message is not well-formed, the operation fails with IOErrorEnum::InvalidArgument.

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 DBusConnection::send_message_with_reply_finish to get the result of the operation. See DBusConnection::send_message_with_reply_sync for the synchronous version.

Note that message must be unlocked, unless flags contain the DBusSendMessageFlags::PreserveSerial 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.

message

a DBusMessage

flags

flags affecting how the message is sent

timeout_msec

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

out_serial

return location for serial number assigned to message when sending it or None

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied or None if you don't care about the result

user_data

The data to pass to callback

pub fn send_message_with_reply_future(
    &self,
    message: &DBusMessage,
    flags: DBusSendMessageFlags,
    timeout_msec: i32
) -> Pin<Box_<dyn Future<Output = Result<DBusMessage, Error>> + 'static>>
[src]

pub fn send_message_with_reply_sync<P: IsA<Cancellable>>(
    &self,
    message: &DBusMessage,
    flags: DBusSendMessageFlags,
    timeout_msec: i32,
    cancellable: Option<&P>
) -> Result<(DBusMessage, u32), Error>
[src]

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

Unless flags contain the DBusSendMessageFlags::PreserveSerial flag, the serial number will be assigned by self and set on message via DBusMessage::set_serial. If out_serial is not None, then the serial number used will be written to this location prior to submitting the message to the underlying transport.

If self is closed then the operation will fail with IOErrorEnum::Closed. If cancellable is canceled, the operation will fail with IOErrorEnum::Cancelled. If message is not well-formed, the operation fails with IOErrorEnum::InvalidArgument.

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 DBusMessageType::Error. Use DBusMessage::to_gerror to transcode this to a glib::Error.

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 DBusSendMessageFlags::PreserveSerial flag.

message

a DBusMessage

flags

flags affecting how the message is sent.

timeout_msec

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

out_serial

return location for serial number assigned to message when sending it or None

cancellable

a Cancellable or None

Returns

a locked DBusMessage that is the reply to message or None if error is set

pub fn set_exit_on_close(&self, exit_on_close: bool)[src]

Sets whether the process should be terminated when self 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 exit_on_close to false for the shared session bus connection, you should make sure that your application exits when the user session ends.

exit_on_close

whether the process should be terminated when self is closed by the remote peer

pub fn start_message_processing(&self)[src]

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

pub fn get_property_closed(&self) -> bool[src]

A boolean specifying whether the connection has been closed.

pub fn get_property_flags(&self) -> DBusConnectionFlags[src]

Flags from the DBusConnectionFlags enumeration.

pub fn new<P: IsA<IOStream>, Q: IsA<Cancellable>, R: FnOnce(Result<DBusConnection, Error>) + Send + 'static>(
    stream: &P,
    guid: Option<&str>,
    flags: DBusConnectionFlags,
    observer: Option<&DBusAuthObserver>,
    cancellable: Option<&Q>,
    callback: R
)
[src]

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 gobject::ObjectExt::unref on it.

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

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

This is an asynchronous failable constructor. See DBusConnection::new_sync for the synchronous version.

stream

a IOStream

guid

the GUID to use if authenticating as a server or None

flags

flags describing how to make the connection

observer

a DBusAuthObserver or None

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied

user_data

the data to pass to callback

pub fn new_future<P: IsA<IOStream> + Clone + 'static>(
    stream: &P,
    guid: Option<&str>,
    flags: DBusConnectionFlags,
    observer: Option<&DBusAuthObserver>
) -> Pin<Box_<dyn Future<Output = Result<DBusConnection, Error>> + 'static>>
[src]

pub fn new_for_address<P: IsA<Cancellable>, Q: FnOnce(Result<DBusConnection, Error>) + Send + 'static>(
    address: &str,
    flags: DBusConnectionFlags,
    observer: Option<&DBusAuthObserver>,
    cancellable: Option<&P>,
    callback: Q
)
[src]

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 DBusConnection::new if you need to act as the server. In particular, flags cannot contain the DBusConnectionFlags::AuthenticationServer or DBusConnectionFlags::AuthenticationAllowAnonymous flags.

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

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

This is an asynchronous failable constructor. See DBusConnection::new_for_address_sync for the synchronous version.

address

a D-Bus address

flags

flags describing how to make the connection

observer

a DBusAuthObserver or None

cancellable

a Cancellable or None

callback

a GAsyncReadyCallback to call when the request is satisfied

user_data

the data to pass to callback

pub fn new_for_address_future(
    address: &str,
    flags: DBusConnectionFlags,
    observer: Option<&DBusAuthObserver>
) -> Pin<Box_<dyn Future<Output = Result<DBusConnection, Error>> + 'static>>
[src]

pub fn connect_closed<F: Fn(&DBusConnection, bool, Option<&Error>) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

Emitted when the connection is closed.

The cause of this event can be

  • If DBusConnection::close is called. In this case remote_peer_vanished is set to false and error is None.

  • If the remote peer closes the connection. In this case remote_peer_vanished is set to true and error is set.

  • If the remote peer sends invalid or malformed data. In this case remote_peer_vanished 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.

remote_peer_vanished

true if connection is closed because the remote peer closed its end of the connection

error

a glib::Error with more details about the event or None

pub fn connect_property_capabilities_notify<F: Fn(&DBusConnection) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

pub fn connect_property_closed_notify<F: Fn(&DBusConnection) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

pub fn connect_property_exit_on_close_notify<F: Fn(&DBusConnection) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

pub fn connect_property_unique_name_notify<F: Fn(&DBusConnection) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

Trait Implementations

impl Clone for DBusConnection

impl Debug for DBusConnection

impl Display for DBusConnection[src]

impl Eq for DBusConnection

impl Hash for DBusConnection

impl Ord for DBusConnection

impl<T: ObjectType> PartialEq<T> for DBusConnection

impl<T: ObjectType> PartialOrd<T> for DBusConnection

impl StaticType for DBusConnection

Auto Trait Implementations

impl RefUnwindSafe for DBusConnection

impl !Send for DBusConnection

impl !Sync for DBusConnection

impl Unpin for DBusConnection

impl UnwindSafe for DBusConnection

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.