diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2012-04-08 10:49:26 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2012-04-08 10:49:26 +0100 |
commit | c50f12f884121dca2081435dea8976de9ac8a8d6 (patch) | |
tree | 1f250997e0bfeb5d054cd9ab15c2dc1e90ee9f42 /src | |
parent | dc777537db0f727951d51a09599c108f34b34dcd (diff) | |
download | telepathy-idle-c50f12f884121dca2081435dea8976de9ac8a8d6.tar.gz |
RoomList: use TpBaseChannel
This moves IdleRoomlistChannel over to TpBaseChannel and cleans up the
tests a little at the same time.
Diffstat (limited to 'src')
-rw-r--r-- | src/idle-roomlist-channel.c | 321 | ||||
-rw-r--r-- | src/idle-roomlist-channel.h | 10 | ||||
-rw-r--r-- | src/idle-roomlist-manager.c | 7 |
3 files changed, 59 insertions, 279 deletions
diff --git a/src/idle-roomlist-channel.c b/src/idle-roomlist-channel.c index 13d3fe2..bc0941f 100644 --- a/src/idle-roomlist-channel.c +++ b/src/idle-roomlist-channel.c @@ -24,50 +24,24 @@ #include <time.h> -#define DBUS_API_SUBJECT_TO_CHANGE #include <dbus/dbus-glib.h> -#include <telepathy-glib/channel-iface.h> -#include <telepathy-glib/dbus.h> -#include <telepathy-glib/enums.h> -#include <telepathy-glib/interfaces.h> -#include <telepathy-glib/errors.h> -#include <telepathy-glib/svc-channel.h> -#include <telepathy-glib/svc-generic.h> -#include <telepathy-glib/util.h> -#include <telepathy-glib/gtypes.h> - /* FIXME: add new debug flag? */ #define IDLE_DEBUG_FLAG IDLE_DEBUG_CONNECTION #include "idle-connection.h" #include "idle-debug.h" #include "idle-text.h" -static void _channel_iface_init (gpointer, gpointer); +static void idle_roomlist_channel_close (TpBaseChannel *channel); static void _roomlist_iface_init (gpointer, gpointer); static void connection_status_changed_cb (IdleConnection* conn, guint status, guint reason, IdleRoomlistChannel *self); static IdleParserHandlerResult _rpl_list_handler (IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data); static IdleParserHandlerResult _rpl_listend_handler (IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data); -G_DEFINE_TYPE_WITH_CODE (IdleRoomlistChannel, idle_roomlist_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_DEFINE_TYPE_WITH_CODE (IdleRoomlistChannel, idle_roomlist_channel, + TP_TYPE_BASE_CHANNEL, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_ROOM_LIST, _roomlist_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL); - G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL);) - -/* property enum */ -enum { - PROP_CONNECTION = 1, - PROP_OBJECT_PATH, - PROP_CHANNEL_TYPE, - PROP_HANDLE_TYPE, - PROP_HANDLE, - PROP_CHANNEL_DESTROYED, - PROP_CHANNEL_PROPERTIES, - LAST_PROPERTY_ENUM -}; - + ) /* private structure */ typedef struct _IdleRoomlistChannelPrivate IdleRoomlistChannelPrivate; @@ -75,7 +49,6 @@ typedef struct _IdleRoomlistChannelPrivate IdleRoomlistChannelPrivate; struct _IdleRoomlistChannelPrivate { IdleConnection *connection; - gchar *object_path; GPtrArray *rooms; TpHandleSet *handles; @@ -97,27 +70,22 @@ idle_roomlist_channel_init (IdleRoomlistChannel *obj) static void idle_roomlist_channel_dispose (GObject *object); static void idle_roomlist_channel_finalize (GObject *object); -static GObject * -idle_roomlist_channel_constructor (GType type, - guint n_props, - GObjectConstructParam *props) +static void +idle_roomlist_channel_constructed (GObject *obj) { - GObject *obj; + TpBaseChannel *base = TP_BASE_CHANNEL (obj); IdleRoomlistChannelPrivate *priv; - TpDBusDaemon *bus; - obj = G_OBJECT_CLASS (idle_roomlist_channel_parent_class)->constructor (type, n_props, props); priv = IDLE_ROOMLIST_CHANNEL_GET_PRIVATE (IDLE_ROOMLIST_CHANNEL (obj)); - bus = tp_dbus_daemon_dup (NULL); - tp_dbus_daemon_register_object (bus, priv->object_path, obj); - g_object_unref (bus); + G_OBJECT_CLASS (idle_roomlist_channel_parent_class)->constructed (obj); + + tp_base_channel_register (base); - g_return_val_if_fail (priv->connection, obj); + priv->connection = IDLE_CONNECTION (tp_base_channel_get_connection (TP_BASE_CHANNEL (obj))); priv->status_changed_id = g_signal_connect (priv->connection, - "status-changed", (GCallback) - connection_status_changed_cb, + "status-changed", (GCallback) connection_status_changed_cb, obj); idle_parser_add_handler (priv->connection->parser, IDLE_PARSER_NUMERIC_LIST, _rpl_list_handler, obj); @@ -128,166 +96,72 @@ idle_roomlist_channel_constructor (GType type, TpHandleRepoIface *room_handles = tp_base_connection_get_handles ( TP_BASE_CONNECTION(priv->connection), TP_HANDLE_TYPE_ROOM); priv->handles = tp_handle_set_new(room_handles); +} - return obj; +static gchar * +idle_roomlist_channel_get_path_suffix (TpBaseChannel *chan) +{ + return g_strdup ("RoomListChannel"); } static void -idle_roomlist_channel_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) +idle_roomlist_channel_get_roomlist_property ( + GObject *object, + GQuark iface, + GQuark name, + GValue *value, + gpointer getter_data) { - IdleRoomlistChannel *chan; - IdleRoomlistChannelPrivate *priv; + g_return_if_fail (iface == TP_IFACE_QUARK_CHANNEL_TYPE_ROOM_LIST); + g_return_if_fail (name == g_quark_from_static_string ("Server")); + g_return_if_fail (G_VALUE_HOLDS_STRING (value)); - g_assert (object != NULL); - g_assert (IDLE_IS_ROOMLIST_CHANNEL (object)); - - chan = IDLE_ROOMLIST_CHANNEL (object); - priv = IDLE_ROOMLIST_CHANNEL_GET_PRIVATE (chan); - - switch (property_id) { - case PROP_CONNECTION: - g_value_set_object (value, priv->connection); - break; - - case PROP_OBJECT_PATH: - g_value_set_string (value, priv->object_path); - break; - - case PROP_CHANNEL_TYPE: - g_value_set_string (value, TP_IFACE_CHANNEL_TYPE_ROOM_LIST); - break; - - case PROP_HANDLE_TYPE: - g_value_set_uint (value, TP_HANDLE_TYPE_NONE); - break; - - case PROP_HANDLE: - g_value_set_uint (value, 0); - break; - - case PROP_CHANNEL_DESTROYED: - /* TODO: this should be FALSE if there are still pending messages, so - * the channel manager can respawn the channel. - */ - g_value_set_boolean (value, TRUE); - break; - - case PROP_CHANNEL_PROPERTIES: - g_value_take_boxed (value, - tp_dbus_properties_mixin_make_properties_hash (object, - TP_IFACE_CHANNEL, "TargetHandle", - TP_IFACE_CHANNEL, "TargetHandleType", - TP_IFACE_CHANNEL, "ChannelType", - NULL)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } + g_value_set_static_string (value, ""); } static void -idle_roomlist_channel_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +idle_roomlist_channel_fill_properties ( + TpBaseChannel *chan, + GHashTable *properties) { - IdleRoomlistChannel *chan = IDLE_ROOMLIST_CHANNEL (object); - IdleRoomlistChannelPrivate *priv; - - g_assert (chan != NULL); - g_assert (IDLE_IS_ROOMLIST_CHANNEL (chan)); - - priv = IDLE_ROOMLIST_CHANNEL_GET_PRIVATE (chan); - - switch (property_id) { - case PROP_CONNECTION: - priv->connection = g_value_get_object (value); - break; + TpBaseChannelClass *klass = TP_BASE_CHANNEL_CLASS (idle_roomlist_channel_parent_class); - case PROP_OBJECT_PATH: - if (priv->object_path) - g_free (priv->object_path); + klass->fill_immutable_properties (chan, properties); - priv->object_path = g_value_dup_string (value); - break; - - case PROP_HANDLE: - case PROP_CHANNEL_TYPE: - case PROP_HANDLE_TYPE: - /* writeable in the interface, but setting them makes - no sense, so ignore them */ - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } + tp_dbus_properties_mixin_fill_properties_hash ( + G_OBJECT (chan), properties, + TP_IFACE_CHANNEL_TYPE_ROOM_LIST, "Server", + NULL); } static void idle_roomlist_channel_class_init (IdleRoomlistChannelClass *idle_roomlist_channel_class) { GObjectClass *object_class = G_OBJECT_CLASS (idle_roomlist_channel_class); - GParamSpec *param_spec; + TpBaseChannelClass *base_channel_class = TP_BASE_CHANNEL_CLASS (idle_roomlist_channel_class); g_type_class_add_private (idle_roomlist_channel_class, sizeof (IdleRoomlistChannelPrivate)); - object_class->constructor = idle_roomlist_channel_constructor; - - object_class->get_property = idle_roomlist_channel_get_property; - object_class->set_property = idle_roomlist_channel_set_property; - + object_class->constructed = idle_roomlist_channel_constructed; object_class->dispose = idle_roomlist_channel_dispose; object_class->finalize = idle_roomlist_channel_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", "IdleConnection object", - "The IdleConnection object that owns this " - "RoomlistChannel object.", - IDLE_TYPE_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); - - static TpDBusPropertiesMixinPropImpl channel_props[] = { - { "TargetHandleType", "handle-type", NULL }, - { "TargetHandle", "handle", NULL }, - { "ChannelType", "channel-type", NULL }, - { NULL } - }; + base_channel_class->channel_type = TP_IFACE_CHANNEL_TYPE_ROOM_LIST; + base_channel_class->target_handle_type = TP_HANDLE_TYPE_NONE; + base_channel_class->close = idle_roomlist_channel_close; + base_channel_class->fill_immutable_properties = idle_roomlist_channel_fill_properties; + base_channel_class->get_object_path_suffix = idle_roomlist_channel_get_path_suffix; static TpDBusPropertiesMixinPropImpl roomlist_props[] = { + { "Server", NULL, NULL }, { NULL } }; - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CHANNEL, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - channel_props, - }, - { TP_IFACE_CHANNEL_TYPE_ROOM_LIST, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - roomlist_props, - }, - { NULL } - }; - idle_roomlist_channel_class->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, G_STRUCT_OFFSET (IdleRoomlistChannelClass, dbus_props_class)); + tp_dbus_properties_mixin_implement_interface (object_class, + TP_IFACE_QUARK_CHANNEL_TYPE_ROOM_LIST, + idle_roomlist_channel_get_roomlist_property, + NULL, + roomlist_props); } @@ -310,12 +184,6 @@ idle_roomlist_channel_dispose (GObject *object) priv->status_changed_id = 0; } - if (!priv->closed) - { - priv->closed = TRUE; - tp_svc_channel_emit_closed ((TpSvcChannel *)(self)); - } - if (priv->rooms) { g_ptr_array_free (priv->rooms, TRUE); @@ -333,11 +201,6 @@ idle_roomlist_channel_finalize (GObject *object) IdleRoomlistChannel *self = IDLE_ROOMLIST_CHANNEL (object); IdleRoomlistChannelPrivate *priv = IDLE_ROOMLIST_CHANNEL_GET_PRIVATE (self); - if (priv->object_path) - { - g_free (priv->object_path); - } - if (priv->handles) { tp_handle_set_destroy (priv->handles); @@ -347,74 +210,14 @@ idle_roomlist_channel_finalize (GObject *object) } -/** - * idle_roomlist_channel_close - * - * Implements DBus method Close - * on interface org.freedesktop.Telepathy.Channel - * - * @error: Used to return a pointer to a GError detailing any error - * that occured, DBus will throw the error only if this - * function returns false. - * - * Returns: TRUE if successful, FALSE if an error was thrown. - */ -static void -idle_roomlist_channel_close (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - IdleRoomlistChannel *obj = IDLE_ROOMLIST_CHANNEL (iface); - - g_assert (obj != NULL); - g_assert (IDLE_IS_ROOMLIST_CHANNEL (obj)); - - g_object_run_dispose (G_OBJECT (iface)); - - tp_svc_channel_return_from_close (context); -} - - -/** - * idle_roomlist_channel_get_channel_type - * - * Implements DBus method GetChannelType - * on interface org.freedesktop.Telepathy.Channel - */ static void -idle_roomlist_channel_get_channel_type (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_channel_type (context, - TP_IFACE_CHANNEL_TYPE_ROOM_LIST); -} - - -/** - * idle_roomlist_channel_get_handle - * - * Implements DBus method GetHandle - * on interface org.freedesktop.Telepathy.Channel - */ -static void -idle_roomlist_channel_get_handle (TpSvcChannel *iface, - DBusGMethodInvocation *context) +idle_roomlist_channel_close (TpBaseChannel *channel) { - tp_svc_channel_return_from_get_handle (context, 0, 0); -} - + IdleRoomlistChannel *self = IDLE_ROOMLIST_CHANNEL (channel); + IdleRoomlistChannelPrivate *priv = IDLE_ROOMLIST_CHANNEL_GET_PRIVATE (self); -/** - * idle_roomlist_channel_get_interfaces - * - * Implements DBus method GetInterfaces - * on interface org.freedesktop.Telepathy.Channel - */ -static void -idle_roomlist_channel_get_interfaces (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - const gchar *interfaces[] = {NULL}; - tp_svc_channel_return_from_get_interfaces (context, interfaces); + idle_parser_remove_handlers_by_data (priv->connection->parser, channel); + tp_base_channel_destroyed (channel); } @@ -495,22 +298,6 @@ idle_roomlist_channel_stop_listing (TpSvcChannelTypeRoomList *iface, static void -_channel_iface_init (gpointer g_iface, - gpointer iface_data) -{ - TpSvcChannelClass *klass = (TpSvcChannelClass *)g_iface; - -#define IMPLEMENT(x) tp_svc_channel_implement_##x (\ - klass, idle_roomlist_channel_##x) - IMPLEMENT (close); - IMPLEMENT (get_channel_type); - IMPLEMENT (get_handle); - IMPLEMENT (get_interfaces); -#undef IMPLEMENT -} - - -static void _roomlist_iface_init (gpointer g_iface, gpointer iface_data) { diff --git a/src/idle-roomlist-channel.h b/src/idle-roomlist-channel.h index ddb23c1..3158123 100644 --- a/src/idle-roomlist-channel.h +++ b/src/idle-roomlist-channel.h @@ -1,7 +1,7 @@ /* * This file is part of telepathy-idle * - * Copyright (C) 2009 Collabora Limited + * Copyright © 2009–2012 Collabora Limited * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -18,13 +18,14 @@ * * Authors: * Jonathon Jongsma <jonathon.jongsma@collabora.co.uk> + * Will Thompson <will.thompson@collabora.co.uk> */ #ifndef __IDLE_ROOMLIST_CHANNEL_H__ #define __IDLE_ROOMLIST_CHANNEL_H__ #include <glib-object.h> -#include <telepathy-glib/dbus-properties-mixin.h> +#include <telepathy-glib/telepathy-glib.h> G_BEGIN_DECLS @@ -32,12 +33,11 @@ typedef struct _IdleRoomlistChannel IdleRoomlistChannel; typedef struct _IdleRoomlistChannelClass IdleRoomlistChannelClass; struct _IdleRoomlistChannelClass { - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; + TpBaseChannelClass parent_class; }; struct _IdleRoomlistChannel { - GObject parent; + TpBaseChannel parent; }; GType idle_roomlist_channel_get_type(void); diff --git a/src/idle-roomlist-manager.c b/src/idle-roomlist-manager.c index f8f46f8..5219966 100644 --- a/src/idle-roomlist-manager.c +++ b/src/idle-roomlist-manager.c @@ -384,22 +384,15 @@ _roomlist_manager_new_channel (IdleRoomlistManager *self, { IdleRoomlistManagerPrivate *priv = IDLE_ROOMLIST_MANAGER_GET_PRIVATE (self); IdleRoomlistChannel *chan; - gchar *object_path = NULL; GSList *requests = NULL; g_assert (priv->channel == NULL); IDLE_DEBUG ("Requested room list channel"); - object_path = g_strdup_printf ("%s/RoomListChannel%u", - priv->conn->parent.object_path, - 0); - chan = g_object_new (IDLE_TYPE_ROOMLIST_CHANNEL, "connection", priv->conn, - "object-path", object_path, NULL); - g_free (object_path); if (request != NULL) requests = g_slist_prepend (requests, request); |