<commit_before>/*
 * media-signalling-channel.c - Source for TfMediaSignallingChannel
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2011 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
 */

/**
 * SECTION:media-signalling-channel
 * @short_description: Handle the MediaSignalling interface on a Channel
 *
 * This class handles the
 * org.freedesktop.Telepathy.Channel.Interface.MediaSignalling on a
 * channel using Farsight2.
 */


#include "media-signalling-channel.h"

#include <telepathy-glib/util.h>
#include <telepathy-glib/interfaces.h>

#include "stream.h"
#include "session-priv.h"
#include "stream-priv.h"
#include "tf-signals-marshal.h"


struct _TfMediaSignallingChannel {
  GObject parent;

  TpChannel *channel_proxy;

  TfNatProperties nat_props;
  guint prop_id_nat_traversal;
  guint prop_id_stun_server;
  guint prop_id_stun_port;
  guint prop_id_gtalk_p2p_relay_token;

  /* sessions is NULL until we've had a reply from GetSessionHandlers */
  TfSession *session;
  gboolean got_sessions;
  GPtrArray *streams;
};

struct _TfMediaSignallingChannelClass{
  GObjectClass parent_class;
};


G_DEFINE_TYPE (TfMediaSignallingChannel, tf_media_signalling_channel,
    G_TYPE_OBJECT);

enum
{
  STREAM_CREATED,
  SESSION_CREATED,
  SESSION_INVALIDATED,
  GET_CODEC_CONFIG,
  SIGNAL_COUNT
};

static guint signals[SIGNAL_COUNT] = {0};

static void tf_media_signalling_channel_dispose (GObject *object);

static void new_media_session_handler (TpChannel *channel_proxy,
    const gchar *session_handler_path, const gchar *type,
    gpointer user_data, GObject *weak_object);

static void get_session_handlers_reply (TpChannel *channel_proxy,
    const GPtrArray *session_handlers, const GError *error,
    gpointer user_data, GObject *weak_object);


static void new_stream_cb (TfSession *session, gchar *object_path,
    guint stream_id, TpMediaStreamType media_type,
    TpMediaStreamDirection direction, gpointer user_data);

static void stream_closed_cb (TfStream *stream,
    gpointer user_data);

static void
tf_media_signalling_channel_error (TfMediaSignallingChannel *chan,
    TpMediaStreamError error,
    const gchar *message);



static void
tf_media_signalling_channel_class_init (TfMediaSignallingChannelClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = tf_media_signalling_channel_dispose;

  /**
   * TfMediaSignallingChannel::stream-created:
   * @channel: the #TfMediaSignallingChannel which has a new stream
   * @stream: The new #TfStream
   *
   * This signal is emitted when a new stream has been created in the connection
   * manager and a local proxy has been generated.
   */

  signals[STREAM_CREATED] =
      g_signal_new ("stream-created",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          g_cclosure_marshal_VOID__OBJECT,
          G_TYPE_NONE, 1, TF_TYPE_STREAM);

  /**
   * TfMediaSignallingChannel::session-created:
   * @channel: the #TfMediaSignallingChannel which has a new stream
   * @conference: the #FsConference of the new session
   * @participant: the #FsParticipant of the new session
   *
   * This signal is emitted when a new session has been created in the
   * connection manager. The user should add the new #FsConference to a pipeline
   * and set it to playing. The user should also set any property he wants to
   * set.
   */

  signals[SESSION_CREATED] =
      g_signal_new ("session-created",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          _tf_marshal_VOID__OBJECT,
          G_TYPE_NONE, 1, FS_TYPE_CONFERENCE);

  /**
   * TfMediaSignallingChannel::session-invalidated:
   * @channel: the #TfMediaSignallingChannel which has a new stream
   * @conference: the #FsConference of the new session
   * @participant: the #FsParticipant of the new session
   *
   * This signal is emitted when a session has been invalidated.
   * The #FsConference and #FsParticipant for this session are returned.
   * The #FsConference should be removed from the pipeline.
   */

  signals[SESSION_INVALIDATED] =
      g_signal_new ("session-invalidated",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          _tf_marshal_VOID__OBJECT_OBJECT,
          G_TYPE_NONE, 2, FS_TYPE_CONFERENCE, FS_TYPE_PARTICIPANT);


  signals[GET_CODEC_CONFIG] =
      g_signal_new ("get-codec-config",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
          0,
          NULL, NULL,
          _tf_marshal_BOXED__UINT,
          FS_TYPE_CODEC_LIST, 1, G_TYPE_UINT);
}

static void
tf_media_signalling_channel_init (TfMediaSignallingChannel *self)
{
  self->streams = g_ptr_array_new ();
}

static void<commit_msg>stream-get-codec-config signal does not have details, removing hint<commit_after>/*
 * media-signalling-channel.c - Source for TfMediaSignallingChannel
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2011 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
 */

/**
 * SECTION:media-signalling-channel
 * @short_description: Handle the MediaSignalling interface on a Channel
 *
 * This class handles the
 * org.freedesktop.Telepathy.Channel.Interface.MediaSignalling on a
 * channel using Farsight2.
 */


#include "media-signalling-channel.h"

#include <telepathy-glib/util.h>
#include <telepathy-glib/interfaces.h>

#include "stream.h"
#include "session-priv.h"
#include "stream-priv.h"
#include "tf-signals-marshal.h"


struct _TfMediaSignallingChannel {
  GObject parent;

  TpChannel *channel_proxy;

  TfNatProperties nat_props;
  guint prop_id_nat_traversal;
  guint prop_id_stun_server;
  guint prop_id_stun_port;
  guint prop_id_gtalk_p2p_relay_token;

  /* sessions is NULL until we've had a reply from GetSessionHandlers */
  TfSession *session;
  gboolean got_sessions;
  GPtrArray *streams;
};

struct _TfMediaSignallingChannelClass{
  GObjectClass parent_class;
};


G_DEFINE_TYPE (TfMediaSignallingChannel, tf_media_signalling_channel,
    G_TYPE_OBJECT);

enum
{
  STREAM_CREATED,
  SESSION_CREATED,
  SESSION_INVALIDATED,
  GET_CODEC_CONFIG,
  SIGNAL_COUNT
};

static guint signals[SIGNAL_COUNT] = {0};

static void tf_media_signalling_channel_dispose (GObject *object);

static void new_media_session_handler (TpChannel *channel_proxy,
    const gchar *session_handler_path, const gchar *type,
    gpointer user_data, GObject *weak_object);

static void get_session_handlers_reply (TpChannel *channel_proxy,
    const GPtrArray *session_handlers, const GError *error,
    gpointer user_data, GObject *weak_object);


static void new_stream_cb (TfSession *session, gchar *object_path,
    guint stream_id, TpMediaStreamType media_type,
    TpMediaStreamDirection direction, gpointer user_data);

static void stream_closed_cb (TfStream *stream,
    gpointer user_data);

static void
tf_media_signalling_channel_error (TfMediaSignallingChannel *chan,
    TpMediaStreamError error,
    const gchar *message);



static void
tf_media_signalling_channel_class_init (TfMediaSignallingChannelClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = tf_media_signalling_channel_dispose;

  /**
   * TfMediaSignallingChannel::stream-created:
   * @channel: the #TfMediaSignallingChannel which has a new stream
   * @stream: The new #TfStream
   *
   * This signal is emitted when a new stream has been created in the connection
   * manager and a local proxy has been generated.
   */

  signals[STREAM_CREATED] =
      g_signal_new ("stream-created",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          g_cclosure_marshal_VOID__OBJECT,
          G_TYPE_NONE, 1, TF_TYPE_STREAM);

  /**
   * TfMediaSignallingChannel::session-created:
   * @channel: the #TfMediaSignallingChannel which has a new stream
   * @conference: the #FsConference of the new session
   * @participant: the #FsParticipant of the new session
   *
   * This signal is emitted when a new session has been created in the
   * connection manager. The user should add the new #FsConference to a pipeline
   * and set it to playing. The user should also set any property he wants to
   * set.
   */

  signals[SESSION_CREATED] =
      g_signal_new ("session-created",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          _tf_marshal_VOID__OBJECT,
          G_TYPE_NONE, 1, FS_TYPE_CONFERENCE);

  /**
   * TfMediaSignallingChannel::session-invalidated:
   * @channel: the #TfMediaSignallingChannel which has a new stream
   * @conference: the #FsConference of the new session
   * @participant: the #FsParticipant of the new session
   *
   * This signal is emitted when a session has been invalidated.
   * The #FsConference and #FsParticipant for this session are returned.
   * The #FsConference should be removed from the pipeline.
   */

  signals[SESSION_INVALIDATED] =
      g_signal_new ("session-invalidated",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          _tf_marshal_VOID__OBJECT_OBJECT,
          G_TYPE_NONE, 2, FS_TYPE_CONFERENCE, FS_TYPE_PARTICIPANT);


  signals[GET_CODEC_CONFIG] =
      g_signal_new ("get-codec-config",
          G_OBJECT_CLASS_TYPE (klass),
          G_SIGNAL_RUN_LAST,
          0,
          NULL, NULL,
          _tf_marshal_BOXED__UINT,
          FS_TYPE_CODEC_LIST, 1, G_TYPE_UINT);
}

static void
tf_media_signalling_channel_init (TfMediaSignallingChannel *self)
{
  self->streams = g_ptr_array_new ();
}

static void
{'fraction_non_alphanumeric': 0.07189130825985243, 'fraction_numerical': 0.005758502789274788, 'mean_word_length': 3.830508474576271, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3009748', 'n_tokens_mistral': 3570, 'n_tokens_neox': 3427, 'n_words': 1013}