[telepathy-gabble/master] Add API to GabblePlugin to create sidecars

Will Thompson will.thompson at collabora.co.uk
Sat Nov 14 14:27:30 PST 2009


---
 src/plugin.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/plugin.h |   28 ++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/src/plugin.c b/src/plugin.c
index 5357cff..7694c73 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -20,6 +20,9 @@
 
 #include "plugin.h"
 
+#include <telepathy-glib/errors.h>
+#include <telepathy-glib/util.h>
+
 GType
 gabble_plugin_get_type (void)
 {
@@ -59,3 +62,66 @@ gabble_plugin_get_sidecar_interfaces (GabblePlugin *plugin)
 
   return iface->sidecar_interfaces;
 }
+
+gboolean
+gabble_plugin_implements_sidecar (
+    GabblePlugin *plugin,
+    const gchar *sidecar_interface)
+{
+  GabblePluginInterface *iface = GABBLE_PLUGIN_GET_INTERFACE (plugin);
+
+  return tp_strv_contains (iface->sidecar_interfaces, sidecar_interface);
+}
+
+/**
+ * gabble_plugin_create_sidecar:
+ * @plugin: a plugin
+ * @sidecar_interface: the primary D-Bus interface implemented by the sidecar,
+ *                     which must be a member of the list returned by
+ *                     gabble_plugin_get_sidecar_interfaces ()
+ * @callback: function to call when the new sidecar has been created, or an
+ *            unrecoverable error has occured
+ * @user_data: data to pass to @callback
+ */
+void
+gabble_plugin_create_sidecar (
+    GabblePlugin *plugin,
+    const gchar *sidecar_interface,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  GabblePluginInterface *iface = GABBLE_PLUGIN_GET_INTERFACE (plugin);
+
+  if (!gabble_plugin_implements_sidecar (plugin, sidecar_interface))
+    g_simple_async_report_error_in_idle (G_OBJECT (plugin), callback,
+        user_data, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+        "Gabble is buggy: '%s' doesn't implement sidecar %s",
+        iface->name, sidecar_interface);
+  else if (iface->create_sidecar == NULL)
+    g_simple_async_report_error_in_idle (G_OBJECT (plugin), callback,
+        user_data, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+        "'%s' is buggy: it claims to implement %s, but does not implement "
+        "create_sidecar", iface->name, sidecar_interface);
+  else
+    iface->create_sidecar (plugin, sidecar_interface, callback, user_data);
+}
+
+GabbleSidecar *
+gabble_plugin_create_sidecar_finish (
+    GabblePlugin *plugin,
+    GAsyncResult *result,
+    GError **error)
+{
+  GabbleSidecar *sidecar;
+
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+          error))
+    return NULL;
+
+  g_return_val_if_fail (g_simple_async_result_is_valid (result,
+    G_OBJECT (plugin), gabble_plugin_create_sidecar), NULL);
+
+  sidecar = GABBLE_SIDECAR (g_simple_async_result_get_op_res_gpointer (
+      G_SIMPLE_ASYNC_RESULT (result)));
+  return g_object_ref (sidecar);
+}
diff --git a/src/plugin.h b/src/plugin.h
index 3200f23..e11a3e9 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -24,6 +24,8 @@
 
 #include <gio/gio.h>
 
+#include "sidecar.h"
+
 #define GABBLE_TYPE_PLUGIN (gabble_plugin_get_type ())
 #define GABBLE_PLUGIN(obj) \
     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GABBLE_TYPE_PLUGIN, GabblePlugin))
@@ -36,6 +38,12 @@
 typedef struct _GabblePlugin GabblePlugin;
 typedef struct _GabblePluginInterface GabblePluginInterface;
 
+typedef void (*GabblePluginCreateSidecarImpl) (
+    GabblePlugin *plugin,
+    const gchar *sidecar_interface,
+    GAsyncReadyCallback callback,
+    gpointer user_data);
+
 struct _GabblePluginInterface {
     GTypeInterface parent;
 
@@ -49,6 +57,11 @@ struct _GabblePluginInterface {
      * implemented by this plugin.
      */
     const gchar * const *sidecar_interfaces;
+
+    /**
+     * An implementation of gabble_plugin_create_sidecar().
+     */
+    GabblePluginCreateSidecarImpl create_sidecar;
 };
 
 GType gabble_plugin_get_type (void);
@@ -58,6 +71,21 @@ const gchar *gabble_plugin_get_name (
 const gchar * const *gabble_plugin_get_sidecar_interfaces (
     GabblePlugin *plugin);
 
+gboolean gabble_plugin_implements_sidecar (
+    GabblePlugin *plugin,
+    const gchar *sidecar_interface);
+
+void gabble_plugin_create_sidecar (
+    GabblePlugin *plugin,
+    const gchar *sidecar_interface,
+    GAsyncReadyCallback callback,
+    gpointer user_data);
+
+GabbleSidecar *gabble_plugin_create_sidecar_finish (
+    GabblePlugin *plugin,
+    GAsyncResult *result,
+    GError **error);
+
 /**
  * gabble_plugin_create:
  *
-- 
1.5.6.5




More information about the telepathy-commits mailing list