From bb0fd96dbf11c7f3977b3711384a3551ad1bdab2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 19 Sep 2012 12:26:09 +0100 Subject: [PATCH 08/15] tp_account_channel_request_new_vardict: add Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55099 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/account-channel-request.c | 49 ++++++++++++++ telepathy-glib/account-channel-request.h | 5 ++ tests/dbus/account-channel-request.c | 97 ++++++++++++---------------- 4 files changed, 95 insertions(+), 57 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index fe3a403..5ae79c3 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -6165,6 +6165,7 @@ tp_svc_channel_type_contact_search_get_type telepathy-glib/telepathy-glib.h TpAccountChannelRequest tp_account_channel_request_new +tp_account_channel_request_new_vardict tp_account_channel_request_get_request tp_account_channel_request_get_user_action_time tp_account_channel_request_get_account diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c index 1d2edf0..59cd1e3 100644 --- a/telepathy-glib/account-channel-request.c +++ b/telepathy-glib/account-channel-request.c @@ -86,6 +86,7 @@ #include #include #include +#include #define DEBUG_FLAG TP_DEBUG_CLIENT #include "telepathy-glib/debug-internal.h" @@ -492,6 +493,54 @@ tp_account_channel_request_new ( } /** + * tp_account_channel_request_new_vardict: + * @account: a #TpAccount + * @request: the requested + * properties of the channel (see #TpAccountChannelRequest:request) + * as a %G_VARIANT_TYPE_VARDICT + * @user_action_time: the time of the user action that caused this request, + * or one of the special values %TP_USER_ACTION_TIME_NOT_USER_ACTION or + * %TP_USER_ACTION_TIME_CURRENT_TIME (see + * #TpAccountChannelRequest:user-action-time) + * + * Convenience function to create a new #TpAccountChannelRequest object. + * + * If @request is a floating reference, this function will + * take ownership of it, much like g_variant_ref_sink(). See documentation of + * that function for details. + * + * Returns: a new #TpAccountChannelRequest object + * + * Since: 0.UNRELEASED + */ +TpAccountChannelRequest * +tp_account_channel_request_new_vardict ( + TpAccount *account, + GVariant *request, + gint64 user_action_time) +{ + GHashTable *hash; + TpAccountChannelRequest *ret; + + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (request != NULL, NULL); + g_return_val_if_fail (g_variant_is_of_type (request, G_VARIANT_TYPE_VARDICT), + NULL); + + g_variant_ref_sink (request); + hash = _tp_asv_from_vardict (request); + g_variant_unref (request); + + ret = g_object_new (TP_TYPE_ACCOUNT_CHANNEL_REQUEST, + "account", account, + "request", hash, + "user-action-time", user_action_time, + NULL); + g_hash_table_unref (hash); + return ret; +} + +/** * tp_account_channel_request_get_account: * @self: a #TpAccountChannelRequest * diff --git a/telepathy-glib/account-channel-request.h b/telepathy-glib/account-channel-request.h index b78f114..fe0b102 100644 --- a/telepathy-glib/account-channel-request.h +++ b/telepathy-glib/account-channel-request.h @@ -66,6 +66,11 @@ TpAccountChannelRequest * tp_account_channel_request_new ( TpAccount *account, GHashTable *request, gint64 user_action_time) G_GNUC_WARN_UNUSED_RESULT; +_TP_AVAILABLE_IN_UNRELEASED +TpAccountChannelRequest * tp_account_channel_request_new_vardict ( + TpAccount *account, + GVariant *request, + gint64 user_action_time) G_GNUC_WARN_UNUSED_RESULT; TpAccount * tp_account_channel_request_get_account ( TpAccountChannelRequest *self); diff --git a/tests/dbus/account-channel-request.c b/tests/dbus/account-channel-request.c index 6621f1e..895f1b8 100644 --- a/tests/dbus/account-channel-request.c +++ b/tests/dbus/account-channel-request.c @@ -189,6 +189,16 @@ create_request (void) NULL); } +static GVariant * +floating_request (void) +{ + return g_variant_new_parsed ( + "{ %s: <%s>, %s: <%u>, %s: <%s> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_TEXT, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, (guint32) TP_HANDLE_TYPE_CONTACT, + TP_PROP_CHANNEL_TARGET_ID, "alice"); +} + static void test_handle_create_success (Test *test, gconstpointer data G_GNUC_UNUSED) @@ -481,18 +491,16 @@ static void test_handle_cancel_before (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); g_cancellable_cancel (test->cancellable); tp_account_channel_request_ensure_and_handle_channel_async (req, test->cancellable, create_and_handle_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -512,11 +520,10 @@ static void test_handle_cancel_after_create (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_ensure_and_handle_channel_async (req, test->cancellable, create_and_handle_cb, test); @@ -524,7 +531,6 @@ test_handle_cancel_after_create (Test *test, g_signal_connect (test->cd_service, "channel-request-created", G_CALLBACK (channel_request_created_cb), test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -553,11 +559,10 @@ static void test_handle_re_handle (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req, *req2; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_ensure_and_handle_channel_async (req, NULL, ensure_and_handle_cb, test); @@ -569,7 +574,8 @@ test_handle_re_handle (Test *test, G_CALLBACK (re_handled_cb), test); /* Ensure the same channel to re-handle it */ - req2 = tp_account_channel_request_new (test->account, request, 666); + req2 = tp_account_channel_request_new_vardict (test->account, + floating_request (), 666); tp_account_channel_request_ensure_and_handle_channel_async (req2, NULL, ensure_and_handle_cb, test); @@ -578,7 +584,6 @@ test_handle_re_handle (Test *test, test->count = 2; g_main_loop_run (test->mainloop); - g_hash_table_unref (request); g_object_unref (req); g_object_unref (req2); } @@ -636,12 +641,11 @@ static void test_handle_create_success_hints (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; GHashTable *hints; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); hints = create_hints (); tp_account_channel_request_set_hints (req, hints); @@ -650,7 +654,6 @@ test_handle_create_success_hints (Test *test, tp_account_channel_request_create_and_handle_channel_async (req, NULL, create_and_handle_hints_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -721,7 +724,6 @@ static void test_handle_delegated (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; GPtrArray *requests, *requests_satisified, *channels; GHashTable *hints, *request_props, *info; @@ -729,8 +731,8 @@ test_handle_delegated (Test *test, TpBaseClient *base_client; TpClient *client; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); /* Allow other clients to preempt the channel */ tp_account_channel_request_set_delegated_channel_callback (req, @@ -739,7 +741,6 @@ test_handle_delegated (Test *test, tp_account_channel_request_create_and_handle_channel_async (req, NULL, create_and_handle_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -827,16 +828,14 @@ static void test_forget_create_success (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_create_channel_async (req, "Fake", NULL, create_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -861,16 +860,14 @@ static void test_forget_ensure_success (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_ensure_channel_async (req, "Fake", NULL, ensure_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -960,18 +957,16 @@ static void test_forget_cancel_before (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); g_cancellable_cancel (test->cancellable); tp_account_channel_request_create_channel_async (req, "Fake", test->cancellable, create_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -982,11 +977,10 @@ static void test_forget_cancel_after_create (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_create_channel_async (req, "Fake", test->cancellable, create_cb, test); @@ -994,7 +988,6 @@ test_forget_cancel_after_create (Test *test, g_signal_connect (test->cd_service, "channel-request-created", G_CALLBACK (channel_request_created_cb), test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -1026,16 +1019,14 @@ static void test_observe_create_success (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_create_and_observe_channel_async (req, "Fake", NULL, create_and_observe_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -1144,16 +1135,14 @@ static void test_observe_ensure_success (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_ensure_and_observe_channel_async (req, "Fake", NULL, ensure_and_observe_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -1165,18 +1154,16 @@ static void test_observe_cancel_before (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); g_cancellable_cancel (test->cancellable); tp_account_channel_request_create_and_observe_channel_async (req, "Fake", test->cancellable, create_and_observe_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -1187,11 +1174,10 @@ static void test_observe_cancel_after_create (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_create_and_observe_channel_async (req, "Fake", test->cancellable, create_and_observe_cb, test); @@ -1199,7 +1185,6 @@ test_observe_cancel_after_create (Test *test, g_signal_connect (test->cd_service, "channel-request-created", G_CALLBACK (channel_request_created_cb), test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); @@ -1211,16 +1196,14 @@ static void test_observe_no_channel (Test *test, gconstpointer data G_GNUC_UNUSED) { - GHashTable *request; TpAccountChannelRequest *req; - request = create_request (); - req = tp_account_channel_request_new (test->account, request, 0); + req = tp_account_channel_request_new_vardict (test->account, + floating_request (), 0); tp_account_channel_request_create_and_observe_channel_async (req, "FakeNoChannel", NULL, create_and_observe_cb, test); - g_hash_table_unref (request); g_object_unref (req); g_main_loop_run (test->mainloop); -- 1.7.10.4