1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::{error::ErrorDomain, translate::*};
use crate::DBusMethodInvocation;
impl DBusMethodInvocation {
/// Finishes handling a D-Bus method call by returning an error.
///
/// See `g_dbus_error_encode_gerror()` for details about what error name
/// will be returned on the wire. In a nutshell, if the given error is
/// registered using `g_dbus_error_register_error()` the name given
/// during registration is used. Otherwise, a name of the form
/// `org.gtk.GDBus.UnmappedGError.Quark...` is used. This provides
/// transparent mapping of [`glib::Error`][crate::glib::Error] between applications using GDBus.
///
/// If you are writing an application intended to be portable,
/// always register errors with `g_dbus_error_register_error()`
/// or use [`return_dbus_error()`][Self::return_dbus_error()].
///
/// This method will take ownership of `self`. See
/// `GDBusInterfaceVTable` for more information about the ownership of
/// `self`.
///
/// Since 2.48, if the method call requested for a reply not to be sent
/// then this call will free `self` but otherwise do nothing (as per
/// the recommendations of the D-Bus specification).
/// ## `domain`
/// A `GQuark` for the [`glib::Error`][crate::glib::Error] error domain.
/// ## `code`
/// The error code.
/// ## `format`
/// `printf()`-style format.
#[doc(alias = "g_dbus_method_invocation_return_error_literal")]
pub fn return_error<T: ErrorDomain>(&self, error: T, message: &str) {
unsafe {
ffi::g_dbus_method_invocation_return_error_literal(
self.to_glib_full(),
T::domain().into_glib(),
error.code(),
message.to_glib_none().0,
);
}
}
/// Like `g_dbus_method_invocation_return_error()` but takes a [`glib::Error`][crate::glib::Error]
/// instead of the error domain, error code and message.
///
/// This method will take ownership of `self`. See
/// `GDBusInterfaceVTable` for more information about the ownership of
/// `self`.
/// ## `error`
/// A [`glib::Error`][crate::glib::Error].
#[doc(alias = "g_dbus_method_invocation_return_gerror")]
pub fn return_gerror(&self, error: glib::Error) {
unsafe {
ffi::g_dbus_method_invocation_return_gerror(
self.to_glib_full(),
error.to_glib_none().0,
);
}
}
}