diff options
author | Joe Barnett <jbarnett@stanfordalumni.org> | 2012-05-22 13:24:16 -0700 |
---|---|---|
committer | Joe Barnett <jbarnett@stanfordalumni.org> | 2012-05-22 13:24:16 -0700 |
commit | ef12f9364e8b577660938fe67fec248fe187b6f5 (patch) | |
tree | 7e0fb7cb5b386b42953069aa83825a9c3537bb35 | |
parent | afbf3fcb761133896dab44ec9694f235313ff562 (diff) |
some muc manager get channel work
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/kindling-muc-manager.c | 59 |
2 files changed, 55 insertions, 8 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f2dfdc1..2cd9117 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,7 +29,9 @@ telepathy_kindling_SOURCES = \ kindling-roomlist-manager.c \ kindling-roomlist-manager.h \ kindling-roomlist-channel.c \ - kindling-roomlist-channel.h + kindling-roomlist-channel.h \ + kindling-muc-channel.c \ + kindling-muc-channel.h telepathy_kindling_LDFLAGS = \ -Wl,--export-dynamic diff --git a/src/kindling-muc-manager.c b/src/kindling-muc-manager.c index 6e72194..25a84cd 100644 --- a/src/kindling-muc-manager.c +++ b/src/kindling-muc-manager.c @@ -22,7 +22,9 @@ telepathy-kindling is free software: you can redistribute it and/or modify it #include <telepathy-glib/interfaces.h> #include <telepathy-glib/util.h> #include <telepathy-glib/handle.h> +#include <telepathy-glib/dbus.h> #include "kindling-connection.h" +#include "kindling-muc-channel.h" static void _muc_manager_iface_init(gpointer, gpointer); @@ -39,7 +41,7 @@ enum { typedef struct _KindlingMUCManagerPrivate KindlingMUCManagerPrivate; struct _KindlingMUCManagerPrivate { KindlingConnection *conn; - guint timeout_id; + GHashTable *channels; }; #define KINDLING_MUC_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), KINDLING_TYPE_MUC_MANAGER, KindlingMUCManagerPrivate)) @@ -74,8 +76,8 @@ static void kindling_muc_manager_init (KindlingMUCManager *kindling_muc_manager) { g_printf("init kindling muc manager\n"); - - /* TODO: Add initialization code here */ + KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(kindling_muc_manager); + priv->channels = g_hash_table_new (g_direct_hash, g_direct_equal); } @@ -118,22 +120,66 @@ static void kindling_muc_manager_type_foreach_channel_class(GType type, TpChanne g_hash_table_destroy(table); } -static void kindling_muc_manager_ensure_channel(TpChannelManager *manager, +static gboolean kindling_muc_manager_handle_channel(TpChannelManager *manager, + gpointer request_token, + GHashTable *request_properties, + gboolean require_new) { + TpHandleType handle_type; + const gchar *channel_type; + TpHandle handle; + GError *error = NULL; + KindlingMUCManagerPrivate *priv = KINDLING_MUC_MANAGER_GET_PRIVATE(manager); + TpBaseConnection *base_conn = TP_BASE_CONNECTION(priv->conn); + TpHandleRepoIface *room_repo = tp_base_connection_get_handles(base_conn, TP_HANDLE_TYPE_ROOM); + KindlingMUCChannel *channel; + + handle_type = tp_asv_get_uint32(request_properties, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL); + channel_type = tp_asv_get_string (request_properties, TP_PROP_CHANNEL_CHANNEL_TYPE); + if (handle_type != TP_HANDLE_TYPE_ROOM || tp_strdiff(channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)) { + return FALSE; + } + handle = tp_asv_get_uint32(request_properties, TP_PROP_CHANNEL_TARGET_HANDLE, NULL); + if (!tp_handle_is_valid (room_repo, handle, &error)) { + tp_channel_manager_emit_request_failed (manager, request_token, error->domain, error->code, error->message); + g_error_free(error); + return TRUE; + } + channel = g_hash_table_lookup (priv->channels, GINT_TO_POINTER(handle)); + if (channel != NULL) { + if (require_new) { + g_set_error ( &error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE, "That channel has already been created"); + tp_channel_manager_emit_request_failed (manager, request_token, error->domain, error->code, error->message); + g_error_free(error); + return TRUE; + } + // if channel is ready + tp_channel_manager_emit_request_already_satisfied (manager, request_token, TP_EXPORTABLE_CHANNEL(channel)); + return TRUE; + } else { + // create channel + } + return FALSE; +} + +static gboolean kindling_muc_manager_ensure_channel(TpChannelManager *manager, gpointer request_token, GHashTable *request_properties) { g_printf("ensure channel %s\n", tp_asv_get_string (request_properties,TP_IFACE_CHANNEL ".ChannelType")); + return kindling_muc_manager_handle_channel(manager, request_token, request_properties, FALSE); } -static void kindling_muc_manager_request_channel(TpChannelManager *manager, +static gboolean kindling_muc_manager_request_channel(TpChannelManager *manager, gpointer request_token, GHashTable *request_properties) { g_printf("request channel %s\n", tp_asv_get_string (request_properties,TP_IFACE_CHANNEL ".ChannelType")); + return kindling_muc_manager_handle_channel(manager, request_token, request_properties, FALSE); } -static void kindling_muc_manager_create_channel(TpChannelManager *manager, +static gboolean kindling_muc_manager_create_channel(TpChannelManager *manager, gpointer request_token, GHashTable *request_properties) { g_printf("create channel %s\n", tp_asv_get_string (request_properties,TP_IFACE_CHANNEL ".ChannelType")); + return kindling_muc_manager_handle_channel(manager, request_token, request_properties, TRUE); } static void @@ -141,7 +187,6 @@ kindling_muc_manager_class_init (KindlingMUCManagerClass *klass) { g_printf("class init kindling muc manager\n"); GObjectClass* object_class = G_OBJECT_CLASS (klass); - GObjectClass* parent_class = G_OBJECT_CLASS (klass); GParamSpec *param_spec; g_type_class_add_private (klass, sizeof(KindlingMUCManagerPrivate)); |