summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiraj Razick <siraj.razick@collabora.co.uk>2012-01-13 16:32:48 (GMT)
committerSiraj Razick <siraj.razick@collabora.co.uk>2012-02-06 17:06:49 (GMT)
commitf54da139bb483fce675d6f11bfc000ec2d6732aa (patch)
tree19f5988d1b8ef9d42d686b4a57320dadd712128b
parentbb63a668664a2003c966b7e3d9806c98d0875bf5 (diff)
downloadtelepathy-gabble-f54da139bb483fce675d6f11bfc000ec2d6732aa.tar.gz
telepathy-gabble-f54da139bb483fce675d6f11bfc000ec2d6732aa.tar.xz
fd.o#44649 - Gabble plugin API symbols should be factored out to a separate library
This patch refactors gabble connection by introducing a new GInterface which the plugins will link agaist. And GabbleConnection implements the new Interface. https://bugs.freedesktop.org/show_bug.cgi?id=44649
-rw-r--r--gabble/Makefile.am2
-rw-r--r--gabble/gabble.h2
-rw-r--r--gabble/plugin-connection.h132
-rw-r--r--gabble/plugin.h8
-rw-r--r--plugins/console.c4
-rw-r--r--plugins/gateways.c4
-rw-r--r--plugins/test.c30
-rw-r--r--plugins/test.h5
-rw-r--r--src/Makefile.am18
-rw-r--r--src/connection.c82
-rw-r--r--src/connection.h64
-rw-r--r--src/plugin-connection.c181
-rw-r--r--src/plugin-loader.c10
-rw-r--r--src/plugin-loader.h5
-rw-r--r--src/plugin.c7
15 files changed, 496 insertions, 58 deletions
diff --git a/gabble/Makefile.am b/gabble/Makefile.am
index f42c837..26b8748 100644
--- a/gabble/Makefile.am
+++ b/gabble/Makefile.am
@@ -8,7 +8,7 @@ gabbleinclude_HEADERS = \
capabilities-set.h \
caps-channel-manager.h \
caps-hash.h \
- connection.h \
+ plugin-connection.h \
error.h \
gabble.h \
namespaces.h \
diff --git a/gabble/gabble.h b/gabble/gabble.h
index 8393ae8..4465c34 100644
--- a/gabble/gabble.h
+++ b/gabble/gabble.h
@@ -28,7 +28,7 @@
#include <gabble/capabilities-set.h>
#include <gabble/caps-channel-manager.h>
#include <gabble/caps-hash.h>
-#include <gabble/connection.h>
+#include <gabble/plugin-connection.h>
#include <gabble/error.h>
#include <gabble/namespaces.h>
#include <gabble/plugin.h>
diff --git a/gabble/plugin-connection.h b/gabble/plugin-connection.h
new file mode 100644
index 0000000..66302a7
--- /dev/null
+++ b/gabble/plugin-connection.h
@@ -0,0 +1,132 @@
+/*
+ * plugin-connection.h — Connection API available to telepathy-gabble plugins
+ * Copyright © 2012 Collabora Ltd.
+ *
+ * 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 GABBLE_PLUGIN_CONNECTION_H
+#define GABBLE_PLUGIN_CONNECTION_H
+
+#include <glib-object.h>
+
+#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/base-contact-list.h>
+
+#include <gabble/capabilities-set.h>
+#include <gabble/types.h>
+
+#include <wocky/wocky.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GabblePluginConnection GabblePluginConnection;
+typedef struct _GabblePluginConnectionInterface GabblePluginConnectionInterface;
+
+#define GABBLE_TYPE_PLUGIN_CONNECTION (gabble_plugin_connection_get_type ())
+#define GABBLE_PLUGIN_CONNECTION(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((o), GABBLE_TYPE_PLUGIN_CONNECTION, \
+ GabblePluginConnection))
+#define GABBLE_IS_PLUGIN_CONNECTION(o) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((o), GABBLE_TYPE_PLUGIN_CONNECTION))
+#define GABBLE_PLUGIN_CONNECTION_GET_IFACE(o) \
+ (G_TYPE_INSTANCE_GET_INTERFACE ((o), GABBLE_TYPE_PLUGIN_CONNECTION, \
+ GabblePluginConnectionInterface))
+
+GType gabble_plugin_connection_get_type (void) G_GNUC_CONST;
+
+typedef gchar * (*GabblePluginConnectionAddSidecarCapsFunc) (
+ GabblePluginConnection *connection_service,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities);
+
+typedef gchar * (*GabblePluginConnectionAddSidecarCapsFullFunc) (
+ GabblePluginConnection *plugin_connection,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities,
+ GPtrArray *data_forms);
+
+typedef WockySession * (*GabblePluginConnectionGetSessionFunc) (
+ GabblePluginConnection *plugin_connection);
+
+typedef gchar *(*GabblePluginConnectionGetFullJidFunc) (
+ GabblePluginConnection *plugin_connection);
+
+typedef const gchar * (*GabblePluginConnectionGetJidForCapsFunc) (
+ GabblePluginConnection *plugin_connection,
+ WockyXep0115Capabilities *caps);
+
+typedef const gchar* (*GabblePluginConnectionPickBestResourceForCaps) (
+ GabblePluginConnection *plugin_connection,
+ const gchar *jid,
+ GabbleCapabilitySetPredicate predicate,
+ gconstpointer user_data);
+
+typedef TpBaseContactList * (*GabblePluginConnectionGetContactList) (
+ GabblePluginConnection *plugin_connection);
+
+typedef WockyXep0115Capabilities * (*GabblePluginConnectionGetCaps) (
+ GabblePluginConnection *plugin_connection,
+ TpHandle handle);
+
+struct _GabblePluginConnectionInterface
+{
+ GTypeInterface parent;
+ GabblePluginConnectionAddSidecarCapsFunc add_sidecar_own_caps;
+ GabblePluginConnectionAddSidecarCapsFullFunc add_sidecar_own_caps_full;
+ GabblePluginConnectionGetSessionFunc get_session;
+ GabblePluginConnectionGetFullJidFunc get_full_jid;
+ GabblePluginConnectionGetJidForCapsFunc get_jid_for_caps;
+ GabblePluginConnectionPickBestResourceForCaps pick_best_resource_for_caps;
+ GabblePluginConnectionGetContactList get_contact_list;
+ GabblePluginConnectionGetCaps get_caps;
+};
+
+gchar *gabble_plugin_connection_add_sidecar_own_caps (
+ GabblePluginConnection *plugin_service,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities);
+
+gchar *gabble_plugin_connection_add_sidecar_own_caps_full (
+ GabblePluginConnection *plugin_connection,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities,
+ GPtrArray *data_forms) G_GNUC_WARN_UNUSED_RESULT;
+
+WockySession *gabble_plugin_connection_get_session (
+ GabblePluginConnection *plugin_connection);
+
+gchar *gabble_plugin_connection_get_full_jid (GabblePluginConnection *conn);
+
+const gchar *gabble_plugin_connection_get_jid_for_caps (
+ GabblePluginConnection *plugin_connection,
+ WockyXep0115Capabilities *caps);
+
+const gchar *gabble_plugin_connection_pick_best_resource_for_caps (
+ GabblePluginConnection *plugin_connection,
+ const gchar *jid,
+ GabbleCapabilitySetPredicate predicate,
+ gconstpointer user_data);
+
+TpBaseContactList *gabble_plugin_connection_get_contact_list (
+ GabblePluginConnection *plugin_connection);
+
+WockyXep0115Capabilities *gabble_plugin_connection_get_caps (
+ GabblePluginConnection *plugin_connection,
+ TpHandle handle);
+
+G_END_DECLS
+
+#endif
diff --git a/gabble/plugin.h b/gabble/plugin.h
index d608a55..c8e0699 100644
--- a/gabble/plugin.h
+++ b/gabble/plugin.h
@@ -28,7 +28,7 @@
#include <telepathy-glib/presence-mixin.h>
#include <wocky/wocky.h>
-#include <gabble/connection.h>
+#include <gabble/plugin-connection.h>
#include <gabble/sidecar.h>
#include <gabble/types.h>
@@ -48,7 +48,7 @@ typedef struct _GabblePluginInterface GabblePluginInterface;
typedef void (*GabblePluginCreateSidecarImpl) (
GabblePlugin *plugin,
const gchar *sidecar_interface,
- GabbleConnection *connection,
+ GabblePluginConnection *plugin_connection,
WockySession *session,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -58,6 +58,7 @@ typedef void (*GabblePluginCreateSidecarImpl) (
* not have a free function. */
typedef GPtrArray * (*GabblePluginCreateChannelManagersImpl) (
GabblePlugin *plugin,
+ GabblePluginConnection *plugin_connection,
TpBaseConnection *connection);
typedef GabbleSidecar * (*GabblePluginCreateSidecarFinishImpl) (
@@ -133,7 +134,7 @@ gboolean gabble_plugin_implements_sidecar (
void gabble_plugin_create_sidecar_async (
GabblePlugin *plugin,
const gchar *sidecar_interface,
- GabbleConnection *connection,
+ GabblePluginConnection *plugin_connection,
WockySession *session,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -155,6 +156,7 @@ const gchar *gabble_plugin_presence_status_for_privacy_list (
const gchar *list_name);
GPtrArray * gabble_plugin_create_channel_managers (GabblePlugin *plugin,
+ GabblePluginConnection *plugin_connection,
TpBaseConnection *connection);
/**
diff --git a/plugins/console.c b/plugins/console.c
index d6ecb50..6e24e4f 100644
--- a/plugins/console.c
+++ b/plugins/console.c
@@ -76,7 +76,7 @@ static void
gabble_console_plugin_create_sidecar_async (
GabblePlugin *plugin,
const gchar *sidecar_interface,
- GabbleConnection *connection,
+ GabblePluginConnection *connection,
WockySession *session,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -311,7 +311,7 @@ gabble_console_sidecar_class_init (GabbleConsoleSidecarClass *klass)
g_object_class_install_property (object_class, PROP_CONNECTION,
g_param_spec_object ("connection", "Connection",
"Gabble connection",
- GABBLE_TYPE_CONNECTION,
+ GABBLE_TYPE_PLUGIN_CONNECTION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_SESSION,
diff --git a/plugins/gateways.c b/plugins/gateways.c
index 02e2f58..b9b2323 100644
--- a/plugins/gateways.c
+++ b/plugins/gateways.c
@@ -76,7 +76,7 @@ static void
gabble_gateway_plugin_create_sidecar_async (
GabblePlugin *plugin,
const gchar *sidecar_interface,
- GabbleConnection *connection,
+ GabblePluginConnection *connection,
WockySession *session,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -351,7 +351,7 @@ gabble_gateway_sidecar_class_init (GabbleGatewaySidecarClass *klass)
g_object_class_install_property (object_class, PROP_CONNECTION,
g_param_spec_object ("connection", "Connection",
"Gabble connection",
- GABBLE_TYPE_CONNECTION,
+ GABBLE_TYPE_PLUGIN_CONNECTION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_SESSION,
diff --git a/plugins/test.c b/plugins/test.c
index eca6079..c506cc1 100644
--- a/plugins/test.c
+++ b/plugins/test.c
@@ -82,7 +82,7 @@ static void
test_plugin_create_sidecar_async (
GabblePlugin *plugin,
const gchar *sidecar_interface,
- GabbleConnection *connection,
+ GabblePluginConnection *plugin_connection,
WockySession *session,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -105,7 +105,7 @@ test_plugin_create_sidecar_async (
{
g_async_initable_new_async (TEST_TYPE_SIDECAR_IQ, G_PRIORITY_DEFAULT,
NULL, sidecar_iq_created_cb, result, "session", session,
- "connection", connection, NULL);
+ "plugin-connection", plugin_connection, NULL);
return;
}
else
@@ -148,15 +148,16 @@ test_plugin_create_sidecar_finish (
static GPtrArray *
test_plugin_create_channel_managers (GabblePlugin *plugin,
+ GabblePluginConnection *plugin_connection,
TpBaseConnection *connection)
{
GPtrArray *ret = g_ptr_array_new ();
- DEBUG ("plugin %p on connection %p", plugin, connection);
+ DEBUG ("plugin %p on connection %p", plugin, plugin_connection);
g_ptr_array_add (ret,
g_object_new (TEST_TYPE_CHANNEL_MANAGER,
- "connection", connection,
+ "plugin-connection", plugin_connection,
NULL));
return ret;
@@ -359,7 +360,7 @@ test_sidecar_iq_set_property (
g_ptr_array_add (identities, identity);
/* set own caps so we proper reply to disco#info */
- hash = gabble_connection_add_sidecar_own_caps (self->connection,
+ hash = gabble_plugin_connection_add_sidecar_own_caps (self->connection,
features, identities);
g_free (hash);
@@ -398,9 +399,9 @@ test_sidecar_iq_class_init (TestSidecarIQClass *klass)
WOCKY_TYPE_SESSION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_CONNECTION,
- g_param_spec_object ("connection", "Gabble Connection",
- "Gabble connection",
- GABBLE_TYPE_CONNECTION,
+ g_param_spec_object ("plugin-connection", "Gabble Plugin Connection",
+ "Gabble Plugin Connection",
+ GABBLE_TYPE_PLUGIN_CONNECTION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
}
@@ -538,7 +539,7 @@ test_channel_manager_set_property (
/* Not reffing this: the connection owns all channel managers, so it
* must outlive us. Taking a reference leads to a cycle.
*/
- self->connection = g_value_get_object (value);
+ self->plugin_connection = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -557,7 +558,7 @@ test_channel_manager_get_property (
switch (property_id)
{
case PROP_CONNECTION:
- g_value_set_object (value, self->connection);
+ g_value_set_object (value, self->plugin_connection);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -582,7 +583,8 @@ test_channel_manager_constructed (GObject *object)
if (G_OBJECT_CLASS (test_channel_manager_parent_class)->constructed != NULL)
G_OBJECT_CLASS (test_channel_manager_parent_class)->constructed (object);
- tp_g_signal_connect_object (self->connection, "porter-available",
+ tp_g_signal_connect_object (self->plugin_connection,
+ "porter-available",
G_CALLBACK (test_channel_manager_porter_available_cb),
self, 0);
}
@@ -597,9 +599,9 @@ test_channel_manager_class_init (TestChannelManagerClass *klass)
oclass->constructed = test_channel_manager_constructed;
g_object_class_install_property (oclass, PROP_CONNECTION,
- g_param_spec_object ("connection", "Gabble Connection",
- "Gabble connection",
- GABBLE_TYPE_CONNECTION,
+ g_param_spec_object ("plugin-connection", "Gabble Plugin Connection",
+ "Gabble Plugin Connection",
+ GABBLE_TYPE_PLUGIN_CONNECTION,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
}
diff --git a/plugins/test.h b/plugins/test.h
index 16a209c..3b5d89d 100644
--- a/plugins/test.h
+++ b/plugins/test.h
@@ -3,6 +3,7 @@
#include <gio/gio.h>
#include <wocky/wocky.h>
#include <gabble/gabble.h>
+#include <gabble/plugin-connection.h>
/* Plugin */
typedef struct _TestPluginClass TestPluginClass;
@@ -104,7 +105,7 @@ struct _TestSidecarIQ {
GObject parent;
GSimpleAsyncResult *result;
WockySession *session;
- GabbleConnection *connection;
+ GabblePluginConnection *connection;
};
GType test_sidecar_iq_get_type (void);
@@ -134,7 +135,7 @@ struct _TestChannelManagerClass {
struct _TestChannelManager {
GObject parent;
- GabbleConnection *connection;
+ GabblePluginConnection *plugin_connection;
};
GType test_channel_manager_get_type (void);
diff --git a/src/Makefile.am b/src/Makefile.am
index ffcd3d6..d36a77e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -77,7 +77,6 @@ libgabble_convenience_la_SOURCES = \
conn-util.c \
conn-mail-notif.h \
conn-mail-notif.c \
- $(top_srcdir)/gabble/connection.h \
connection.h \
connection.c \
connection-manager.h \
@@ -213,6 +212,7 @@ libgabble_convenience_la_LIBADD = \
$(top_builddir)/extensions/libgabble-extensions.la \
$(top_builddir)/lib/gibber/libgibber.la \
$(top_builddir)/lib/ext/telepathy-yell/telepathy-yell/libtelepathy-yell.la \
+ libgabble-plugins.la \
$(ALL_LIBS)
nodist_libgabble_convenience_la_SOURCES = \
@@ -238,6 +238,22 @@ telepathy_gabble_LDFLAGS = -export-dynamic
noinst_LTLIBRARIES = libgabble-convenience.la
+lib_LTLIBRARIES = libgabble-plugins.la
+
+libgabble_plugins_la_LIBADD = \
+ $(top_builddir)/lib/ext/telepathy-yell/telepathy-yell/libtelepathy-yell.la \
+ $(ALL_LIBS)
+
+libgabble_plugins_la_SOURCES = $(top_srcdir)/gabble/plugin.h \
+ $(top_srcdir)/gabble/caps-channel-manager.h \
+ $(top_srcdir)/gabble/plugin-connection.h \
+ plugin-connection.c \
+ caps-channel-manager.c \
+ plugin.c \
+ capabilities.c \
+ debug.c \
+ sidecar.c
+
AM_CFLAGS = $(ERROR_CFLAGS) -I$(top_srcdir) -I$(top_builddir) \
@TP_YELL_CFLAGS@ \
@DBUS_CFLAGS@ @GLIB_CFLAGS@ @WOCKY_CFLAGS@ \
diff --git a/src/connection.c b/src/connection.c
index 25ae603..0befb44 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -45,6 +45,7 @@
#include "bytestream-factory.h"
#include "gabble/capabilities.h"
#include "gabble/caps-channel-manager.h"
+#include "gabble/plugin-connection.h"
#include "caps-hash.h"
#include "auth-manager.h"
#include "conn-aliasing.h"
@@ -91,6 +92,13 @@ static void conn_capabilities_fill_contact_attributes (GObject *obj,
const GArray *contacts, GHashTable *attributes_hash);
static void conn_contact_capabilities_fill_contact_attributes (GObject *obj,
const GArray *contacts, GHashTable *attributes_hash);
+static void gabble_plugin_connection_iface_init (
+ GabblePluginConnectionInterface *iface,
+ gpointer conn);
+static gchar *_gabble_plugin_connection_get_full_jid (
+ GabblePluginConnection *conn);
+static TpBaseContactList *_gabble_plugin_connection_get_contact_list (
+ GabblePluginConnection *conn);
G_DEFINE_TYPE_WITH_CODE(GabbleConnection,
gabble_connection,
@@ -136,6 +144,8 @@ G_DEFINE_TYPE_WITH_CODE(GabbleConnection,
conn_power_saving_iface_init);
G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CONNECTION_INTERFACE_ADDRESSING,
conn_addressing_iface_init);
+ G_IMPLEMENT_INTERFACE (GABBLE_TYPE_PLUGIN_CONNECTION,
+ gabble_plugin_connection_iface_init);
)
/* properties */
@@ -295,8 +305,6 @@ struct _GabbleConnectionPrivate
gboolean dispose_has_run;
};
-static guint sig_id_porter_available = 0;
-
static void connection_capabilities_update_cb (GabblePresenceCache *cache,
TpHandle handle,
const GabbleCapabilitySet *old_cap_set,
@@ -317,6 +325,7 @@ static GPtrArray *
_gabble_connection_create_channel_managers (TpBaseConnection *conn)
{
GabbleConnection *self = GABBLE_CONNECTION (conn);
+ GabblePluginConnection *plugin_connection = GABBLE_PLUGIN_CONNECTION (self);
GPtrArray *channel_managers = g_ptr_array_sized_new (5);
GabblePluginLoader *loader;
GPtrArray *tmp;
@@ -374,7 +383,8 @@ _gabble_connection_create_channel_managers (TpBaseConnection *conn)
/* plugin channel managers */
loader = gabble_plugin_loader_dup ();
- tmp = gabble_plugin_loader_create_channel_managers (loader, conn);
+ tmp = gabble_plugin_loader_create_channel_managers (loader,
+ plugin_connection, conn);
g_object_unref (loader);
g_ptr_array_foreach (tmp, add_to_array, channel_managers);
@@ -383,6 +393,23 @@ _gabble_connection_create_channel_managers (TpBaseConnection *conn)
return channel_managers;
}
+static void
+gabble_plugin_connection_iface_init (
+ GabblePluginConnectionInterface *iface,
+ gpointer conn)
+{
+ iface->add_sidecar_own_caps = gabble_connection_add_sidecar_own_caps;
+ iface->add_sidecar_own_caps_full=
+ gabble_connection_add_sidecar_own_caps_full;
+ iface->get_session = gabble_connection_get_session;
+ iface->get_full_jid = _gabble_plugin_connection_get_full_jid;
+ iface->get_jid_for_caps = gabble_connection_get_jid_for_caps;
+ iface->pick_best_resource_for_caps =
+ gabble_connection_pick_best_resource_for_caps;
+ iface->get_contact_list = _gabble_plugin_connection_get_contact_list;
+ iface->get_caps = gabble_connection_get_caps;
+}
+
static GObject *
gabble_connection_constructor (GType type,
guint n_construct_properties,
@@ -1167,17 +1194,6 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class)
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
- /**
- * @self: a connection
- * @porter: a porter
- *
- * Emitted when the WockyPorter becomes available.
- */
- sig_id_porter_available = g_signal_new ("porter-available",
- G_OBJECT_CLASS_TYPE (gabble_connection_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, WOCKY_TYPE_PORTER);
-
gabble_connection_class->properties_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (GabbleConnectionClass, properties_class));
@@ -1372,6 +1388,13 @@ gabble_connection_get_full_jid (GabbleConnection *conn)
return g_strconcat (bare_jid, "/", conn->priv->resource, NULL);
}
+static gchar *
+_gabble_plugin_connection_get_full_jid (GabblePluginConnection *plugin_conn)
+{
+ GabbleConnection *conn = GABBLE_CONNECTION (plugin_conn);
+ return gabble_connection_get_full_jid (conn);
+}
+
/**
* gabble_connection_dup_porter:
*
@@ -1393,8 +1416,10 @@ WockyPorter *gabble_connection_dup_porter (GabbleConnection *conn)
}
WockySession *
-gabble_connection_get_session (GabbleConnection *connection)
+gabble_connection_get_session (GabblePluginConnection *plugin_connection)
{
+ GabbleConnection *connection = GABBLE_CONNECTION (plugin_connection);
+
g_return_val_if_fail (GABBLE_IS_CONNECTION (connection), NULL);
return connection->session;
@@ -1870,7 +1895,7 @@ connector_connected (GabbleConnection *self,
g_signal_connect (priv->porter, "remote-error",
G_CALLBACK (remote_error_cb), self);
- g_signal_emit (self, sig_id_porter_available, 0, priv->porter);
+ g_signal_emit_by_name (self, "porter-available", priv->porter);
connect_iq_callbacks (self);
wocky_pep_service_start (self->pep_location, self->session);
@@ -3815,11 +3840,12 @@ gabble_connection_update_sidecar_capabilities (GabbleConnection *self,
/* identities is actually a WockyDiscoIdentityArray */
gchar *
-gabble_connection_add_sidecar_own_caps_full (GabbleConnection *self,
+gabble_connection_add_sidecar_own_caps_full (GabblePluginConnection *self,
const GabbleCapabilitySet *cap_set,
const GPtrArray *identities,
GPtrArray *data_forms)
{
+ GabbleConnection *conn = GABBLE_CONNECTION (self);
GPtrArray *identities_copy = ((identities == NULL) ?
wocky_disco_identity_array_new () :
wocky_disco_identity_array_copy (identities));
@@ -3833,7 +3859,7 @@ gabble_connection_add_sidecar_own_caps_full (GabbleConnection *self,
ver = gabble_caps_hash_compute_full (cap_set, identities_copy, data_forms);
- gabble_presence_cache_add_own_caps (self->presence_cache, ver,
+ gabble_presence_cache_add_own_caps (conn->presence_cache, ver,
cap_set, identities_copy, data_forms);
wocky_disco_identity_array_free (identities_copy);
@@ -3842,7 +3868,7 @@ gabble_connection_add_sidecar_own_caps_full (GabbleConnection *self,
}
gchar *
-gabble_connection_add_sidecar_own_caps (GabbleConnection *self,
+gabble_connection_add_sidecar_own_caps (GabblePluginConnection *self,
const GabbleCapabilitySet *cap_set,
const GPtrArray *identities)
{
@@ -3851,12 +3877,13 @@ gabble_connection_add_sidecar_own_caps (GabbleConnection *self,
}
const gchar *
-gabble_connection_get_jid_for_caps (GabbleConnection *conn,
+gabble_connection_get_jid_for_caps (GabblePluginConnection *plugin_conn,
WockyXep0115Capabilities *caps)
{
TpHandle handle;
TpBaseConnection *base;
TpHandleRepoIface *contact_handles;
+ GabbleConnection *conn = GABBLE_CONNECTION (plugin_conn);
g_return_val_if_fail (GABBLE_IS_CONNECTION (conn), NULL);
g_return_val_if_fail (GABBLE_IS_PRESENCE (caps), NULL);
@@ -3880,7 +3907,8 @@ gabble_connection_get_jid_for_caps (GabbleConnection *conn,
}
const gchar *
-gabble_connection_pick_best_resource_for_caps (GabbleConnection *connection,
+gabble_connection_pick_best_resource_for_caps (
+ GabblePluginConnection *plugin_connection,
const gchar *jid,
GabbleCapabilitySetPredicate predicate,
gconstpointer user_data)
@@ -3888,6 +3916,7 @@ gabble_connection_pick_best_resource_for_caps (GabbleConnection *connection,
TpBaseConnection *base;
TpHandleRepoIface *contact_handles;
TpHandle handle;
+ GabbleConnection *connection = GABBLE_CONNECTION (plugin_connection);
GabblePresence *presence;
g_return_val_if_fail (GABBLE_IS_CONNECTION (connection), NULL);
@@ -3921,11 +3950,20 @@ gabble_connection_get_contact_list (GabbleConnection *connection)
return (TpBaseContactList *) connection->roster;
}
+static TpBaseContactList *
+_gabble_plugin_connection_get_contact_list (
+ GabblePluginConnection *plugin_connection)
+{
+ GabbleConnection *connection = GABBLE_CONNECTION (plugin_connection);
+ return gabble_connection_get_contact_list (connection);
+}
+
WockyXep0115Capabilities *
-gabble_connection_get_caps (GabbleConnection *connection,
+gabble_connection_get_caps (GabblePluginConnection *plugin_connection,
TpHandle handle)
{
GabblePresence *presence;
+ GabbleConnection *connection = GABBLE_CONNECTION (plugin_connection);
g_return_val_if_fail (GABBLE_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (handle > 0, NULL);
diff --git a/src/connection.h b/src/connection.h
index 1c783e0..91778e6 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -1,7 +1,7 @@
/*
* gabble-connection.h - Header for GabbleConnection
- * Copyright (C) 2005 Collabora Ltd.
- * Copyright (C) 2005 Nokia Corporation
+ * Copyright © 2005-2012 Collabora Ltd.
+ * Copyright © 2005-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
@@ -33,7 +33,6 @@
#include <wocky/wocky.h>
-#include "gabble/connection.h"
#include "gabble/capabilities.h"
#ifdef ENABLE_FILE_TRANSFER
#include "ft-manager.h"
@@ -42,8 +41,67 @@
#include "muc-factory.h"
#include "types.h"
+#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/base-contact-list.h>
+
+#include <gabble/capabilities-set.h>
+#include <gabble/types.h>
+#include <gabble/plugin-connection.h>
+
G_BEGIN_DECLS
+#define GABBLE_TYPE_CONNECTION (gabble_connection_get_type ())
+#define GABBLE_CONNECTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), GABBLE_TYPE_CONNECTION, GabbleConnection))
+#define GABBLE_CONNECTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), GABBLE_TYPE_CONNECTION, \
+ GabbleConnectionClass))
+#define GABBLE_IS_CONNECTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GABBLE_TYPE_CONNECTION))
+#define GABBLE_IS_CONNECTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GABBLE_TYPE_CONNECTION))
+#define GABBLE_CONNECTION_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), GABBLE_TYPE_CONNECTION, \
+ GabbleConnectionClass))
+
+typedef struct _GabbleConnectionClass GabbleConnectionClass;
+
+GType gabble_connection_get_type (void);
+
+void gabble_connection_update_sidecar_capabilities (
+ GabbleConnection *connection,
+ const GabbleCapabilitySet *add_set,
+ const GabbleCapabilitySet *remove_set);
+gchar *gabble_connection_add_sidecar_own_caps (
+ GabblePluginConnection *connection,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities) G_GNUC_WARN_UNUSED_RESULT;
+gchar *gabble_connection_add_sidecar_own_caps_full (
+ GabblePluginConnection *connection,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities,
+ GPtrArray *data_forms) G_GNUC_WARN_UNUSED_RESULT;
+
+WockySession *gabble_connection_get_session (
+ GabblePluginConnection *connection);
+
+gchar *gabble_connection_get_full_jid (GabbleConnection *conn);
+
+const gchar * gabble_connection_get_jid_for_caps (GabblePluginConnection *conn,
+ WockyXep0115Capabilities *caps);
+
+const gchar * gabble_connection_pick_best_resource_for_caps (
+ GabblePluginConnection *connection,
+ const gchar *jid,
+ GabbleCapabilitySetPredicate predicate,
+ gconstpointer user_data);
+
+TpBaseContactList * gabble_connection_get_contact_list (
+ GabbleConnection *connection);
+
+WockyXep0115Capabilities * gabble_connection_get_caps (
+ GabblePluginConnection *connection, TpHandle handle);
+
/* Default parameters for optional parameters */
#define GABBLE_PARAMS_DEFAULT_HTTPS_PROXY_PORT 443
#define GABBLE_PARAMS_DEFAULT_STUN_PORT 3478
diff --git a/src/plugin-connection.c b/src/plugin-connection.c
new file mode 100644
index 0000000..abec9e4
--- /dev/null
+++ b/src/plugin-connection.c
@@ -0,0 +1,181 @@
+/*
+ * plugin-connection.c — API for telepathy-gabble plugins
+ * Copyright © 2012 Collabora Ltd.
+ *
+ * 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 "gabble/plugin-connection.h"
+
+#include <glib-object.h>
+#include <gabble/types.h>
+#include <telepathy-glib/errors.h>
+#include <debug.h>
+
+
+static guint sig_id_porter_available = 0;
+
+/**
+ * SECTION: gabble-plugin-connection
+ * @title: GabblePluginConnection
+ * @short_description: Object representing gabble connection, implemented by
+ * Gabble internals.
+ *
+ * This Object represents Gabble Connection.
+ *
+ * Virtual methods in GabblePluginConnectionInterface interface are implemented
+ * by GabbleConnection object. And only Gabble should implement this interface.
+ */
+G_DEFINE_INTERFACE (GabblePluginConnection,
+ gabble_plugin_connection,
+ G_TYPE_OBJECT);
+
+static void
+gabble_plugin_connection_default_init (GabblePluginConnectionInterface *iface)
+{
+ static gsize once = 0;
+
+ if (g_once_init_enter (&once))
+ {
+ /**
+ * @self: a connection interface
+ * @porter: a porter
+ *
+ * Emitted when the WockyPorter becomes available.
+ */
+ sig_id_porter_available = g_signal_new (
+ "porter-available",
+ G_OBJECT_CLASS_TYPE (iface),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, WOCKY_TYPE_PORTER);
+ g_once_init_leave (&once, 1);
+ }
+}
+
+gchar *
+gabble_plugin_connection_add_sidecar_own_caps (
+ GabblePluginConnection *plugin_connection,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->add_sidecar_own_caps != NULL, NULL);
+
+ return iface->add_sidecar_own_caps (plugin_connection, cap_set, identities);
+}
+
+gchar *
+gabble_plugin_connection_add_sidecar_own_caps_full (
+ GabblePluginConnection *plugin_connection,
+ const GabbleCapabilitySet *cap_set,
+ const GPtrArray *identities,
+ GPtrArray *data_forms)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->add_sidecar_own_caps_full != NULL, NULL);
+
+ return iface->add_sidecar_own_caps_full (plugin_connection, cap_set, identities,
+ data_forms);
+}
+
+WockySession *
+gabble_plugin_connection_get_session (
+ GabblePluginConnection *plugin_connection)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->get_session != NULL, NULL);
+
+ return iface->get_session (plugin_connection);
+}
+
+gchar *
+gabble_plugin_connection_get_full_jid (
+ GabblePluginConnection *plugin_connection)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->get_full_jid != NULL, NULL);
+
+ return iface->get_full_jid (plugin_connection);
+}
+
+const gchar *
+gabble_plugin_connection_get_jid_for_caps (
+ GabblePluginConnection *plugin_connection,
+ WockyXep0115Capabilities *caps)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->get_jid_for_caps != NULL, NULL);
+
+ return iface->get_jid_for_caps (plugin_connection, caps);
+}
+
+const gchar *
+gabble_plugin_connection_pick_best_resource_for_caps (
+ GabblePluginConnection *plugin_connection,
+ const gchar *jid,
+ GabbleCapabilitySetPredicate predicate,
+ gconstpointer user_data)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->pick_best_resource_for_caps != NULL, NULL);
+
+ return iface->pick_best_resource_for_caps (plugin_connection, jid, predicate,
+ user_data);
+}
+
+TpBaseContactList *
+gabble_plugin_connection_get_contact_list (
+ GabblePluginConnection *plugin_connection)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->get_contact_list != NULL, NULL);
+
+ return iface->get_contact_list (plugin_connection);
+}
+
+WockyXep0115Capabilities *
+gabble_plugin_connection_get_caps (
+ GabblePluginConnection *plugin_connection,
+ TpHandle handle)
+{
+ GabblePluginConnectionInterface *iface =
+ GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->get_contact_list != NULL, NULL);
+
+ return iface->get_caps (plugin_connection, handle);
+}
diff --git a/src/plugin-loader.c b/src/plugin-loader.c
index 7e016b8..d5a451f 100644
--- a/src/plugin-loader.c
+++ b/src/plugin-loader.c
@@ -290,8 +290,10 @@ gabble_plugin_loader_create_sidecar (
GSimpleAsyncResult *res = g_simple_async_result_new (G_OBJECT (self),
callback, user_data, gabble_plugin_loader_create_sidecar);
- gabble_plugin_create_sidecar_async (p, sidecar_interface, connection, session,
- create_sidecar_cb, res);
+ GabblePluginConnection *gabble_conn =
+ GABBLE_PLUGIN_CONNECTION (connection);
+ gabble_plugin_create_sidecar_async (p, sidecar_interface,
+ gabble_conn, session, create_sidecar_cb, res);
return;
}
}
@@ -383,6 +385,7 @@ copy_to_other_array (gpointer data,
GPtrArray *
gabble_plugin_loader_create_channel_managers (
GabblePluginLoader *self,
+ GabblePluginConnection *plugin_connection,
TpBaseConnection *connection)
{
GPtrArray *out = g_ptr_array_new ();
@@ -393,7 +396,8 @@ gabble_plugin_loader_create_channel_managers (
GabblePlugin *plugin = g_ptr_array_index (self->priv->plugins, i);
GPtrArray *managers;
- managers = gabble_plugin_create_channel_managers (plugin, connection);
+ managers = gabble_plugin_create_channel_managers (plugin,
+ plugin_connection, connection);
if (managers == NULL)
continue;
diff --git a/src/plugin-loader.h b/src/plugin-loader.h
index 2100420..0447e6d 100644
--- a/src/plugin-loader.h
+++ b/src/plugin-loader.h
@@ -28,6 +28,7 @@
#include <wocky/wocky.h>
#include "gabble/sidecar.h"
+#include "gabble/plugin-connection.h"
typedef struct _GabblePluginLoader GabblePluginLoader;
typedef struct _GabblePluginLoaderClass GabblePluginLoaderClass;
@@ -86,6 +87,8 @@ const gchar *gabble_plugin_loader_presence_status_for_privacy_list (
const gchar *list_name);
GPtrArray * gabble_plugin_loader_create_channel_managers (
- GabblePluginLoader *self, TpBaseConnection *connection);
+ GabblePluginLoader *self,
+ GabblePluginConnection *plugin_connection,
+ TpBaseConnection *connection);
#endif /* #ifndef __PLUGIN_LOADER_H__ */
diff --git a/src/plugin.c b/src/plugin.c
index 783e721..fe38abe 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -99,7 +99,7 @@ void
gabble_plugin_create_sidecar_async (
GabblePlugin *plugin,
const gchar *sidecar_interface,
- GabbleConnection *connection,
+ GabblePluginConnection *plugin_connection,
WockySession *session,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -122,7 +122,7 @@ gabble_plugin_create_sidecar_async (
"'%s' is buggy: does not imlement create_sidecar_finish",
iface->name);
else
- iface->create_sidecar_async (plugin, sidecar_interface, connection, session,
+ iface->create_sidecar_async (plugin, sidecar_interface, plugin_connection, session,
callback, user_data);
}
@@ -211,6 +211,7 @@ gabble_plugin_presence_status_for_privacy_list (
GPtrArray *
gabble_plugin_create_channel_managers (GabblePlugin *plugin,
+ GabblePluginConnection *plugin_connection,
TpBaseConnection *connection)
{
GabblePluginInterface *iface = GABBLE_PLUGIN_GET_INTERFACE (plugin);
@@ -218,7 +219,7 @@ gabble_plugin_create_channel_managers (GabblePlugin *plugin,
GPtrArray *out = NULL;
if (func != NULL)
- out = func (plugin, connection);
+ out = func (plugin, plugin_connection, connection);
return out;
}