1.19 <GDBusMethodInvocation>

Class: <GDBusMethodInvocation>

It derives from <GObject>.

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 dbus-connection:register-object.

Procedures

Method: dbus-method-invocation:get-connection self ⇒ %return
Method: get-connection self ⇒ %return

Gets the <GDBusConnection> the method was invoked on.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a <GDBusConnection>.

A <GDBusConnection>. Do not free, it is owned by self.

Method: dbus-method-invocation:get-interface-name self ⇒ %return
Method: get-interface-name self ⇒ %return

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

This can be NULL if it was not specified by the sender. See GDBusInterfaceMethodCallFunc or the D-Bus Specification for details on when this can happen and how it should be handled.

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.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a string, or #f.

A string. Do not free, it is owned by self.

Method: dbus-method-invocation:get-message self ⇒ %return
Method: get-message self ⇒ %return

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][class@Gio.DBusConnection#an-example-d-bus-server] and [client][class@Gio.DBusConnection#an-example-for-file-descriptor-passing] for an example of how to use this low-level API to send and receive UNIX file descriptors.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a <GDBusMessage>.

<GDBusMessage>. Do not free, it is owned by self.

Method: dbus-method-invocation:get-method-info self ⇒ %return
Method: get-method-info self ⇒ %return

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 #f will be returned. See dbus-method-invocation:get-property-info and GDBusInterfaceVTable for more information.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a <GDBusMethodInfo>, or #f.

A <GDBusMethodInfo> or #f. Do not free, it is owned by self.

Method: dbus-method-invocation:get-method-name self ⇒ %return
Method: get-method-name self ⇒ %return

Gets the name of the method that was invoked.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a string.

A string. Do not free, it is owned by self.

Method: dbus-method-invocation:get-object-path self ⇒ %return
Method: get-object-path self ⇒ %return

Gets the object path the method was invoked on.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a string.

A string. Do not free, it is owned by self.

Method: dbus-method-invocation:get-parameters self ⇒ %return
Method: get-parameters self ⇒ %return

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.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a <GVariant>.

A <GVariant> tuple. Do not unref this because it is owned by self.

Method: dbus-method-invocation:get-property-info self ⇒ %return
Method: get-property-info self ⇒ %return

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, #f will be returned.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>

%return

Returned: a <GDBusPropertyInfo>, or #f.

a <GDBusPropertyInfo> or #f

Method: dbus-method-invocation:get-sender self ⇒ %return
Method: get-sender self ⇒ %return

Gets the bus name that invoked the method.

This can return #f if not specified by the caller, e.g. on peer-to-peer connections.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

%return

Returned: a string, or #f.

A string. Do not free, it is owned by self.

Method: dbus-method-invocation:return-dbus-error self error-name error-message
Method: return-dbus-error self error-name error-message

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

This method will take ownership of self. See GDBusInterfaceVTable for more information about the ownership of self.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

error-name

Passed: a string.

A valid D-Bus error name.

error-message

Passed: a string.

A valid D-Bus error message.

Method: dbus-method-invocation:return-error-literal self domain code message
Method: return-error-literal self domain code message

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

This method will take ownership of self. See GDBusInterfaceVTable for more information about the ownership of self.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

domain

Passed: an unsigned 32-bit integer.

A GQuark for the <GError> error domain.

code

Passed: a 32-bit integer.

The error code.

message

Passed: a string.

The error message.

Method: dbus-method-invocation:return-gerror self error
Method: return-gerror self error

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 self. See GDBusInterfaceVTable for more information about the ownership of self.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

error

Passed: a <GError>.

A <GError>.

Method: dbus-method-invocation:return-value self [parameters]
Method: return-value self [parameters]

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 #f 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 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 sink parameters and free self, but otherwise do nothing (as per the recommendations of the D-Bus specification).

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

parameters

Passed, or left out: a <GVariant>, or #f.

A <GVariant> tuple with out parameters for the method or #f if not passing any parameters.

Method: dbus-method-invocation:return-value-with-unix-fd-list self [parameters] [fd-list]
Method: return-value-with-unix-fd-list self [parameters] [fd-list]

Like dbus-method-invocation:return-value but also takes a <GUnixFDList>.

This method is only available on UNIX.

This method will take ownership of self. See GDBusInterfaceVTable for more information about the ownership of self.

self

Passed: a <GDBusMethodInvocation>.

A <GDBusMethodInvocation>.

parameters

Passed, or left out: a <GVariant>, or #f.

A <GVariant> tuple with out parameters for the method or #f if not passing any parameters.

fd-list

Passed, or left out: a <GUnixFDList>, or #f.

A <GUnixFDList> or #f.