/* GDBus - GLib D-Bus Library
*
- * Copyright (C) 2008-2009 Red Hat, Inc.
+ * Copyright (C) 2008-2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#include "gdbuserror.h"
#include "gdbusprivate.h"
+#ifdef G_OS_UNIX
+#include "gunixfdlist.h"
+#endif
+
#include "glibintl.h"
-#include "gioalias.h"
/**
* SECTION:gdbusmethodinvocation
* 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().
*/
-struct _GDBusMethodInvocationPrivate
+typedef struct _GDBusMethodInvocationClass GDBusMethodInvocationClass;
+
+/**
+ * GDBusMethodInvocationClass:
+ *
+ * Class structure for #GDBusMethodInvocation.
+ *
+ * Since: 2.26
+ */
+struct _GDBusMethodInvocationClass
{
+ /*< private >*/
+ GObjectClass parent_class;
+};
+
+/**
+ * GDBusMethodInvocation:
+ *
+ * The #GDBusMethodInvocation structure contains only private data and
+ * should only be accessed using the provided API.
+ *
+ * Since: 2.26
+ */
+struct _GDBusMethodInvocation
+{
+ /*< private >*/
+ GObject parent_instance;
+
/* construct-only properties */
gchar *sender;
gchar *object_path;
gchar *interface_name;
gchar *method_name;
- const GDBusMethodInfo *method_info;
+ GDBusMethodInfo *method_info;
+ GDBusPropertyInfo *property_info;
GDBusConnection *connection;
GDBusMessage *message;
GVariant *parameters;
gpointer user_data;
};
-enum
-{
- PROP_0,
- PROP_SENDER,
- PROP_OBJECT_PATH,
- PROP_INTERFACE_NAME,
- PROP_METHOD_NAME,
- PROP_METHOD_INFO,
- PROP_CONNECTION,
- PROP_PARAMETERS,
- PROP_MESSAGE,
- PROP_USER_DATA
-};
-
G_DEFINE_TYPE (GDBusMethodInvocation, g_dbus_method_invocation, G_TYPE_OBJECT);
static void
{
GDBusMethodInvocation *invocation = G_DBUS_METHOD_INVOCATION (object);
- g_free (invocation->priv->sender);
- g_free (invocation->priv->object_path);
- g_free (invocation->priv->interface_name);
- g_free (invocation->priv->method_name);
- g_object_unref (invocation->priv->connection);
- g_object_unref (invocation->priv->message);
- g_variant_unref (invocation->priv->parameters);
-
- if (G_OBJECT_CLASS (g_dbus_method_invocation_parent_class)->finalize != NULL)
- G_OBJECT_CLASS (g_dbus_method_invocation_parent_class)->finalize (object);
-}
-
-static void
-g_dbus_method_invocation_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GDBusMethodInvocation *invocation = G_DBUS_METHOD_INVOCATION (object);
-
- switch (prop_id)
- {
- case PROP_SENDER:
- g_value_set_string (value, g_dbus_method_invocation_get_sender (invocation));
- break;
-
- case PROP_OBJECT_PATH:
- g_value_set_string (value, g_dbus_method_invocation_get_object_path (invocation));
- break;
-
- case PROP_INTERFACE_NAME:
- g_value_set_string (value, g_dbus_method_invocation_get_interface_name (invocation));
- break;
-
- case PROP_METHOD_NAME:
- g_value_set_string (value, g_dbus_method_invocation_get_method_name (invocation));
- break;
-
- case PROP_METHOD_INFO:
- g_value_set_boxed (value, g_dbus_method_invocation_get_method_info (invocation));
- break;
-
- case PROP_CONNECTION:
- g_value_set_object (value, g_dbus_method_invocation_get_connection (invocation));
- break;
-
- case PROP_PARAMETERS:
- g_value_set_boxed (value, g_dbus_method_invocation_get_parameters (invocation));
- break;
-
- case PROP_MESSAGE:
- g_value_set_object (value, g_dbus_method_invocation_get_message (invocation));
- break;
-
- case PROP_USER_DATA:
- g_value_set_pointer (value, g_dbus_method_invocation_get_user_data (invocation));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-g_dbus_method_invocation_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GDBusMethodInvocation *invocation = G_DBUS_METHOD_INVOCATION (object);
-
- switch (prop_id)
- {
- case PROP_SENDER:
- invocation->priv->sender = g_value_dup_string (value);
- break;
-
- case PROP_OBJECT_PATH:
- invocation->priv->object_path = g_value_dup_string (value);
- break;
-
- case PROP_INTERFACE_NAME:
- invocation->priv->interface_name = g_value_dup_string (value);
- break;
-
- case PROP_METHOD_NAME:
- invocation->priv->method_name = g_value_dup_string (value);
- break;
-
- case PROP_METHOD_INFO:
- invocation->priv->method_info = g_value_dup_boxed (value);
- break;
-
- case PROP_CONNECTION:
- invocation->priv->connection = g_value_dup_object (value);
- break;
-
- case PROP_PARAMETERS:
- invocation->priv->parameters = g_value_dup_boxed (value);
- break;
-
- case PROP_MESSAGE:
- invocation->priv->message = g_value_dup_object (value);
- break;
-
- case PROP_USER_DATA:
- invocation->priv->user_data = g_value_get_pointer (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ g_free (invocation->sender);
+ g_free (invocation->object_path);
+ g_free (invocation->interface_name);
+ g_free (invocation->method_name);
+ if (invocation->method_info)
+ g_dbus_method_info_unref (invocation->method_info);
+ g_object_unref (invocation->connection);
+ g_object_unref (invocation->message);
+ g_variant_unref (invocation->parameters);
+
+ G_OBJECT_CLASS (g_dbus_method_invocation_parent_class)->finalize (object);
}
-
static void
g_dbus_method_invocation_class_init (GDBusMethodInvocationClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->finalize = g_dbus_method_invocation_finalize;
- gobject_class->set_property = g_dbus_method_invocation_set_property;
- gobject_class->get_property = g_dbus_method_invocation_get_property;
-
- /**
- * GDBusMethodInvocation:sender:
- *
- * The bus name that invoked the method or %NULL if the connection is not a bus connection.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_SENDER,
- g_param_spec_string ("sender",
- _("Sender"),
- _("The bus name that invoked the method."),
- NULL,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:object-path:
- *
- * The object path the method was invoked on.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_OBJECT_PATH,
- g_param_spec_string ("object-path",
- _("Object Path"),
- _("The object path the method was invoked on."),
- NULL,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:interface-name:
- *
- * The name of the D-Bus interface the method was invoked on.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_INTERFACE_NAME,
- g_param_spec_string ("interface-name",
- _("Interface Name"),
- _("The name of the D-Bus interface the method was invoked on."),
- NULL,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:method-name:
- *
- * The name of the method that was invoked.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_METHOD_NAME,
- g_param_spec_string ("method-name",
- _("Method Name"),
- _("The name of the method that was invoked."),
- NULL,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:method-info:
- *
- * Information about the method that was invoked, if any.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_METHOD_INFO,
- g_param_spec_boxed ("method-info",
- _("Method Info"),
- _("Information about the method that was invoked, if any."),
- G_TYPE_DBUS_METHOD_INFO,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:connection:
- *
- * The #GDBusConnection the method was invoked on.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_CONNECTION,
- g_param_spec_object ("connection",
- _("Connection"),
- _("The #GDBusConnection the method was invoked on."),
- G_TYPE_DBUS_CONNECTION,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:message:
- *
- * The D-Bus message.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_MESSAGE,
- g_param_spec_object ("message",
- _("Message"),
- _("The D-Bus Message."),
- G_TYPE_DBUS_MESSAGE,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:parameters:
- *
- * The parameters as a #GVariant tuple.
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_PARAMETERS,
- g_param_spec_boxed ("parameters",
- _("Parameters"),
- _("The parameters as a #GVariant tuple."),
- G_TYPE_VARIANT,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * GDBusMethodInvocation:user-data:
- *
- * The @user_data #gpointer passed to g_dbus_connection_register_object().
- *
- * Since: 2.26
- */
- g_object_class_install_property (gobject_class,
- PROP_USER_DATA,
- g_param_spec_pointer ("user-data",
- _("User Data"),
- _("The gpointer passed to g_dbus_connection_register_object()."),
- G_PARAM_READABLE |
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- g_type_class_add_private (klass, sizeof (GDBusMethodInvocationPrivate));
+ gobject_class->finalize = g_dbus_method_invocation_finalize;
}
static void
g_dbus_method_invocation_init (GDBusMethodInvocation *invocation)
{
- invocation->priv = G_TYPE_INSTANCE_GET_PRIVATE (invocation,
- G_TYPE_DBUS_METHOD_INVOCATION,
- GDBusMethodInvocationPrivate);
}
/**
g_dbus_method_invocation_get_sender (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->sender;
+ return invocation->sender;
}
/**
g_dbus_method_invocation_get_object_path (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->object_path;
+ return invocation->object_path;
}
/**
*
* 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.
+ *
* Returns: A string. Do not free, it is owned by @invocation.
*
* Since: 2.26
g_dbus_method_invocation_get_interface_name (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->interface_name;
+ return invocation->interface_name;
}
/**
*
* 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 %NULL will be
+ * returned. See g_dbus_method_invocation_get_property_info() and
+ * #GDBusInterfaceVTable for more information.
+ *
* Returns: A #GDBusMethodInfo or %NULL. Do not free, it is owned by @invocation.
*
* Since: 2.26
g_dbus_method_invocation_get_method_info (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->method_info;
+ return invocation->method_info;
+}
+
+/**
+ * g_dbus_method_invocation_get_property_info:
+ * @invocation: A #GDBusMethodInvocation
+ *
+ * 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, %NULL will be returned.
+ *
+ * Returns: (transfer none): a #GDBusPropertyInfo or %NULL
+ *
+ * Since: 2.38
+ */
+const GDBusPropertyInfo *
+g_dbus_method_invocation_get_property_info (GDBusMethodInvocation *invocation)
+{
+ g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
+ return invocation->property_info;
}
/**
g_dbus_method_invocation_get_method_name (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->method_name;
+ return invocation->method_name;
}
/**
*
* Gets the #GDBusConnection the method was invoked on.
*
- * Returns: A #GDBusConnection. Do not free, it is owned by @invocation.
+ * Returns: (transfer none):A #GDBusConnection. Do not free, it is owned by @invocation.
*
* Since: 2.26
*/
g_dbus_method_invocation_get_connection (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->connection;
+ return invocation->connection;
}
/**
* descriptor passing, that cannot be properly expressed in the
* #GVariant API.
*
- * See <xref linkend="gdbus-server"/> and <xref
- * linkend="gdbus-unix-fd-client"/> for an example of how to use this
- * low-level API to send and receive UNIX file descriptors.
+ * 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.
*
- * Returns: A #GDBusMessage. Do not free, it is owned by @invocation.
+ * Returns: (transfer none): #GDBusMessage. Do not free, it is owned by @invocation.
*
* Since: 2.26
*/
g_dbus_method_invocation_get_message (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->message;
+ return invocation->message;
}
/**
* g_dbus_method_invocation_get_parameters:
* @invocation: A #GDBusMethodInvocation.
*
- * Gets the parameters of the method invocation.
+ * 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.
*
- * Returns: A #GVariant. Do not free, it is owned by @invocation.
+ * Returns: (transfer none): A #GVariant tuple. Do not unref this because it is owned by @invocation.
*
* Since: 2.26
*/
g_dbus_method_invocation_get_parameters (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->parameters;
+ return invocation->parameters;
}
/**
- * g_dbus_method_invocation_get_user_data:
+ * g_dbus_method_invocation_get_user_data: (skip)
* @invocation: A #GDBusMethodInvocation.
*
* Gets the @user_data #gpointer passed to g_dbus_connection_register_object().
g_dbus_method_invocation_get_user_data (GDBusMethodInvocation *invocation)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
- return invocation->priv->user_data;
+ return invocation->user_data;
}
-/**
- * g_dbus_method_invocation_new:
- * @sender: The bus name that invoked the method or %NULL if @connection is not a bus connection.
+/* < internal >
+ * _g_dbus_method_invocation_new:
+ * @sender: (allow-none): The bus name that invoked the method or %NULL if @connection is not a bus connection.
* @object_path: The object path the method was invoked on.
* @interface_name: The name of the D-Bus interface the method was invoked on.
* @method_name: The name of the method that was invoked.
- * @method_info: Information about the method call or %NULL.
+ * @method_info: (allow-none): Information about the method call or %NULL.
+ * @property_info: (allow-none): Information about the property or %NULL.
* @connection: The #GDBusConnection the method was invoked on.
* @message: The D-Bus message as a #GDBusMessage.
* @parameters: The parameters as a #GVariant tuple.
* Since: 2.26
*/
GDBusMethodInvocation *
-g_dbus_method_invocation_new (const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- const GDBusMethodInfo *method_info,
- GDBusConnection *connection,
- GDBusMessage *message,
- GVariant *parameters,
- gpointer user_data)
+_g_dbus_method_invocation_new (const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ const GDBusMethodInfo *method_info,
+ const GDBusPropertyInfo *property_info,
+ GDBusConnection *connection,
+ GDBusMessage *message,
+ GVariant *parameters,
+ gpointer user_data)
{
+ GDBusMethodInvocation *invocation;
+
g_return_val_if_fail (sender == NULL || g_dbus_is_name (sender), NULL);
g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
g_return_val_if_fail (interface_name == NULL || g_dbus_is_interface_name (interface_name), NULL);
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
g_return_val_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);
- return G_DBUS_METHOD_INVOCATION (g_object_new (G_TYPE_DBUS_METHOD_INVOCATION,
- "sender", sender,
- "object-path", object_path,
- "interface-name", interface_name,
- "method-name", method_name,
- "method-info", method_info,
- "connection", connection,
- "message", message,
- "parameters", parameters,
- "user-data", user_data,
- NULL));
+ invocation = G_DBUS_METHOD_INVOCATION (g_object_new (G_TYPE_DBUS_METHOD_INVOCATION, NULL));
+ invocation->sender = g_strdup (sender);
+ invocation->object_path = g_strdup (object_path);
+ invocation->interface_name = g_strdup (interface_name);
+ invocation->method_name = g_strdup (method_name);
+ if (method_info)
+ invocation->method_info = g_dbus_method_info_ref ((GDBusMethodInfo *)method_info);
+ if (property_info)
+ invocation->property_info = g_dbus_property_info_ref ((GDBusPropertyInfo *)property_info);
+ invocation->connection = g_object_ref (connection);
+ invocation->message = g_object_ref (message);
+ invocation->parameters = g_variant_ref (parameters);
+ invocation->user_data = user_data;
+
+ return invocation;
}
/* ---------------------------------------------------------------------------------------------------- */
-/**
- * g_dbus_method_invocation_return_value:
- * @invocation: A #GDBusMethodInvocation.
- * @parameters: A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters.
- *
- * Finishes handling a D-Bus method call by returning @parameters.
- *
- * It is an error if @parameters is not of the right format.
- *
- * This method will free @invocation, you cannot use it afterwards.
- *
- * Since: 2.26
- */
-void
-g_dbus_method_invocation_return_value (GDBusMethodInvocation *invocation,
- GVariant *parameters)
+static void
+g_dbus_method_invocation_return_value_internal (GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ GUnixFDList *fd_list)
{
GDBusMessage *reply;
GError *error;
g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation));
g_return_if_fail ((parameters == NULL) || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE));
- if (parameters != NULL)
- g_variant_ref_sink (parameters);
+ if (parameters == NULL)
+ parameters = g_variant_new_tuple (NULL, 0);
/* if we have introspection data, check that the signature of @parameters is correct */
- if (invocation->priv->method_info != NULL)
+ if (invocation->method_info != NULL)
{
- gchar *signature;
- const gchar *type_string;
+ GVariantType *type;
- type_string = "()";
- if (parameters != NULL)
- type_string = g_variant_get_type_string (parameters);
- signature = _g_dbus_compute_complete_signature (invocation->priv->method_info->out_args, TRUE);
+ type = _g_dbus_compute_complete_signature (invocation->method_info->out_args);
- if (g_strcmp0 (type_string, signature) != 0)
+ if (!g_variant_is_of_type (parameters, type))
{
- g_warning (_("Type of return value is incorrect, got `%s', expected `%s'"),
- type_string,
- signature);
- g_free (signature);
+ gchar *type_string = g_variant_type_dup_string (type);
+
+ g_warning ("Type of return value is incorrect: expected '%s', got '%s''",
+ type_string, g_variant_get_type_string (parameters));
+ g_variant_type_free (type);
+ g_free (type_string);
goto out;
}
- g_free (signature);
+ g_variant_type_free (type);
+ }
+
+ /* property_info is only non-NULL if set that way from
+ * GDBusConnection, so this must be the case of async property
+ * handling on either 'Get', 'Set' or 'GetAll'.
+ */
+ if (invocation->property_info != NULL)
+ {
+ if (g_str_equal (invocation->method_name, "Get"))
+ {
+ GVariant *nested;
+
+ if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(v)")))
+ {
+ g_warning ("Type of return value for property 'Get' call should be '(v)' but got '%s'",
+ g_variant_get_type_string (parameters));
+ goto out;
+ }
+
+ /* Go deeper and make sure that the value inside of the
+ * variant matches the property type.
+ */
+ g_variant_get (parameters, "(v)", &nested);
+ if (!g_str_equal (g_variant_get_type_string (nested), invocation->property_info->signature))
+ {
+ g_warning ("Value returned from property 'Get' call for '%s' should be '%s' but is '%s'",
+ invocation->property_info->name, invocation->property_info->signature,
+ g_variant_get_type_string (nested));
+ g_variant_unref (nested);
+ goto out;
+ }
+ g_variant_unref (nested);
+ }
+
+ else if (g_str_equal (invocation->method_name, "GetAll"))
+ {
+ if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})")))
+ {
+ g_warning ("Type of return value for property 'GetAll' call should be '(a{sv})' but got '%s'",
+ g_variant_get_type_string (parameters));
+ goto out;
+ }
+
+ /* Could iterate the list of properties and make sure that all
+ * of them are actually on the interface and with the correct
+ * types, but let's not do that for now...
+ */
+ }
+
+ else if (g_str_equal (invocation->method_name, "Set"))
+ {
+ if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE_UNIT))
+ {
+ g_warning ("Type of return value for property 'Set' call should be '()' but got '%s'",
+ g_variant_get_type_string (parameters));
+ goto out;
+ }
+ }
+
+ else
+ g_assert_not_reached ();
}
- reply = g_dbus_message_new_method_reply (invocation->priv->message);
+ if (G_UNLIKELY (_g_dbus_debug_return ()))
+ {
+ _g_dbus_debug_print_lock ();
+ g_print ("========================================================================\n"
+ "GDBus-debug:Return:\n"
+ " >>>> METHOD RETURN\n"
+ " in response to %s.%s()\n"
+ " on object %s\n"
+ " to name %s\n"
+ " reply-serial %d\n",
+ invocation->interface_name, invocation->method_name,
+ invocation->object_path,
+ invocation->sender,
+ g_dbus_message_get_serial (invocation->message));
+ _g_dbus_debug_print_unlock ();
+ }
+
+ reply = g_dbus_message_new_method_reply (invocation->message);
g_dbus_message_set_body (reply, parameters);
+
+#ifdef G_OS_UNIX
+ if (fd_list != NULL)
+ g_dbus_message_set_unix_fd_list (reply, fd_list);
+#endif
+
error = NULL;
- if (!g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, NULL, &error))
+ if (!g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error))
{
- g_warning (_("Error sending message: %s"), error->message);
+ g_warning ("Error sending message: %s", error->message);
g_error_free (error);
}
g_object_unref (reply);
out:
g_object_unref (invocation);
- if (parameters != NULL)
- g_variant_unref (parameters);
}
+/**
+ * g_dbus_method_invocation_return_value:
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
+ * @parameters: (allow-none): A #GVariant tuple with out parameters for the method or %NULL if not passing any 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.
+ *
+ * This method will free @invocation, you cannot use it afterwards.
+ *
+ * Since: 2.26
+ */
+void
+g_dbus_method_invocation_return_value (GDBusMethodInvocation *invocation,
+ GVariant *parameters)
+{
+ g_dbus_method_invocation_return_value_internal (invocation, parameters, NULL);
+}
+
+#ifdef G_OS_UNIX
+/**
+ * g_dbus_method_invocation_return_value_with_unix_fd_list:
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
+ * @parameters: (allow-none): A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters.
+ * @fd_list: (allow-none): A #GUnixFDList or %NULL.
+ *
+ * Like g_dbus_method_invocation_return_value() but also takes a #GUnixFDList.
+ *
+ * This method is only available on UNIX.
+ *
+ * This method will free @invocation, you cannot use it afterwards.
+ *
+ * Since: 2.30
+ */
+void
+g_dbus_method_invocation_return_value_with_unix_fd_list (GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ GUnixFDList *fd_list)
+{
+ g_dbus_method_invocation_return_value_internal (invocation, parameters, fd_list);
+}
+#endif
+
/* ---------------------------------------------------------------------------------------------------- */
/**
* g_dbus_method_invocation_return_error:
- * @invocation: A #GDBusMethodInvocation.
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
* @domain: A #GQuark for the #GError error domain.
* @code: The error code.
* @format: printf()-style format.
* 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
- * <literal>org.gtk.GDBus.UnmappedGError.Quark...</literal> is
- * used. This provides transparent mapping of #GError between
- * applications using GDBus.
+ * `org.gtk.GDBus.UnmappedGError.Quark...` is used. This provides
+ * transparent mapping of #GError between applications using GDBus.
*
* If you are writing an application intended to be portable,
- * <emphasis>always</emphasis> register errors with g_dbus_error_register_error()
+ * always register errors with g_dbus_error_register_error()
* or use g_dbus_method_invocation_return_dbus_error().
*
* This method will free @invocation, you cannot use it afterwards.
/**
* g_dbus_method_invocation_return_error_valist:
- * @invocation: A #GDBusMethodInvocation.
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
* @domain: A #GQuark for the #GError error domain.
* @code: The error code.
* @format: printf()-style format.
/**
* g_dbus_method_invocation_return_error_literal:
- * @invocation: A #GDBusMethodInvocation.
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
* @domain: A #GQuark for the #GError error domain.
* @code: The error code.
* @message: The error message.
/**
* g_dbus_method_invocation_return_gerror:
- * @invocation: A #GDBusMethodInvocation.
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
* @error: A #GError.
*
* Like g_dbus_method_invocation_return_error() but takes a #GError
}
/**
+ * g_dbus_method_invocation_take_error: (skip)
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
+ * @error: (transfer full): A #GError.
+ *
+ * Like g_dbus_method_invocation_return_gerror() but takes ownership
+ * of @error so the caller does not need to free it.
+ *
+ * This method will free @invocation, you cannot use it afterwards.
+ *
+ * Since: 2.30
+ */
+void
+g_dbus_method_invocation_take_error (GDBusMethodInvocation *invocation,
+ GError *error)
+{
+ g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation));
+ g_return_if_fail (error != NULL);
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+}
+
+/**
* g_dbus_method_invocation_return_dbus_error:
- * @invocation: A #GDBusMethodInvocation.
+ * @invocation: (transfer full): A #GDBusMethodInvocation.
* @error_name: A valid D-Bus error name.
* @error_message: A valid D-Bus error message.
*
g_return_if_fail (error_name != NULL && g_dbus_is_name (error_name));
g_return_if_fail (error_message != NULL);
- reply = g_dbus_message_new_method_error_literal (invocation->priv->message,
+ if (G_UNLIKELY (_g_dbus_debug_return ()))
+ {
+ _g_dbus_debug_print_lock ();
+ g_print ("========================================================================\n"
+ "GDBus-debug:Return:\n"
+ " >>>> METHOD ERROR %s\n"
+ " message '%s'\n"
+ " in response to %s.%s()\n"
+ " on object %s\n"
+ " to name %s\n"
+ " reply-serial %d\n",
+ error_name,
+ error_message,
+ invocation->interface_name, invocation->method_name,
+ invocation->object_path,
+ invocation->sender,
+ g_dbus_message_get_serial (invocation->message));
+ _g_dbus_debug_print_unlock ();
+ }
+
+ reply = g_dbus_message_new_method_error_literal (invocation->message,
error_name,
error_message);
- g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, NULL, NULL);
+ g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
g_object_unref (invocation);
}
-
-#define __G_DBUS_METHOD_INVOCATION_C__
-#include "gioaliasdef.c"