GDBus: Make message serialization routines take capabilities param
[platform/upstream/glib.git] / gio / gdbusconnection.c
index 4921e97..80ae8b6 100644 (file)
@@ -33,9 +33,7 @@
  * - Need to rewrite GDBusAuth and rework GDBusAuthMechanism. In particular
  *   the mechanism VFuncs need to be able to set an error.
  *
- * - Need to document usage of DBUS_SYSTEM_ADDRESS and
- *   DBUS_SESSION_BUS_ADDRESS environment variables. Also need to
- *   document other mechanisms/sources for determining the D-Bus
+ * - Need to document other mechanisms/sources for determining the D-Bus
  *   address of a well-known bus.
  *
  *   - e.g. on Win32 we need code like from here
  *  - Mention in all API that the GVariant is sunk. Also mention
  *    when the returned GVariant is floating.
  *
- *  - Small example snippet for each method where useful (won't
- *    have to compile) where it makes sense (e.g. connetion_call()
- *    and using a floating GVariant).
- *
  *  - Consistent timeout handling (25s vs 30s?)
  *
- *  - GDBusProxy subclass example
- *
- *  - Update GDBusAuthObserver (is_same_user(), s/deny/authorize/)
- *
- *  - Remove properties on GDBusMethodInvocation
- *
+ *  - Update GDBusAuthObserver (s/deny/authorize/)
  */
 
 #include "config.h"
  * <example id="gdbus-subtree-server"><title>D-Bus subtree example</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gdbus-example-subtree.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
  *
  * <example id="gdbus-unix-fd-client"><title>D-Bus UNIX File Descriptor example</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gdbus-example-unix-fd-client.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
+ *
+ * <example id="gdbus-export"><title>Exporting a GObject</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gdbus-example-export.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
  */
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -1018,6 +1009,7 @@ g_dbus_connection_send_message_unlocked (GDBusConnection   *connection,
 
   blob = g_dbus_message_to_blob (message,
                                  &blob_size,
+                                 connection->priv->capabilities,
                                  error);
   if (blob == NULL)
     goto out;
@@ -1435,6 +1427,7 @@ g_dbus_connection_send_message_with_reply (GDBusConnection     *connection,
 
 /**
  * g_dbus_connection_send_message_with_reply_finish:
+ * @connection: a #GDBusConnection
  * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_connection_send_message_with_reply().
  * @error: Return location for error or %NULL.
  *
@@ -1949,7 +1942,7 @@ async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
  * @stream: A #GIOStream.
  * @guid: The GUID to use if a authenticating as a server or %NULL.
  * @flags: Flags describing how to make the connection.
- * @authentication_observer: A #GDBusAuthObserver or %NULL.
+ * @observer: A #GDBusAuthObserver or %NULL.
  * @cancellable: A #GCancellable or %NULL.
  * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
  * @user_data: The data to pass to @callback.
@@ -1958,7 +1951,7 @@ async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
  * with the end represented by @stream.
  *
  * If %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER is set in @flags,
- * @auth_observer (if not %NULL) is used to assist in the client
+ * @observer (if not %NULL) is used to assist in the client
  * authentication process.
  *
  * When the operation is finished, @callback will be invoked. You can
@@ -1975,7 +1968,7 @@ void
 g_dbus_connection_new (GIOStream            *stream,
                        const gchar          *guid,
                        GDBusConnectionFlags  flags,
-                       GDBusAuthObserver    *authentication_observer,
+                       GDBusAuthObserver    *observer,
                        GCancellable         *cancellable,
                        GAsyncReadyCallback   callback,
                        gpointer              user_data)
@@ -1989,7 +1982,7 @@ g_dbus_connection_new (GIOStream            *stream,
                               "stream", stream,
                               "guid", guid,
                               "flags", flags,
-                              "authentication-observer", authentication_observer,
+                              "authentication-observer", observer,
                               NULL);
 }
 
@@ -2031,7 +2024,7 @@ g_dbus_connection_new_finish (GAsyncResult  *res,
  * @stream: A #GIOStream.
  * @guid: The GUID to use if a authenticating as a server or %NULL.
  * @flags: Flags describing how to make the connection.
- * @authentication_observer: A #GDBusAuthObserver or %NULL.
+ * @observer: A #GDBusAuthObserver or %NULL.
  * @cancellable: A #GCancellable or %NULL.
  * @error: Return location for error or %NULL.
  *
@@ -2039,7 +2032,7 @@ g_dbus_connection_new_finish (GAsyncResult  *res,
  * with the end represented by @stream.
  *
  * If %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER is set in @flags,
- * @auth_observer (if not %NULL) is used to assist in the client
+ * @observer (if not %NULL) is used to assist in the client
  * authentication process.
  *
  * This is a synchronous failable constructor. See
@@ -2053,7 +2046,7 @@ GDBusConnection *
 g_dbus_connection_new_sync (GIOStream             *stream,
                             const gchar           *guid,
                             GDBusConnectionFlags   flags,
-                            GDBusAuthObserver     *authentication_observer,
+                            GDBusAuthObserver     *observer,
                             GCancellable          *cancellable,
                             GError               **error)
 {
@@ -2065,7 +2058,7 @@ g_dbus_connection_new_sync (GIOStream             *stream,
                          "stream", stream,
                          "guid", guid,
                          "flags", flags,
-                         "authentication-observer", authentication_observer,
+                         "authentication-observer", observer,
                          NULL);
 }
 
@@ -2366,6 +2359,15 @@ purge_all_filters (GDBusConnection *connection)
     }
 }
 
+/**
+ * g_dbus_connection_remove_filter:
+ * @connection: a #GDBusConnection
+ * @filter_id: an identifier obtained from g_dbus_connection_add_filter()
+ *
+ * Removes a filter.
+ *
+ * Since: 2.26
+ */
 void
 g_dbus_connection_remove_filter (GDBusConnection *connection,
                                  guint            filter_id)
@@ -3548,6 +3550,7 @@ static const gchar introspect_standard_interfaces[] =
   "    <signal name=\"PropertiesChanged\">\n"
   "      <arg type=\"s\" name=\"interface_name\"/>\n"
   "      <arg type=\"a{sv}\" name=\"changed_properties\"/>\n"
+  "      <arg type=\"as\" name=\"invalidated_properties\"/>\n"
   "    </signal>\n"
   "  </interface>\n"
   "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
@@ -3892,7 +3895,6 @@ obj_message_func (GDBusConnection *connection,
  * g_dbus_connection_register_object:
  * @connection: A #GDBusConnection.
  * @object_path: The object path to register at.
- * @interface_name: The D-Bus interface to register.
  * @introspection_data: Introspection data for the interface.
  * @vtable: A #GDBusInterfaceVTable to call into or %NULL.
  * @user_data: Data to pass to functions in @vtable.
@@ -3900,7 +3902,7 @@ obj_message_func (GDBusConnection *connection,
  * @error: Return location for error or %NULL.
  *
  * Registers callbacks for exported objects at @object_path with the
- * D-Bus interface @interface_name.
+ * D-Bus interface that is described in @introspection_data.
  *
  * Calls to functions in @vtable (and @user_data_free_func) will
  * happen in the <link linkend="g-main-context-push-thread-default">thread-default main
@@ -3924,6 +3926,13 @@ obj_message_func (GDBusConnection *connection,
  * If an existing callback is already registered at @object_path and
  * @interface_name, then @error is set to #G_IO_ERROR_EXISTS.
  *
+ * GDBus automatically implements the standard D-Bus interfaces
+ * org.freedesktop.DBus.Properties, org.freedesktop.DBus.Introspectable
+ * and org.freedesktop.Peer, so you don't have to implement those for
+ * the objects you export. You <emphasis>can</emphasis> implement
+ * org.freedesktop.DBus.Properties yourself, e.g. to handle getting
+ * and setting of properties asynchronously.
+ *
  * See <xref linkend="gdbus-server"/> for an example of how to use this method.
  *
  * Returns: 0 if @error is set, otherwise a registration id (never 0)
@@ -3934,7 +3943,6 @@ obj_message_func (GDBusConnection *connection,
 guint
 g_dbus_connection_register_object (GDBusConnection            *connection,
                                    const gchar                *object_path,
-                                   const gchar                *interface_name,
                                    const GDBusInterfaceInfo   *introspection_data,
                                    const GDBusInterfaceVTable *vtable,
                                    gpointer                    user_data,
@@ -3948,8 +3956,8 @@ g_dbus_connection_register_object (GDBusConnection            *connection,
   g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
   g_return_val_if_fail (!g_dbus_connection_is_closed (connection), 0);
   g_return_val_if_fail (object_path != NULL && g_variant_is_object_path (object_path), 0);
-  g_return_val_if_fail (interface_name == NULL || g_dbus_is_interface_name (interface_name), 0);
   g_return_val_if_fail (introspection_data != NULL, 0);
+  g_return_val_if_fail (g_dbus_is_interface_name (introspection_data->name), 0);
   g_return_val_if_fail (error == NULL || *error == NULL, 0);
 
   ret = 0;
@@ -3969,14 +3977,14 @@ g_dbus_connection_register_object (GDBusConnection            *connection,
       g_hash_table_insert (connection->priv->map_object_path_to_eo, eo->object_path, eo);
     }
 
-  ei = g_hash_table_lookup (eo->map_if_name_to_ei, interface_name);
+  ei = g_hash_table_lookup (eo->map_if_name_to_ei, introspection_data->name);
   if (ei != NULL)
     {
       g_set_error (error,
                    G_IO_ERROR,
                    G_IO_ERROR_EXISTS,
                    _("An object is already exported for the interface %s at %s"),
-                   interface_name,
+                   introspection_data->name,
                    object_path);
       goto out;
     }
@@ -3988,7 +3996,7 @@ g_dbus_connection_register_object (GDBusConnection            *connection,
   ei->user_data_free_func = user_data_free_func;
   ei->vtable = vtable;
   ei->introspection_data = introspection_data;
-  ei->interface_name = g_strdup (interface_name);
+  ei->interface_name = g_strdup (introspection_data->name);
   ei->context = g_main_context_get_thread_default ();
   if (ei->context != NULL)
     g_main_context_ref (ei->context);
@@ -4148,6 +4156,24 @@ add_call_flags (GDBusMessage           *message,
  * not compatible with the D-Bus protocol, the operation fails with
  * %G_IO_ERROR_INVALID_ARGUMENT.
  *
+ * If the @parameters #GVariant is floating, it is consumed. This allows
+ * convenient 'inline' use of g_variant_new(), e.g.:
+ * |[
+ *  g_dbus_connection_call (connection,
+ *                          "org.freedesktop.StringThings",
+ *                          "/org/freedesktop/StringThings",
+ *                          "org.freedesktop.StringThings",
+ *                          "TwoStrings",
+ *                          g_variant_new ("(ss)",
+ *                                         "Thing One",
+ *                                         "Thing Two"),
+ *                          G_DBUS_CALL_FLAGS_NONE,
+ *                          -1,
+ *                          NULL,
+ *                          (GAsyncReadyCallback) two_strings_done,
+ *                          NULL);
+ * ]|
+ *
  * This is an asynchronous method. When the operation is finished, @callback will be invoked
  * in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
  * of the thread you are calling this method from. You can then call
@@ -4298,6 +4324,23 @@ g_dbus_connection_call_finish (GDBusConnection  *connection,
  * contains a value not compatible with the D-Bus protocol, the operation
  * fails with %G_IO_ERROR_INVALID_ARGUMENT.
  *
+ * If the @parameters #GVariant is floating, it is consumed.
+ * This allows convenient 'inline' use of g_variant_new(), e.g.:
+ * |[
+ *  g_dbus_connection_call_sync (connection,
+ *                               "org.freedesktop.StringThings",
+ *                               "/org/freedesktop/StringThings",
+ *                               "org.freedesktop.StringThings",
+ *                               "TwoStrings",
+ *                               g_variant_new ("(ss)",
+ *                                              "Thing One",
+ *                                              "Thing Two"),
+ *                               G_DBUS_CALL_FLAGS_NONE,
+ *                               -1,
+ *                               NULL,
+ *                               &amp;error);
+ * ]|
+ *
  * The calling thread is blocked until a reply is received. See
  * g_dbus_connection_call() for the asynchronous version of
  * this method.
@@ -5238,7 +5281,7 @@ get_uninitialized_connection (GBusType       bus_type,
  * The returned object is a singleton, that is, shared with other
  * callers of g_bus_get() and g_bus_get_sync() for @bus_type. In the
  * event that you need a private message bus connection, use
- * g_dbus_address_get_for_bus() and
+ * g_dbus_address_get_for_bus_sync() and
  * g_dbus_connection_new_for_address().
  *
  * Note that the returned #GDBusConnection object will (usually) have