From 35e33407873ff037ef7d6b9ea31f7185531b14d0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 12 Apr 2012 18:24:27 +0100 Subject: [PATCH 3/3] tp_connection_dup_detailed_error_vardict: add and test --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/connection.c | 33 ++++++++++++++++++++++++++++ telepathy-glib/connection.h | 3 +++ tests/dbus/connection-error.c | 19 ++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 7a1aade..070915d 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -4192,6 +4192,7 @@ tp_connection_set_contact_info_finish TP_UNKNOWN_CONNECTION_STATUS TP_ERRORS_DISCONNECTED tp_connection_get_detailed_error +tp_connection_dup_detailed_error_vardict tp_connection_add_client_interest tp_connection_add_client_interest_by_id tp_connection_bind_connection_status_to_property diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index 8acd374..6eb42a0 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -3302,6 +3302,39 @@ tp_connection_get_detailed_error (TpConnection *self, } /** + * tp_connection_dup_detailed_error_vardict: + * @self: a connection + * @details: (out) (allow-none) (transfer full): + * optionally used to return a %G_VARIANT_TYPE_VARDICT with details + * of the error + * + * If the connection has disconnected, return the D-Bus error name with which + * it disconnected (in particular, this is %TP_ERROR_STR_CANCELLED if it was + * disconnected by a user request). + * + * Otherwise, return %NULL, without altering @details. + * + * Returns: (transfer full) (allow-none): a D-Bus error name, or %NULL. + * + * Since: 0.19.UNRELEASED + */ +gchar * +tp_connection_dup_detailed_error_vardict (TpConnection *self, + GVariant **details) +{ + const GHashTable *asv; + const gchar *error = tp_connection_get_detailed_error (self, &asv); + + if (error == NULL) + return NULL; + + if (details != NULL) + *details = _tp_asv_to_vardict (asv); + + return g_strdup (error); +} + +/** * tp_connection_add_client_interest: * @self: a connection * @interested_in: a string identifying an interface or part of an interface diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h index faf2ede..68ceff6 100644 --- a/telepathy-glib/connection.h +++ b/telepathy-glib/connection.h @@ -188,6 +188,9 @@ gboolean tp_connection_parse_object_path (TpConnection *self, gchar **protocol, const gchar *tp_connection_get_detailed_error (TpConnection *self, const GHashTable **details); +gchar *tp_connection_dup_detailed_error_vardict (TpConnection *self, + GVariant **details) G_GNUC_WARN_UNUSED_RESULT; + void tp_connection_add_client_interest (TpConnection *self, const gchar *interested_in); diff --git a/tests/dbus/connection-error.c b/tests/dbus/connection-error.c index 4e27b39..c602183 100644 --- a/tests/dbus/connection-error.c +++ b/tests/dbus/connection-error.c @@ -291,6 +291,10 @@ test_detailed_error (Test *test, { GError *error = NULL; const GHashTable *asv; + gchar *str; + GVariant *variant; + gboolean ok; + gint32 bees; asv = GUINT_TO_POINTER (0xDEADBEEF); g_assert_cmpstr (tp_connection_get_detailed_error (test->conn, NULL), ==, @@ -353,6 +357,21 @@ test_detailed_error (Test *test, "not enough bees"); g_assert_cmpint (tp_asv_get_int32 (asv, "bees-required", NULL), ==, 2342); + str = tp_connection_dup_detailed_error_vardict (test->conn, NULL); + g_assert_cmpstr (str, ==, "com.example.DomainSpecificError"); + g_free (str); + str = tp_connection_dup_detailed_error_vardict (test->conn, &variant); + g_assert_cmpstr (str, ==, "com.example.DomainSpecificError"); + g_free (str); + g_assert (variant != NULL); + ok = g_variant_lookup (variant, "debug-message", "s", &str); + g_assert (ok); + g_assert_cmpstr (str, ==, "not enough bees"); + g_free (str); + ok = g_variant_lookup (variant, "bees-required", "i", &bees); + g_assert (ok); + g_assert_cmpint (bees, ==, 2342); + g_assert_cmpstr (g_quark_to_string (error->domain), ==, g_quark_to_string (example_com_error_quark ())); g_assert_cmpuint (error->code, ==, DOMAIN_SPECIFIC_ERROR); -- 1.7.10