[telepathy-qt4/master] Merge 'callable' example CM from telepathy-glib 0.7.36.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Sep 22 16:04:34 PDT 2009
---
tests/lib/callable/media-channel.c | 38 +++++++++++++++++++++-------------
tests/lib/callable/media-manager.c | 38 +++++++++++++++++++++-------------
tests/lib/callable/media-stream.c | 39 ++++++++++++++++++++++++++++++++---
3 files changed, 81 insertions(+), 34 deletions(-)
diff --git a/tests/lib/callable/media-channel.c b/tests/lib/callable/media-channel.c
index c3707ca..22a00ee 100644
--- a/tests/lib/callable/media-channel.c
+++ b/tests/lib/callable/media-channel.c
@@ -1037,6 +1037,7 @@ example_callable_media_channel_add_stream (ExampleCallableMediaChannel *self,
{
ExampleCallableMediaStream *stream;
guint id = self->priv->next_stream_id++;
+ guint state, direction, pending_send;
if (locally_requested)
{
@@ -1049,6 +1050,7 @@ example_callable_media_channel_add_stream (ExampleCallableMediaChannel *self,
"id", id,
"handle", self->priv->handle,
"type", media_type,
+ "locally-requested", locally_requested,
NULL);
g_hash_table_insert (self->priv->streams, GUINT_TO_POINTER (id), stream);
@@ -1056,6 +1058,27 @@ example_callable_media_channel_add_stream (ExampleCallableMediaChannel *self,
tp_svc_channel_type_streamed_media_emit_stream_added (self, id,
self->priv->handle, media_type);
+ g_object_get (stream,
+ "state", &state,
+ "direction", &direction,
+ "pending-send", &pending_send,
+ NULL);
+
+ /* this is the "implicit" initial state mandated by telepathy-spec */
+ if (state != TP_MEDIA_STREAM_STATE_DISCONNECTED)
+ {
+ tp_svc_channel_type_streamed_media_emit_stream_state_changed (self, id,
+ state);
+ }
+
+ /* this is the "implicit" initial direction mandated by telepathy-spec */
+ if (direction != TP_MEDIA_STREAM_DIRECTION_RECEIVE ||
+ pending_send != TP_MEDIA_STREAM_PENDING_LOCAL_SEND)
+ {
+ tp_svc_channel_type_streamed_media_emit_stream_direction_changed (self,
+ id, direction, pending_send);
+ }
+
g_signal_connect (stream, "removed", G_CALLBACK (stream_removed_cb),
self);
g_signal_connect (stream, "notify::state",
@@ -1063,21 +1086,6 @@ example_callable_media_channel_add_stream (ExampleCallableMediaChannel *self,
g_signal_connect (stream, "direction-changed",
G_CALLBACK (stream_direction_changed_cb), self);
- if (locally_requested)
- {
- /* the local user wants this stream to be bidirectional (which
- * requires remote acknowledgement */
- example_callable_media_stream_change_direction (stream,
- TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL, NULL);
- }
- else
- {
- /* the remote user wants this stream to be bidirectional (which
- * requires local acknowledgement) */
- example_callable_media_stream_receive_direction_request (stream,
- TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL);
- }
-
if (self->priv->progress == PROGRESS_ACTIVE)
{
example_callable_media_stream_connect (stream);
diff --git a/tests/lib/callable/media-manager.c b/tests/lib/callable/media-manager.c
index c5548eb..5e21c3d 100644
--- a/tests/lib/callable/media-manager.c
+++ b/tests/lib/callable/media-manager.c
@@ -55,8 +55,10 @@ struct _ExampleCallableMediaManagerPrivate
TpBaseConnection *conn;
guint simulation_delay;
- /* List of ExampleCallableMediaChannel */
- GList *channels;
+ /* Map from reffed ExampleCallableMediaChannel to the same pointer; used as a
+ * set.
+ */
+ GHashTable *channels;
/* Next channel will be ("MediaChannel%u", next_channel_index) */
guint next_channel_index;
@@ -73,7 +75,8 @@ example_callable_media_manager_init (ExampleCallableMediaManager *self)
ExampleCallableMediaManagerPrivate);
self->priv->conn = NULL;
- self->priv->channels = NULL;
+ self->priv->channels = g_hash_table_new_full (NULL, NULL, g_object_unref,
+ NULL);
self->priv->status_changed_id = 0;
self->priv->available_id = 0;
}
@@ -83,12 +86,11 @@ example_callable_media_manager_close_all (ExampleCallableMediaManager *self)
{
if (self->priv->channels != NULL)
{
- GList *tmp = self->priv->channels;
+ GHashTable *tmp = self->priv->channels;
self->priv->channels = NULL;
- g_list_foreach (tmp, (GFunc) g_object_unref, NULL);
- g_list_free (tmp);
+ g_hash_table_unref (tmp);
}
if (self->priv->available_id != 0)
@@ -279,8 +281,13 @@ example_callable_media_manager_foreach_channel (
gpointer user_data)
{
ExampleCallableMediaManager *self = EXAMPLE_CALLABLE_MEDIA_MANAGER (iface);
+ GHashTableIter iter;
+ gpointer chan;
+
+ g_hash_table_iter_init (&iter, self->priv->channels);
- g_list_foreach (self->priv->channels, (GFunc) callback, user_data);
+ while (g_hash_table_iter_next (&iter, &chan, NULL))
+ callback (chan, user_data);
}
static void
@@ -291,9 +298,7 @@ channel_closed_cb (ExampleCallableMediaChannel *chan,
TP_EXPORTABLE_CHANNEL (chan));
if (self->priv->channels != NULL)
- {
- self->priv->channels = g_list_remove_all (self->priv->channels, chan);
- }
+ g_hash_table_remove (self->priv->channels, chan);
}
static ExampleCallableMediaChannel *
@@ -328,7 +333,7 @@ new_channel (ExampleCallableMediaManager *self,
g_signal_connect (chan, "closed", G_CALLBACK (channel_closed_cb), self);
- self->priv->channels = g_list_prepend (self->priv->channels, chan);
+ g_hash_table_insert (self->priv->channels, chan, chan);
if (request_token != NULL)
requests = g_slist_prepend (requests, request_token);
@@ -421,20 +426,23 @@ example_callable_media_manager_request (ExampleCallableMediaManager *self,
if (!require_new)
{
/* see if we're already calling that handle */
- const GList *link;
+ GHashTableIter iter;
+ gpointer chan;
+
+ g_hash_table_iter_init (&iter, self->priv->channels);
- for (link = self->priv->channels; link != NULL; link = link->next)
+ while (g_hash_table_iter_next (&iter, &chan, NULL))
{
guint its_handle;
- g_object_get (link->data,
+ g_object_get (chan,
"handle", &its_handle,
NULL);
if (its_handle == handle)
{
tp_channel_manager_emit_request_already_satisfied (self,
- request_token, TP_EXPORTABLE_CHANNEL (link->data));
+ request_token, TP_EXPORTABLE_CHANNEL (chan));
return TRUE;
}
}
diff --git a/tests/lib/callable/media-stream.c b/tests/lib/callable/media-stream.c
index 2b59d4b..3290029 100644
--- a/tests/lib/callable/media-stream.c
+++ b/tests/lib/callable/media-stream.c
@@ -45,6 +45,7 @@ enum
PROP_DIRECTION,
PROP_STREAM_INFO,
PROP_SIMULATION_DELAY,
+ PROP_LOCALLY_REQUESTED,
N_PROPS
};
@@ -74,6 +75,7 @@ struct _ExampleCallableMediaStreamPrivate
guint connected_event_id;
+ gboolean locally_requested;
gboolean removed;
};
@@ -84,10 +86,10 @@ example_callable_media_stream_init (ExampleCallableMediaStream *self)
EXAMPLE_TYPE_CALLABLE_MEDIA_STREAM,
ExampleCallableMediaStreamPrivate);
- /* FIXME: no particular "implicit" direction is currently mandated by
- * telepathy-spec */
+ /* start off directionless */
self->priv->direction = TP_MEDIA_STREAM_DIRECTION_NONE;
self->priv->pending_send = 0;
+ self->priv->state = TP_MEDIA_STREAM_STATE_DISCONNECTED;
}
static void
@@ -188,6 +190,10 @@ get_property (GObject *object,
g_value_set_uint (value, self->priv->simulation_delay);
break;
+ case PROP_LOCALLY_REQUESTED:
+ g_value_set_boolean (value, self->priv->locally_requested);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -225,6 +231,22 @@ set_property (GObject *object,
self->priv->simulation_delay = g_value_get_uint (value);
break;
+ case PROP_LOCALLY_REQUESTED:
+ self->priv->locally_requested = g_value_get_boolean (value);
+
+ if (self->priv->locally_requested)
+ {
+ example_callable_media_stream_change_direction (self,
+ TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL, NULL);
+ }
+ else
+ {
+ example_callable_media_stream_receive_direction_request (self,
+ TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL);
+ }
+
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -339,6 +361,13 @@ example_callable_media_stream_class_init (ExampleCallableMediaStreamClass *klass
g_object_class_install_property (object_class, PROP_SIMULATION_DELAY,
param_spec);
+ param_spec = g_param_spec_boolean ("locally-requested", "Locally requested?",
+ "True if this channel was requested by the local user",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_LOCALLY_REQUESTED,
+ param_spec);
+
signals[SIGNAL_REMOVED] = g_signal_new ("removed",
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
@@ -360,12 +389,14 @@ example_callable_media_stream_close (ExampleCallableMediaStream *self)
g_message ("Sending to server: Closing stream %u",
self->priv->id);
- g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
-
if (self->priv->connected_event_id != 0)
{
g_source_remove (self->priv->connected_event_id);
}
+
+ /* this has to come last, because the MediaChannel may unref us in
+ * response to the removed signal */
+ g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
}
}
--
1.5.6.5
More information about the telepathy-commits
mailing list