Function gio::source ·
pub fn bus_own_name<BusAcquired, NameAcquired, NameLost>( bus_type: BusType, name: &str, flags: BusNameOwnerFlags, bus_acquired: BusAcquired, name_acquired: NameAcquired, name_lost: NameLost ) -> OwnerIdwhere BusAcquired: Fn(DBusConnection, &str) + Send + Sync + 'static, NameAcquired: Fn(DBusConnection, &str) + Send + Sync + 'static, NameLost: Fn(Option<DBusConnection>, &str) + Send + Sync + 'static,
name on the bus specified by
bus_type and calls
name_lost_handler when the name is
acquired respectively lost. Callbacks will be invoked in the
[thread-default main context][g-main-context-push-thread-default]
of the thread you are calling this function from.
You are guaranteed that one of the
callbacks will be invoked after calling this function - there are three
Noneconnection (if a connection to the bus can’t be made).
name_lost_handler(if the name can’t be obtained)
name_acquired_handler(if the name was obtained).
When you are done owning the name, just call
with the owner id this function returns.
If the name is acquired or lost (for example another application
could acquire the name if you allow replacement or the application
currently owning the name exits), the handlers are also invoked.
DBusConnection that is used for attempting to own the name
name_lost_handler is invoked since it is no longer
possible for other processes to access the process.
You cannot use
g_bus_own_name() several times for the same name (unless
interleaved with calls to
g_bus_unown_name()) - only the first call
Another guarantee is that invocations of
name_lost_handler are guaranteed to alternate; that
name_acquired_handler is invoked then you are
guaranteed that the next time one of the handlers is invoked, it
name_lost_handler. The reverse is also true.
If you plan on exporting objects (using e.g.
g_dbus_connection_register_object()), note that it is generally too late
to export the objects in
name_acquired_handler. Instead, you can do this
bus_acquired_handler since you are guaranteed that this will run
name is requested from the bus.
This behavior makes it very simple to write applications that wants
to [own names][gdbus-owning-names] and export objects.
Simply register objects to be exported in
unregister the objects (if any) in
the type of bus to own a name on
the well-known name to own
a set of flags from the
handler to invoke when connected to the bus of type
handler to invoke when
name is acquired or
handler to invoke when
name is lost or
an identifier (never 0) that can be used with
g_bus_unown_name() to stop owning the name.