summaryrefslogtreecommitdiff
path: root/src/roomlist-channel.c
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2012-02-01 14:06:10 -0500
committerJonny Lamb <jonny.lamb@collabora.co.uk>2012-02-01 14:06:10 -0500
commit86edee63407e092fa9f9996fa6b953ab2545e89f (patch)
treeb42fcf89039393694518d3cb9e30499af36a86a9 /src/roomlist-channel.c
parent1850348fac4651d7cba09fe8fbef7418a8ddb73c (diff)
downloadtelepathy-salut-86edee63407e092fa9f9996fa6b953ab2545e89f.tar.gz
roomlist-channel: subclass TpBaseChannel
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src/roomlist-channel.c')
-rw-r--r--src/roomlist-channel.c402
1 files changed, 44 insertions, 358 deletions
diff --git a/src/roomlist-channel.c b/src/roomlist-channel.c
index 66ca70d9..566db977 100644
--- a/src/roomlist-channel.c
+++ b/src/roomlist-channel.c
@@ -29,25 +29,17 @@
#include <telepathy-glib/enums.h>
#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/interfaces.h>
-#include <telepathy-glib/channel-iface.h>
#include <telepathy-glib/svc-channel.h>
-#include <telepathy-glib/svc-generic.h>
#define DEBUG_FLAG DEBUG_ROOMLIST
#include "debug.h"
-static void channel_iface_init (gpointer, gpointer);
static void roomlist_iface_init (gpointer, gpointer);
G_DEFINE_TYPE_WITH_CODE (SalutRoomlistChannel, salut_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);
+ TP_TYPE_BASE_CHANNEL,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_ROOM_LIST,
roomlist_iface_init);
- G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL);
- G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL)
);
static const char *salut_roomlist_channel_interfaces[] = { NULL };
@@ -55,69 +47,25 @@ static const char *salut_roomlist_channel_interfaces[] = { NULL };
/* properties */
enum
{
- PROP_OBJECT_PATH = 1,
- PROP_CHANNEL_TYPE,
- PROP_HANDLE_TYPE,
- PROP_HANDLE,
- PROP_CONNECTION,
- PROP_INTERFACES,
- PROP_CONFERENCE_SERVER,
- PROP_TARGET_ID,
- PROP_INITIATOR_HANDLE,
- PROP_INITIATOR_ID,
- PROP_REQUESTED,
- PROP_CHANNEL_DESTROYED,
- PROP_CHANNEL_PROPERTIES,
+ PROP_CONFERENCE_SERVER = 1,
LAST_PROPERTY
};
/* private structure */
-typedef struct _SalutRoomlistChannelPrivate SalutRoomlistChannelPrivate;
-
struct _SalutRoomlistChannelPrivate
{
- SalutConnection *connection;
- gchar *object_path;
-
GPtrArray *rooms;
- gboolean closed;
gboolean dispose_has_run;
};
-#define SALUT_ROOMLIST_CHANNEL_GET_PRIVATE(obj) \
- ((SalutRoomlistChannelPrivate *) ((SalutRoomlistChannel *) obj)->priv)
-
static void
salut_roomlist_channel_init (SalutRoomlistChannel *self)
{
- SalutRoomlistChannelPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
SALUT_TYPE_ROOMLIST_CHANNEL, SalutRoomlistChannelPrivate);
- self->priv = priv;
-
- priv->rooms = g_ptr_array_new ();
-}
-
-static GObject *
-salut_roomlist_channel_constructor (GType type,
- guint n_props,
- GObjectConstructParam *props)
-{
- GObject *obj;
- SalutRoomlistChannelPrivate *priv;
- TpDBusDaemon *bus;
- TpBaseConnection *base_conn;
-
- obj = G_OBJECT_CLASS (salut_roomlist_channel_parent_class)->constructor (
- type, n_props, props);
- priv = SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (SALUT_ROOMLIST_CHANNEL (obj));
-
- base_conn = TP_BASE_CONNECTION (priv->connection);
- bus = tp_base_connection_get_dbus_daemon (base_conn);
- tp_dbus_daemon_register_object (bus, priv->object_path, obj);
-
- return obj;
+ self->priv->rooms = g_ptr_array_new ();
}
static void
@@ -126,151 +74,47 @@ salut_roomlist_channel_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- SalutRoomlistChannel *chan = SALUT_ROOMLIST_CHANNEL (object);
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (chan);
- TpBaseConnection *conn = (TpBaseConnection *) priv->connection;
-
switch (property_id) {
- case PROP_OBJECT_PATH:
- g_value_set_string (value, priv->object_path);
- break;
- case PROP_CHANNEL_TYPE:
- g_value_set_static_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_CONNECTION:
- g_value_set_object (value, priv->connection);
- break;
- case PROP_INTERFACES:
- g_value_set_static_boxed (value, salut_roomlist_channel_interfaces);
- break;
case PROP_CONFERENCE_SERVER:
/* Salut does not use a server, so this string is always empty */
g_value_set_string (value, "");
break;
- case PROP_TARGET_ID:
- g_value_set_static_string (value, "");
- break;
- case PROP_INITIATOR_HANDLE:
- /* Room listing is always initiated by the local user */
- g_value_set_uint (value, conn->self_handle);
- break;
- case PROP_INITIATOR_ID:
- {
- TpHandleRepoIface *repo = tp_base_connection_get_handles (conn,
- TP_HANDLE_TYPE_CONTACT);
-
- g_value_set_string (value,
- tp_handle_inspect (repo, conn->self_handle));
- }
- break;
- case PROP_REQUESTED:
- g_value_set_boolean (value, TRUE);
- break;
- case PROP_CHANNEL_DESTROYED:
- g_value_set_boolean (value, priv->closed);
- 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",
- TP_IFACE_CHANNEL, "TargetID",
- TP_IFACE_CHANNEL, "InitiatorHandle",
- TP_IFACE_CHANNEL, "InitiatorID",
- TP_IFACE_CHANNEL, "Requested",
- TP_IFACE_CHANNEL, "Interfaces",
- TP_IFACE_CHANNEL_TYPE_ROOM_LIST, "Server",
- NULL));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
+static void salut_roomlist_channel_dispose (GObject *object);
+static void salut_roomlist_channel_finalize (GObject *object);
+
static void
-salut_roomlist_channel_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+salut_roomlist_channel_fill_immutable_properties (TpBaseChannel *chan,
+ GHashTable *properties)
{
- SalutRoomlistChannel *chan = SALUT_ROOMLIST_CHANNEL (object);
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (chan);
- const gchar *value_str;
+ TpBaseChannelClass *cls = TP_BASE_CHANNEL_CLASS (
+ salut_roomlist_channel_parent_class);
- switch (property_id) {
- case PROP_OBJECT_PATH:
- g_free (priv->object_path);
- priv->object_path = g_value_dup_string (value);
- break;
- case PROP_CHANNEL_TYPE:
- /* this property is writable in the interface (in
- * telepathy-glib > 0.7.0), but not actually
- * meaningfully changeable on this channel, so we do nothing */
- value_str = g_value_get_string (value);
- g_assert (value_str == NULL || !tp_strdiff (value_str,
- TP_IFACE_CHANNEL_TYPE_ROOM_LIST));
- break;
- case PROP_HANDLE:
- /* this property is writable in the interface, but not actually
- * meaningfully changable on this channel, so we do nothing */
- g_assert (g_value_get_uint (value) == 0);
- break;
- case PROP_HANDLE_TYPE:
- /* this property is writable in the interface, but not actually
- * meaningfully changable on this channel, so we do nothing.
- * */
- g_assert (g_value_get_uint (value) == TP_HANDLE_TYPE_NONE
- || g_value_get_uint (value) == TP_UNKNOWN_HANDLE_TYPE);
- break;
- case PROP_CONNECTION:
- priv->connection = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
+ cls->fill_immutable_properties (chan, properties);
-static void salut_roomlist_channel_dispose (GObject *object);
-static void salut_roomlist_channel_finalize (GObject *object);
+ tp_dbus_properties_mixin_fill_properties_hash (
+ G_OBJECT (chan), properties,
+ TP_IFACE_CHANNEL_TYPE_ROOM_LIST, "Server",
+ NULL);
+}
static void
salut_roomlist_channel_class_init (
SalutRoomlistChannelClass *salut_roomlist_channel_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (salut_roomlist_channel_class);
+ TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (salut_roomlist_channel_class);
GParamSpec *param_spec;
- static TpDBusPropertiesMixinPropImpl channel_props[] = {
- { "TargetHandleType", "handle-type", NULL },
- { "TargetHandle", "handle", NULL },
- { "TargetID", "target-id", NULL },
- { "InitiatorHandle", "initiator-handle", NULL },
- { "InitiatorID", "initiator-id", NULL },
- { "Requested", "requested", NULL },
- { "ChannelType", "channel-type", NULL },
- { "Interfaces", "interfaces", NULL },
- { NULL }
- };
static TpDBusPropertiesMixinPropImpl roomlist_props[] = {
{ "Server", "conference-server", 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,
@@ -282,67 +126,15 @@ salut_roomlist_channel_class_init (
g_type_class_add_private (salut_roomlist_channel_class,
sizeof (SalutRoomlistChannelPrivate));
- object_class->constructor = salut_roomlist_channel_constructor;
-
object_class->get_property = salut_roomlist_channel_get_property;
- object_class->set_property = salut_roomlist_channel_set_property;
-
object_class->dispose = salut_roomlist_channel_dispose;
object_class->finalize = salut_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_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", "Target JID",
- "The string obtained by inspecting this channel's 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_READABLE | 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 bare JID",
- "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);
-
- param_spec = g_param_spec_object ("connection", "SalutConnection object",
- "Salut connection object that owns this "
- "room list channel object.",
- SALUT_TYPE_CONNECTION,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
+ base_class->channel_type = TP_IFACE_CHANNEL_TYPE_ROOM_LIST;
+ base_class->interfaces = salut_roomlist_channel_interfaces;
+ base_class->target_handle_type = TP_HANDLE_TYPE_NONE;
+ base_class->fill_immutable_properties =
+ salut_roomlist_channel_fill_immutable_properties;
param_spec = g_param_spec_string ("conference-server",
"Name of conference server to use",
@@ -361,30 +153,17 @@ salut_roomlist_channel_class_init (
static void
rooms_free (SalutRoomlistChannel *self)
{
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
- TpBaseConnection *base_connection = (TpBaseConnection *) (priv->connection);
- TpHandleRepoIface *room_repo =
- tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_ROOM);
+ SalutRoomlistChannelPrivate *priv = self->priv;
guint i;
g_assert (priv->rooms != NULL);
for (i = 0; i < priv->rooms->len; i++)
{
- GValue room = {0,};
gpointer boxed;
- TpHandle handle;
boxed = g_ptr_array_index (priv->rooms, i);
- g_value_init (&room, TP_STRUCT_TYPE_ROOM_INFO);
- g_value_set_static_boxed (&room, boxed);
- dbus_g_type_struct_get (&room,
- 0, &handle,
- G_MAXUINT);
-
g_boxed_free (TP_STRUCT_TYPE_ROOM_INFO, boxed);
- tp_handle_unref (room_repo, handle);
}
g_ptr_array_unref (priv->rooms);
@@ -395,20 +174,13 @@ static void
salut_roomlist_channel_dispose (GObject *object)
{
SalutRoomlistChannel *self = SALUT_ROOMLIST_CHANNEL (object);
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
+ SalutRoomlistChannelPrivate *priv = self->priv;
if (priv->dispose_has_run)
return;
priv->dispose_has_run = TRUE;
- if (!priv->closed)
- {
- priv->closed = TRUE;
- tp_svc_channel_emit_closed ((TpSvcChannel *) object);
- }
-
if (G_OBJECT_CLASS (salut_roomlist_channel_parent_class)->dispose)
G_OBJECT_CLASS (salut_roomlist_channel_parent_class)->dispose (object);
}
@@ -417,40 +189,44 @@ static void
salut_roomlist_channel_finalize (GObject *object)
{
SalutRoomlistChannel *self = SALUT_ROOMLIST_CHANNEL (object);
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
+ SalutRoomlistChannelPrivate *priv = self->priv;
/* free any data held directly by the object here */
- g_free (priv->object_path);
-
if (priv->rooms != NULL)
rooms_free (self);
- G_OBJECT_CLASS (salut_roomlist_channel_parent_class)->finalize (object);
+ if (G_OBJECT_CLASS (salut_roomlist_channel_parent_class)->finalize)
+ G_OBJECT_CLASS (salut_roomlist_channel_parent_class)->finalize (object);
}
SalutRoomlistChannel *
salut_roomlist_channel_new (SalutConnection *conn,
const gchar *object_path)
{
+ TpHandle initiator;
+
g_return_val_if_fail (SALUT_IS_CONNECTION (conn), NULL);
g_return_val_if_fail (object_path != NULL, NULL);
+ initiator = tp_base_connection_get_self_handle ((TpBaseConnection *) conn);
+
return SALUT_ROOMLIST_CHANNEL (
g_object_new (SALUT_TYPE_ROOMLIST_CHANNEL,
- "connection", conn,
- "object-path", object_path,
- NULL));
+ "connection", conn,
+ "object-path", object_path,
+ "initiator-handle", initiator,
+ "requested", TRUE,
+ NULL));
}
void
salut_roomlist_channel_add_room (SalutRoomlistChannel *self,
const gchar *room_name)
{
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
- TpBaseConnection *base_connection = (TpBaseConnection *) (priv->connection);
+ SalutRoomlistChannelPrivate *priv = self->priv;
+ TpBaseConnection *base_connection = tp_base_channel_get_connection (
+ TP_BASE_CHANNEL (self));
TpHandleRepoIface *room_repo =
tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_ROOM);
GValue room = {0,};
@@ -487,9 +263,9 @@ void
salut_roomlist_channel_remove_room (SalutRoomlistChannel *self,
const gchar *room_name)
{
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
- TpBaseConnection *base_connection = (TpBaseConnection *) (priv->connection);
+ SalutRoomlistChannelPrivate *priv = self->priv;
+ TpBaseConnection *base_connection = tp_base_channel_get_connection (
+ TP_BASE_CHANNEL (self));
TpHandleRepoIface *room_repo =
tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_ROOM);
TpHandle handle;
@@ -516,83 +292,12 @@ salut_roomlist_channel_remove_room (SalutRoomlistChannel *self,
{
g_boxed_free (TP_STRUCT_TYPE_ROOM_INFO, boxed);
g_ptr_array_remove_index_fast (priv->rooms, i);
- tp_handle_unref (room_repo, handle);
DEBUG ("remove %s", room_name);
break;
}
}
}
-/************************* D-Bus Method definitions **************************/
-
-/**
- * salut_roomlist_channel_close
- *
- * Implements D-Bus method Close
- * on interface org.freedesktop.Telepathy.Channel
- */
-static void
-salut_roomlist_channel_close (TpSvcChannel *iface,
- DBusGMethodInvocation *context)
-{
- SalutRoomlistChannel *self = SALUT_ROOMLIST_CHANNEL (iface);
- SalutRoomlistChannelPrivate *priv =
- SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
- g_assert (SALUT_IS_ROOMLIST_CHANNEL (self));
-
- DEBUG ("called on %p", self);
-
- tp_svc_channel_emit_closed (iface);
- priv->closed = TRUE;
-
- tp_svc_channel_return_from_close (context);
-}
-
-
-/**
- * salut_roomlist_channel_get_channel_type
- *
- * Implements D-Bus method GetChannelType
- * on interface org.freedesktop.Telepathy.Channel
- */
-static void
-salut_roomlist_channel_get_channel_type (TpSvcChannel *iface,
- DBusGMethodInvocation *context)
-{
- tp_svc_channel_return_from_get_channel_type (context,
- TP_IFACE_CHANNEL_TYPE_ROOM_LIST);
-}
-
-
-/**
- * salut_roomlist_channel_get_handle
- *
- * Implements D-Bus method GetHandle
- * on interface org.freedesktop.Telepathy.Channel
- */
-static void
-salut_roomlist_channel_get_handle (TpSvcChannel *self,
- DBusGMethodInvocation *context)
-{
- tp_svc_channel_return_from_get_handle (context, 0, 0);
-}
-
-
-/**
- * salut_roomlist_channel_get_interfaces
- *
- * Implements D-Bus method GetInterfaces
- * on interface org.freedesktop.Telepathy.Channel
- */
-static void
-salut_roomlist_channel_get_interfaces (TpSvcChannel *iface,
- DBusGMethodInvocation *context)
-{
- tp_svc_channel_return_from_get_interfaces (context,
- salut_roomlist_channel_interfaces);
-}
-
-
/**
* salut_roomlist_channel_get_listing_rooms
*
@@ -635,11 +340,7 @@ salut_roomlist_channel_list_rooms (TpSvcChannelTypeRoomList *iface,
DBusGMethodInvocation *context)
{
SalutRoomlistChannel *self = SALUT_ROOMLIST_CHANNEL (iface);
- SalutRoomlistChannelPrivate *priv;
-
- g_assert (SALUT_IS_ROOMLIST_CHANNEL (self));
-
- priv = SALUT_ROOMLIST_CHANNEL_GET_PRIVATE (self);
+ SalutRoomlistChannelPrivate *priv = self->priv;
tp_svc_channel_type_room_list_emit_listing_rooms (iface, TRUE);
tp_svc_channel_type_room_list_emit_got_rooms (iface, priv->rooms);
@@ -662,21 +363,6 @@ salut_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, salut_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)
{