## D-Bus Utilities

D-Bus Utilities — Various utilities related to D-Bus.

## Synopsis

    #include <gio/gio.h>

    gchar *             g_dbus_generate_guid                (void);
    gboolean            g_dbus_is_guid                      (const gchar *string);
    gboolean            g_dbus_is_name                      (const gchar *string);
    gboolean            g_dbus_is_unique_name               (const gchar *string);
    gboolean            g_dbus_is_member_name               (const gchar *string);
    gboolean            g_dbus_is_interface_name            (const gchar *string);
    GVariant *          g_dbus_gvalue_to_gvariant           (const GValue *gvalue,
                                                             const GVariantType *type);
    void                g_dbus_gvariant_to_gvalue           (GVariant *value,
                                                             GValue *out_gvalue);

## Description

Various utility routines related to D-Bus.

## Details

### g_dbus_generate_guid ()

    gchar *             g_dbus_generate_guid                (void);

Generate a D-Bus GUID that can be used with e.g. `g_dbus_connection_new()`.

See the D-Bus specification regarding what strings are valid D-Bus GUID (for example, D-Bus GUIDs are not RFC-4122 compliant).

Returns : | A valid D-Bus GUID. Free with `g_free()`.

Since 2.26

### g_dbus_is_guid ()

    gboolean            g_dbus_is_guid                      (const gchar *string);

Checks if `string` is a D-Bus GUID.

See the D-Bus specification regarding what strings are valid D-Bus GUID (for example, D-Bus GUIDs are not RFC-4122 compliant).

`string` : | The string to check.
Returns : | `TRUE` if `string` is a guid, `FALSE` otherwise.

Since 2.26

### g_dbus_is_name ()

    gboolean            g_dbus_is_name                      (const gchar *string);

Checks if `string` is a valid D-Bus bus name (either unique or well-known).

`string` : | The string to check.
Returns : | `TRUE` if valid, `FALSE` otherwise.

Since 2.26

### g_dbus_is_unique_name ()

    gboolean            g_dbus_is_unique_name               (const gchar *string);

Checks if `string` is a valid D-Bus unique bus name.

`string` : | The string to check.
Returns : | `TRUE` if valid, `FALSE` otherwise.

Since 2.26

### g_dbus_is_member_name ()

    gboolean            g_dbus_is_member_name               (const gchar *string);

Checks if `string` is a valid D-Bus member (e.g. signal or method) name.

`string` : | The string to check.
Returns : | `TRUE` if valid, `FALSE` otherwise.

Since 2.26

### g_dbus_is_interface_name ()

    gboolean            g_dbus_is_interface_name            (const gchar *string);

Checks if `string` is a valid D-Bus interface name.

`string` : | The string to check.
Returns : | `TRUE` if valid, `FALSE` otherwise.

Since 2.26

### g_dbus_gvalue_to_gvariant ()

    GVariant *          g_dbus_gvalue_to_gvariant           (const GValue *gvalue,
                                                             const GVariantType *type);

Converts a GValue to a GVariant of the type indicated by the `type` parameter.

The conversion is using the following rules:

Table 4. GValue / GVariant conversion rules

If the GType for `gvalue` is... | ... then `type` must be
--- | ---
G_TYPE_STRING | 's', 'o', 'g' or 'ay'
G_TYPE_STRV | 'as' or 'aay'
G_TYPE_BOOLEAN | 'b'
G_TYPE_UCHAR | 'y'
G_TYPE_INT | 'i' or 'n'
G_TYPE_UINT | 'u' or 'q'
G_TYPE_INT64 | 'x'
G_TYPE_UINT64 | 't'
G_TYPE_INT | 'h'
G_TYPE_DOUBLE | 'd'
G_TYPE_VARIANT | Any GVariantType

This can fail if e.g. `gvalue` is of type G_TYPE_STRING and `type` is 'i'. It will also fail for any GType (including e.g. G_TYPE_OBJECT and G_TYPE_BOXED derived-types) not in the table above.

Note that if `gvalue` is of type G_TYPE_VARIANT and its value is `NULL`, the empty GVariant instance (never `NULL`) for `type` is returned (e.g. 0 for scalar types, the empty string for string types, `'/'` for object path types, the empty array for any array type and so on).

See the `g_dbus_gvariant_to_gvalue()` function for how to convert a GVariant to a GValue.

`gvalue` : | A GValue to convert to a GVariant.
`type` : | A GVariantType.
Returns : | A GVariant (never floating) of GVariantType `type` holding the data from `gvalue` or `NULL` in case of failure. Free with `g_variant_unref()`.

Since 2.30

### g_dbus_gvariant_to_gvalue ()

    void                g_dbus_gvariant_to_gvalue           (GVariant *value,
                                                             GValue *out_gvalue);

Converts a GVariant to a GValue. If `value` is floating, it is consumed.

The rules specified in the `g_dbus_gvalue_to_gvariant()` function are used - this function is essentially its reverse form.

The conversion never fails - a valid GValue is always returned in `out_gvalue`.

`value` : | A GVariant.
`out_gvalue` : | Return location pointing to a zero-filled (uninitialized) GValue.

Since 2.30