[Telepathy-commits] [telepathy-qt4/master] Added echo2 test from tp-glib.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Jan 27 06:34:40 PST 2009
Added echo2 test from tp-glib (supports ensure/createChannel).
---
configure.ac | 1 +
tests/lib/Makefile.am | 2 +
tests/lib/echo2/Makefile.am | 22 ++
tests/lib/echo2/chan.c | 589 ++++++++++++++++++++++++++++++++++++++++++
tests/lib/echo2/chan.h | 58 ++++
tests/lib/echo2/conn.c | 193 ++++++++++++++
tests/lib/echo2/conn.h | 54 ++++
tests/lib/echo2/im-manager.c | 389 ++++++++++++++++++++++++++++
tests/lib/echo2/im-manager.h | 54 ++++
9 files changed, 1362 insertions(+), 0 deletions(-)
create mode 100644 tests/lib/echo2/Makefile.am
create mode 100644 tests/lib/echo2/chan.c
create mode 100644 tests/lib/echo2/chan.h
create mode 100644 tests/lib/echo2/conn.c
create mode 100644 tests/lib/echo2/conn.h
create mode 100644 tests/lib/echo2/im-manager.c
create mode 100644 tests/lib/echo2/im-manager.h
diff --git a/configure.ac b/configure.ac
index 9740f10..5f6e39a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,6 +247,7 @@ AC_OUTPUT([
tests/dbus/Makefile
tests/dbus-1/services/account-manager.service
tests/lib/Makefile
+ tests/lib/echo2/Makefile
tests/pinocchio/Makefile
tests/prototype/Makefile
tools/Makefile
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 5457761..31d11b2 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = echo2
+
AM_CFLAGS = $(ERROR_CFLAGS)
MOC_INCLUDES = \
diff --git a/tests/lib/echo2/Makefile.am b/tests/lib/echo2/Makefile.am
new file mode 100644
index 0000000..87e352e
--- /dev/null
+++ b/tests/lib/echo2/Makefile.am
@@ -0,0 +1,22 @@
+AM_CFLAGS = $(ERROR_CFLAGS)
+AM_CXXFLAGS = $(ERROR_CXXFLAGS)
+
+if ENABLE_TP_GLIB_TESTS
+
+AM_CFLAGS += $(TP_GLIB_CFLAGS)
+AM_CXXFLAGS += $(TP_GLIB_CFLAGS)
+
+noinst_LTLIBRARIES = libtp-glib-echo2-tests.la
+
+libtp_glib_echo2_tests_la_SOURCES = \
+ chan.c \
+ chan.h \
+ conn.c \
+ conn.h \
+ im-manager.c \
+ im-manager.h
+
+libtp_glib_echo2_tests_la_LIBADD = \
+ $(TP_GLIB_LIBS)
+
+endif
diff --git a/tests/lib/echo2/chan.c b/tests/lib/echo2/chan.c
new file mode 100644
index 0000000..0f2502d
--- /dev/null
+++ b/tests/lib/echo2/chan.c
@@ -0,0 +1,589 @@
+/*
+ * chan.c - an example text channel talking to a particular
+ * contact. Similar code is used for 1-1 IM channels in many protocols
+ * (IRC private messages ("/query"), XMPP IM etc.)
+ *
+ * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include "chan.h"
+
+#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/channel-iface.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/svc-channel.h>
+#include <telepathy-glib/svc-generic.h>
+
+static void channel_iface_init (gpointer iface, gpointer data);
+static void destroyable_iface_init (gpointer iface, gpointer data);
+
+G_DEFINE_TYPE_WITH_CODE (ExampleEcho2Channel,
+ example_echo_2_channel,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
+ tp_dbus_properties_mixin_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL, channel_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TEXT,
+ tp_message_mixin_text_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_MESSAGES,
+ tp_message_mixin_messages_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_DESTROYABLE,
+ destroyable_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL))
+
+/* type definition stuff */
+
+enum
+{
+ PROP_OBJECT_PATH = 1,
+ PROP_CHANNEL_TYPE,
+ PROP_HANDLE_TYPE,
+ PROP_HANDLE,
+ PROP_TARGET_ID,
+ PROP_REQUESTED,
+ PROP_INITIATOR_HANDLE,
+ PROP_INITIATOR_ID,
+ PROP_CONNECTION,
+ PROP_INTERFACES,
+ PROP_CHANNEL_DESTROYED,
+ PROP_CHANNEL_PROPERTIES,
+ N_PROPS
+};
+
+struct _ExampleEcho2ChannelPrivate
+{
+ TpBaseConnection *conn;
+ gchar *object_path;
+ TpHandle handle;
+ TpHandle initiator;
+
+ /* These are really booleans, but gboolean is signed. Thanks, GLib */
+ unsigned closed:1;
+ unsigned disposed:1;
+};
+
+static const char * example_echo_2_channel_interfaces[] = {
+ TP_IFACE_CHANNEL_INTERFACE_MESSAGES,
+ NULL };
+/* FIXME: when supported, add TP_IFACE_CHANNEL_INTERFACE_DESTROYABLE */
+
+static void
+example_echo_2_channel_init (ExampleEcho2Channel *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EXAMPLE_TYPE_ECHO_2_CHANNEL,
+ ExampleEcho2ChannelPrivate);
+}
+
+
+static void
+send_message (GObject *object,
+ TpMessage *message,
+ TpMessageSendingFlags flags)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (object);
+ time_t timestamp = time (NULL);
+ guint len = tp_message_count_parts (message);
+ TpMessage *received = NULL;
+ guint i;
+
+ if (tp_asv_get_string (tp_message_peek (message, 0), "interface") != NULL)
+ {
+ /* this message is interface-specific - let's not echo it */
+ goto finally;
+ }
+
+ received = tp_message_new (self->priv->conn, 1, len);
+
+ /* Copy/modify the headers for the "received" message */
+ {
+ TpChannelTextMessageType message_type;
+ gboolean valid;
+
+ tp_message_set_handle (received, 0, "message-sender",
+ TP_HANDLE_TYPE_CONTACT, self->priv->handle);
+
+ message_type = tp_asv_get_uint32 (tp_message_peek (message, 0),
+ "message-type", &valid);
+
+ /* The check for 'valid' means that if message-type is missing or of the
+ * wrong type, fall back to NORMAL (this is in fact a no-op, since
+ * NORMAL == 0 and tp_asv_get_uint32 returns 0 on missing or wrongly
+ * typed values) */
+ if (valid && message_type != TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)
+ tp_message_set_uint32 (received, 0, "message-type", message_type);
+
+ tp_message_set_uint32 (received, 0, "message-sent", timestamp);
+ tp_message_set_uint32 (received, 0, "message-received", timestamp);
+ }
+
+ /* Copy the content for the "received" message */
+ for (i = 1; i < len; i++)
+ {
+ const GHashTable *input = tp_message_peek (message, i);
+ const gchar *s;
+ const GValue *value;
+ guint j;
+
+ /* in this example we ignore interface-specific parts */
+
+ s = tp_asv_get_string (input, "type");
+
+ if (s == NULL)
+ continue;
+
+ s = tp_asv_get_string (input, "interface");
+
+ if (s != NULL)
+ continue;
+
+ /* OK, we want to copy this part */
+
+ j = tp_message_append_part (received);
+
+ s = tp_asv_get_string (input, "type");
+ g_assert (s != NULL); /* already checked */
+ tp_message_set_string (received, j, "type", s);
+
+ s = tp_asv_get_string (input, "identifier");
+
+ if (s != NULL)
+ tp_message_set_string (received, j, "identifier", s);
+
+ s = tp_asv_get_string (input, "alternative");
+
+ if (s != NULL)
+ tp_message_set_string (received, j, "alternative", s);
+
+ s = tp_asv_get_string (input, "lang");
+
+ if (s != NULL)
+ tp_message_set_string (received, j, "lang", s);
+
+ value = tp_asv_lookup (input, "content");
+
+ if (value != NULL)
+ tp_message_set (received, j, "content", value);
+ }
+
+finally:
+ /* "OK, we've sent the message" (after calling this, message must not be
+ * dereferenced) */
+ tp_message_mixin_sent (object, message, flags, "", NULL);
+
+ if (received != NULL)
+ {
+ /* Pretend the other user sent us back the same message. After this call,
+ * the received message is owned by the mixin */
+ tp_message_mixin_take_received (object, received);
+ }
+}
+
+
+static GObject *
+constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
+{
+ GObject *object =
+ G_OBJECT_CLASS (example_echo_2_channel_parent_class)->constructor (type,
+ n_props, props);
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (object);
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles
+ (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+ DBusGConnection *bus;
+ static TpChannelTextMessageType const types[] = {
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE
+ };
+ static const char * const content_types[] = { "*/*", NULL };
+
+ tp_handle_ref (contact_repo, self->priv->handle);
+
+ if (self->priv->initiator != 0)
+ tp_handle_ref (contact_repo, self->priv->initiator);
+
+ bus = tp_get_bus ();
+ dbus_g_connection_register_g_object (bus, self->priv->object_path, object);
+
+ tp_message_mixin_init (object, G_STRUCT_OFFSET (ExampleEcho2Channel, text),
+ self->priv->conn);
+
+ tp_message_mixin_implement_sending (object, send_message,
+ (sizeof (types) / sizeof (types[0])), types,
+ TP_MESSAGE_PART_SUPPORT_FLAG_ONE_ATTACHMENT |
+ TP_MESSAGE_PART_SUPPORT_FLAG_MULTIPLE_ATTACHMENTS,
+ 0, /* aka no TpDeliveryReportingSupportFlags */
+ content_types);
+
+ return object;
+}
+
+static void
+get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (object);
+
+ switch (property_id)
+ {
+ case PROP_OBJECT_PATH:
+ g_value_set_string (value, self->priv->object_path);
+ break;
+ case PROP_CHANNEL_TYPE:
+ g_value_set_static_string (value, TP_IFACE_CHANNEL_TYPE_TEXT);
+ break;
+ case PROP_HANDLE_TYPE:
+ g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT);
+ break;
+ case PROP_HANDLE:
+ g_value_set_uint (value, self->priv->handle);
+ break;
+ case PROP_TARGET_ID:
+ {
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+ self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+
+ g_value_set_string (value,
+ tp_handle_inspect (contact_repo, self->priv->handle));
+ }
+ break;
+ case PROP_REQUESTED:
+ g_value_set_boolean (value,
+ (self->priv->initiator == self->priv->conn->self_handle));
+ break;
+ case PROP_INITIATOR_HANDLE:
+ g_value_set_uint (value, self->priv->initiator);
+ break;
+ case PROP_INITIATOR_ID:
+ {
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+ self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+
+ g_value_set_string (value,
+ self->priv->initiator == 0
+ ? ""
+ : tp_handle_inspect (contact_repo, self->priv->initiator));
+ }
+ break;
+ case PROP_CONNECTION:
+ g_value_set_object (value, self->priv->conn);
+ break;
+ case PROP_INTERFACES:
+ g_value_set_boxed (value, example_echo_2_channel_interfaces);
+ break;
+ case PROP_CHANNEL_DESTROYED:
+ g_value_set_boolean (value, self->priv->closed);
+ break;
+ case PROP_CHANNEL_PROPERTIES:
+ g_value_take_boxed (value,
+ tp_dbus_properties_mixin_make_properties_hash (object,
+ TP_IFACE_CHANNEL, "ChannelType",
+ TP_IFACE_CHANNEL, "TargetHandleType",
+ TP_IFACE_CHANNEL, "TargetHandle",
+ TP_IFACE_CHANNEL, "TargetID",
+ TP_IFACE_CHANNEL, "InitiatorHandle",
+ TP_IFACE_CHANNEL, "InitiatorID",
+ TP_IFACE_CHANNEL, "Requested",
+ TP_IFACE_CHANNEL, "Interfaces",
+ NULL));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (object);
+
+ switch (property_id)
+ {
+ case PROP_OBJECT_PATH:
+ g_free (self->priv->object_path);
+ self->priv->object_path = g_value_dup_string (value);
+ break;
+ case PROP_HANDLE:
+ /* we don't ref it here because we don't necessarily have access to the
+ * contact repo yet - instead we ref it in the constructor.
+ */
+ self->priv->handle = g_value_get_uint (value);
+ break;
+ case PROP_INITIATOR_HANDLE:
+ /* likewise */
+ self->priv->initiator = g_value_get_uint (value);
+ break;
+ case PROP_HANDLE_TYPE:
+ case PROP_CHANNEL_TYPE:
+ /* these properties are writable in the interface, but not actually
+ * meaningfully changable on this channel, so we do nothing */
+ break;
+ case PROP_CONNECTION:
+ self->priv->conn = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+dispose (GObject *object)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (object);
+
+ if (self->priv->disposed)
+ return;
+
+ self->priv->disposed = TRUE;
+
+ if (!self->priv->closed)
+ {
+ self->priv->closed = TRUE;
+ tp_svc_channel_emit_closed (self);
+ }
+
+ ((GObjectClass *) example_echo_2_channel_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (object);
+ TpHandleRepoIface *contact_handles = tp_base_connection_get_handles
+ (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+
+ tp_handle_unref (contact_handles, self->priv->handle);
+
+ if (self->priv->initiator != 0)
+ tp_handle_unref (contact_handles, self->priv->initiator);
+
+ g_free (self->priv->object_path);
+
+ tp_message_mixin_finalize (object);
+
+ ((GObjectClass *) example_echo_2_channel_parent_class)->finalize (object);
+}
+
+static void
+example_echo_2_channel_class_init (ExampleEcho2ChannelClass *klass)
+{
+ static TpDBusPropertiesMixinPropImpl channel_props[] = {
+ { "TargetHandleType", "handle-type", NULL },
+ { "TargetHandle", "handle", NULL },
+ { "ChannelType", "channel-type", NULL },
+ { "Interfaces", "interfaces", NULL },
+ { "TargetID", "target-id", NULL },
+ { "Requested", "requested", NULL },
+ { "InitiatorHandle", "initiator-handle", NULL },
+ { "InitiatorID", "initiator-id", NULL },
+ { NULL }
+ };
+ static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
+ { TP_IFACE_CHANNEL,
+ tp_dbus_properties_mixin_getter_gobject_properties,
+ NULL,
+ channel_props,
+ },
+ { NULL }
+ };
+ GObjectClass *object_class = (GObjectClass *) klass;
+ GParamSpec *param_spec;
+
+ g_type_class_add_private (klass, sizeof (ExampleEcho2ChannelPrivate));
+
+ object_class->constructor = constructor;
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+
+ g_object_class_override_property (object_class, PROP_OBJECT_PATH,
+ "object-path");
+ g_object_class_override_property (object_class, PROP_CHANNEL_TYPE,
+ "channel-type");
+ g_object_class_override_property (object_class, PROP_HANDLE_TYPE,
+ "handle-type");
+ g_object_class_override_property (object_class, PROP_HANDLE, "handle");
+
+ g_object_class_override_property (object_class, PROP_CHANNEL_DESTROYED,
+ "channel-destroyed");
+ g_object_class_override_property (object_class, PROP_CHANNEL_PROPERTIES,
+ "channel-properties");
+
+ param_spec = g_param_spec_object ("connection", "TpBaseConnection object",
+ "Connection object that owns this channel",
+ TP_TYPE_BASE_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
+
+ param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
+ "Additional Channel.Interface.* interfaces",
+ G_TYPE_STRV,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
+
+ param_spec = g_param_spec_string ("target-id", "Peer's ID",
+ "The string obtained by inspecting the target handle",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_TARGET_ID, param_spec);
+
+ param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
+ "The contact who initiated the channel",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
+ param_spec);
+
+ param_spec = g_param_spec_string ("initiator-id", "Initiator's ID",
+ "The string obtained by inspecting the initiator-handle",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INITIATOR_ID,
+ param_spec);
+
+ param_spec = g_param_spec_boolean ("requested", "Requested?",
+ "True if this channel was requested by the local user",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_REQUESTED, param_spec);
+
+ klass->dbus_properties_class.interfaces = prop_interfaces;
+ tp_dbus_properties_mixin_class_init (object_class,
+ G_STRUCT_OFFSET (ExampleEcho2ChannelClass, dbus_properties_class));
+
+ tp_message_mixin_init_dbus_properties (object_class);
+}
+
+static void
+example_echo_2_channel_close (ExampleEcho2Channel *self)
+{
+ GObject *object = (GObject *) self;
+
+ if (!self->priv->closed)
+ {
+ TpHandle first_sender;
+
+ /* The manager wants to be able to respawn the channel if it has pending
+ * messages. When respawned, the channel must have the initiator set
+ * to the contact who sent us those messages (if it isn't already),
+ * and the messages must be marked as having been rescued so they
+ * don't get logged twice. */
+ if (tp_message_mixin_has_pending_messages (object, &first_sender))
+ {
+ if (self->priv->initiator != first_sender)
+ {
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles
+ (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
+ TpHandle old_initiator = self->priv->initiator;
+
+ if (first_sender != 0)
+ tp_handle_ref (contact_repo, first_sender);
+
+ self->priv->initiator = first_sender;
+
+ if (old_initiator != 0)
+ tp_handle_unref (contact_repo, old_initiator);
+ }
+
+ tp_message_mixin_set_rescued (object);
+ }
+ else
+ {
+ /* No pending messages, so it's OK to really close */
+ self->priv->closed = TRUE;
+ }
+
+ tp_svc_channel_emit_closed (self);
+ }
+}
+
+static void
+channel_close (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (iface);
+
+ example_echo_2_channel_close (self);
+ tp_svc_channel_return_from_close (context);
+}
+
+static void
+channel_get_channel_type (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ tp_svc_channel_return_from_get_channel_type (context,
+ TP_IFACE_CHANNEL_TYPE_TEXT);
+}
+
+static void
+channel_get_handle (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (iface);
+
+ tp_svc_channel_return_from_get_handle (context, TP_HANDLE_TYPE_CONTACT,
+ self->priv->handle);
+}
+
+static void
+channel_get_interfaces (TpSvcChannel *iface,
+ DBusGMethodInvocation *context)
+{
+ tp_svc_channel_return_from_get_interfaces (context,
+ example_echo_2_channel_interfaces);
+}
+
+static void
+channel_iface_init (gpointer iface,
+ gpointer data)
+{
+ TpSvcChannelClass *klass = iface;
+
+#define IMPLEMENT(x) tp_svc_channel_implement_##x (klass, channel_##x)
+ IMPLEMENT (close);
+ IMPLEMENT (get_channel_type);
+ IMPLEMENT (get_handle);
+ IMPLEMENT (get_interfaces);
+#undef IMPLEMENT
+}
+
+static void
+destroyable_destroy (TpSvcChannelInterfaceDestroyable *iface,
+ DBusGMethodInvocation *context)
+{
+ ExampleEcho2Channel *self = EXAMPLE_ECHO_2_CHANNEL (iface);
+
+ tp_message_mixin_clear ((GObject *) self);
+ example_echo_2_channel_close (self);
+ g_assert (self->priv->closed);
+ tp_svc_channel_interface_destroyable_return_from_destroy (context);
+}
+
+static void
+destroyable_iface_init (gpointer iface,
+ gpointer data)
+{
+ TpSvcChannelInterfaceDestroyableClass *klass = iface;
+
+#define IMPLEMENT(x) \
+ tp_svc_channel_interface_destroyable_implement_##x (klass, destroyable_##x)
+ IMPLEMENT (destroy);
+#undef IMPLEMENT
+}
diff --git a/tests/lib/echo2/chan.h b/tests/lib/echo2/chan.h
new file mode 100644
index 0000000..049991e
--- /dev/null
+++ b/tests/lib/echo2/chan.h
@@ -0,0 +1,58 @@
+/*
+ * chan.h - header for an example channel
+ *
+ * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#ifndef EXAMPLE_ECHO_MESSAGE_PARTS_CHAN_H
+#define EXAMPLE_ECHO_MESSAGE_PARTS_CHAN_H
+
+#include <glib-object.h>
+#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/message-mixin.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ExampleEcho2Channel ExampleEcho2Channel;
+typedef struct _ExampleEcho2ChannelClass ExampleEcho2ChannelClass;
+typedef struct _ExampleEcho2ChannelPrivate ExampleEcho2ChannelPrivate;
+
+GType example_echo_2_channel_get_type (void);
+
+#define EXAMPLE_TYPE_ECHO_2_CHANNEL \
+ (example_echo_2_channel_get_type ())
+#define EXAMPLE_ECHO_2_CHANNEL(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_TYPE_ECHO_2_CHANNEL, \
+ ExampleEcho2Channel))
+#define EXAMPLE_ECHO_2_CHANNEL_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), EXAMPLE_TYPE_ECHO_2_CHANNEL, \
+ ExampleEcho2ChannelClass))
+#define EXAMPLE_IS_ECHO_2_CHANNEL(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EXAMPLE_TYPE_ECHO_2_CHANNEL))
+#define EXAMPLE_IS_ECHO_2_CHANNEL_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), EXAMPLE_TYPE_ECHO_2_CHANNEL))
+#define EXAMPLE_ECHO_2_CHANNEL_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), EXAMPLE_TYPE_ECHO_2_CHANNEL, \
+ ExampleEcho2ChannelClass))
+
+struct _ExampleEcho2ChannelClass {
+ GObjectClass parent_class;
+
+ TpDBusPropertiesMixinClass dbus_properties_class;
+};
+
+struct _ExampleEcho2Channel {
+ GObject parent;
+ TpMessageMixin text;
+
+ ExampleEcho2ChannelPrivate *priv;
+};
+
+G_END_DECLS
+
+#endif
diff --git a/tests/lib/echo2/conn.c b/tests/lib/echo2/conn.c
new file mode 100644
index 0000000..410cb40
--- /dev/null
+++ b/tests/lib/echo2/conn.c
@@ -0,0 +1,193 @@
+/*
+ * conn.c - an example connection
+ *
+ * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include "conn.h"
+
+#include <dbus/dbus-glib.h>
+
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/errors.h>
+#include <telepathy-glib/handle-repo-dynamic.h>
+#include <telepathy-glib/interfaces.h>
+
+#include "im-manager.h"
+
+G_DEFINE_TYPE (ExampleEcho2Connection,
+ example_echo_2_connection,
+ TP_TYPE_BASE_CONNECTION)
+
+enum
+{
+ PROP_ACCOUNT = 1,
+ N_PROPS
+};
+
+struct _ExampleEcho2ConnectionPrivate
+{
+ gchar *account;
+};
+
+static void
+example_echo_2_connection_init (ExampleEcho2Connection *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EXAMPLE_TYPE_ECHO_2_CONNECTION,
+ ExampleEcho2ConnectionPrivate);
+}
+
+static void
+get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *spec)
+{
+ ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (object);
+
+ switch (property_id) {
+ case PROP_ACCOUNT:
+ g_value_set_string (value, self->priv->account);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
+ }
+}
+
+static void
+set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *spec)
+{
+ ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (object);
+
+ switch (property_id) {
+ case PROP_ACCOUNT:
+ g_free (self->priv->account);
+ self->priv->account = g_utf8_strdown (g_value_get_string (value), -1);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
+ }
+}
+
+static void
+finalize (GObject *object)
+{
+ ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (object);
+
+ g_free (self->priv->account);
+
+ G_OBJECT_CLASS (example_echo_2_connection_parent_class)->finalize (object);
+}
+
+static gchar *
+get_unique_connection_name (TpBaseConnection *conn)
+{
+ ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (conn);
+
+ return g_strdup (self->priv->account);
+}
+
+static gchar *
+example_normalize_contact (TpHandleRepoIface *repo,
+ const gchar *id,
+ gpointer context,
+ GError **error)
+{
+ if (id[0] == '\0')
+ {
+ g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_HANDLE,
+ "ID must not be empty");
+ return NULL;
+ }
+
+ return g_utf8_strdown (id, -1);
+}
+
+static void
+create_handle_repos (TpBaseConnection *conn,
+ TpHandleRepoIface *repos[NUM_TP_HANDLE_TYPES])
+{
+ repos[TP_HANDLE_TYPE_CONTACT] = tp_dynamic_handle_repo_new
+ (TP_HANDLE_TYPE_CONTACT, example_normalize_contact, NULL);
+}
+
+static GPtrArray *
+create_channel_managers (TpBaseConnection *conn)
+{
+ GPtrArray *ret = g_ptr_array_sized_new (1);
+
+ g_ptr_array_add (ret, g_object_new (EXAMPLE_TYPE_ECHO_2_IM_MANAGER,
+ "connection", conn,
+ NULL));
+
+ return ret;
+}
+
+static gboolean
+start_connecting (TpBaseConnection *conn,
+ GError **error)
+{
+ ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (conn);
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
+ TP_HANDLE_TYPE_CONTACT);
+
+ /* In a real connection manager we'd ask the underlying implementation to
+ * start connecting, then go to state CONNECTED when finished, but here
+ * we can do it immediately. */
+
+ conn->self_handle = tp_handle_ensure (contact_repo, self->priv->account,
+ NULL, NULL);
+
+ tp_base_connection_change_status (conn, TP_CONNECTION_STATUS_CONNECTED,
+ TP_CONNECTION_STATUS_REASON_REQUESTED);
+
+ return TRUE;
+}
+
+static void
+shut_down (TpBaseConnection *conn)
+{
+ /* In a real connection manager we'd ask the underlying implementation to
+ * start shutting down, then call this function when finished, but here
+ * we can do it immediately. */
+ tp_base_connection_finish_shutdown (conn);
+}
+
+static void
+example_echo_2_connection_class_init (ExampleEcho2ConnectionClass *klass)
+{
+ static const gchar *interfaces_always_present[] = {
+ TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
+ NULL };
+ TpBaseConnectionClass *base_class =
+ (TpBaseConnectionClass *) klass;
+ GObjectClass *object_class = (GObjectClass *) klass;
+ GParamSpec *param_spec;
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+ object_class->finalize = finalize;
+ g_type_class_add_private (klass, sizeof (ExampleEcho2ConnectionPrivate));
+
+ base_class->create_handle_repos = create_handle_repos;
+ base_class->get_unique_connection_name = get_unique_connection_name;
+ base_class->create_channel_managers = create_channel_managers;
+ base_class->start_connecting = start_connecting;
+ base_class->shut_down = shut_down;
+ base_class->interfaces_always_present = interfaces_always_present;
+
+ param_spec = g_param_spec_string ("account", "Account name",
+ "The username of this user", NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec);
+}
diff --git a/tests/lib/echo2/conn.h b/tests/lib/echo2/conn.h
new file mode 100644
index 0000000..4813eae
--- /dev/null
+++ b/tests/lib/echo2/conn.h
@@ -0,0 +1,54 @@
+/*
+ * conn.h - header for an example connection
+ *
+ * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#ifndef EXAMPLE_ECHO_MESSAGE_PARTS_CONN_H
+#define EXAMPLE_ECHO_MESSAGE_PARTS_CONN_H
+
+#include <glib-object.h>
+#include <telepathy-glib/base-connection.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ExampleEcho2Connection ExampleEcho2Connection;
+typedef struct _ExampleEcho2ConnectionClass ExampleEcho2ConnectionClass;
+typedef struct _ExampleEcho2ConnectionPrivate ExampleEcho2ConnectionPrivate;
+
+struct _ExampleEcho2ConnectionClass {
+ TpBaseConnectionClass parent_class;
+};
+
+struct _ExampleEcho2Connection {
+ TpBaseConnection parent;
+
+ ExampleEcho2ConnectionPrivate *priv;
+};
+
+GType example_echo_2_connection_get_type (void);
+
+#define EXAMPLE_TYPE_ECHO_2_CONNECTION \
+ (example_echo_2_connection_get_type ())
+#define EXAMPLE_ECHO_2_CONNECTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), EXAMPLE_TYPE_ECHO_2_CONNECTION, \
+ ExampleEcho2Connection))
+#define EXAMPLE_ECHO_2_CONNECTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), EXAMPLE_TYPE_ECHO_2_CONNECTION, \
+ ExampleEcho2ConnectionClass))
+#define EXAMPLE_IS_ECHO_2_CONNECTION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), EXAMPLE_TYPE_ECHO_2_CONNECTION))
+#define EXAMPLE_IS_ECHO_2_CONNECTION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), EXAMPLE_TYPE_ECHO_2_CONNECTION))
+#define EXAMPLE_ECHO_2_CONNECTION_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), EXAMPLE_TYPE_ECHO_2_CONNECTION, \
+ ExampleEcho2ConnectionClass))
+
+G_END_DECLS
+
+#endif
diff --git a/tests/lib/echo2/im-manager.c b/tests/lib/echo2/im-manager.c
new file mode 100644
index 0000000..5562b30
--- /dev/null
+++ b/tests/lib/echo2/im-manager.c
@@ -0,0 +1,389 @@
+/*
+ * im-manager.c - an example channel manager for channels talking to a
+ * particular contact. Similar code is used for 1-1 IM channels in many
+ * protocols (IRC private messages ("/query"), XMPP IM etc.)
+ *
+ * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include "im-manager.h"
+
+#include <dbus/dbus-glib.h>
+
+#include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/channel-manager.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/errors.h>
+#include <telepathy-glib/interfaces.h>
+
+#include "chan.h"
+
+static void channel_manager_iface_init (gpointer, gpointer);
+
+G_DEFINE_TYPE_WITH_CODE (ExampleEcho2ImManager,
+ example_echo_2_im_manager,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER,
+ channel_manager_iface_init))
+
+/* type definition stuff */
+
+enum
+{
+ PROP_CONNECTION = 1,
+ N_PROPS
+};
+
+struct _ExampleEcho2ImManagerPrivate
+{
+ TpBaseConnection *conn;
+
+ /* GUINT_TO_POINTER (handle) => ExampleEcho2Channel */
+ GHashTable *channels;
+ gulong status_changed_id;
+};
+
+static void
+example_echo_2_im_manager_init (ExampleEcho2ImManager *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EXAMPLE_TYPE_ECHO_2_IM_MANAGER,
+ ExampleEcho2ImManagerPrivate);
+
+ self->priv->channels = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, g_object_unref);
+}
+
+static void example_echo_2_im_manager_close_all (ExampleEcho2ImManager *self);
+
+static void
+dispose (GObject *object)
+{
+ ExampleEcho2ImManager *self = EXAMPLE_ECHO_2_IM_MANAGER (object);
+
+ example_echo_2_im_manager_close_all (self);
+ g_assert (self->priv->channels == NULL);
+
+ ((GObjectClass *) example_echo_2_im_manager_parent_class)->dispose (object);
+}
+
+static void
+get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ExampleEcho2ImManager *self = EXAMPLE_ECHO_2_IM_MANAGER (object);
+
+ switch (property_id)
+ {
+ case PROP_CONNECTION:
+ g_value_set_object (value, self->priv->conn);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ExampleEcho2ImManager *self = EXAMPLE_ECHO_2_IM_MANAGER (object);
+
+ switch (property_id)
+ {
+ case PROP_CONNECTION:
+ /* We don't ref the connection, because it owns a reference to the
+ * channel manager, and it guarantees that the manager's lifetime is
+ * less than its lifetime */
+ self->priv->conn = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+status_changed_cb (TpBaseConnection *conn,
+ guint status,
+ guint reason,
+ ExampleEcho2ImManager *self)
+{
+ if (status == TP_CONNECTION_STATUS_DISCONNECTED)
+ example_echo_2_im_manager_close_all (self);
+}
+
+static void
+constructed (GObject *object)
+{
+ ExampleEcho2ImManager *self = EXAMPLE_ECHO_2_IM_MANAGER (object);
+ void (*chain_up) (GObject *) =
+ ((GObjectClass *) example_echo_2_im_manager_parent_class)->constructed;
+
+ if (chain_up != NULL)
+ {
+ chain_up (object);
+ }
+
+ self->priv->status_changed_id = g_signal_connect (self->priv->conn,
+ "status-changed", (GCallback) status_changed_cb, self);
+}
+
+static void
+example_echo_2_im_manager_class_init (ExampleEcho2ImManagerClass *klass)
+{
+ GParamSpec *param_spec;
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ object_class->constructed = constructed;
+ object_class->dispose = dispose;
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ param_spec = g_param_spec_object ("connection", "Connection object",
+ "The connection that owns this channel manager",
+ TP_TYPE_BASE_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
+
+ g_type_class_add_private (klass, sizeof (ExampleEcho2ImManagerPrivate));
+}
+
+static void
+example_echo_2_im_manager_close_all (ExampleEcho2ImManager *self)
+{
+ if (self->priv->channels != NULL)
+ {
+ GHashTable *tmp = self->priv->channels;
+
+ self->priv->channels = NULL;
+ g_hash_table_destroy (tmp);
+ }
+
+ if (self->priv->status_changed_id != 0)
+ {
+ g_signal_handler_disconnect (self->priv->conn,
+ self->priv->status_changed_id);
+ self->priv->status_changed_id = 0;
+ }
+}
+
+static void
+example_echo_2_im_manager_foreach_channel (TpChannelManager *iface,
+ TpExportableChannelFunc callback,
+ gpointer user_data)
+{
+ ExampleEcho2ImManager *self = EXAMPLE_ECHO_2_IM_MANAGER (iface);
+ GHashTableIter iter;
+ gpointer handle, channel;
+
+ g_hash_table_iter_init (&iter, self->priv->channels);
+
+ while (g_hash_table_iter_next (&iter, &handle, &channel))
+ {
+ callback (TP_EXPORTABLE_CHANNEL (channel), user_data);
+ }
+}
+
+static void
+channel_closed_cb (ExampleEcho2Channel *chan,
+ ExampleEcho2ImManager *self)
+{
+ tp_channel_manager_emit_channel_closed_for_object (self,
+ TP_EXPORTABLE_CHANNEL (chan));
+
+ if (self->priv->channels != NULL)
+ {
+ TpHandle handle;
+ gboolean really_destroyed;
+
+ g_object_get (chan,
+ "handle", &handle,
+ "channel-destroyed", &really_destroyed,
+ NULL);
+
+ /* Re-announce the channel if it's not yet ready to go away (pending
+ * messages) */
+ if (really_destroyed)
+ {
+ g_hash_table_remove (self->priv->channels,
+ GUINT_TO_POINTER (handle));
+ }
+ else
+ {
+ tp_channel_manager_emit_new_channel (self,
+ TP_EXPORTABLE_CHANNEL (chan), NULL);
+ }
+ }
+}
+
+static ExampleEcho2Channel *
+new_channel (ExampleEcho2ImManager *self,
+ TpHandle handle,
+ TpHandle initiator,
+ gpointer request_token)
+{
+ ExampleEcho2Channel *chan;
+ gchar *object_path;
+ GSList *requests = NULL;
+
+ object_path = g_strdup_printf ("%s/Echo2Channel%u",
+ self->priv->conn->object_path, handle);
+
+ chan = g_object_new (EXAMPLE_TYPE_ECHO_2_CHANNEL,
+ "connection", self->priv->conn,
+ "object-path", object_path,
+ "handle", handle,
+ "initiator-handle", initiator,
+ NULL);
+
+ g_free (object_path);
+
+ g_signal_connect (chan, "closed", (GCallback) channel_closed_cb, self);
+
+ g_hash_table_insert (self->priv->channels, GUINT_TO_POINTER (handle), chan);
+
+ if (request_token != NULL)
+ requests = g_slist_prepend (requests, request_token);
+
+ tp_channel_manager_emit_new_channel (self, TP_EXPORTABLE_CHANNEL (chan),
+ requests);
+ g_slist_free (requests);
+
+ return chan;
+}
+
+static const gchar * const fixed_properties[] = {
+ TP_IFACE_CHANNEL ".ChannelType",
+ TP_IFACE_CHANNEL ".TargetHandleType",
+ NULL
+};
+
+static const gchar * const allowed_properties[] = {
+ TP_IFACE_CHANNEL ".TargetHandle",
+ TP_IFACE_CHANNEL ".TargetID",
+ NULL
+};
+
+static void
+example_echo_2_im_manager_foreach_channel_class (TpChannelManager *manager,
+ TpChannelManagerChannelClassFunc func,
+ gpointer user_data)
+{
+ GHashTable *table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, (GDestroyNotify) tp_g_value_slice_free);
+ GValue *value;
+
+ value = tp_g_value_slice_new (G_TYPE_STRING);
+ g_value_set_static_string (value, TP_IFACE_CHANNEL_TYPE_TEXT);
+ g_hash_table_insert (table, TP_IFACE_CHANNEL ".ChannelType", value);
+
+ value = tp_g_value_slice_new (G_TYPE_UINT);
+ g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT);
+ g_hash_table_insert (table, TP_IFACE_CHANNEL ".TargetHandleType", value);
+
+ func (manager, table, allowed_properties, user_data);
+
+ g_hash_table_destroy (table);
+}
+
+static gboolean
+example_echo_2_im_manager_request (ExampleEcho2ImManager *self,
+ gpointer request_token,
+ GHashTable *request_properties,
+ gboolean require_new)
+{
+ TpHandle handle;
+ ExampleEcho2Channel *chan;
+ GError *error = NULL;
+
+ if (tp_strdiff (tp_asv_get_string (request_properties,
+ TP_IFACE_CHANNEL ".ChannelType"),
+ TP_IFACE_CHANNEL_TYPE_TEXT))
+ {
+ return FALSE;
+ }
+
+ if (tp_asv_get_uint32 (request_properties,
+ TP_IFACE_CHANNEL ".TargetHandleType", NULL) != TP_HANDLE_TYPE_CONTACT)
+ {
+ return FALSE;
+ }
+
+ handle = tp_asv_get_uint32 (request_properties,
+ TP_IFACE_CHANNEL ".TargetHandle", NULL);
+ g_assert (handle != 0);
+
+ if (tp_channel_manager_asv_has_unknown_properties (request_properties,
+ fixed_properties, allowed_properties, &error))
+ {
+ goto error;
+ }
+
+ chan = g_hash_table_lookup (self->priv->channels, GUINT_TO_POINTER (handle));
+
+ if (chan == NULL)
+ {
+ chan = new_channel (self, handle, self->priv->conn->self_handle,
+ request_token);
+ }
+ else if (require_new)
+ {
+ g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "An echo2 channel to contact #%u already exists", handle);
+ goto error;
+ }
+ else
+ {
+ tp_channel_manager_emit_request_already_satisfied (self,
+ request_token, TP_EXPORTABLE_CHANNEL (chan));
+ }
+
+ return TRUE;
+
+error:
+ tp_channel_manager_emit_request_failed (self, request_token,
+ error->domain, error->code, error->message);
+ g_error_free (error);
+ return TRUE;
+}
+
+static gboolean
+example_echo_2_im_manager_create_channel (TpChannelManager *manager,
+ gpointer request_token,
+ GHashTable *request_properties)
+{
+ return example_echo_2_im_manager_request (EXAMPLE_ECHO_2_IM_MANAGER (manager),
+ request_token, request_properties, TRUE);
+}
+
+static gboolean
+example_echo_2_im_manager_ensure_channel (TpChannelManager *manager,
+ gpointer request_token,
+ GHashTable *request_properties)
+{
+ return example_echo_2_im_manager_request (EXAMPLE_ECHO_2_IM_MANAGER (manager),
+ request_token, request_properties, FALSE);
+}
+
+static void
+channel_manager_iface_init (gpointer g_iface,
+ gpointer data G_GNUC_UNUSED)
+{
+ TpChannelManagerIface *iface = g_iface;
+
+ iface->foreach_channel = example_echo_2_im_manager_foreach_channel;
+ iface->foreach_channel_class = example_echo_2_im_manager_foreach_channel_class;
+ iface->create_channel = example_echo_2_im_manager_create_channel;
+ iface->ensure_channel = example_echo_2_im_manager_ensure_channel;
+ /* In this channel manager, Request has the same semantics as Ensure */
+ iface->request_channel = example_echo_2_im_manager_ensure_channel;
+}
diff --git a/tests/lib/echo2/im-manager.h b/tests/lib/echo2/im-manager.h
new file mode 100644
index 0000000..28cfef9
--- /dev/null
+++ b/tests/lib/echo2/im-manager.h
@@ -0,0 +1,54 @@
+/*
+ * manager.h - header for an example channel manager
+ *
+ * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#ifndef EXAMPLE_ECHO_MESSAGE_PARTS_IM_MANAGER_H
+#define EXAMPLE_ECHO_MESSAGE_PARTS_IM_MANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ExampleEcho2ImManager ExampleEcho2ImManager;
+typedef struct _ExampleEcho2ImManagerClass ExampleEcho2ImManagerClass;
+typedef struct _ExampleEcho2ImManagerPrivate ExampleEcho2ImManagerPrivate;
+
+struct _ExampleEcho2ImManagerClass {
+ GObjectClass parent_class;
+};
+
+struct _ExampleEcho2ImManager {
+ GObject parent;
+
+ ExampleEcho2ImManagerPrivate *priv;
+};
+
+GType example_echo_2_im_manager_get_type (void);
+
+/* TYPE MACROS */
+#define EXAMPLE_TYPE_ECHO_2_IM_MANAGER \
+ (example_echo_2_im_manager_get_type ())
+#define EXAMPLE_ECHO_2_IM_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), EXAMPLE_TYPE_ECHO_2_IM_MANAGER, \
+ ExampleEcho2ImManager))
+#define EXAMPLE_ECHO_2_IM_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), EXAMPLE_TYPE_ECHO_2_IM_MANAGER, \
+ ExampleEcho2ImManagerClass))
+#define EXAMPLE_IS_ECHO_2_IM_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), EXAMPLE_TYPE_ECHO_2_IM_MANAGER))
+#define EXAMPLE_IS_ECHO_2_IM_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), EXAMPLE_TYPE_ECHO_2_IM_MANAGER))
+#define EXAMPLE_ECHO_2_IM_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), EXAMPLE_TYPE_ECHO_2_IM_MANAGER, \
+ ExampleEcho2ImManagerClass))
+
+G_END_DECLS
+
+#endif
--
1.5.6.5
More information about the Telepathy-commits
mailing list