<commit_before>/*
 * base-call-content.c - Source for TpBaseCallContent
 * Copyright © 2009–2011 Collabora Ltd.
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * 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
 */

/**
 * SECTION:base-call-content
 * @title: TpBaseCallContent
 * @short_description: base class for #TpSvcCallContent implementations
 * @see_also: #TpSvcCallContent, #TpBaseCallChannel and #TpBaseCallStream
 *
 * This base class makes it easier to write #TpSvcCallContent
 * implementations by implementing its properties, and some of its methods.
 *
 * Subclasses should fill in #TpBaseCallContentClass.extra_interfaces,
 * and #TpBaseCallContentClass.deinit virtual function.
 *
 * Since: 0.UNRELEASED
 */

/**
 * TpBaseCallContent:
 *
 * A base class for call content implementations
 *
 * Since: 0.UNRELEASED
 */

/**
 * TpBaseCallContentClass:
 * @extra_interfaces: extra interfaces provided by this content (this SHOULD NOT
 *  include %TP_IFACE_CALL_CONTENT itself)
 * @deinit: optional; virtual method called by #TpBaseCallChannel when removing
 *  the content
 *
 * The class structure for #TpBaseCallContent
 *
 * Since: 0.UNRELEASED
 */

/**
 * TpBaseCallContentDeinitFunc:
 * @self: a #TpBaseCallContent
 *
 * Signature of an implementation of #TpBaseCallContentClass.deinit.
 *
 * Since: 0.UNRELEASED
 */

#include "config.h"
#include "telepathy-glib/base-call-content.h"

#define DEBUG_FLAG TP_DEBUG_CALL

#include "telepathy-glib/base-call-channel.h"
#include "telepathy-glib/base-call-internal.h"
#include "telepathy-glib/base-connection.h"
#include "telepathy-glib/debug-internal.h"
#include "telepathy-glib/dbus.h"
#include "telepathy-glib/dbus-properties-mixin.h"
#include "telepathy-glib/gtypes.h"
#include "telepathy-glib/interfaces.h"
#include "telepathy-glib/svc-call.h"
#include "telepathy-glib/svc-generic.h"
#include "telepathy-glib/util.h"

static void call_content_iface_init (gpointer g_iface, gpointer iface_data);

G_DEFINE_TYPE_WITH_CODE(TpBaseCallContent, tp_base_call_content,
    G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
        tp_dbus_properties_mixin_iface_init);
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CALL_CONTENT,
        call_content_iface_init);
    );

struct _TpBaseCallContentPrivate
{
  TpBaseConnection *conn;

  gchar *object_path;

  gchar *name;
  TpMediaStreamType media_type;
  TpHandle creator;
  TpCallContentDisposition disposition;

  /* GList or reffed TpBaseCallStream */
  GList *streams;

  /* Borrowed */
  TpBaseCallChannel *channel;

  gboolean deinit_has_run;
};

enum
{
  PROP_OBJECT_PATH = 1,
  PROP_CONNECTION,

  PROP_INTERFACES,
  PROP_NAME,
  PROP_MEDIA_TYPE,
  PROP_CREATOR,
  PROP_DISPOSITION,
  PROP_STREAMS
};

static void
tp_base_call_content_init (TpBaseCallContent *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      TP_TYPE_BASE_CALL_CONTENT, TpBaseCallContentPrivate);
}

static void
tp_base_call_content_constructed (GObject *obj)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (obj);
  TpDBusDaemon *bus = tp_base_connection_get_dbus_daemon (
      (TpBaseConnection *) self->priv->conn);

  if (G_OBJECT_CLASS (tp_base_call_content_parent_class)->constructed != NULL)
    G_OBJECT_CLASS (tp_base_call_content_parent_class)->constructed (obj);

  DEBUG ("Registering %s", self->priv->object_path);
  tp_dbus_daemon_register_object (bus, self->priv->object_path, obj);
}

static void
stream_list_destroy (GList *streams)
{
  g_list_free_full (streams, g_object_unref);
}

static void
base_call_content_deinit_real (TpBaseCallContent *self)
{
  TpDBusDaemon *bus = tp_base_connection_get_dbus_daemon (
      (TpBaseConnection *) self->priv->conn);

  tp_dbus_daemon_unregister_object (bus, G_OBJECT (self));

  tp_clear_pointer (&self->priv->streams, stream_list_destroy);
}

static void
tp_base_call_content_dispose (GObject *object)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (object);

  g_assert (self->priv->deinit_has_run);
<commit_msg>base-call-content: deinit the content instead of just asserting<commit_after>/*
 * base-call-content.c - Source for TpBaseCallContent
 * Copyright © 2009–2011 Collabora Ltd.
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * 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
 */

/**
 * SECTION:base-call-content
 * @title: TpBaseCallContent
 * @short_description: base class for #TpSvcCallContent implementations
 * @see_also: #TpSvcCallContent, #TpBaseCallChannel and #TpBaseCallStream
 *
 * This base class makes it easier to write #TpSvcCallContent
 * implementations by implementing its properties, and some of its methods.
 *
 * Subclasses should fill in #TpBaseCallContentClass.extra_interfaces,
 * and #TpBaseCallContentClass.deinit virtual function.
 *
 * Since: 0.UNRELEASED
 */

/**
 * TpBaseCallContent:
 *
 * A base class for call content implementations
 *
 * Since: 0.UNRELEASED
 */

/**
 * TpBaseCallContentClass:
 * @extra_interfaces: extra interfaces provided by this content (this SHOULD NOT
 *  include %TP_IFACE_CALL_CONTENT itself)
 * @deinit: optional; virtual method called by #TpBaseCallChannel when removing
 *  the content
 *
 * The class structure for #TpBaseCallContent
 *
 * Since: 0.UNRELEASED
 */

/**
 * TpBaseCallContentDeinitFunc:
 * @self: a #TpBaseCallContent
 *
 * Signature of an implementation of #TpBaseCallContentClass.deinit.
 *
 * Since: 0.UNRELEASED
 */

#include "config.h"
#include "telepathy-glib/base-call-content.h"

#define DEBUG_FLAG TP_DEBUG_CALL

#include "telepathy-glib/base-call-channel.h"
#include "telepathy-glib/base-call-internal.h"
#include "telepathy-glib/base-connection.h"
#include "telepathy-glib/debug-internal.h"
#include "telepathy-glib/dbus.h"
#include "telepathy-glib/dbus-properties-mixin.h"
#include "telepathy-glib/gtypes.h"
#include "telepathy-glib/interfaces.h"
#include "telepathy-glib/svc-call.h"
#include "telepathy-glib/svc-generic.h"
#include "telepathy-glib/util.h"

static void call_content_iface_init (gpointer g_iface, gpointer iface_data);

G_DEFINE_TYPE_WITH_CODE(TpBaseCallContent, tp_base_call_content,
    G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
        tp_dbus_properties_mixin_iface_init);
    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CALL_CONTENT,
        call_content_iface_init);
    );

struct _TpBaseCallContentPrivate
{
  TpBaseConnection *conn;

  gchar *object_path;

  gchar *name;
  TpMediaStreamType media_type;
  TpHandle creator;
  TpCallContentDisposition disposition;

  /* GList or reffed TpBaseCallStream */
  GList *streams;

  /* Borrowed */
  TpBaseCallChannel *channel;

  gboolean deinit_has_run;
};

enum
{
  PROP_OBJECT_PATH = 1,
  PROP_CONNECTION,

  PROP_INTERFACES,
  PROP_NAME,
  PROP_MEDIA_TYPE,
  PROP_CREATOR,
  PROP_DISPOSITION,
  PROP_STREAMS
};

static void
tp_base_call_content_init (TpBaseCallContent *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      TP_TYPE_BASE_CALL_CONTENT, TpBaseCallContentPrivate);
}

static void
tp_base_call_content_constructed (GObject *obj)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (obj);
  TpDBusDaemon *bus = tp_base_connection_get_dbus_daemon (
      (TpBaseConnection *) self->priv->conn);

  if (G_OBJECT_CLASS (tp_base_call_content_parent_class)->constructed != NULL)
    G_OBJECT_CLASS (tp_base_call_content_parent_class)->constructed (obj);

  DEBUG ("Registering %s", self->priv->object_path);
  tp_dbus_daemon_register_object (bus, self->priv->object_path, obj);
}

static void
stream_list_destroy (GList *streams)
{
  g_list_free_full (streams, g_object_unref);
}

static void
base_call_content_deinit_real (TpBaseCallContent *self)
{
  TpDBusDaemon *bus = tp_base_connection_get_dbus_daemon (
      (TpBaseConnection *) self->priv->conn);

  tp_dbus_daemon_unregister_object (bus, G_OBJECT (self));

  tp_clear_pointer (&self->priv->streams, stream_list_destroy);
}

static void
tp_base_call_content_dispose (GObject *object)
{
  TpBaseCallContent *self = TP_BASE_CALL_CONTENT (object);

  if (!self->priv->deinit_has_run)
    _tp_base_call_content_deinit (self);

  g_assert (self->priv->deinit_has_run);

{'fraction_non_alphanumeric': 0.09482488238369054, 'fraction_numerical': 0.005436487192890748, 'mean_word_length': 5.012570710245129, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 53, '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': '7229924', 'n_tokens_mistral': 3343, 'n_tokens_neox': 3212, 'n_words': 787}