+ <sect2 id="glib-typemappings">
+ <title>D-Bus - GLib type mappings</title>
+ <para>
+ The heart of the GLib bindings for D-Bus is the mapping it
+ provides between D-Bus "type signatures" and GLib types
+ (<literal>GType</literal>). The D-Bus type system is composed of
+ a number of "basic" types, along with several "container" types.
+ </para>
+ <sect3 id="glib-basic-typemappings">
+ <title>Basic type mappings</title>
+ <para>
+ Below is a list of the basic types, along with their associated
+ mapping to a <literal>GType</literal>.
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>D-Bus basic type</entry>
+ <entry>GType</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>BYTE</literal></entry>
+ <entry><literal>G_TYPE_UCHAR</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>BOOLEAN</literal></entry>
+ <entry><literal>G_TYPE_BOOLEAN</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>INT16</literal></entry>
+ <entry><literal>G_TYPE_INT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_INT16</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>UINT16</literal></entry>
+ <entry><literal>G_TYPE_UINT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_UINT16</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>INT32</literal></entry>
+ <entry><literal>G_TYPE_INT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_INT32</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>UINT32</literal></entry>
+ <entry><literal>G_TYPE_UINT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_UINT32</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>INT64</literal></entry>
+ <entry><literal>G_TYPE_GINT64</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>UINT64</literal></entry>
+ <entry><literal>G_TYPE_GUINT64</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>DOUBLE</literal></entry>
+ <entry><literal>G_TYPE_DOUBLE</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>STRING</literal></entry>
+ <entry><literal>G_TYPE_STRING</literal></entry>
+ <entry><literal>g_free</literal></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>OBJECT_PATH</literal></entry>
+ <entry><literal>DBUS_TYPE_G_PROXY</literal></entry>
+ <entry><literal>g_object_unref</literal></entry>
+ <entry>The returned proxy does not have an interface set; use <literal>dbus_g_proxy_set_interface</literal> to invoke methods</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ As you can see, the basic mapping is fairly straightforward.
+ </para>
+ </sect3>
+ <sect3 id="glib-container-typemappings">
+ <title>Container type mappings</title>
+ <para>
+ The D-Bus type system also has a number of "container"
+ types, such as <literal>DBUS_TYPE_ARRAY</literal> and
+ <literal>DBUS_TYPE_STRUCT</literal>. The D-Bus type system
+ is fully recursive, so one can for example have an array of
+ array of strings (i.e. type signature
+ <literal>aas</literal>).
+ </para>
+ <para>
+ However, not all of these types are in common use; for
+ example, at the time of this writing the author knows of no
+ one using <literal>DBUS_TYPE_STRUCT</literal>, or a
+ <literal>DBUS_TYPE_ARRAY</literal> containing any non-basic
+ type. The approach the GLib bindings take is pragmatic; try
+ to map the most common types in the most obvious way, and
+ let using less common and more complex types be less
+ "natural".
+ </para>
+ <para>
+ First, D-Bus type signatures which have an "obvious"
+ corresponding built-in GLib type are mapped using that type:
+ <informaltable>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>D-Bus type signature</entry>
+ <entry>Description</entry>
+ <entry>GType</entry>
+ <entry>C typedef</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>as</literal></entry>
+ <entry>Array of strings</entry>
+ <entry><literal>G_TYPE_STRV</literal></entry>
+ <entry><literal>char **</literal></entry>
+ <entry><literal>g_strfreev</literal></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>v</literal></entry>
+ <entry>Generic value container</entry>
+ <entry><literal>G_TYPE_VALUE</literal></entry>
+ <entry><literal>GValue *</literal></entry>
+ <entry><literal>g_value_unset</literal></entry>
+ <entry>The calling conventions for values expect that method callers have allocated return values; see below.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ <para>
+ The next most common recursive type signatures are arrays of
+ basic values. The most obvious mapping for arrays of basic
+ types is a <literal>GArray</literal>. Now, GLib does not
+ provide a builtin <literal>GType</literal> for
+ <literal>GArray</literal>. However, we actually need more than
+ that - we need a "parameterized" type which includes the
+ contained type. Why we need this we will see below.
+ </para>
+ <para>
+ The approach taken is to create these types in the D-Bus GLib
+ bindings; however, there is nothing D-Bus specific about them.
+ In the future, we hope to include such "fundamental" types in GLib
+ itself.
+ <informaltable>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>D-Bus type signature</entry>
+ <entry>Description</entry>
+ <entry>GType</entry>
+ <entry>C typedef</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>ay</literal></entry>
+ <entry>Array of bytes</entry>
+ <entry><literal>DBUS_TYPE_G_BYTE_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>au</literal></entry>
+ <entry>Array of uint</entry>
+ <entry><literal>DBUS_TYPE_G_UINT_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ai</literal></entry>
+ <entry>Array of int</entry>
+ <entry><literal>DBUS_TYPE_G_INT_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ax</literal></entry>
+ <entry>Array of int64</entry>
+ <entry><literal>DBUS_TYPE_G_INT64_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>at</literal></entry>
+ <entry>Array of uint64</entry>
+ <entry><literal>DBUS_TYPE_G_UINT64_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ad</literal></entry>
+ <entry>Array of double</entry>
+ <entry><literal>DBUS_TYPE_G_DOUBLE_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ab</literal></entry>
+ <entry>Array of boolean</entry>
+ <entry><literal>DBUS_TYPE_G_BOOLEAN_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ <para>
+ D-Bus also includes a special type DBUS_TYPE_DICT_ENTRY which
+ is only valid in arrays. It's intended to be mapped to a "dictionary"
+ type by bindings. The obvious GLib mapping here is GHashTable. Again,
+ however, there is no builtin <literal>GType</literal> for a GHashTable.
+ Moreover, just like for arrays, we need a parameterized type so that
+ the bindings can communiate which types are contained in the hash table.
+ </para>
+ <para>
+ At present, only strings are supported. Work is in progress to
+ include more types.
+ <informaltable>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>D-Bus type signature</entry>
+ <entry>Description</entry>
+ <entry>GType</entry>
+ <entry>C typedef</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>a{ss}</literal></entry>
+ <entry>Dictionary mapping strings to strings</entry>
+ <entry><literal>DBUS_TYPE_G_STRING_STRING_HASHTABLE</literal></entry>
+ <entry><literal>GHashTable *</literal></entry>
+ <entry>g_hash_table_destroy</entry>
+ <entry></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </sect3>
+ <sect3 id="glib-generic-typemappings">
+ <title>Arbitrarily recursive type mappings</title>
+ <para>
+ Finally, it is possible users will want to write or invoke D-Bus
+ methods which have arbitrarily complex type signatures not
+ directly supported by these bindings. For this case, we have a
+ <literal>DBusGValue</literal> which acts as a kind of special
+ variant value which may be iterated over manually. The
+ <literal>GType</literal> associated is
+ <literal>DBUS_TYPE_G_VALUE</literal>.
+ </para>
+ <para>
+ TODO insert usage of <literal>DBUS_TYPE_G_VALUE</literal> here.
+ </para>
+ </sect3>
+ </sect2>
+ <sect2 id="sample-program-1">
+ <title>A sample program</title>
+ <para>Here is a D-Bus program using the GLib bindings.