class Gio::DBusMethodInvocation

Overview

Instances of the #GDBusMethodInvocation class are used when handling D-Bus method calls. It provides a way to asynchronously return results and errors.

The normal way to obtain a #GDBusMethodInvocation object is to receive it as an argument to the handle_method_call() function in a #GDBusInterfaceVTable that was passed to g_dbus_connection_register_object().

Defined in:

lib/gi-crystal/src/auto/gio-2.0/d_bus_method_invocation.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new #

Initialize a new DBusMethodInvocation.


Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def connection : Gio::DBusConnection #

Gets the #GDBusConnection the method was invoked on.


def interface_name : String #

Gets the name of the D-Bus interface the method was invoked on.

If this method call is a property Get, Set or GetAll call that has been redirected to the method call handler then "org.freedesktop.DBus.Properties" will be returned. See #GDBusInterfaceVTable for more information.


def message : Gio::DBusMessage #

Gets the #GDBusMessage for the method invocation. This is useful if you need to use low-level protocol features, such as UNIX file descriptor passing, that cannot be properly expressed in the #GVariant API.

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.


def method_info : Gio::DBusMethodInfo? #

Gets information about the method call, if any.

If this method invocation is a property Get, Set or GetAll call that has been redirected to the method call handler then nil will be returned. See g_dbus_method_invocation_get_property_info() and #GDBusInterfaceVTable for more information.


def method_name : String #

Gets the name of the method that was invoked.


def object_path : String #

Gets the object path the method was invoked on.


def parameters : GLib::Variant #

Gets the parameters of the method invocation. If there are no input parameters then this will return a GVariant with 0 children rather than NULL.


def property_info : Gio::DBusPropertyInfo? #

Gets information about the property that this method call is for, if any.

This will only be set in the case of an invocation in response to a property Get or Set call that has been directed to the method call handler for an object on account of its property_get() or property_set() vtable pointers being unset.

See #GDBusInterfaceVTable for more information.

If the call was GetAll, nil will be returned.


def return_dbus_error(error_name : String, error_message : String) : Nil #

Finishes handling a D-Bus method call by returning an error.

This method will take ownership of @invocation. See #GDBusInterfaceVTable for more information about the ownership of @invocation.


def return_error_literal(domain : UInt32, code : Int32, message : String) : Nil #

Like g_dbus_method_invocation_return_error() but without printf()-style formatting.

This method will take ownership of @invocation. See #GDBusInterfaceVTable for more information about the ownership of @invocation.


def return_gerror(error : GLib::Error) : Nil #

Like g_dbus_method_invocation_return_error() but takes a #GError instead of the error domain, error code and message.

This method will take ownership of @invocation. See #GDBusInterfaceVTable for more information about the ownership of @invocation.


def return_value(parameters : _?) : Nil #

Finishes handling a D-Bus method call by returning @parameters. If the @parameters GVariant is floating, it is consumed.

It is an error if @parameters is not of the right format: it must be a tuple containing the out-parameters of the D-Bus method. Even if the method has a single out-parameter, it must be contained in a tuple. If the method has no out-parameters, @parameters may be nil or an empty tuple.

|[ GDBusMethodInvocation *invocation = some_invocation; g_autofree gchar *result_string = NULL; g_autoptr (GError) error = NULL;

result_string = calculate_result (&error);

if (error != NULL) g_dbus_method_invocation_return_gerror (invocation, error); else g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", result_string));

// Do not free @invocation here; returning a value does that ]|

This method will take ownership of @invocation. See #GDBusInterfaceVTable for more information about the ownership of @invocation.

Since 2.48, if the method call requested for a reply not to be sent then this call will sink @parameters and free @invocation, but otherwise do nothing (as per the recommendations of the D-Bus specification).


def return_value_with_unix_fd_list(parameters : _?, fd_list : Gio::UnixFDList?) : Nil #

Like g_dbus_method_invocation_return_value() but also takes a #GUnixFDList.

This method is only available on UNIX.

This method will take ownership of @invocation. See #GDBusInterfaceVTable for more information about the ownership of @invocation.


def sender : String #

Gets the bus name that invoked the method.