From 5262d495ae17c65b654d22bcb9f1699d4d866143 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Tue, 15 Mar 2011 14:11:34 +0000 Subject: salut: define SalutConnection so it can be referred to in plugins Signed-off-by: Jonny Lamb --- salut/Makefile.am | 1 + salut/connection.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 salut/connection.h (limited to 'salut') diff --git a/salut/Makefile.am b/salut/Makefile.am index ca46c477..7419dff2 100644 --- a/salut/Makefile.am +++ b/salut/Makefile.am @@ -4,6 +4,7 @@ pkgconfig_DATA = telepathy-salut.pc salutincludedir = $(includedir)/telepathy-salut-0/salut salutinclude_HEADERS = \ + connection.h \ plugin.h \ protocol.h diff --git a/salut/connection.h b/salut/connection.h new file mode 100644 index 00000000..79f3a37b --- /dev/null +++ b/salut/connection.h @@ -0,0 +1,47 @@ +/* + * connection.h - connection API available to telepathy-salut plugins + * Copyright © 2010 Collabora Ltd. + * Copyright © 2010 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef SALUT_PLUGINS_CONNECTION_H +#define SALUT_PLUGINS_CONNECTION_H + +G_BEGIN_DECLS + +#define SALUT_TYPE_CONNECTION (salut_connection_get_type ()) +#define SALUT_CONNECTION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), SALUT_TYPE_CONNECTION, SalutConnection)) +#define SALUT_CONNECTION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), SALUT_TYPE_CONNECTION, \ + SalutConnectionClass)) +#define SALUT_IS_CONNECTION(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), SALUT_TYPE_CONNECTION)) +#define SALUT_IS_CONNECTION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), SALUT_TYPE_CONNECTION)) +#define SALUT_CONNECTION_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), SALUT_TYPE_CONNECTION, \ + SalutConnectionClass)) + +typedef struct _SalutConnection SalutConnection; +typedef struct _SalutConnectionClass SalutConnectionClass; + +GType salut_connection_get_type (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 04c5ef4799db15e400bb407396c161e930ab2389 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Tue, 15 Mar 2011 14:39:03 +0000 Subject: plugins: add sidecar support to plugins Signed-off-by: Jonny Lamb --- plugins/Makefile.am | 2 +- salut/Makefile.am | 3 +- salut/plugin.h | 43 ++++++++++++++++++++++++++ salut/sidecar.h | 67 ++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 5 ++- src/plugin-loader.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/plugin-loader.h | 17 +++++++++++ src/plugin.c | 64 ++++++++++++++++++++++++++++++++++++++ src/sidecar.c | 47 ++++++++++++++++++++++++++++ 9 files changed, 331 insertions(+), 5 deletions(-) create mode 100644 salut/sidecar.h create mode 100644 src/sidecar.c (limited to 'salut') diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 4120d82c..3bef2ce0 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -27,6 +27,6 @@ test_la_LDFLAGS = $(AM_LDFLAGS) -rpath $(plugindir) AM_CFLAGS = $(ERROR_CFLAGS) \ -I $(top_srcdir) -I $(top_builddir) \ - @GLIB_CFLAGS@ @TELEPATHY_GLIB_CFLAGS@ \ + @GLIB_CFLAGS@ @TELEPATHY_GLIB_CFLAGS@ @WOCKY_CFLAGS@ \ -I $(top_srcdir)/salut -I $(top_builddir)/salut \ -I $(top_srcdir)/plugins diff --git a/salut/Makefile.am b/salut/Makefile.am index 7419dff2..8c4f2e42 100644 --- a/salut/Makefile.am +++ b/salut/Makefile.am @@ -6,6 +6,7 @@ salutincludedir = $(includedir)/telepathy-salut-0/salut salutinclude_HEADERS = \ connection.h \ plugin.h \ - protocol.h + protocol.h \ + sidecar.h endif diff --git a/salut/plugin.h b/salut/plugin.h index 975446c6..c0f2a062 100644 --- a/salut/plugin.h +++ b/salut/plugin.h @@ -26,6 +26,11 @@ #include #include +#include + +#include +#include + G_BEGIN_DECLS #define SALUT_TYPE_PLUGIN (salut_plugin_get_type ()) @@ -40,6 +45,14 @@ G_BEGIN_DECLS typedef struct _SalutPlugin SalutPlugin; typedef struct _SalutPluginInterface SalutPluginInterface; +typedef void (*SalutPluginCreateSidecarImpl) ( + SalutPlugin *plugin, + const gchar *sidecar_interface, + SalutConnection *connection, + WockySession *session, + GAsyncReadyCallback callback, + gpointer user_data); + /* The caller of this function takes ownership of the returned * GPtrArray and the channel managers inside the array. This has the * same semantics as TpBaseConnectionCreateChannelManagersImpl. */ @@ -74,6 +87,17 @@ struct _SalutPluginInterface */ const gchar *version; + /** + * A %NULL-terminated array of strings listing the sidecar D-Bus interfaces + * implemented by this plugin. + */ + const gchar * const *sidecar_interfaces; + + /** + * An implementation of salut_plugin_create_sidecar(). + */ + SalutPluginCreateSidecarImpl create_sidecar; + /** * An implementation of salut_plugin_initialize(). */ @@ -93,6 +117,25 @@ const gchar * salut_plugin_get_name ( SalutPlugin *plugin); const gchar * salut_plugin_get_version ( SalutPlugin *plugin); +const gchar * const *salut_plugin_get_sidecar_interfaces ( + SalutPlugin *plugin); + +gboolean salut_plugin_implements_sidecar ( + SalutPlugin *plugin, + const gchar *sidecar_interface); + +void salut_plugin_create_sidecar_async ( + SalutPlugin *plugin, + const gchar *sidecar_interface, + SalutConnection *connection, + WockySession *session, + GAsyncReadyCallback callback, + gpointer user_data); + +SalutSidecar * salut_plugin_create_sidecar_finish ( + SalutPlugin *plugin, + GAsyncResult *result, + GError **error); void salut_plugin_initialize ( SalutPlugin *plugin, diff --git a/salut/sidecar.h b/salut/sidecar.h new file mode 100644 index 00000000..3d521941 --- /dev/null +++ b/salut/sidecar.h @@ -0,0 +1,67 @@ +/* + * sidecar.h — sidecar API available to telepathy-salut plugins + * Copyright © 2009 Collabora Ltd. + * Copyright © 2009 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef SALUT_PLUGINS_SIDECAR_H +#define SALUT_PLUGINS_SIDECAR_H + +#include + +#include + +G_BEGIN_DECLS + +#define SALUT_TYPE_SIDECAR (salut_sidecar_get_type ()) +#define SALUT_SIDECAR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), SALUT_TYPE_SIDECAR, SalutSidecar)) +#define SALUT_IS_SIDECAR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SALUT_TYPE_SIDECAR)) +#define SALUT_SIDECAR_GET_INTERFACE(obj) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((obj), SALUT_TYPE_SIDECAR, \ + SalutSidecarInterface)) + +typedef struct _SalutSidecar SalutSidecar; +typedef struct _SalutSidecarInterface SalutSidecarInterface; + +typedef GHashTable * (*SalutSidecarGetImmutablePropertiesImpl) ( + SalutSidecar *); + +struct _SalutSidecarInterface +{ + GTypeInterface parent; + + /** + * The D-Bus interface implemented by this sidecar. + */ + const gchar *interface; + + /** + * An implementation of salut_sidecar_get_immutable_properties(). + */ + SalutSidecarGetImmutablePropertiesImpl get_immutable_properties; +}; + +GType salut_sidecar_get_type (void); + +const gchar * salut_sidecar_get_interface (SalutSidecar *sidecar); +GHashTable * salut_sidecar_get_immutable_properties (SalutSidecar *sidecar); + +G_END_DECLS + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index e09f852f..819ef13f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -90,7 +90,10 @@ CORE_SOURCES = \ plugin-loader.c \ plugin-loader.h \ $(top_srcdir)/salut/plugin.h \ - plugin.c + plugin.c \ + $(top_srcdir)/salut/connection.h \ + $(top_srcdir)/salut/sidecar.h \ + sidecar.c AVAHI_BACKEND_SOURCES = \ salut-avahi-discovery-client.h \ diff --git a/src/plugin-loader.c b/src/plugin-loader.c index 59ef2e27..4bc9016b 100644 --- a/src/plugin-loader.c +++ b/src/plugin-loader.c @@ -90,13 +90,17 @@ plugin_loader_try_to_load ( } else { + gchar *sidecars = g_strjoinv (", ", + (gchar **) salut_plugin_get_sidecar_interfaces (plugin)); const gchar *version = salut_plugin_get_version (plugin); if (version == NULL) version = "(unspecified)"; - DEBUG ("loaded '%s' version %s (%s)", - salut_plugin_get_name (plugin), version, path); + DEBUG ("loaded '%s' version %s (%s), implementing these sidecars: %s", + salut_plugin_get_name (plugin), version, path, sidecars); + + g_free (sidecars); g_ptr_array_add (self->priv->plugins, plugin); } @@ -226,6 +230,86 @@ salut_plugin_loader_dup () return g_object_new (SALUT_TYPE_PLUGIN_LOADER, NULL); } +static void +create_sidecar_cb ( + GObject *plugin_obj, + GAsyncResult *nested_result, + gpointer user_data) +{ + GSimpleAsyncResult *result = user_data; + SalutSidecar *sidecar; + GError *error = NULL; + + sidecar = salut_plugin_create_sidecar_finish (SALUT_PLUGIN (plugin_obj), + nested_result, &error); + + if (sidecar == NULL) + { + g_simple_async_result_set_from_error (result, error); + g_clear_error (&error); + } + else + { + g_simple_async_result_set_op_res_gpointer (result, sidecar, + g_object_unref); + } + + g_simple_async_result_complete (result); + g_object_unref (result); +} + +void +salut_plugin_loader_create_sidecar_async ( + SalutPluginLoader *self, + const gchar *sidecar_interface, + SalutConnection *connection, + WockySession *session, + GAsyncReadyCallback callback, + gpointer user_data) +{ + SalutPluginLoaderPrivate *priv = self->priv; + guint i; + + for (i = 0; i < priv->plugins->len; i++) + { + SalutPlugin *p = g_ptr_array_index (priv->plugins, i); + + if (salut_plugin_implements_sidecar (p, sidecar_interface)) + { + GSimpleAsyncResult *res = g_simple_async_result_new (G_OBJECT (self), + callback, user_data, salut_plugin_loader_create_sidecar_async); + + salut_plugin_create_sidecar_async (p, sidecar_interface, connection, session, + create_sidecar_cb, res); + return; + } + } + + g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data, + TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "No plugin implements sidecar '%s'", + sidecar_interface); +} + +SalutSidecar * +salut_plugin_loader_create_sidecar_finish ( + SalutPluginLoader *self, + GAsyncResult *result, + GError **error) +{ + SalutSidecar *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 (self), salut_plugin_loader_create_sidecar_async), NULL); + + sidecar = SALUT_SIDECAR (g_simple_async_result_get_op_res_gpointer ( + G_SIMPLE_ASYNC_RESULT (result))); + return g_object_ref (sidecar); +} + void salut_plugin_loader_initialize (SalutPluginLoader *self, TpBaseConnectionManager *connection_manager) diff --git a/src/plugin-loader.h b/src/plugin-loader.h index 1e3eefa7..b1b65db8 100644 --- a/src/plugin-loader.h +++ b/src/plugin-loader.h @@ -25,6 +25,10 @@ #include #include +#include + +#include "salut/sidecar.h" + typedef struct _SalutPluginLoader SalutPluginLoader; typedef struct _SalutPluginLoaderClass SalutPluginLoaderClass; typedef struct _SalutPluginLoaderPrivate SalutPluginLoaderPrivate; @@ -60,6 +64,19 @@ GType salut_plugin_loader_get_type (void); SalutPluginLoader * salut_plugin_loader_dup (void); +void salut_plugin_loader_create_sidecar_async ( + SalutPluginLoader *self, + const gchar *sidecar_interface, + SalutConnection *connection, + WockySession *session, + GAsyncReadyCallback callback, + gpointer user_data); + +SalutSidecar *salut_plugin_loader_create_sidecar_finish ( + SalutPluginLoader *self, + GAsyncResult *result, + GError **error); + void salut_plugin_loader_initialize ( SalutPluginLoader *self, TpBaseConnectionManager *connection_manager); diff --git a/src/plugin.c b/src/plugin.c index 370be53a..488893af 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -48,6 +48,70 @@ salut_plugin_get_version (SalutPlugin *plugin) return iface->version; } +const gchar * const * +salut_plugin_get_sidecar_interfaces (SalutPlugin *plugin) +{ + SalutPluginInterface *iface = SALUT_PLUGIN_GET_INTERFACE (plugin); + + return iface->sidecar_interfaces; +} + +gboolean +salut_plugin_implements_sidecar ( + SalutPlugin *plugin, + const gchar *sidecar_interface) +{ + SalutPluginInterface *iface = SALUT_PLUGIN_GET_INTERFACE (plugin); + + return tp_strv_contains (iface->sidecar_interfaces, sidecar_interface); +} + +void +salut_plugin_create_sidecar_async ( + SalutPlugin *plugin, + const gchar *sidecar_interface, + SalutConnection *connection, + WockySession *session, + GAsyncReadyCallback callback, + gpointer user_data) +{ + SalutPluginInterface *iface = SALUT_PLUGIN_GET_INTERFACE (plugin); + + if (!salut_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, + "Salut 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, connection, session, + callback, user_data); +} + +SalutSidecar * +salut_plugin_create_sidecar_finish ( + SalutPlugin *plugin, + GAsyncResult *result, + GError **error) +{ + SalutSidecar *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), salut_plugin_create_sidecar_async), NULL); + + sidecar = SALUT_SIDECAR (g_simple_async_result_get_op_res_gpointer ( + G_SIMPLE_ASYNC_RESULT (result))); + return g_object_ref (sidecar); +} + void salut_plugin_initialize (SalutPlugin *plugin, TpBaseConnectionManager *connection_manager) diff --git a/src/sidecar.c b/src/sidecar.c new file mode 100644 index 00000000..9e0c4e2d --- /dev/null +++ b/src/sidecar.c @@ -0,0 +1,47 @@ +/* + * sidecar.c — interface for connection sidecars + * Copyright © 2009 Collabora Ltd. + * Copyright © 2009 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "salut/sidecar.h" + +G_DEFINE_INTERFACE (SalutSidecar, salut_sidecar, G_TYPE_OBJECT) + +static void +salut_sidecar_default_init (SalutSidecarInterface *iface) +{ +} + +const gchar * +salut_sidecar_get_interface (SalutSidecar *sidecar) +{ + SalutSidecarInterface *iface = SALUT_SIDECAR_GET_INTERFACE (sidecar); + + return iface->interface; +} + +GHashTable * +salut_sidecar_get_immutable_properties (SalutSidecar *sidecar) +{ + SalutSidecarInterface *iface = SALUT_SIDECAR_GET_INTERFACE (sidecar); + + if (iface->get_immutable_properties) + return iface->get_immutable_properties (sidecar); + else + return g_hash_table_new (NULL, NULL); +} -- cgit v1.2.3 From 14e2d72bbeae565a53fe8bd32f375c0cec3715c0 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 16 Mar 2011 14:28:47 +0000 Subject: sidecar: update copyright years Signed-off-by: Jonny Lamb --- salut/sidecar.h | 2 +- src/sidecar.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'salut') diff --git a/salut/sidecar.h b/salut/sidecar.h index 3d521941..1f5e78ff 100644 --- a/salut/sidecar.h +++ b/salut/sidecar.h @@ -1,6 +1,6 @@ /* * sidecar.h — sidecar API available to telepathy-salut plugins - * Copyright © 2009 Collabora Ltd. + * Copyright © 2009-2011 Collabora Ltd. * Copyright © 2009 Nokia Corporation * * This library is free software; you can redistribute it and/or diff --git a/src/sidecar.c b/src/sidecar.c index 9e0c4e2d..481c68df 100644 --- a/src/sidecar.c +++ b/src/sidecar.c @@ -1,6 +1,6 @@ /* * sidecar.c — interface for connection sidecars - * Copyright © 2009 Collabora Ltd. + * Copyright © 2009-2011 Collabora Ltd. * Copyright © 2009 Nokia Corporation * * This library is free software; you can redistribute it and/or -- cgit v1.2.3