diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-01-10 11:53:44 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-07-28 12:59:06 +0100 |
commit | 6d7396ac8066d44c14e6573163f8d02f97d37e5d (patch) | |
tree | 0d949e9336e3285ec9402cb7a17e3a8bf8575d47 | |
parent | dece3d5667673858017ec0bbf922d1ab67062d28 (diff) |
simple-channel-manager: add object with emits ::request on a channel request
The TpBaseConnection is in the public struct so it can be created
without the connection at first and then added later.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | tests/lib/Makefile.am | 2 | ||||
-rw-r--r-- | tests/lib/simple-channel-manager.c | 92 | ||||
-rw-r--r-- | tests/lib/simple-channel-manager.h | 54 |
3 files changed, 148 insertions, 0 deletions
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 1fc2d1704..4cad02b27 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -46,6 +46,8 @@ libtp_glib_tests_la_SOURCES = \ simple-account.h \ simple-account-manager.c\ simple-account-manager.h\ + simple-channel-manager.c \ + simple-channel-manager.h \ simple-channel-dispatch-operation.c \ simple-channel-dispatch-operation.h \ simple-channel-dispatcher.c \ diff --git a/tests/lib/simple-channel-manager.c b/tests/lib/simple-channel-manager.c new file mode 100644 index 000000000..9e5f43ed2 --- /dev/null +++ b/tests/lib/simple-channel-manager.c @@ -0,0 +1,92 @@ +/* + * simple-channel-manager.c + * + * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * + * 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 <telepathy-glib/channel-manager.h> + +#include "simple-channel-manager.h" +#include "util.h" +#include "echo-chan.h" + +static void channel_manager_iface_init (gpointer, gpointer); + +G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelManager, + tp_tests_simple_channel_manager, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER, channel_manager_iface_init); + ) + +/* signals */ +enum { + REQUEST, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +static void +tp_tests_simple_channel_manager_class_init (TpTestsSimpleChannelManagerClass *klass) +{ + signals[REQUEST] = g_signal_new ("request", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, G_TYPE_HASH_TABLE); +} + +static void +tp_tests_simple_channel_manager_init (TpTestsSimpleChannelManager *self) +{ +} + +static gboolean +tp_tests_simple_channel_manager_request (TpChannelManager *manager, + gpointer request_token, + GHashTable *request_properties) +{ + TpTestsSimpleChannelManager *self = + TP_TESTS_SIMPLE_CHANNEL_MANAGER (manager); + GSList *tokens; + TpExportableChannel *channel; + TpHandle handle = tp_asv_get_uint32 (request_properties, + TP_PROP_CHANNEL_TARGET_HANDLE, NULL); + gchar *path; + + g_signal_emit (manager, signals[REQUEST], 0, request_properties); + + tokens = g_slist_append (NULL, request_token); + + path = g_strdup_printf ("%s/Channel", self->conn->object_path); + + channel = tp_tests_object_new_static_class ( + TP_TESTS_TYPE_ECHO_CHANNEL, + "connection", self->conn, + "object-path", path, + "handle", handle, + NULL); + + tp_channel_manager_emit_new_channel (manager, channel, tokens); + + g_free (path); + g_slist_free (tokens); + g_object_unref (channel); + + return TRUE; +} + +static void +channel_manager_iface_init (gpointer g_iface, + gpointer giface_data G_GNUC_UNUSED) +{ + TpChannelManagerIface *iface = g_iface; + + iface->create_channel = tp_tests_simple_channel_manager_request; + iface->ensure_channel = tp_tests_simple_channel_manager_request; + iface->request_channel = tp_tests_simple_channel_manager_request; +} diff --git a/tests/lib/simple-channel-manager.h b/tests/lib/simple-channel-manager.h new file mode 100644 index 000000000..ee22ca3ff --- /dev/null +++ b/tests/lib/simple-channel-manager.h @@ -0,0 +1,54 @@ +/* + * simple-channel-manager.h + * + * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * + * 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 __TP_TESTS_SIMPLE_CHANNEL_MANAGER_H__ +#define __TP_TESTS_SIMPLE_CHANNEL_MANAGER_H__ + +#include <glib-object.h> + +#include <telepathy-glib/base-connection.h> + +typedef struct _TpTestsSimpleChannelManager TpTestsSimpleChannelManager; +typedef struct _TpTestsSimpleChannelManagerClass TpTestsSimpleChannelManagerClass; + +struct _TpTestsSimpleChannelManager +{ + GObject parent; + + TpBaseConnection *conn; +}; + +struct _TpTestsSimpleChannelManagerClass +{ + GObjectClass parent_class; +}; + +GType tp_tests_simple_channel_manager_get_type (void); + +/* TYPE MACROS */ +#define TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER \ + (tp_tests_simple_channel_manager_get_type ()) +#define TP_TESTS_SIMPLE_CHANNEL_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, \ + TpTestsSimpleChannelManager)) +#define TP_TESTS_SIMPLE_CHANNEL_MANAGER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, \ + TpTestsSimpleChannelManagerClass)) +#define TP_TESTS_IS_SIMPLE_CHANNEL_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER)) +#define TP_TESTS_IS_SIMPLE_CHANNEL_MANAGER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER)) +#define TP_TESTS_SIMPLE_CHANNEL_MANAGER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CHANNEL_MANAGER, \ + TpTestsSimpleChannelManagerClass)) + +G_END_DECLS + +#endif /* #ifndef __TP_TESTS_SIMPLE_CHANNEL_MANAGER_H__ */ |