<commit_before>/* vi: set et sw=4 ts=4 cino=t0,(0: */
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * mc-dispatch-operation.c - Telepathy Account Manager D-Bus interface
 * (client side)
 *
 * Copyright (C) 2008 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <string.h>
#include "mc-dispatch-operation.h"
#include "dbus-api.h"
#include "mc-signals-marshal.h"

#include <telepathy-glib/proxy-subclass.h>

#include "_gen/cli-dispatch-operation-body.h"
#include "_gen/signals-marshal.h"

/**
 * SECTION:mc-dispatch-operation
 * @title: McDispatchOperation
 * @short_description: proxy object for the Telepathy ChannelDispatchOperation
 * D-Bus API
 *
 * This module provides a client-side proxy object for the Telepathy
 * ChannelDispatchOperation D-Bus API.
 */

/**
 * McDispatchOperationClass:
 *
 * The class of a #McDispatchOperation.
 */
struct _McDispatchOperationClass {
    TpProxyClass parent_class;
    /*<private>*/
    gpointer priv;
};

typedef struct _McDispatchOperationProps {
    gchar *connection;
    gchar *account;
    gchar **possible_handlers;
    GList *channels;
} McDispatchOperationProps;

struct _McDispatchOperationPrivate {
    McDispatchOperationProps *props;
};

/**
 * McDispatchOperation:
 *
 * A proxy object for the Telepathy DispatchOperation D-Bus API. This is a
 * subclass of #TpProxy.
 */
struct _McDispatchOperation {
    TpProxy parent;
    /*<private>*/
    McDispatchOperationPrivate *priv;
};

G_DEFINE_TYPE (McDispatchOperation, mc_dispatch_operation, TP_TYPE_PROXY);

enum
{
    PROP_0,
    PROP_PROPERTIES,
};

/* if this turns out to work well, we can move this definition to a common
 * header and use it in every module */
typedef struct {
    gchar *name;
    gchar *dbus_signature;
    void (*update_property) (const gchar *name, const GValue *value,
                             gpointer props_struct);
} McProperty;

#define MAX_PROPERTY_NAME_LEN  64
#define MC_QUALIFIED_PROPERTY_NAME_LEN \
    (sizeof(MC_IFACE_CHANNEL_DISPATCH_OPERATION) + MAX_PROPERTY_NAME_LEN)

static void
mc_dispatch_operation_init (McDispatchOperation *operation)
{
    operation->priv =
        G_TYPE_INSTANCE_GET_PRIVATE(operation, MC_TYPE_DISPATCH_OPERATION,
                                    McDispatchOperationPrivate);
}

static void
mc_channel_details_free (McChannelDetails *details)
{
    g_free (details->object_path);
    g_hash_table_destroy (details->properties);
    g_slice_free (McChannelDetails, details);
}

static inline void
operation_props_free (McDispatchOperationProps *props)
{
    g_strfreev (props->possible_handlers);
    g_free (props->connection);
    g_free (props->account);
    g_list_foreach (props->channels, (GFunc)mc_channel_details_free, NULL);
    g_list_free (props->channels);
    g_slice_free (McDispatchOperationProps, props);
}

static inline GList *
create_channels_prop (const GValue *value)
{
    GList *list = NULL;
    GPtrArray *channels;
    guint i;

    channels = g_value_get_boxed (value);
    for (i = channels->len - 1; i >= 0; i--)
    {
        McChannelDetails *details;
        GValueArray *va;

        details = g_slice_new (McChannelDetails);
        va = g_ptr_array_index (channels, i);
        details->object_path = g_value_dup_boxed (va->values);
        details->properties = g_value_dup_boxed (va->values + 1);
        list = g_list_prepend (list, details);
    }
    return list;
}

static void
set_connection (const gchar *name, const GValue *value, gpointer props_struct)
{
    McDispatchOperationProps *props = props_struct;
    g_free (props->connection);
    props->connection = g_value_dup_boxed (value);
}

static void
set_account (const gchar *name, const GValue *value, gpointer props_struct)<commit_msg>Make the iterator a signed int, or it will never be negative<commit_after>/* vi: set et sw=4 ts=4 cino=t0,(0: */
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * mc-dispatch-operation.c - Telepathy Account Manager D-Bus interface
 * (client side)
 *
 * Copyright (C) 2008 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <string.h>
#include "mc-dispatch-operation.h"
#include "dbus-api.h"
#include "mc-signals-marshal.h"

#include <telepathy-glib/proxy-subclass.h>

#include "_gen/cli-dispatch-operation-body.h"
#include "_gen/signals-marshal.h"

/**
 * SECTION:mc-dispatch-operation
 * @title: McDispatchOperation
 * @short_description: proxy object for the Telepathy ChannelDispatchOperation
 * D-Bus API
 *
 * This module provides a client-side proxy object for the Telepathy
 * ChannelDispatchOperation D-Bus API.
 */

/**
 * McDispatchOperationClass:
 *
 * The class of a #McDispatchOperation.
 */
struct _McDispatchOperationClass {
    TpProxyClass parent_class;
    /*<private>*/
    gpointer priv;
};

typedef struct _McDispatchOperationProps {
    gchar *connection;
    gchar *account;
    gchar **possible_handlers;
    GList *channels;
} McDispatchOperationProps;

struct _McDispatchOperationPrivate {
    McDispatchOperationProps *props;
};

/**
 * McDispatchOperation:
 *
 * A proxy object for the Telepathy DispatchOperation D-Bus API. This is a
 * subclass of #TpProxy.
 */
struct _McDispatchOperation {
    TpProxy parent;
    /*<private>*/
    McDispatchOperationPrivate *priv;
};

G_DEFINE_TYPE (McDispatchOperation, mc_dispatch_operation, TP_TYPE_PROXY);

enum
{
    PROP_0,
    PROP_PROPERTIES,
};

/* if this turns out to work well, we can move this definition to a common
 * header and use it in every module */
typedef struct {
    gchar *name;
    gchar *dbus_signature;
    void (*update_property) (const gchar *name, const GValue *value,
                             gpointer props_struct);
} McProperty;

#define MAX_PROPERTY_NAME_LEN  64
#define MC_QUALIFIED_PROPERTY_NAME_LEN \
    (sizeof(MC_IFACE_CHANNEL_DISPATCH_OPERATION) + MAX_PROPERTY_NAME_LEN)

static void
mc_dispatch_operation_init (McDispatchOperation *operation)
{
    operation->priv =
        G_TYPE_INSTANCE_GET_PRIVATE(operation, MC_TYPE_DISPATCH_OPERATION,
                                    McDispatchOperationPrivate);
}

static void
mc_channel_details_free (McChannelDetails *details)
{
    g_free (details->object_path);
    g_hash_table_destroy (details->properties);
    g_slice_free (McChannelDetails, details);
}

static inline void
operation_props_free (McDispatchOperationProps *props)
{
    g_strfreev (props->possible_handlers);
    g_free (props->connection);
    g_free (props->account);
    g_list_foreach (props->channels, (GFunc)mc_channel_details_free, NULL);
    g_list_free (props->channels);
    g_slice_free (McDispatchOperationProps, props);
}

static inline GList *
create_channels_prop (const GValue *value)
{
    GList *list = NULL;
    GPtrArray *channels;
    gint i;

    channels = g_value_get_boxed (value);
    for (i = channels->len - 1; i >= 0; i--)
    {
        McChannelDetails *details;
        GValueArray *va;

        details = g_slice_new (McChannelDetails);
        va = g_ptr_array_index (channels, i);
        details->object_path = g_value_dup_boxed (va->values);
        details->properties = g_value_dup_boxed (va->values + 1);
        list = g_list_prepend (list, details);
    }
    return list;
}

static void
set_connection (const gchar *name, const GValue *value, gpointer props_struct)
{
    McDispatchOperationProps *props = props_struct;
    g_free (props->connection);
    props->connection = g_value_dup_boxed (value);
}

static void
set_account (const gchar *name, const GValue *value, gpointer props_struct)
{'fraction_non_alphanumeric': 0.09373606776638431, 'fraction_numerical': 0.006241640659830584, 'mean_word_length': 3.819011815252417, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3205285', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2707, 'n_words': 822}