[Telepathy-commits] [telepathy-gabble/master] jingle-session.c: refactor content creation code
Senko Rasic
senko.rasic at collabora.co.uk
Tue Dec 2 04:34:10 PST 2008
---
src/jingle-session.c | 103 +++++++++++++++++++++++++------------------------
1 files changed, 53 insertions(+), 50 deletions(-)
diff --git a/src/jingle-session.c b/src/jingle-session.c
index efee07b..617a6fe 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -543,6 +543,55 @@ fire_idle_content_reject (GabbleJingleSession *sess, const gchar *name,
g_idle_add (idle_content_reject, ctx);
}
+static GabbleJingleContent *
+create_content (GabbleJingleSession *sess, GType content_type,
+ JingleMediaType type, const gchar *content_ns, const gchar *name,
+ LmMessageNode *content_node, GError **error)
+{
+ GabbleJingleSessionPrivate *priv = GABBLE_JINGLE_SESSION_GET_PRIVATE (sess);
+ GabbleJingleContent *c;
+
+ DEBUG ("session creating new content type, conn == %p, jf == %p", priv->conn, priv->conn->jingle_factory);
+ c = g_object_new (content_type,
+ "connection", priv->conn,
+ "session", sess,
+ "content-ns", content_ns,
+ "name", name,
+ NULL);
+
+ if (type != JINGLE_MEDIA_TYPE_NONE)
+ {
+ g_object_set (c, "media-type", type, NULL);
+ }
+
+ g_signal_connect (c, "ready",
+ (GCallback) content_ready_cb, sess);
+ g_signal_connect (c, "removed",
+ (GCallback) content_removed_cb, sess);
+
+ /* if we are called by parser, parse content add */
+ if (content_node != NULL)
+ {
+ gabble_jingle_content_parse_add (c, content_node,
+ JINGLE_IS_GOOGLE_DIALECT (priv->dialect), error);
+
+ if (*error != NULL)
+ {
+ g_object_unref (c);
+ return NULL;
+ }
+
+ /* gtalk streams don't have name, so use whatever Content came up with */
+ if (name == NULL)
+ g_object_get (c, "name", &name, NULL);
+ }
+
+ /* This will override existing content if it exists. */
+ g_hash_table_replace (priv->contents, g_strdup (name), c);
+ g_signal_emit (sess, signals[NEW_CONTENT], 0, c);
+ return c;
+}
+
static void
_each_content_add (GabbleJingleSession *sess, GabbleJingleContent *c,
@@ -604,38 +653,8 @@ _each_content_add (GabbleJingleSession *sess, GabbleJingleContent *c,
}
}
- DEBUG ("session creating new content type, conn == %p, jf == %p", priv->conn, priv->conn->jingle_factory);
- c = g_object_new (content_type,
- "connection", priv->conn,
- "session", sess,
- "content-ns", content_ns,
- NULL);
-
- g_signal_connect (c, "ready",
- (GCallback) content_ready_cb, sess);
- g_signal_connect (c, "removed",
- (GCallback) content_removed_cb, sess);
-
- gabble_jingle_content_parse_add (c, content_node,
- ((priv->dialect == JINGLE_DIALECT_GTALK3) ||
- (priv->dialect == JINGLE_DIALECT_GTALK4)), error);
-
- if (*error != NULL)
- {
- g_object_unref (c);
- return;
- }
-
- /* gtalk streams don't have name, so use whatever Content came up with */
- if (name == NULL)
- {
- g_object_get (c, "name", &name, NULL);
- }
-
- /* This will override existing content if it exists. */
- g_hash_table_replace (priv->contents, g_strdup (name), c);
-
- g_signal_emit (sess, signals[NEW_CONTENT], 0, c);
+ create_content (sess, content_type, JINGLE_MEDIA_TYPE_NONE,
+ content_ns, NULL, content_node, error);
}
static void
@@ -1564,24 +1583,8 @@ gabble_jingle_session_add_content (GabbleJingleSession *sess, JingleMediaType mt
g_assert (content_type != 0);
- c = g_object_new (content_type,
- "connection", priv->conn,
- "session", sess,
- "media-type", mtype,
- "content-ns", content_ns,
- "transport-ns", transport_ns,
- "name", name,
- "disposition", "session",
- "senders", JINGLE_CONTENT_SENDERS_BOTH,
- NULL);
-
- g_signal_connect (c, "ready",
- (GCallback) content_ready_cb, sess);
- g_signal_connect (c, "removed",
- (GCallback) content_removed_cb, sess);
-
- g_hash_table_insert (priv->contents, g_strdup (name), c);
- g_signal_emit (sess, signals[NEW_CONTENT], 0, c);
+ c = create_content (sess, content_type, JINGLE_MEDIA_TYPE_NONE,
+ content_ns, name, NULL, NULL);
return c;
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list