[telepathy-gabble/master] Add a plugin for use in the test suite

Will Thompson will.thompson at collabora.co.uk
Tue Nov 17 09:19:04 PST 2009


---
 Makefile.am         |    2 +-
 configure.ac        |    3 +-
 plugins/Makefile.am |   10 +++
 plugins/test.c      |  204 +++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/test.h      |   89 ++++++++++++++++++++++
 5 files changed, 306 insertions(+), 2 deletions(-)
 create mode 100644 plugins/Makefile.am
 create mode 100644 plugins/test.c
 create mode 100644 plugins/test.h

diff --git a/Makefile.am b/Makefile.am
index 8d3edc8..f12225f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = docs tools extensions lib src data m4 tests
+SUBDIRS = docs tools extensions lib src data m4 plugins tests
 
 DISTCHECK_CONFIGURE_FLAGS = --disable-debug --enable-wocky-gtk-doc
 
diff --git a/configure.ac b/configure.ac
index d55a598..a35565f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -263,5 +263,6 @@ AC_OUTPUT( Makefile \
            lib/Makefile \
            lib/ext/Makefile \
            lib/gibber/Makefile \
-           lib/loudmouth/Makefile
+           lib/loudmouth/Makefile \
+           plugins/Makefile
 )
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
new file mode 100644
index 0000000..43dfd38
--- /dev/null
+++ b/plugins/Makefile.am
@@ -0,0 +1,10 @@
+plugindir = $(libdir)/telepathy/gabble-0
+
+noinst_LTLIBRARIES = \
+	test.la
+
+test_la_LDFLAGS = -module -avoid-version -rpath $(plugindir) -lm
+
+AM_CFLAGS = $(ERROR_CFLAGS) @DBUS_CFLAGS@ @GLIB_CFLAGS@ @WOCKY_CFLAGS@ \
+    @TP_GLIB_CFLAGS@ \
+    -I $(top_srcdir)/src -I $(top_builddir)/src
diff --git a/plugins/test.c b/plugins/test.c
new file mode 100644
index 0000000..626b639
--- /dev/null
+++ b/plugins/test.c
@@ -0,0 +1,204 @@
+#include "test.h"
+
+#include <stdio.h>
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/util.h>
+#include <telepathy-glib/errors.h>
+
+#include "extensions/extensions.h"
+
+#include "plugin.h"
+
+#define DEBUG(msg, ...) \
+  g_debug ("%s: " msg, G_STRFUNC, ##__VA_ARGS__)
+
+/*****************************
+ * TestPlugin implementation *
+ *****************************/
+
+static void plugin_iface_init (
+    gpointer g_iface,
+    gpointer data);
+
+#define IFACE_TEST "org.freedesktop.Telepathy.Gabble.Plugin.Test"
+#define IFACE_TEST_PROPS IFACE_TEST ".Props"
+#define IFACE_TEST_BUGGY IFACE_TEST ".Buggy"
+
+static const gchar * const sidecar_interfaces[] = {
+    IFACE_TEST,
+    IFACE_TEST_PROPS,
+    IFACE_TEST_BUGGY,
+    NULL
+};
+
+G_DEFINE_TYPE_WITH_CODE (TestPlugin, test_plugin, G_TYPE_OBJECT,
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_PLUGIN, plugin_iface_init);
+    )
+
+static void
+test_plugin_init (TestPlugin *object)
+{
+  DEBUG ("%p", object);
+}
+
+static void
+test_plugin_class_init (TestPluginClass *klass)
+{
+}
+
+static void
+test_plugin_create_sidecar (
+    GabblePlugin *plugin,
+    const gchar *sidecar_interface,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (plugin),
+      callback, user_data,
+      /* sic: all plugins share gabble_plugin_create_sidecar_finish() so we
+       * need to use the same source tag.
+       */
+      gabble_plugin_create_sidecar);
+  GabbleSidecar *sidecar = NULL;
+
+  if (!tp_strdiff (sidecar_interface, IFACE_TEST))
+    {
+      sidecar = g_object_new (TEST_TYPE_SIDECAR, NULL);
+    }
+  else if (!tp_strdiff (sidecar_interface, IFACE_TEST_PROPS))
+    {
+      sidecar = g_object_new (TEST_TYPE_SIDECAR_PROPS, NULL);
+    }
+  else
+    {
+      /* This deliberately doesn't check for IFACE_TEST_BUGGY, to test Gabble's
+       * reactions to buggy plugins. :)
+       */
+      g_simple_async_result_set_error (result, TP_ERRORS,
+          TP_ERROR_NOT_IMPLEMENTED, "'%s' not implemented", sidecar_interface);
+    }
+
+  if (sidecar != NULL)
+    g_simple_async_result_set_op_res_gpointer (result, sidecar, g_object_unref);
+
+  g_simple_async_result_complete_in_idle (result);
+  g_object_unref (result);
+}
+
+static void
+plugin_iface_init (
+    gpointer g_iface,
+    gpointer data G_GNUC_UNUSED)
+{
+  GabblePluginInterface *iface = g_iface;
+
+  iface->name = "Sidecar test plugin";
+  iface->sidecar_interfaces = sidecar_interfaces;
+  iface->create_sidecar = test_plugin_create_sidecar;
+}
+
+GabblePlugin *
+gabble_plugin_create ()
+{
+  return g_object_new (test_plugin_get_type (), NULL);
+}
+
+/******************************
+ * TestSidecar implementation *
+ ******************************/
+
+static void sidecar_iface_init (
+    gpointer g_iface,
+    gpointer data);
+
+G_DEFINE_TYPE_WITH_CODE (TestSidecar, test_sidecar, G_TYPE_OBJECT,
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SIDECAR, sidecar_iface_init);
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_GABBLE_PLUGIN_TEST, NULL);
+    )
+
+static void
+test_sidecar_init (TestSidecar *object)
+{
+  DEBUG ("%p", object);
+}
+
+static void
+test_sidecar_class_init (TestSidecarClass *klass)
+{
+}
+
+static void sidecar_iface_init (
+    gpointer g_iface,
+    gpointer data)
+{
+  GabbleSidecarInterface *iface = g_iface;
+
+  iface->interface = IFACE_TEST;
+  iface->get_immutable_properties = NULL;
+}
+
+/***********************************
+ * TestSidecarProps implementation *
+ ***********************************/
+
+static void sidecar_props_iface_init (
+    gpointer g_iface,
+    gpointer data);
+
+G_DEFINE_TYPE_WITH_CODE (TestSidecarProps, test_sidecar_props, G_TYPE_OBJECT,
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SIDECAR, sidecar_props_iface_init);
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_GABBLE_PLUGIN_TEST, NULL);
+    )
+
+static void
+test_sidecar_props_init (TestSidecarProps *object)
+{
+  DEBUG ("%p", object);
+
+  object->props = tp_asv_new (
+      IFACE_TEST_PROPS ".Greeting", G_TYPE_STRING, "oh hai",
+      NULL);
+}
+
+static void
+test_sidecar_props_finalize (GObject *object)
+{
+  TestSidecarProps *self = TEST_SIDECAR_PROPS (object);
+  void (*chain_up) (GObject *) =
+      G_OBJECT_CLASS (test_sidecar_props_parent_class)->finalize;
+
+  g_hash_table_unref (self->props);
+
+  if (chain_up != NULL)
+    chain_up (object);
+}
+
+static void
+test_sidecar_props_class_init (TestSidecarPropsClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = test_sidecar_props_finalize;
+}
+
+static GHashTable *
+sidecar_props_get_immutable_properties (GabbleSidecar *sidecar)
+{
+  TestSidecarProps *self = TEST_SIDECAR_PROPS (sidecar);
+
+  return g_hash_table_ref (self->props);
+}
+
+static void sidecar_props_iface_init (
+    gpointer g_iface,
+    gpointer data)
+{
+  GabbleSidecarInterface *iface = g_iface;
+
+  iface->interface = IFACE_TEST_PROPS;
+  iface->get_immutable_properties = sidecar_props_get_immutable_properties;
+}
+
+
+
diff --git a/plugins/test.h b/plugins/test.h
new file mode 100644
index 0000000..d71c484
--- /dev/null
+++ b/plugins/test.h
@@ -0,0 +1,89 @@
+#include <glib-object.h>
+
+/* Plugin */
+typedef struct _TestPluginClass TestPluginClass;
+typedef struct _TestPlugin TestPlugin;
+
+struct _TestPluginClass {
+    GObjectClass parent;
+};
+
+struct _TestPlugin {
+    GObject parent;
+};
+
+GType test_plugin_get_type (void);
+
+#define TEST_TYPE_PLUGIN \
+  (test_plugin_get_type ())
+#define TEST_PLUGIN(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), TEST_TYPE_PLUGIN, TestPlugin))
+#define TEST_PLUGIN_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), TEST_TYPE_PLUGIN, \
+                           TestPluginClass))
+#define TEST_IS_PLUGIN(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), TEST_TYPE_PLUGIN))
+#define TEST_IS_PLUGIN_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), TEST_TYPE_PLUGIN))
+#define TEST_PLUGIN_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_PLUGIN, \
+                              TestPluginClass))
+
+/* Sidecar */
+typedef struct _TestSidecarClass TestSidecarClass;
+typedef struct _TestSidecar TestSidecar;
+
+struct _TestSidecarClass {
+    GObjectClass parent;
+};
+
+struct _TestSidecar {
+    GObject parent;
+};
+
+GType test_sidecar_get_type (void);
+
+#define TEST_TYPE_SIDECAR \
+  (test_sidecar_get_type ())
+#define TEST_SIDECAR(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), TEST_TYPE_SIDECAR, TestSidecar))
+#define TEST_SIDECAR_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), TEST_TYPE_SIDECAR, \
+                           TestSidecarClass))
+#define TEST_IS_SIDECAR(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), TEST_TYPE_SIDECAR))
+#define TEST_IS_SIDECAR_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), TEST_TYPE_SIDECAR))
+#define TEST_SIDECAR_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_SIDECAR, \
+                              TestSidecarClass))
+
+/* Sidecar with properties */
+typedef struct _TestSidecarPropsClass TestSidecarPropsClass;
+typedef struct _TestSidecarProps TestSidecarProps;
+
+struct _TestSidecarPropsClass {
+    GObjectClass parent;
+};
+
+struct _TestSidecarProps {
+    GObject parent;
+    GHashTable *props;
+};
+
+GType test_sidecar_props_get_type (void);
+
+#define TEST_TYPE_SIDECAR_PROPS \
+  (test_sidecar_props_get_type ())
+#define TEST_SIDECAR_PROPS(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), TEST_TYPE_SIDECAR_PROPS, TestSidecarProps))
+#define TEST_SIDECAR_PROPS_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), TEST_TYPE_SIDECAR_PROPS, \
+                           TestSidecarPropsClass))
+#define TEST_IS_SIDECAR_PROPS(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), TEST_TYPE_SIDECAR_PROPS))
+#define TEST_IS_SIDECAR_PROPS_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), TEST_TYPE_SIDECAR_PROPS))
+#define TEST_SIDECAR_PROPS_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_SIDECAR_PROPS, \
+                              TestSidecarPropsClass))
-- 
1.5.6.5




More information about the telepathy-commits mailing list