Beispiel #1
0
static gboolean
ibus_attr_list_serialize (IBusAttrList    *attr_list,
                          IBusMessageIter *iter)
{
    IBusMessageIter array_iter;
    gboolean retval;
    guint i;

    retval = IBUS_SERIALIZABLE_CLASS (ibus_attr_list_parent_class)->serialize ((IBusSerializable *)attr_list, iter);
    g_return_val_if_fail (retval, FALSE);

    g_return_val_if_fail (IBUS_IS_ATTR_LIST (attr_list), FALSE);

    retval = ibus_message_iter_open_container (iter,
                                               IBUS_TYPE_ARRAY,
                                               "v",
                                               &array_iter);
    g_return_val_if_fail (retval, FALSE);

    for (i = 0;; i++) {
        IBusAttribute *attr;

        attr = ibus_attr_list_get (attr_list, i);
        if (attr == NULL)
            break;

        retval = ibus_message_iter_append (&array_iter, IBUS_TYPE_ATTRIBUTE, &attr);
        g_return_val_if_fail (retval, FALSE);
    }

    retval = ibus_message_iter_close_container (iter, &array_iter);
    g_return_val_if_fail (retval, FALSE);

    return TRUE;
}
Beispiel #2
0
static gboolean
ibus_serializable_real_serialize (IBusSerializable *object,
                                  IBusMessageIter  *iter)
{
    IBusSerializablePrivate *priv;
    IBusMessageIter array_iter;
    gboolean retval;

    priv = IBUS_SERIALIZABLE_GET_PRIVATE (object);

    retval = ibus_message_iter_open_container (iter,
                                               IBUS_TYPE_ARRAY,
                                               "{sv}",
                                               &array_iter);
    g_return_val_if_fail (retval, FALSE);

    g_datalist_foreach (&priv->attachments,
                        (GDataForeachFunc) _serialize_cb,
                        &array_iter);

    retval = ibus_message_iter_close_container (iter, &array_iter);
    g_return_val_if_fail (retval, FALSE);

    return TRUE;
}
Beispiel #3
0
static void
_serialize_cb (GQuark           key,
               GValue          *value,
               IBusMessageIter *iter)
{
    IBusMessageIter dict_entry;
    gboolean retval;
    const gchar *name;

    retval = ibus_message_iter_open_container (iter,
                                               IBUS_TYPE_DICT_ENTRY,
                                               NULL,
                                               &dict_entry);
    g_return_if_fail (retval);
    name = g_quark_to_string (key);
    retval = ibus_message_iter_append (&dict_entry,
                                       G_TYPE_STRING,
                                       &name);
    g_return_if_fail (retval);

    retval = _g_value_serialize (value, &dict_entry);
    g_return_if_fail (retval);

    retval = ibus_message_iter_close_container (iter, &dict_entry);
    g_return_if_fail (retval);
}
Beispiel #4
0
static IBusMessage *
_dbus_list_names (BusDBusImpl       *dbus,
                  IBusMessage       *message,
                  BusConnection     *connection)
{
    IBusMessage *reply_message;
    IBusMessageIter iter, sub_iter;
    GList *name, *names;

    reply_message = ibus_message_new_method_return (message);

    ibus_message_iter_init_append (message, &iter);
    ibus_message_iter_open_container (&iter, IBUS_TYPE_ARRAY, "s", &sub_iter);

    // append unique names
    names = g_hash_table_get_keys (dbus->unique_names);

    names = g_list_sort (names, (GCompareFunc) g_strcmp0);
    for (name = names; name != NULL; name = name->next) {
        ibus_message_iter_append (&sub_iter, G_TYPE_STRING, &(name->data));
    }
    g_list_free (names);

    // append well-known names
    names = g_hash_table_get_keys (dbus->names);
    names = g_list_sort (names, (GCompareFunc) g_strcmp0);
    for (name = names; name != NULL; name = name->next) {
        ibus_message_iter_append (&sub_iter, G_TYPE_STRING, &(name->data));
    }
    g_list_free (names);

    ibus_message_iter_close_container (&iter, &sub_iter);

    return reply_message;
}
Beispiel #5
0
gboolean
ibus_serializable_serialize (IBusSerializable *object,
                             IBusMessageIter  *iter)
{
    g_return_val_if_fail (IBUS_IS_SERIALIZABLE (object), FALSE);
    g_return_val_if_fail (iter != NULL, FALSE);

    IBusMessageIter variant_iter;
    IBusMessageIter sub_iter;
    gboolean retval;

    gchar *signature;

    signature = g_strdup_printf ("(s%s)", IBUS_SERIALIZABLE_GET_CLASS (object)->signature->str);
    retval = ibus_message_iter_open_container (iter,
                                               IBUS_TYPE_VARIANT,
                                               signature,
                                               &variant_iter);
    g_free (signature);
    g_return_val_if_fail (retval, FALSE);

    retval = ibus_message_iter_open_container (&variant_iter,
                                               IBUS_TYPE_STRUCT,
                                               NULL,
                                               &sub_iter);
    g_return_val_if_fail (retval, FALSE);

    const gchar *type_name = g_type_name (G_OBJECT_TYPE (object));
    g_return_val_if_fail (type_name != NULL, FALSE);

    retval = ibus_message_iter_append (&sub_iter,
                                       G_TYPE_STRING,
                                       &type_name);
    g_return_val_if_fail (retval, FALSE);

    retval = IBUS_SERIALIZABLE_GET_CLASS (object)->serialize (object, &sub_iter);
    g_return_val_if_fail (retval, FALSE);

    retval = ibus_message_iter_close_container (&variant_iter, &sub_iter);
    g_return_val_if_fail (retval, FALSE);

    retval = ibus_message_iter_close_container (iter, &variant_iter);
    g_return_val_if_fail (retval, FALSE);

    return TRUE;
}
Beispiel #6
0
gboolean
ibus_message_iter_copy_data (IBusMessageIter *dst,
                             IBusMessageIter *src)
{
    GType type;
    gboolean retval;

    type = ibus_message_iter_get_arg_type (src);

    g_return_val_if_fail (type != G_TYPE_INVALID, FALSE);

    if (gtype_is_basic (type)) {
        gchar data[16];
        ibus_message_iter_get_basic (src, data);
        retval = ibus_message_iter_append (dst, type, data);
        g_return_val_if_fail (retval, FALSE);
        return TRUE;
    }

    if (type == IBUS_TYPE_VARIANT) {
        IBusMessageIter subdst, subsrc;
        gchar *signature;

        retval = ibus_message_iter_recurse (src, IBUS_TYPE_VARIANT, &subsrc);
        g_return_val_if_fail (retval, FALSE);

        signature = dbus_message_iter_get_signature (&subsrc);
        g_return_val_if_fail (signature != NULL, FALSE);
        retval = ibus_message_iter_open_container (dst,
                                                   IBUS_TYPE_VARIANT,
                                                   signature,
                                                   &subdst);
        dbus_free (signature);
        g_return_val_if_fail (retval, FALSE);

        retval = ibus_message_iter_copy_data (&subdst, &subsrc);
        g_return_val_if_fail (retval, FALSE);

        retval = ibus_message_iter_close_container (dst, &subdst);
        g_return_val_if_fail (retval, FALSE);

        return TRUE;
    }
    else if (type == IBUS_TYPE_ARRAY) {
        IBusMessageIter subdst, subsrc;
        gchar *signature;

        retval = ibus_message_iter_recurse (src, IBUS_TYPE_ARRAY, &subsrc);
        g_return_val_if_fail (retval, FALSE);

        signature = dbus_message_iter_get_signature (src);
        g_return_val_if_fail (signature != NULL, FALSE);

        retval = ibus_message_iter_open_container (dst,
                                                   IBUS_TYPE_ARRAY,
                                                   signature + 1,
                                                   &subdst);
        dbus_free (signature);
        g_return_val_if_fail (retval, FALSE);

        while (ibus_message_iter_get_arg_type (&subsrc) != G_TYPE_INVALID) {
            retval = ibus_message_iter_copy_data (&subdst, &subsrc);
            g_return_val_if_fail (retval, FALSE);
            ibus_message_iter_next (&subsrc);
        }

        retval = ibus_message_iter_close_container (dst, &subdst);
        g_return_val_if_fail (retval, FALSE);

        return TRUE;
    }
    else if (type == IBUS_TYPE_STRUCT) {
        IBusMessageIter subdst, subsrc;

        retval = ibus_message_iter_recurse (src, IBUS_TYPE_STRUCT, &subsrc);
        g_return_val_if_fail (retval, FALSE);

        retval = ibus_message_iter_open_container (dst,
                                                   IBUS_TYPE_STRUCT,
                                                   NULL,
                                                   &subdst);
        g_return_val_if_fail (retval, FALSE);

        while (ibus_message_iter_get_arg_type (&subsrc) != G_TYPE_INVALID) {
            retval = ibus_message_iter_copy_data (&subdst, &subsrc);
            ibus_message_iter_next (&subsrc);
            g_return_val_if_fail (retval, FALSE);
        }

        retval = ibus_message_iter_close_container (dst, &subdst);
        g_return_val_if_fail (retval, FALSE);

        return TRUE;
    }
    else if (type == IBUS_TYPE_DICT_ENTRY) {
        IBusMessageIter subdst, subsrc;

        retval = ibus_message_iter_recurse (src, IBUS_TYPE_DICT_ENTRY, &subsrc);
        g_return_val_if_fail (retval, FALSE);

        retval = ibus_message_iter_open_container (dst,
                                                   IBUS_TYPE_DICT_ENTRY,
                                                   NULL,
                                                   &subdst);
        g_return_val_if_fail (retval, FALSE);

        /* copy key */
        retval = ibus_message_iter_copy_data (&subdst, &subsrc);
        g_return_val_if_fail (retval, FALSE);
        ibus_message_iter_next (&subsrc);

        /* copy value */
        retval = ibus_message_iter_copy_data (&subdst, &subsrc);
        g_return_val_if_fail (retval, FALSE);
        ibus_message_iter_next (&subsrc);

        retval = ibus_message_iter_close_container (dst, &subdst);
        g_return_val_if_fail (retval, FALSE);

        return TRUE;
    }

    return FALSE;

}