From 08e9073e9ff26067b31f868ce7c1e0fe61e95c45 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 19 Sep 2012 13:08:32 +0100 Subject: [PATCH 11/15] tp_base_client_add_observer_filter_vardict etc.: add --- docs/reference/telepathy-glib-sections.txt | 3 + telepathy-glib/base-client.c | 98 ++++++++++++++++++++++++++++ telepathy-glib/base-client.h | 10 ++- tests/dbus/simple-approver.c | 28 ++++---- tests/dbus/simple-handler.c | 28 ++++---- tests/dbus/simple-observer.c | 28 ++++---- 6 files changed, 149 insertions(+), 46 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index e20651a..3c1d5d0 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5740,12 +5740,14 @@ TpDebugSenderPrivate TpBaseClient TpBaseClientClass tp_base_client_add_observer_filter +tp_base_client_add_observer_filter_vardict tp_base_client_take_observer_filter tp_base_client_set_observer_recover tp_base_client_set_observer_delay_approvers TpBaseClientClassObserveChannelsImpl tp_base_client_implement_observe_channels tp_base_client_add_approver_filter +tp_base_client_add_approver_filter_vardict tp_base_client_take_approver_filter TpBaseClientClassAddDispatchOperationImpl tp_base_client_implement_add_dispatch_operation @@ -5753,6 +5755,7 @@ tp_base_client_add_handler_capabilities tp_base_client_add_handler_capabilities_varargs tp_base_client_add_handler_capability tp_base_client_add_handler_filter +tp_base_client_add_handler_filter_vardict tp_base_client_take_handler_filter tp_base_client_be_a_handler TpBaseClientClassHandleChannelsImpl diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c index 5ebaee8..ef71b2b 100644 --- a/telepathy-glib/base-client.c +++ b/telepathy-glib/base-client.c @@ -205,6 +205,7 @@ #include "telepathy-glib/deprecated-internal.h" #include "telepathy-glib/simple-client-factory-internal.h" #include "telepathy-glib/util-internal.h" +#include "telepathy-glib/variant-util-internal.h" static void observer_iface_init (gpointer, gpointer); static void approver_iface_init (gpointer, gpointer); @@ -409,6 +410,43 @@ tp_base_client_take_observer_filter (TpBaseClient *self, } /** + * tp_base_client_add_observer_filter_vardict: + * @self: a client + * @filter: (transfer none): a variant of type %G_VARIANT_TYPE_VARDICT + * + * Register a new channel class as Observer.ObserverChannelFilter. + * The #TpBaseClientClass.observe_channels virtual method will be called + * whenever a new channel's properties match the ones in @filter. + * + * This method may only be called before tp_base_client_register() is + * called, and may only be called on objects whose class implements + * #TpBaseClientClass.observe_channels. + * + * If the variant is floating (see g_variant_ref_sink()), ownership + * will be taken, allowing for uses like this: + * + * |[ + * tp_base_client_add_observer_filter_vardict (client, + * g_variant_new_parsed ("{ %s: <%s>, %s: <%u>, ... }", + * TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_TEXT, + * TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, (guint32) TP_HANDLE_TYPE_CONTACT, + * ...)); + * ]| + * + * Since: 0.UNRELEASED + */ +void +tp_base_client_add_observer_filter_vardict (TpBaseClient *self, + GVariant *filter) +{ + g_return_if_fail (g_variant_is_of_type (filter, G_VARIANT_TYPE_VARDICT)); + + g_variant_ref_sink (filter); + tp_base_client_take_observer_filter (self, _tp_asv_from_vardict (filter)); + g_variant_unref (filter); +} + +/** * tp_base_client_set_observer_recover: * @self: a #TpBaseClient * @recover: the value of the Observer.Recover property @@ -555,6 +593,36 @@ tp_base_client_take_approver_filter (TpBaseClient *self, } /** + * tp_base_client_add_approver_filter_vardict: + * @self: a client + * @filter: (transfer none): a variant of type %G_VARIANT_TYPE_VARDICT + * + * Register a new channel class as Approver.ApproverChannelFilter. + * The #TpBaseClientClass.add_dispatch_operation virtual method will be called + * whenever a new channel's properties match the ones in @filter. + * + * This method may only be called before tp_base_client_register() is + * called, and may only be called on objects whose class implements + * #TpBaseClientClass.add_dispatch_operation. + * + * If the variant is floating (see g_variant_ref_sink()), ownership + * will be taken. See tp_base_client_add_observer_filter_vardict() for + * more details. + * + * Since: 0.UNRELEASED + */ +void +tp_base_client_add_approver_filter_vardict (TpBaseClient *self, + GVariant *filter) +{ + g_return_if_fail (g_variant_is_of_type (filter, G_VARIANT_TYPE_VARDICT)); + + g_variant_ref_sink (filter); + tp_base_client_take_approver_filter (self, _tp_asv_from_vardict (filter)); + g_variant_unref (filter); +} + +/** * tp_base_client_be_a_handler: * @self: a #TpBaseClient * @@ -642,6 +710,36 @@ tp_base_client_take_handler_filter (TpBaseClient *self, } /** + * tp_base_client_add_handler_filter_vardict: + * @self: a client + * @filter: (transfer none): a variant of type %G_VARIANT_TYPE_VARDICT + * + * Register a new channel class as Handler.HandlerChannelFilter. + * The #TpBaseClientClass.handle_channels virtual method will be called + * whenever a new channel's properties match the ones in @filter. + * + * This method may only be called before tp_base_client_register() is + * called, and may only be called on objects whose class implements + * #TpBaseClientClass.handle_channels. + * + * If the variant is floating (see g_variant_ref_sink()), ownership + * will be taken. See tp_base_client_add_observer_filter_vardict() for + * more details. + * + * Since: 0.UNRELEASED + */ +void +tp_base_client_add_handler_filter_vardict (TpBaseClient *self, + GVariant *filter) +{ + g_return_if_fail (g_variant_is_of_type (filter, G_VARIANT_TYPE_VARDICT)); + + g_variant_ref_sink (filter); + tp_base_client_take_handler_filter (self, _tp_asv_from_vardict (filter)); + g_variant_unref (filter); +} + +/** * tp_base_client_set_handler_bypass_approval: * @self: a #TpBaseClient * @bypass_approval: the value of the Handler.BypassApproval property diff --git a/telepathy-glib/base-client.h b/telepathy-glib/base-client.h index ae5ba3d..a3cffff 100644 --- a/telepathy-glib/base-client.h +++ b/telepathy-glib/base-client.h @@ -111,7 +111,9 @@ void tp_base_client_implement_handle_channels (TpBaseClientClass *klass, void tp_base_client_add_observer_filter (TpBaseClient *self, GHashTable *filter); - +_TP_AVAILABLE_IN_UNRELEASED +void tp_base_client_add_observer_filter_vardict (TpBaseClient *self, + GVariant *filter); void tp_base_client_take_observer_filter (TpBaseClient *self, GHashTable *filter); @@ -124,6 +126,9 @@ void tp_base_client_add_approver_filter (TpBaseClient *self, GHashTable *filter); void tp_base_client_take_approver_filter (TpBaseClient *self, GHashTable *filter); +_TP_AVAILABLE_IN_UNRELEASED +void tp_base_client_add_approver_filter_vardict (TpBaseClient *self, + GVariant *filter); void tp_base_client_be_a_handler (TpBaseClient *self); @@ -131,6 +136,9 @@ void tp_base_client_add_handler_filter (TpBaseClient *self, GHashTable *filter); void tp_base_client_take_handler_filter (TpBaseClient *self, GHashTable *filter); +_TP_AVAILABLE_IN_UNRELEASED +void tp_base_client_add_handler_filter_vardict (TpBaseClient *self, + GVariant *filter); void tp_base_client_set_handler_bypass_approval (TpBaseClient *self, gboolean bypass_approval); diff --git a/tests/dbus/simple-approver.c b/tests/dbus/simple-approver.c index 62d50f5..9995d9d 100644 --- a/tests/dbus/simple-approver.c +++ b/tests/dbus/simple-approver.c @@ -277,16 +277,14 @@ test_properties (Test *test, { create_simple_approver (test, add_dispatch_success); - tp_base_client_take_approver_filter (test->simple_approver, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, - NULL)); + tp_base_client_add_approver_filter_vardict (test->simple_approver, + g_variant_new_parsed ("{ %s: <%s> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_TEXT)); - tp_base_client_take_approver_filter (test->simple_approver, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_CONTACT, - NULL)); + tp_base_client_add_approver_filter_vardict (test->simple_approver, + g_variant_new_parsed ("{ %s: <%s>, %s: <%u> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, (guint32) TP_HANDLE_TYPE_CONTACT)); tp_base_client_register (test->simple_approver, &test->error); g_assert_no_error (test->error); @@ -394,8 +392,8 @@ test_success (Test *test, { create_simple_approver (test, add_dispatch_success); - tp_base_client_take_approver_filter (test->simple_approver, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_approver_filter_vardict (test->simple_approver, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_approver, &test->error); g_assert_no_error (test->error); @@ -440,8 +438,8 @@ test_delayed (Test *test, { create_simple_approver (test, add_dispatch_async); - tp_base_client_take_approver_filter (test->simple_approver, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_approver_filter_vardict (test->simple_approver, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_approver, &test->error); g_assert_no_error (test->error); @@ -473,8 +471,8 @@ test_fail (Test *test, { create_simple_approver (test, add_dispatch_fail); - tp_base_client_take_approver_filter (test->simple_approver, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_approver_filter_vardict (test->simple_approver, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_approver, &test->error); g_assert_no_error (test->error); diff --git a/tests/dbus/simple-handler.c b/tests/dbus/simple-handler.c index 69a69ba..691a8d9 100644 --- a/tests/dbus/simple-handler.c +++ b/tests/dbus/simple-handler.c @@ -298,16 +298,14 @@ test_properties (Test *test, { create_simple_handler (test, FALSE, TRUE, handle_channels_success); - tp_base_client_take_handler_filter (test->simple_handler, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, - NULL)); + tp_base_client_add_handler_filter_vardict (test->simple_handler, + g_variant_new_parsed ("{ %s: <%s> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_TEXT)); - tp_base_client_take_handler_filter (test->simple_handler, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_CONTACT, - NULL)); + tp_base_client_add_handler_filter_vardict (test->simple_handler, + g_variant_new_parsed ("{ %s: <%s>, %s: <%u> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, (guint32) TP_HANDLE_TYPE_CONTACT)); tp_base_client_register (test->simple_handler, &test->error); g_assert_no_error (test->error); @@ -412,8 +410,8 @@ test_success (Test *test, { create_simple_handler (test, FALSE, FALSE, handle_channels_success); - tp_base_client_take_handler_filter (test->simple_handler, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_handler_filter_vardict (test->simple_handler, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_handler, &test->error); g_assert_no_error (test->error); @@ -455,8 +453,8 @@ test_delayed (Test *test, { create_simple_handler (test, FALSE, FALSE, handle_channels_async); - tp_base_client_take_handler_filter (test->simple_handler, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_handler_filter_vardict (test->simple_handler, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_handler, &test->error); g_assert_no_error (test->error); @@ -489,8 +487,8 @@ test_fail (Test *test, { create_simple_handler (test, FALSE, FALSE, handle_channels_fail); - tp_base_client_take_handler_filter (test->simple_handler, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_handler_filter_vardict (test->simple_handler, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_handler, &test->error); g_assert_no_error (test->error); diff --git a/tests/dbus/simple-observer.c b/tests/dbus/simple-observer.c index 5226676..099efbc 100644 --- a/tests/dbus/simple-observer.c +++ b/tests/dbus/simple-observer.c @@ -266,16 +266,14 @@ test_properties (Test *test, { create_simple_observer (test, TRUE, observe_channels_success); - tp_base_client_take_observer_filter (test->simple_observer, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, - NULL)); + tp_base_client_add_observer_filter_vardict (test->simple_observer, + g_variant_new_parsed ("{ %s: <%s> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_TEXT)); - tp_base_client_take_observer_filter (test->simple_observer, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_CONTACT, - NULL)); + tp_base_client_add_observer_filter_vardict (test->simple_observer, + g_variant_new_parsed ("{ %s: <%s>, %s: <%u> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, (guint32) TP_HANDLE_TYPE_CONTACT)); tp_base_client_register (test->simple_observer, &test->error); g_assert_no_error (test->error); @@ -378,8 +376,8 @@ test_success (Test *test, { create_simple_observer (test, TRUE, observe_channels_success); - tp_base_client_take_observer_filter (test->simple_observer, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_observer_filter_vardict (test->simple_observer, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_observer, &test->error); g_assert_no_error (test->error); @@ -421,8 +419,8 @@ test_delayed (Test *test, { create_simple_observer (test, TRUE, observe_channels_async); - tp_base_client_take_observer_filter (test->simple_observer, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_observer_filter_vardict (test->simple_observer, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_observer, &test->error); g_assert_no_error (test->error); @@ -455,8 +453,8 @@ test_fail (Test *test, { create_simple_observer (test, TRUE, observe_channels_fail); - tp_base_client_take_observer_filter (test->simple_observer, - g_hash_table_new (NULL, NULL)); + tp_base_client_add_observer_filter_vardict (test->simple_observer, + g_variant_new_parsed ("@a{sv} {}")); tp_base_client_register (test->simple_observer, &test->error); g_assert_no_error (test->error); -- 1.7.10.4