<commit_before>/*
 * kludge-transport.c - the shortest path to NM integration
 * Copyright ©2011 Collabora Ltd.
 *
 * 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 "kludge-transport.h"

#include <telepathy-glib/util.h>

#include "mcd-debug.h"

#include "connectivity-monitor.h"

struct _McdKludgeTransportPrivate {
    /* Rawr! I'm a mythical creature. */
    McdConnectivityMonitor *minotaur;

    GList *one;

    /* Hold a set of McdAccounts which would like to go online. */
    GHashTable *pending_accounts;
};

static void transport_iface_init (
    gpointer g_iface,
    gpointer iface_data);
static void monitor_state_changed_cb (
    McdConnectivityMonitor *monitor,
    gboolean connected,
    gpointer user_data);

G_DEFINE_TYPE_WITH_CODE (McdKludgeTransport, mcd_kludge_transport,
    G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (MCD_TYPE_TRANSPORT_PLUGIN, transport_iface_init);
    )

static void
mcd_kludge_transport_init (McdKludgeTransport *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      MCD_TYPE_KLUDGE_TRANSPORT, McdKludgeTransportPrivate);
}

static void
mcd_kludge_transport_constructed (GObject *object)
{
  McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (object);
  McdKludgeTransportPrivate *priv = self->priv;
  GObjectClass *parent_class = mcd_kludge_transport_parent_class;

  if (parent_class->constructed != NULL)
    parent_class->constructed (object);

  priv->minotaur = mcd_connectivity_monitor_new ();
  tp_g_signal_connect_object (priv->minotaur, "state-change",
      (GCallback) monitor_state_changed_cb, self, G_CONNECT_AFTER);

  /* We just use ourself as the McdTransport pointer... */
  priv->one = g_list_prepend (NULL, self);

  priv->pending_accounts = g_hash_table_new_full (NULL, NULL,
      g_object_unref, NULL);
}

static void
mcd_kludge_transport_dispose (GObject *object)
{
  McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (object);
  McdKludgeTransportPrivate *priv = self->priv;
  GObjectClass *parent_class = mcd_kludge_transport_parent_class;

  tp_clear_object (&priv->minotaur);
  g_list_free (priv->one);
  priv->one = NULL;

  g_hash_table_unref (priv->pending_accounts);

  if (parent_class->dispose != NULL)
    parent_class->dispose (object);
}

static void
mcd_kludge_transport_class_init (McdKludgeTransportClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = mcd_kludge_transport_constructed;
  object_class->dispose = mcd_kludge_transport_dispose;

  g_type_class_add_private (klass, sizeof (McdKludgeTransportPrivate));
}

static const gchar *
mcd_kludge_transport_get_name (
    McdTransportPlugin *plugin)
{
  g_return_val_if_fail (MCD_IS_KLUDGE_TRANSPORT (plugin), NULL);

  return "McdKludgeTransport";
}

static const GList *
mcd_kludge_transport_get_transports (
    McdTransportPlugin *plugin)
{
  McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (plugin);

  g_return_val_if_fail (MCD_IS_KLUDGE_TRANSPORT (plugin), NULL);

  return self->priv->one;
}

static const gchar *
mcd_kludge_transport_get_transport_name (
    McdTransportPlugin *plugin,
    McdTransport *transport)<commit_msg>KludgeTransport: explain the one-element list o' transports<commit_after>/*
 * kludge-transport.c - the shortest path to NM integration
 * Copyright ©2011 Collabora Ltd.
 *
 * 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 "kludge-transport.h"

#include <telepathy-glib/util.h>

#include "mcd-debug.h"

#include "connectivity-monitor.h"

struct _McdKludgeTransportPrivate {
    /* Rawr! I'm a mythical creature. */
    McdConnectivityMonitor *minotaur;

    /* Pointers representing network connections, exposed to the application as
     * opaque McdTransport pointers.
     *
     * In this generate example of an McdTransportPlugin, we only have one
     * transport, representing "the internet". So in fact this list always
     * contains a single pointer, namely the McdKludgeTransport instance
     * itself.
     */
    GList *transports;

    /* Hold a set of McdAccounts which would like to go online. */
    GHashTable *pending_accounts;
};

static void transport_iface_init (
    gpointer g_iface,
    gpointer iface_data);
static void monitor_state_changed_cb (
    McdConnectivityMonitor *monitor,
    gboolean connected,
    gpointer user_data);

G_DEFINE_TYPE_WITH_CODE (McdKludgeTransport, mcd_kludge_transport,
    G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (MCD_TYPE_TRANSPORT_PLUGIN, transport_iface_init);
    )

static void
mcd_kludge_transport_init (McdKludgeTransport *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      MCD_TYPE_KLUDGE_TRANSPORT, McdKludgeTransportPrivate);
}

static void
mcd_kludge_transport_constructed (GObject *object)
{
  McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (object);
  McdKludgeTransportPrivate *priv = self->priv;
  GObjectClass *parent_class = mcd_kludge_transport_parent_class;

  if (parent_class->constructed != NULL)
    parent_class->constructed (object);

  priv->minotaur = mcd_connectivity_monitor_new ();
  tp_g_signal_connect_object (priv->minotaur, "state-change",
      (GCallback) monitor_state_changed_cb, self, G_CONNECT_AFTER);

  /* We just use ourself as the McdTransport pointer... */
  priv->transports = g_list_prepend (NULL, self);

  priv->pending_accounts = g_hash_table_new_full (NULL, NULL,
      g_object_unref, NULL);
}

static void
mcd_kludge_transport_dispose (GObject *object)
{
  McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (object);
  McdKludgeTransportPrivate *priv = self->priv;
  GObjectClass *parent_class = mcd_kludge_transport_parent_class;

  tp_clear_object (&priv->minotaur);
  g_list_free (priv->transports);
  priv->transports = NULL;

  g_hash_table_unref (priv->pending_accounts);

  if (parent_class->dispose != NULL)
    parent_class->dispose (object);
}

static void
mcd_kludge_transport_class_init (McdKludgeTransportClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = mcd_kludge_transport_constructed;
  object_class->dispose = mcd_kludge_transport_dispose;

  g_type_class_add_private (klass, sizeof (McdKludgeTransportPrivate));
}

static const gchar *
mcd_kludge_transport_get_name (
    McdTransportPlugin *plugin)
{
  g_return_val_if_fail (MCD_IS_KLUDGE_TRANSPORT (plugin), NULL);

  return "McdKludgeTransport";
}

static const GList *
mcd_kludge_transport_get_transports (
    McdTransportPlugin *plugin)
{
  McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (plugin);

  g_return_val_if_fail (MCD_IS_KLUDGE_TRANSPORT (plugin), NULL);

  return self->priv->transports;
}

static const gchar *
mcd_kludge_transport_get_transport_name (
    McdTransportPlugin *plugin,
    McdTransport *transport)
{'fraction_non_alphanumeric': 0.07947673701098358, 'fraction_numerical': 0.004195976798716525, 'mean_word_length': 4.932650073206442, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6502565', 'n_tokens_mistral': 2698, 'n_tokens_neox': 2611, 'n_words': 689}