[Telepathy-commits] [telepathy-glib/master] Add a simple C binding for ConnectionError

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Jan 28 03:30:02 PST 2009


Unfortunately, dbus-glib doesn't expose the algorithm it uses to
map from a GError to a D-Bus error name, so we can't just take a
GError as argument. When that's fixed, we can add a version that
takes a GError, so I've reserved the simpler name for that.
---
 docs/reference/telepathy-glib-sections.txt |    1 +
 telepathy-glib/base-connection.c           |   42 ++++++++++++++++++++++++++++
 telepathy-glib/base-connection.h           |   10 ++++++
 3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 90a29c8..71a4da8 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -42,6 +42,7 @@ tp_base_connection_get_handles
 tp_base_connection_get_self_handle
 tp_base_connection_set_self_handle
 tp_base_connection_change_status
+tp_base_connection_disconnect_with_dbus_error
 tp_base_connection_finish_shutdown
 tp_base_connection_add_interfaces
 tp_base_connection_dbus_request_handles
diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c
index 60d33e6..ccee5eb 100644
--- a/telepathy-glib/base-connection.c
+++ b/telepathy-glib/base-connection.c
@@ -2542,6 +2542,48 @@ void tp_base_connection_finish_shutdown (TpBaseConnection *self)
 }
 
 /**
+ * tp_base_connection_disconnect_with_dbus_error:
+ * @self: The connection
+ * @error_name: The D-Bus error with which the connection changed status to
+ *              Disconnected
+ * @details: Further details of the error, as a hash table where the keys
+ *           are strings as defined in the Telepathy specification, and the
+ *           values are GValues. %NULL is allowed, and treated as empty.
+ * @reason: The reason code to use in the StatusChanged signal
+ *          (a less specific, non-extensible version of @error_name)
+ *
+ * Change the status of the connection to %TP_CONNECTION_STATUS_DISCONNECTED,
+ * as if by a call to tp_base_connection_change_status(). Before doing so,
+ * emit the ConnectionError D-Bus signal to give more details of the error.
+ *
+ * @details may contain, among other entries, the well-known key
+ * "debug-message", whose value should have type G_TYPE_STRING.
+ */
+void
+tp_base_connection_disconnect_with_dbus_error (TpBaseConnection *self,
+                                               const gchar *error_name,
+                                               GHashTable *details,
+                                               TpConnectionStatusReason reason)
+{
+  GHashTable *dup = NULL;
+
+  g_return_if_fail (tp_dbus_check_valid_interface_name (error_name, NULL));
+
+  if (details == NULL)
+    {
+      dup = g_hash_table_new (g_str_hash, g_str_equal);
+      details = dup;
+    }
+
+  tp_svc_connection_emit_connection_error (self, error_name, details);
+  tp_base_connection_change_status (self, TP_CONNECTION_STATUS_DISCONNECTED,
+      reason);
+
+  if (dup != NULL)
+    g_hash_table_destroy (dup);
+}
+
+/**
  * tp_base_connection_change_status:
  * @self: The connection
  * @status: The new status
diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h
index 2aa9cf2..94b62f6 100644
--- a/telepathy-glib/base-connection.h
+++ b/telepathy-glib/base-connection.h
@@ -115,6 +115,16 @@ gboolean tp_base_connection_register (TpBaseConnection *self,
     const gchar *cm_name, gchar **bus_name, gchar **object_path,
     GError **error);
 
+/* FIXME: when dbus-glib exposes its GError -> D-Bus error name mapping,
+we could also add:
+void tp_base_connection_disconnect_with_error (TpBaseConnection *self,
+    const GError *error, GHashTable *details, TpConnectionStatusReason reason);
+*/
+
+void tp_base_connection_disconnect_with_dbus_error (TpBaseConnection *self,
+    const gchar *error_name, GHashTable *details,
+    TpConnectionStatusReason reason);
+
 void tp_base_connection_change_status (TpBaseConnection *self,
     TpConnectionStatus status, TpConnectionStatusReason reason);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list