summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-04-12 18:24:27 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-04-12 18:42:42 +0100
commit35e33407873ff037ef7d6b9ea31f7185531b14d0 (patch)
treeaed6e2f55aeb4d41b2ed1e8a5d9ec4d340593d1f
parentd94685b66760fe5ec30fc54fbe4926d871915d14 (diff)
tp_connection_dup_detailed_error_vardict: add and testasv
-rw-r--r--docs/reference/telepathy-glib-sections.txt1
-rw-r--r--telepathy-glib/connection.c33
-rw-r--r--telepathy-glib/connection.h3
-rw-r--r--tests/dbus/connection-error.c19
4 files changed, 56 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 7a1aade7b..070915d42 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 8acd374d4..6eb42a039 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 faf2ede0b..68ceff635 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 4e27b3932..c60218375 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);