summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/telepathy-glib-sections.txt1
-rw-r--r--telepathy-glib/base-client.c34
-rw-r--r--telepathy-glib/base-client.h3
-rw-r--r--tests/dbus/base-client.c20
4 files changed, 58 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index dbca57b..86db383 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -4798,6 +4798,7 @@ tp_base_client_add_connection_features_varargs
tp_base_client_add_channel_features
tp_base_client_add_channel_features_varargs
tp_base_client_get_handled_channels
+tp_base_client_is_handling_channel
tp_base_client_get_pending_requests
tp_base_client_set_handler_bypass_approval
tp_base_client_set_handler_request_notification
diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c
index f620cd3..4e4f813 100644
--- a/telepathy-glib/base-client.c
+++ b/telepathy-glib/base-client.c
@@ -2751,3 +2751,37 @@ tp_base_client_get_channel_factory (TpBaseClient *self)
return self->priv->channel_factory;
}
+
+/**
+ * tp_base_client_is_handling_channel:
+ * @self: a #TpBaseClient
+ * @channel: a #TpChannel
+ *
+ * Check if @self is currently handling @channel.
+ *
+ * Returns: %TRUE if @self is handling @channel, %FALSE otherwise
+ * Since: 0.15.UNRELEASED
+ */
+gboolean
+tp_base_client_is_handling_channel (TpBaseClient *self,
+ TpChannel *channel)
+{
+ GList *channels, *l;
+ gboolean found = FALSE;
+
+ g_return_val_if_fail (TP_IS_BASE_CLIENT (self), FALSE);
+ g_return_val_if_fail (self->priv->flags & CLIENT_IS_HANDLER, FALSE);
+
+ channels = tp_base_client_get_handled_channels (self);
+ for (l = channels; l != NULL && !found; l = g_list_next (l))
+ {
+ TpChannel *chan = l->data;
+
+ if (!tp_strdiff (tp_proxy_get_object_path (channel),
+ tp_proxy_get_object_path (chan)))
+ found = TRUE;
+ }
+
+ g_list_free (channels);
+ return found;
+}
diff --git a/telepathy-glib/base-client.h b/telepathy-glib/base-client.h
index 40efce1..1925b66 100644
--- a/telepathy-glib/base-client.h
+++ b/telepathy-glib/base-client.h
@@ -170,6 +170,9 @@ gboolean tp_base_client_register (TpBaseClient *self,
GList *tp_base_client_get_pending_requests (TpBaseClient *self);
GList *tp_base_client_get_handled_channels (TpBaseClient *self);
+gboolean tp_base_client_is_handling_channel (TpBaseClient *self,
+ TpChannel *channel);
+
const gchar *tp_base_client_get_name (TpBaseClient *self);
gboolean tp_base_client_get_uniquify_name (TpBaseClient *self);
const gchar *tp_base_client_get_bus_name (TpBaseClient *self);
diff --git a/tests/dbus/base-client.c b/tests/dbus/base-client.c
index d426bdb..7a8fb04 100644
--- a/tests/dbus/base-client.c
+++ b/tests/dbus/base-client.c
@@ -858,6 +858,11 @@ test_handler (Test *test,
g_main_loop_run (test->mainloop);
g_assert_no_error (test->error);
+ g_assert (!tp_base_client_is_handling_channel (test->base_client,
+ test->text_chan));
+ g_assert (!tp_base_client_is_handling_channel (test->base_client,
+ test->text_chan_2));
+
/* Call HandleChannels */
channels = g_ptr_array_sized_new (2);
add_channel_to_ptr_array (channels, test->text_chan);
@@ -885,6 +890,11 @@ test_handler (Test *test,
g_assert_cmpuint (g_list_length (chans), ==, 2);
g_list_free (chans);
+ g_assert (tp_base_client_is_handling_channel (test->base_client,
+ test->text_chan));
+ g_assert (tp_base_client_is_handling_channel (test->base_client,
+ test->text_chan_2));
+
/* One of the channel is closed */
g_signal_connect (test->text_chan, "invalidated",
G_CALLBACK (channel_invalidated_cb), test);
@@ -895,6 +905,11 @@ test_handler (Test *test,
g_assert_cmpuint (g_list_length (chans), ==, 1);
g_list_free (chans);
+ g_assert (!tp_base_client_is_handling_channel (test->base_client,
+ test->text_chan));
+ g_assert (tp_base_client_is_handling_channel (test->base_client,
+ test->text_chan_2));
+
/* Create another client sharing the same unique name */
client_2 = tp_tests_simple_client_new (test->dbus, "Test", TRUE);
tp_base_client_be_a_handler (TP_BASE_CLIENT (client_2));
@@ -905,6 +920,11 @@ test_handler (Test *test,
g_assert_cmpuint (g_list_length (chans), ==, 1);
g_list_free (chans);
+ g_assert (!tp_base_client_is_handling_channel (TP_BASE_CLIENT (client_2),
+ test->text_chan));
+ g_assert (tp_base_client_is_handling_channel (TP_BASE_CLIENT (client_2),
+ test->text_chan_2));
+
g_object_unref (client_2);
g_ptr_array_foreach (channels, free_channel_details, NULL);