telepathy-gabble: console: add a channel manager
Simon McVittie
smcv at kemper.freedesktop.org
Mon Oct 14 08:21:20 PDT 2013
Module: telepathy-gabble
Branch: master
Commit: e996dd8b1f69eb1367582916b92e702426dfdf25
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=e996dd8b1f69eb1367582916b92e702426dfdf25
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Sat Jun 22 18:38:05 2013 +0100
console: add a channel manager
I am already losing the will to live at the thought of implementing the
actual requesting and closing bits.
---
plugins/Makefile.am | 2 +
plugins/console/channel-manager.c | 125 +++++++++++++++++++++++++++++++++++++
plugins/console/channel-manager.h | 51 +++++++++++++++
plugins/console/plugin.c | 16 +++++
tests/twisted/console.py | 11 +++
5 files changed, 205 insertions(+), 0 deletions(-)
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 159ecb1..8cdbb42 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -62,6 +62,8 @@ libgateways_la_SOURCES = \
gateways.h
libconsole_la_SOURCES = \
+ console/channel-manager.c \
+ console/channel-manager.h \
console/debug.c \
console/debug.h \
console/plugin.c \
diff --git a/plugins/console/channel-manager.c b/plugins/console/channel-manager.c
new file mode 100644
index 0000000..44f4a8b
--- /dev/null
+++ b/plugins/console/channel-manager.c
@@ -0,0 +1,125 @@
+/* XML console plugin
+ *
+ * Copyright © 2011â2013 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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 "config.h"
+#include "console/channel-manager.h"
+
+#include "extensions/extensions.h"
+
+static void channel_manager_iface_init (gpointer, gpointer);
+
+G_DEFINE_TYPE_WITH_CODE (GabbleConsoleChannelManager, gabble_console_channel_manager,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER, channel_manager_iface_init)
+ G_IMPLEMENT_INTERFACE (GABBLE_TYPE_CAPS_CHANNEL_MANAGER, NULL);
+ )
+
+enum {
+ PROP_CONNECTION = 1,
+};
+
+static void
+gabble_console_channel_manager_init (GabbleConsoleChannelManager *self)
+{
+}
+
+static void
+gabble_console_channel_manager_set_property (
+ GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GabbleConsoleChannelManager *self = GABBLE_CONSOLE_CHANNEL_MANAGER (object);
+
+ switch (property_id)
+ {
+ case PROP_CONNECTION:
+ /* Not reffing this: the connection owns all channel managers, so it
+ * must outlive us. Taking a reference leads to a cycle.
+ */
+ self->plugin_connection = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+gabble_console_channel_manager_get_property (
+ GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GabbleConsoleChannelManager *self = GABBLE_CONSOLE_CHANNEL_MANAGER (object);
+
+ switch (property_id)
+ {
+ case PROP_CONNECTION:
+ g_value_set_object (value, self->plugin_connection);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+gabble_console_channel_manager_class_init (GabbleConsoleChannelManagerClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ oclass->set_property = gabble_console_channel_manager_set_property;
+ oclass->get_property = gabble_console_channel_manager_get_property;
+
+ g_object_class_install_property (oclass, PROP_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));
+}
+
+static void
+gabble_console_channel_manager_type_foreach_channel_class (GType type,
+ TpChannelManagerTypeChannelClassFunc func,
+ gpointer user_data)
+{
+ GHashTable *table = tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, GABBLE_IFACE_GABBLE_PLUGIN_CONSOLE,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_NONE,
+ NULL);
+
+ func (type, table, NULL, user_data);
+
+ g_hash_table_unref (table);
+}
+
+static void
+channel_manager_iface_init (gpointer g_iface,
+ gpointer iface_data)
+{
+ TpChannelManagerIface *iface = g_iface;
+
+ iface->type_foreach_channel_class = gabble_console_channel_manager_type_foreach_channel_class;
+
+ /* not requestable. */
+ iface->ensure_channel = NULL;
+ iface->create_channel = NULL;
+ iface->request_channel = NULL;
+}
diff --git a/plugins/console/channel-manager.h b/plugins/console/channel-manager.h
new file mode 100644
index 0000000..a876a7b
--- /dev/null
+++ b/plugins/console/channel-manager.h
@@ -0,0 +1,51 @@
+/* XML console plugin
+ *
+ * Copyright © 2011â2013 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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 <glib-object.h>
+#include <gabble/gabble.h>
+
+typedef struct _GabbleConsoleChannelManager GabbleConsoleChannelManager;
+typedef struct _GabbleConsoleChannelManagerClass GabbleConsoleChannelManagerClass;
+
+struct _GabbleConsoleChannelManagerClass {
+ GObjectClass parent_class;
+};
+
+struct _GabbleConsoleChannelManager {
+ GObject parent;
+
+ GabblePluginConnection *plugin_connection;
+};
+
+GType gabble_console_channel_manager_get_type (void);
+
+#define GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER \
+ (gabble_console_channel_manager_get_type ())
+#define GABBLE_CONSOLE_CHANNEL_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER, GabbleConsoleChannelManager))
+#define GABBLE_CONSOLE_CHANNEL_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER,\
+ GabbleConsoleChannelManagerClass))
+#define GABBLE_IS_CONSOLE_CHANNEL_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER))
+#define GABBLE_IS_CONSOLE_CHANNEL_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER))
+#define GABBLE_CONSOLE_CHANNEL_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER,\
+ GabbleConsoleChannelManagerClass))
diff --git a/plugins/console/plugin.c b/plugins/console/plugin.c
index d5f0215..222c583 100644
--- a/plugins/console/plugin.c
+++ b/plugins/console/plugin.c
@@ -25,6 +25,7 @@
#include <gabble/gabble.h>
#include "extensions/extensions.h"
+#include "console/channel-manager.h"
#include "console/debug.h"
#include "console/sidecar.h"
@@ -108,6 +109,20 @@ gabble_console_plugin_create_sidecar_finish (
return g_object_ref (sidecar);
}
+static GPtrArray *
+gabble_console_plugin_create_channel_managers (GabblePlugin *plugin,
+ GabblePluginConnection *plugin_connection)
+{
+ GPtrArray *ret = g_ptr_array_new ();
+
+ g_ptr_array_add (ret,
+ g_object_new (GABBLE_TYPE_CONSOLE_CHANNEL_MANAGER,
+ "plugin-connection", plugin_connection,
+ NULL));
+
+ return ret;
+}
+
static void
plugin_iface_init (
gpointer g_iface,
@@ -120,6 +135,7 @@ plugin_iface_init (
iface->sidecar_interfaces = sidecar_interfaces;
iface->create_sidecar_async = gabble_console_plugin_create_sidecar_async;
iface->create_sidecar_finish = gabble_console_plugin_create_sidecar_finish;
+ iface->create_channel_managers = gabble_console_plugin_create_channel_managers;
}
GabblePlugin *
diff --git a/tests/twisted/console.py b/tests/twisted/console.py
index 95c76a3..8aab65f 100644
--- a/tests/twisted/console.py
+++ b/tests/twisted/console.py
@@ -10,6 +10,7 @@ from gabbletest import exec_test, acknowledge_iq, elem, elem_iq
from config import PLUGINS_ENABLED
from twisted.words.xish import domish
import ns
+import constants as cs
CONSOLE_PLUGIN_IFACE = "org.freedesktop.Telepathy.Gabble.Plugin.Console"
STACY = 'stacy at pilgrim.lit'
@@ -27,6 +28,16 @@ def send_unrecognised_get(q, stream):
return q.expect('stream-iq', iq_type='error')
def test(q, bus, conn, stream):
+ rccs = conn.Properties.Get(cs.CONN_IFACE_REQUESTS,
+ 'RequestableChannelClasses')
+
+ fixed = {
+ cs.CHANNEL_TYPE: CONSOLE_PLUGIN_IFACE,
+ cs.TARGET_HANDLE_TYPE: cs.HT_NONE,
+ }
+ allowed = []
+ assertContains((fixed, allowed), rccs)
+
path, _ = conn.Future.EnsureSidecar(CONSOLE_PLUGIN_IFACE)
console = ProxyWrapper(bus.get_object(conn.bus_name, path),
CONSOLE_PLUGIN_IFACE)
More information about the telepathy-commits
mailing list