diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-02-29 15:36:48 -0500 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-02-29 15:36:48 -0500 |
commit | a7f90f99a38181ab05353296f0c7b6eaf3b664f4 (patch) | |
tree | 704ff382234b2d1d54a90b4c4da001b13a18d6f6 | |
parent | a842971ca3c1aa11c3495fd88ddcad89eee321c0 (diff) | |
parent | 5a78e81a093ed320f1a3ed4a3018fefd60bc6f46 (diff) |
Merge branch 'cleanups'
-rw-r--r-- | src/avahi-muc-channel.c | 1 | ||||
-rw-r--r-- | src/file-transfer-channel.c | 487 | ||||
-rw-r--r-- | src/file-transfer-channel.h | 6 | ||||
-rw-r--r-- | src/ft-manager.c | 2 | ||||
-rw-r--r-- | src/im-channel.c | 444 | ||||
-rw-r--r-- | src/im-channel.h | 8 | ||||
-rw-r--r-- | src/im-manager.c | 4 | ||||
-rw-r--r-- | src/muc-channel.c | 583 | ||||
-rw-r--r-- | src/muc-channel.h | 8 | ||||
-rw-r--r-- | src/muc-manager.c | 2 | ||||
-rw-r--r-- | src/roomlist-channel.c | 402 | ||||
-rw-r--r-- | src/roomlist-channel.h | 9 | ||||
-rw-r--r-- | src/roomlist-manager.c | 3 |
13 files changed, 414 insertions, 1545 deletions
diff --git a/src/avahi-muc-channel.c b/src/avahi-muc-channel.c index ebe3d19a..28c6b9c1 100644 --- a/src/avahi-muc-channel.c +++ b/src/avahi-muc-channel.c @@ -326,7 +326,6 @@ salut_avahi_muc_channel_new (SalutConnection *connection, "name", name, "discovery-client", discovery_client, "initiator-handle", initiator, - "creator", creator, "requested", requested, NULL); } diff --git a/src/file-transfer-channel.c b/src/file-transfer-channel.c index cd4f0ccf..2c0318ab 100644 --- a/src/file-transfer-channel.c +++ b/src/file-transfer-channel.c @@ -59,17 +59,10 @@ #include <telepathy-glib/gtypes.h> static void -channel_iface_init (gpointer g_iface, gpointer iface_data); -static void file_transfer_iface_init (gpointer g_iface, gpointer iface_data); G_DEFINE_TYPE_WITH_CODE (SalutFileTransferChannel, salut_file_transfer_channel, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL, channel_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL); - G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL); + TP_TYPE_BASE_CHANNEL, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_FILE_TRANSFER, file_transfer_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA, @@ -85,23 +78,7 @@ static const char *salut_file_transfer_channel_interfaces[] = { NULL }; /* properties */ enum { - PROP_OBJECT_PATH = 1, - - /* org.freedesktop.Telepathy.Channel D-Bus properties */ - PROP_CHANNEL_TYPE, - PROP_INTERFACES, - PROP_HANDLE, - PROP_TARGET_ID, - PROP_HANDLE_TYPE, - PROP_REQUESTED, - PROP_INITIATOR_HANDLE, - PROP_INITIATOR_ID, - - PROP_CHANNEL_DESTROYED, - PROP_CHANNEL_PROPERTIES, - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer D-Bus properties */ - PROP_STATE, + PROP_STATE = 1, PROP_CONTENT_TYPE, PROP_FILENAME, PROP_SIZE, @@ -126,16 +103,11 @@ enum /* private structure */ struct _SalutFileTransferChannelPrivate { gboolean dispose_has_run; - gboolean closed; - gchar *object_path; - TpHandle handle; SalutContact *contact; - SalutConnection *connection; GibberFileTransfer *ft; GTimeVal last_transferred_bytes_emitted; guint progress_timer; GValue *socket_address; - TpHandle initiator; gboolean remote_accepted; gchar *path; @@ -156,15 +128,26 @@ struct _SalutFileTransferChannelPrivate { GHashTable *metadata; }; +static void salut_file_transfer_channel_set_state ( + TpSvcChannelTypeFileTransfer *iface, TpFileTransferState state, + TpFileTransferStateChangeReason reason); + static void -salut_file_transfer_channel_do_close (SalutFileTransferChannel *self) +salut_file_transfer_channel_close (TpBaseChannel *base) { - if (self->priv->closed) - return; + SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (base); + + if (self->priv->state != TP_FILE_TRANSFER_STATE_COMPLETED && + self->priv->state != TP_FILE_TRANSFER_STATE_CANCELLED) + { + gibber_file_transfer_cancel (self->priv->ft, 406); + salut_file_transfer_channel_set_state ( + TP_SVC_CHANNEL_TYPE_FILE_TRANSFER (self), + TP_FILE_TRANSFER_STATE_CANCELLED, + TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED); + } - DEBUG ("Emitting closed signal for %s", self->priv->object_path); - tp_svc_channel_emit_closed (self); - self->priv->closed = TRUE; + tp_base_channel_destroyed (base); } static void @@ -174,14 +157,9 @@ salut_file_transfer_channel_init (SalutFileTransferChannel *obj) SALUT_TYPE_FILE_TRANSFER_CHANNEL, SalutFileTransferChannelPrivate); /* allocate any data required by the object here */ - obj->priv->object_path = NULL; obj->priv->contact = NULL; } -static void salut_file_transfer_channel_set_state ( - TpSvcChannelTypeFileTransfer *iface, TpFileTransferState state, - TpFileTransferStateChangeReason reason); - static void contact_lost_cb (SalutContact *contact, SalutFileTransferChannel *self) @@ -209,58 +187,12 @@ salut_file_transfer_channel_get_property (GObject *object, GParamSpec *pspec) { SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (object); - TpBaseConnection *base_conn = (TpBaseConnection *) self->priv->connection; 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_FILE_TRANSFER); - break; - case PROP_HANDLE_TYPE: - g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT); - break; - case PROP_TARGET_ID: - { - TpHandleRepoIface *repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); - - g_value_set_string (value, tp_handle_inspect (repo, - self->priv->handle)); - } - break; - case PROP_HANDLE: - g_value_set_uint (value, self->priv->handle); - break; - case PROP_REQUESTED: - g_value_set_boolean (value, (self->priv->initiator == - base_conn->self_handle)); - break; - case PROP_INITIATOR_HANDLE: - g_value_set_uint (value, self->priv->initiator); - break; - case PROP_INITIATOR_ID: - { - TpHandleRepoIface *repo = tp_base_connection_get_handles ( - base_conn, TP_HANDLE_TYPE_CONTACT); - - g_assert (self->priv->initiator != 0); - g_value_set_string (value, - tp_handle_inspect (repo, self->priv->initiator)); - } - break; case PROP_CONTACT: g_value_set_object (value, self->priv->contact); break; - case PROP_CONNECTION: - g_value_set_object (value, self->priv->connection); - break; - case PROP_INTERFACES: - g_value_set_boxed (value, salut_file_transfer_channel_interfaces); - break; case PROP_STATE: g_value_set_uint (value, self->priv->state); break; @@ -317,47 +249,6 @@ salut_file_transfer_channel_get_property (GObject *object, } } break; - case PROP_CHANNEL_DESTROYED: - g_value_set_boolean (value, self->priv->closed); - break; - case PROP_CHANNEL_PROPERTIES: - { - GHashTable *props; - - props = tp_dbus_properties_mixin_make_properties_hash (object, - TP_IFACE_CHANNEL, "ChannelType", - TP_IFACE_CHANNEL, "Interfaces", - TP_IFACE_CHANNEL, "TargetHandle", - TP_IFACE_CHANNEL, "TargetID", - TP_IFACE_CHANNEL, "TargetHandleType", - TP_IFACE_CHANNEL, "Requested", - TP_IFACE_CHANNEL, "InitiatorHandle", - TP_IFACE_CHANNEL, "InitiatorID", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "ContentType", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Filename", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Size", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "ContentHashType", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "ContentHash", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Description", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Date", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "AvailableSocketTypes", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "TransferredBytes", - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "InitialOffset", - TP_IFACE_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA, "ServiceName", - TP_IFACE_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA, "Metadata", - NULL); - - /* URI is immutable only for outgoing transfers */ - if (self->priv->initiator == base_conn->self_handle) - { - tp_dbus_properties_mixin_fill_properties_hash (object, props, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "URI", NULL); - } - - g_value_take_boxed (value, props); - } - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -374,32 +265,11 @@ salut_file_transfer_channel_set_property (GObject *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: - self->priv->handle = g_value_get_uint (value); - break; case PROP_CONTACT: self->priv->contact = g_value_dup_object (value); g_signal_connect (self->priv->contact, "lost", G_CALLBACK (contact_lost_cb), self); break; - case PROP_CONNECTION: - self->priv->connection = g_value_get_object (value); - break; - case PROP_HANDLE_TYPE: - /* 0 is the old tp-glib value of unset, TP_UNKNOWN_HANDLE_TYPE is the - * new version */ - g_assert (g_value_get_uint (value) == 0 - || g_value_get_uint (value) == TP_HANDLE_TYPE_CONTACT - || g_value_get_uint (value) == TP_UNKNOWN_HANDLE_TYPE); - break; - case PROP_CHANNEL_TYPE: - /* these properties are writable in the interface, but not actually - * meaningfully changeable on this channel, so we do nothing */ - break; case PROP_STATE: salut_file_transfer_channel_set_state ( TP_SVC_CHANNEL_TYPE_FILE_TRANSFER (object), @@ -428,10 +298,6 @@ salut_file_transfer_channel_set_property (GObject *object, g_free (self->priv->description); self->priv->description = g_value_dup_string (value); break; - case PROP_INITIATOR_HANDLE: - self->priv->initiator = g_value_get_uint (value); - g_assert (self->priv->initiator != 0); - break; case PROP_DATE: self->priv->date = g_value_get_uint64 (value); break; @@ -461,44 +327,29 @@ free_array (GArray *array) g_array_unref (array); } -static GObject * -salut_file_transfer_channel_constructor (GType type, - guint n_props, - GObjectConstructParam *props) +static void +salut_file_transfer_channel_constructed (GObject *obj) { - GObject *obj; - SalutFileTransferChannel *self; - TpDBusDaemon *bus; - TpBaseConnection *base_conn; - TpHandleRepoIface *contact_repo; + SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (obj); + TpBaseChannel *base = TP_BASE_CHANNEL (obj); + TpBaseConnection *base_conn = tp_base_channel_get_connection (base); + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( + base_conn, TP_HANDLE_TYPE_CONTACT); + SalutConnection *conn = SALUT_CONNECTION (base_conn); GArray *unix_access; TpSocketAccessControl access_control; - /* Parent constructor chain */ - obj = G_OBJECT_CLASS (salut_file_transfer_channel_parent_class)-> - constructor (type, n_props, props); - - self = SALUT_FILE_TRANSFER_CHANNEL (obj); + /* Parent constructed chain */ + void (*chain_up) (GObject *) = + ((GObjectClass *) salut_file_transfer_channel_parent_class)->constructed; - /* Ref our handle */ - base_conn = TP_BASE_CONNECTION (self->priv->connection); + if (chain_up != NULL) + chain_up (obj); /* ref our porter */ - wocky_meta_porter_hold (WOCKY_META_PORTER (self->priv->connection->porter), + wocky_meta_porter_hold (WOCKY_META_PORTER (conn->porter), WOCKY_CONTACT (self->priv->contact)); - contact_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); - - tp_handle_ref (contact_repo, self->priv->handle); - - self->priv->object_path = g_strdup_printf ("%s/FileTransferChannel/%p", - base_conn->object_path, self); - - /* Connect to the bus */ - bus = tp_base_connection_get_dbus_daemon (base_conn); - tp_dbus_daemon_register_object (bus, self->priv->object_path, obj); - /* Initialise the available socket types hash table */ self->priv->available_socket_types = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) free_array); @@ -512,17 +363,15 @@ salut_file_transfer_channel_constructor (GType type, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_UNIX), unix_access); DEBUG ("New FT channel created: %s (contact: %s, initiator: %s, " - "file: \"%s\", size: %" G_GUINT64_FORMAT ")", - self->priv->object_path, - tp_handle_inspect (contact_repo, self->priv->handle), - tp_handle_inspect (contact_repo, self->priv->initiator), - self->priv->filename, self->priv->size); + "file: \"%s\", size: %" G_GUINT64_FORMAT ")", + tp_base_channel_get_object_path (base), + tp_handle_inspect (contact_repo, tp_base_channel_get_target_handle (base)), + tp_handle_inspect (contact_repo, tp_base_channel_get_initiator (base)), + self->priv->filename, self->priv->size); - if (self->priv->initiator != base_conn->self_handle) + if (!tp_base_channel_is_requested (base)) /* Incoming transfer, URI has to be set by the handler */ g_assert (self->priv->uri == NULL); - - return obj; } static void @@ -539,7 +388,6 @@ file_transfer_channel_properties_setter (GObject *object, GError **error) { SalutFileTransferChannel *self = (SalutFileTransferChannel *) object; - TpBaseConnection *base_conn = TP_BASE_CONNECTION (self->priv->connection); g_return_val_if_fail (interface == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER, FALSE); @@ -558,7 +406,7 @@ file_transfer_channel_properties_setter (GObject *object, return FALSE; } - if (self->priv->initiator == base_conn->self_handle) + if (tp_base_channel_is_requested (TP_BASE_CHANNEL (self))) { g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, "Channel is not an incoming transfer"); @@ -580,25 +428,56 @@ file_transfer_channel_properties_setter (GObject *object, } static void +salut_file_transfer_channel_fill_immutable_properties (TpBaseChannel *chan, + GHashTable *properties) +{ + TpBaseChannelClass *cls = TP_BASE_CHANNEL_CLASS ( + salut_file_transfer_channel_parent_class); + + cls->fill_immutable_properties (chan, properties); + + tp_dbus_properties_mixin_fill_properties_hash ( + G_OBJECT (chan), properties, + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "ContentType", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Filename", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Size", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "ContentHashType", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "ContentHash", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Description", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "Date", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "AvailableSocketTypes", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "TransferredBytes", + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "InitialOffset", + TP_IFACE_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA, "ServiceName", + TP_IFACE_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA, "Metadata", + NULL); + + /* URI is immutable only for outgoing transfers */ + if (tp_base_channel_is_requested (chan)) + { + tp_dbus_properties_mixin_fill_properties_hash ( + G_OBJECT (chan), properties, + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "URI", NULL); + } +} + +static gchar * +salut_file_transfer_channel_get_object_path_suffix (TpBaseChannel *chan) +{ + return g_strdup_printf ("FileTransferChannel/%p", chan); +} + +static void salut_file_transfer_channel_class_init ( SalutFileTransferChannelClass *salut_file_transfer_channel_class) { GObjectClass *object_class = G_OBJECT_CLASS ( salut_file_transfer_channel_class); + TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS ( + salut_file_transfer_channel_class); GParamSpec *param_spec; - static TpDBusPropertiesMixinPropImpl channel_props[] = { - { "TargetHandleType", "handle-type", NULL }, - { "TargetHandle", "handle", NULL }, - { "TargetID", "target-id", NULL }, - { "ChannelType", "channel-type", NULL }, - { "Interfaces", "interfaces", NULL }, - { "Requested", "requested", NULL }, - { "InitiatorHandle", "initiator-handle", NULL }, - { "InitiatorID", "initiator-id", NULL }, - { NULL } - }; - static TpDBusPropertiesMixinPropImpl file_props[] = { { "State", "state", NULL }, { "ContentType", "content-type", "content-type" }, @@ -622,11 +501,6 @@ salut_file_transfer_channel_class_init ( }; static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CHANNEL, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - channel_props - }, { TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, tp_dbus_properties_mixin_getter_gobject_properties, file_transfer_channel_properties_setter, @@ -644,51 +518,18 @@ salut_file_transfer_channel_class_init ( object_class->dispose = salut_file_transfer_channel_dispose; object_class->finalize = salut_file_transfer_channel_finalize; - - object_class->constructor = salut_file_transfer_channel_constructor; + object_class->constructed = salut_file_transfer_channel_constructed; object_class->get_property = salut_file_transfer_channel_get_property; object_class->set_property = salut_file_transfer_channel_set_property; - 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_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_boolean ("requested", "Requested?", - "True if this channel was requested by the local user", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME); - g_object_class_install_property (object_class, PROP_REQUESTED, 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_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME); - 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_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME); - g_object_class_install_property (object_class, PROP_INITIATOR_ID, - param_spec); + base_class->channel_type = TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER; + base_class->interfaces = salut_file_transfer_channel_interfaces; + base_class->target_handle_type = TP_HANDLE_TYPE_CONTACT; + base_class->close = salut_file_transfer_channel_close; + base_class->fill_immutable_properties = + salut_file_transfer_channel_fill_immutable_properties; + base_class->get_object_path_suffix = + salut_file_transfer_channel_get_object_path_suffix; param_spec = g_param_spec_object ("contact", "SalutContact object", @@ -700,26 +541,6 @@ salut_file_transfer_channel_class_init ( G_PARAM_STATIC_BLURB); g_object_class_install_property (object_class, PROP_CONTACT, param_spec); - param_spec = g_param_spec_object ("connection", - "SalutConnection object", - "Salut Connection that owns the" - "connection for this IM channel", - SALUT_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); - - param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", - "Additional Channel.Interface.* interfaces", - G_TYPE_STRV, - G_PARAM_READABLE | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB | - G_PARAM_STATIC_NAME); - g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); - param_spec = g_param_spec_uint ( "state", "TpFileTransferState state", @@ -891,19 +712,12 @@ void salut_file_transfer_channel_dispose (GObject *object) { SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (object); - TpBaseConnection *base_conn = TP_BASE_CONNECTION (self->priv->connection); - TpHandleRepoIface *handle_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); if (self->priv->dispose_has_run) return; self->priv->dispose_has_run = TRUE; - tp_handle_unref (handle_repo, self->priv->handle); - - salut_file_transfer_channel_do_close (self); - if (self->priv->progress_timer != 0) { g_source_remove (self->priv->progress_timer); @@ -936,7 +750,6 @@ salut_file_transfer_channel_finalize (GObject *object) SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (object); /* free any data held directly by the object here */ - g_free (self->priv->object_path); g_free (self->priv->filename); if (self->priv->socket_address != NULL) tp_g_value_slice_free (self->priv->socket_address); @@ -955,92 +768,8 @@ salut_file_transfer_channel_finalize (GObject *object) g_free (self->priv->path); } - G_OBJECT_CLASS (salut_file_transfer_channel_parent_class)->finalize (object); -} - - -/** - * salut_file_transfer_channel_close - * - * Implements DBus method Close - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_file_transfer_channel_close (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (iface); - - if (self->priv->state != TP_FILE_TRANSFER_STATE_COMPLETED && - self->priv->state != TP_FILE_TRANSFER_STATE_CANCELLED) - { - gibber_file_transfer_cancel (self->priv->ft, 406); - salut_file_transfer_channel_set_state ( - TP_SVC_CHANNEL_TYPE_FILE_TRANSFER (iface), - TP_FILE_TRANSFER_STATE_CANCELLED, - TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED); - } - - salut_file_transfer_channel_do_close (SALUT_FILE_TRANSFER_CHANNEL (iface)); - tp_svc_channel_return_from_close (context); -} - -/** - * salut_file_transfer_channel_get_channel_type - * - * Implements DBus method GetChannelType - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_file_transfer_channel_get_channel_type (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_channel_type (context, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER); -} - -/** - * salut_file_transfer_channel_get_handle - * - * Implements DBus method GetHandle - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_file_transfer_channel_get_handle (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (iface); - - tp_svc_channel_return_from_get_handle (context, TP_HANDLE_TYPE_CONTACT, - self->priv->handle); -} - -/** - * salut_file_transfer_channel_get_interfaces - * - * Implements DBus method GetInterfaces - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_file_transfer_channel_get_interfaces (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_interfaces (context, - salut_file_transfer_channel_interfaces); -} - -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_file_transfer_channel_##x) - IMPLEMENT (close); - IMPLEMENT (get_channel_type); - IMPLEMENT (get_handle); - IMPLEMENT (get_interfaces); -#undef IMPLEMENT + if (G_OBJECT_CLASS (salut_file_transfer_channel_parent_class)->finalize) + G_OBJECT_CLASS (salut_file_transfer_channel_parent_class)->finalize (object); } static void @@ -1050,10 +779,7 @@ error_cb (GibberFileTransfer *ft, const gchar *message, SalutFileTransferChannel *self) { - TpBaseConnection *base_conn = (TpBaseConnection *) self->priv->connection; - gboolean receiver; - - receiver = (self->priv->initiator != base_conn->self_handle); + gboolean receiver = !tp_base_channel_is_requested (TP_BASE_CHANNEL (self)); if (domain == GIBBER_FILE_TRANSFER_ERROR && code == GIBBER_FILE_TRANSFER_ERROR_NOT_FOUND && receiver) @@ -1074,8 +800,9 @@ static void ft_finished_cb (GibberFileTransfer *ft, SalutFileTransferChannel *self) { - SalutFileTransferChannelPrivate *priv = self->priv; - WockyPorter *porter = priv->connection->porter; + SalutConnection *conn = SALUT_CONNECTION ( + tp_base_channel_get_connection (TP_BASE_CHANNEL (self))); + WockyPorter *porter = conn->porter; salut_file_transfer_channel_set_state ( TP_SVC_CHANNEL_TYPE_FILE_TRANSFER (self), @@ -1090,8 +817,9 @@ static void ft_remote_cancelled_cb (GibberFileTransfer *ft, SalutFileTransferChannel *self) { - SalutFileTransferChannelPrivate *priv = self->priv; - WockyPorter *porter = priv->connection->porter; + SalutConnection *conn = SALUT_CONNECTION ( + tp_base_channel_get_connection (TP_BASE_CHANNEL (self))); + WockyPorter *porter = conn->porter; gibber_file_transfer_cancel (ft, 406); salut_file_transfer_channel_set_state ( @@ -1239,12 +967,15 @@ static void send_file_offer (SalutFileTransferChannel *self) { GibberFileTransfer *ft; + SalutConnection *conn = SALUT_CONNECTION ( + tp_base_channel_get_connection (TP_BASE_CHANNEL (self))); + WockyPorter *porter = conn->porter; ft = g_object_new (GIBBER_TYPE_OOB_FILE_TRANSFER, - "self-id", self->priv->connection->name, + "self-id", conn->name, "peer-id", self->priv->contact->name, "filename", self->priv->filename, - "porter", self->priv->connection->porter, + "porter", porter, "contact", self->priv->contact, "description", self->priv->description, "content-type", self->priv->content_type, @@ -1504,10 +1235,10 @@ salut_file_transfer_channel_provide_file ( DBusGMethodInvocation *context) { SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (iface); - TpBaseConnection *base_conn = (TpBaseConnection *) self->priv->connection; + TpBaseChannel *base = TP_BASE_CHANNEL (self); GError *error = NULL; - if (self->priv->initiator != base_conn->self_handle) + if (!tp_base_channel_is_requested (base)) { g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE, "Channel is not an outgoing transfer"); @@ -1836,6 +1567,7 @@ salut_file_transfer_channel_new (SalutConnection *conn, "contact", contact, "handle", handle, "initiator-handle", initiator_handle, + "requested", TRUE, "state", state, "content-type", content_type, "filename", filename, @@ -1896,6 +1628,7 @@ salut_file_transfer_channel_new_from_stanza (SalutConnection *connection, "contact", contact, "handle", handle, "initiator-handle", handle, + "requested", FALSE, "state", state, "filename", ft->filename, "size", gibber_file_transfer_get_size (ft), diff --git a/src/file-transfer-channel.h b/src/file-transfer-channel.h index f1a71b17..c3d2aad9 100644 --- a/src/file-transfer-channel.h +++ b/src/file-transfer-channel.h @@ -31,6 +31,8 @@ #include <extensions/_gen/interfaces.h> #include <extensions/_gen/enums.h> +#include <telepathy-glib/base-channel.h> + #include "contact.h" #include "connection.h" #include "contact.h" @@ -42,12 +44,12 @@ typedef struct _SalutFileTransferChannelClass SalutFileTransferChannelClass; typedef struct _SalutFileTransferChannelPrivate SalutFileTransferChannelPrivate; struct _SalutFileTransferChannelClass { - GObjectClass parent_class; + TpBaseChannelClass parent_class; TpDBusPropertiesMixinClass dbus_props_class; }; struct _SalutFileTransferChannel { - GObject parent; + TpBaseChannel parent; SalutFileTransferChannelPrivate *priv; }; diff --git a/src/ft-manager.c b/src/ft-manager.c index 4228e62f..353fa619 100644 --- a/src/ft-manager.c +++ b/src/ft-manager.c @@ -265,6 +265,8 @@ salut_ft_manager_channel_created (SalutFtManager *self, SalutFtManagerPrivate *priv = SALUT_FT_MANAGER_GET_PRIVATE (self); GSList *requests = NULL; + tp_base_channel_register (TP_BASE_CHANNEL (chan)); + g_signal_connect (chan, "closed", G_CALLBACK (file_channel_closed_cb), self); priv->channels = g_list_append (priv->channels, chan); diff --git a/src/im-channel.c b/src/im-channel.c index 75346f87..de04eca5 100644 --- a/src/im-channel.c +++ b/src/im-channel.c @@ -32,12 +32,8 @@ #include <netdb.h> #endif -#include <dbus/dbus-glib.h> -#include <telepathy-glib/channel-iface.h> #include <telepathy-glib/dbus.h> -#include <telepathy-glib/exportable-channel.h> #include <telepathy-glib/interfaces.h> -#include <telepathy-glib/svc-generic.h> #include <gibber/gibber-linklocal-transport.h> @@ -49,14 +45,7 @@ #include "util.h" #include "text-helper.h" -static void channel_iface_init (gpointer g_iface, gpointer iface_data); - -G_DEFINE_TYPE_WITH_CODE (SalutImChannel, salut_im_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_CHANNEL_IFACE, NULL); - G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL); +G_DEFINE_TYPE_WITH_CODE (SalutImChannel, salut_im_channel, TP_TYPE_BASE_CHANNEL, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TEXT, tp_message_mixin_text_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_MESSAGES, @@ -71,49 +60,26 @@ static const gchar *salut_im_channel_interfaces[] = { /* properties */ enum { - PROP_OBJECT_PATH = 1, - PROP_CHANNEL_TYPE, - PROP_HANDLE_TYPE, - PROP_HANDLE, - PROP_CONTACT, - PROP_CONNECTION, - PROP_INTERFACES, - PROP_TARGET_ID, - PROP_INITIATOR_HANDLE, - PROP_INITIATOR_ID, - PROP_REQUESTED, - PROP_CHANNEL_PROPERTIES, - PROP_CHANNEL_DESTROYED, + PROP_CONTACT = 1, LAST_PROPERTY }; /* private structure */ -typedef struct _SalutImChannelPrivate SalutImChannelPrivate; - struct _SalutImChannelPrivate { gboolean dispose_has_run; - gchar *object_path; - TpHandle handle; - TpHandle initiator; SalutContact *contact; - SalutConnection *connection; guint message_handler_id; - gboolean closed; }; -#define SALUT_IM_CHANNEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE \ - ((o), SALUT_TYPE_IM_CHANNEL, SalutImChannelPrivate)) - static void -salut_im_channel_do_close (SalutImChannel *self) +salut_im_channel_close (TpBaseChannel *base) { - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); - WockyPorter *porter = priv->connection->porter; - - if (priv->closed) - return; - priv->closed = TRUE; + SalutImChannel *self = SALUT_IM_CHANNEL (base); + SalutImChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection (base); + SalutConnection *conn = SALUT_CONNECTION (base_conn); + WockyPorter *porter = conn->porter; wocky_porter_unregister_handler (porter, priv->message_handler_id); @@ -122,17 +88,14 @@ salut_im_channel_do_close (SalutImChannel *self) wocky_meta_porter_unhold (WOCKY_META_PORTER (porter), WOCKY_CONTACT (priv->contact)); - DEBUG ("Emitting closed signal for %s", priv->object_path); - tp_svc_channel_emit_closed (self); + tp_base_channel_destroyed (base); } static void -salut_im_channel_init (SalutImChannel *obj) +salut_im_channel_init (SalutImChannel *self) { - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (obj); - /* allocate any data required by the object here */ - priv->object_path = NULL; - priv->contact = NULL; + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ( + self, SALUT_TYPE_IM_CHANNEL, SalutImChannelPrivate); } @@ -142,80 +105,14 @@ salut_im_channel_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - SalutImChannel *chan = SALUT_IM_CHANNEL (object); - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (chan); - TpBaseConnection *base_conn = (TpBaseConnection *) priv->connection; + SalutImChannel *self = SALUT_IM_CHANNEL (object); + SalutImChannelPrivate *priv = self->priv; 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_TEXT); - break; - case PROP_HANDLE_TYPE: - g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT); - break; - case PROP_HANDLE: - g_value_set_uint (value, priv->handle); - break; case PROP_CONTACT: g_value_set_object (value, priv->contact); break; - case PROP_CONNECTION: - g_value_set_object (value, priv->connection); - break; - case PROP_INTERFACES: - g_value_set_static_boxed (value, salut_im_channel_interfaces); - break; - case PROP_TARGET_ID: - { - TpHandleRepoIface *repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); - - g_value_set_string (value, tp_handle_inspect (repo, priv->handle)); - } - break; - case PROP_INITIATOR_HANDLE: - g_value_set_uint (value, priv->initiator); - break; - case PROP_INITIATOR_ID: - { - TpHandleRepoIface *repo = tp_base_connection_get_handles ( - base_conn, TP_HANDLE_TYPE_CONTACT); - - g_assert (priv->initiator != 0); - g_value_set_string (value, - tp_handle_inspect (repo, priv->initiator)); - } - break; - case PROP_REQUESTED: - g_value_set_boolean (value, (priv->initiator == base_conn->self_handle)); - 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", - TP_IFACE_CHANNEL, "TargetID", - TP_IFACE_CHANNEL, "InitiatorHandle", - TP_IFACE_CHANNEL, "InitiatorID", - TP_IFACE_CHANNEL, "Requested", - TP_IFACE_CHANNEL, "Interfaces", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessagePartSupportFlags", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "DeliveryReportingSupport", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "SupportedContentTypes", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessageTypes", - NULL)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -228,41 +125,14 @@ salut_im_channel_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - SalutImChannel *chan = SALUT_IM_CHANNEL (object); - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (chan); - const gchar *tmp; + SalutImChannel *self = SALUT_IM_CHANNEL (object); + SalutImChannelPrivate *priv = self->priv; switch (property_id) { - case PROP_OBJECT_PATH: - g_free (priv->object_path); - priv->object_path = g_value_dup_string (value); - break; - case PROP_HANDLE: - priv->handle = g_value_get_uint (value); - break; - case PROP_INITIATOR_HANDLE: - priv->initiator = g_value_get_uint (value); - g_assert (priv->initiator != 0); - break; case PROP_CONTACT: priv->contact = g_value_dup_object (value); break; - case PROP_CONNECTION: - priv->connection = g_value_get_object (value); - break; - case PROP_HANDLE_TYPE: - /* 0 is the old tp-glib value of unset, TP_UNKNOWN_HANDLE_TYPE is the - * new version */ - g_assert (g_value_get_uint (value) == 0 - || g_value_get_uint (value) == TP_HANDLE_TYPE_CONTACT - || g_value_get_uint (value) == TP_UNKNOWN_HANDLE_TYPE); - break; - case PROP_CHANNEL_TYPE: - tmp = g_value_get_string (value); - g_assert (tmp == NULL || !tp_strdiff (g_value_get_string (value), - TP_IFACE_CHANNEL_TYPE_TEXT)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -279,17 +149,14 @@ _salut_im_channel_send (GObject *channel, static gboolean new_message_cb (WockyPorter *porter, WockyStanza *stanza, gpointer user_data); -static GObject * -salut_im_channel_constructor (GType type, - guint n_props, - GObjectConstructParam *props) +static void +salut_im_channel_constructed (GObject *obj) { - GObject *obj; - TpDBusDaemon *bus; - SalutImChannelPrivate *priv; - TpBaseConnection *base_conn; - TpHandleRepoIface *contact_repo; - WockyPorter *porter; + SalutImChannel *self = SALUT_IM_CHANNEL (obj); + SalutImChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (obj)); + WockyPorter *porter = SALUT_CONNECTION (base_conn)->porter; gchar *jid; TpChannelTextMessageType types[NUM_SUPPORTED_MESSAGE_TYPES] = { @@ -303,23 +170,12 @@ salut_im_channel_constructor (GType type, NULL }; - /* Parent constructor chain */ - obj = G_OBJECT_CLASS (salut_im_channel_parent_class)-> - constructor (type, n_props, props); - - priv = SALUT_IM_CHANNEL_GET_PRIVATE (SALUT_IM_CHANNEL (obj)); - porter = priv->connection->porter; + /* Parent constructed chain */ + void (*chain_up) (GObject *) = + ((GObjectClass *) salut_im_channel_parent_class)->constructed; - /* Ref our handle and initiator handle */ - base_conn = TP_BASE_CONNECTION (priv->connection); - - contact_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); - - tp_handle_ref (contact_repo, priv->handle); - - g_assert (priv->initiator != 0); - tp_handle_ref (contact_repo, priv->initiator); + if (chain_up != NULL) + chain_up (obj); /* Initialize message mixin */ tp_message_mixin_init (obj, G_STRUCT_OFFSET (SalutImChannel, message_mixin), @@ -330,10 +186,6 @@ salut_im_channel_constructor (GType type, TP_DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_FAILURES, supported_content_types); - /* Connect to the bus */ - bus = tp_base_connection_get_dbus_daemon (base_conn); - tp_dbus_daemon_register_object (bus, priv->object_path, obj); - /* Connect to further messages */ jid = wocky_contact_dup_jid (WOCKY_CONTACT (priv->contact)); @@ -347,85 +199,60 @@ salut_im_channel_constructor (GType type, /* ensure the connection doesn't close */ wocky_meta_porter_hold (WOCKY_META_PORTER (porter), WOCKY_CONTACT (priv->contact)); - - return obj; } static void salut_im_channel_dispose (GObject *object); static void salut_im_channel_finalize (GObject *object); static void +salut_im_channel_fill_immutable_properties (TpBaseChannel *chan, + GHashTable *properties) +{ + TpBaseChannelClass *cls = TP_BASE_CHANNEL_CLASS ( + salut_im_channel_parent_class); + + cls->fill_immutable_properties (chan, properties); + + tp_dbus_properties_mixin_fill_properties_hash ( + G_OBJECT (chan), properties, + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessagePartSupportFlags", + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "DeliveryReportingSupport", + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "SupportedContentTypes", + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessageTypes", + NULL); +} + +static gchar * +salut_im_channel_get_object_path_suffix (TpBaseChannel *chan) +{ + return g_strdup_printf ("ImChannel%u", + tp_base_channel_get_target_handle (chan)); +} + +static void salut_im_channel_class_init (SalutImChannelClass *salut_im_channel_class) { GObjectClass *object_class = G_OBJECT_CLASS (salut_im_channel_class); + TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (salut_im_channel_class); GParamSpec *param_spec; - static TpDBusPropertiesMixinPropImpl channel_props[] = { - { "TargetHandleType", "handle-type", NULL }, - { "TargetHandle", "handle", NULL }, - { "TargetID", "target-id", NULL }, - { "ChannelType", "channel-type", NULL }, - { "Interfaces", "interfaces", 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 } - }; g_type_class_add_private (salut_im_channel_class, sizeof (SalutImChannelPrivate)); object_class->dispose = salut_im_channel_dispose; object_class->finalize = salut_im_channel_finalize; - - object_class->constructor = salut_im_channel_constructor; + object_class->constructed = salut_im_channel_constructed; object_class->get_property = salut_im_channel_get_property; object_class->set_property = salut_im_channel_set_property; - 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_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_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_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 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); + base_class->channel_type = TP_IFACE_CHANNEL_TYPE_TEXT; + base_class->interfaces = salut_im_channel_interfaces; + base_class->target_handle_type = TP_HANDLE_TYPE_CONTACT; + base_class->close = salut_im_channel_close; + base_class->fill_immutable_properties = + salut_im_channel_fill_immutable_properties; + base_class->get_object_path_suffix = + salut_im_channel_get_object_path_suffix; param_spec = g_param_spec_object ( "contact", @@ -435,24 +262,6 @@ salut_im_channel_class_init (SalutImChannelClass *salut_im_channel_class) G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_CONTACT, param_spec); - param_spec = g_param_spec_object ( - "connection", - "SalutConnection object", - "Salut Connection that owns the connection for this IM channel", - 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); - - 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); - - salut_im_channel_class->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (SalutImChannelClass, dbus_props_class)); - tp_message_mixin_init_dbus_properties (object_class); } @@ -460,28 +269,18 @@ void salut_im_channel_dispose (GObject *object) { SalutImChannel *self = SALUT_IM_CHANNEL (object); - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_conn = TP_BASE_CONNECTION (priv->connection); - TpHandleRepoIface *handle_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); + SalutImChannelPrivate *priv = self->priv; if (priv->dispose_has_run) return; priv->dispose_has_run = TRUE; - tp_handle_unref (handle_repo, priv->handle); - - if (priv->initiator != 0) - tp_handle_unref (handle_repo, priv->initiator); - - salut_im_channel_do_close (self); + /* release any references held by the object here */ g_object_unref (priv->contact); priv->contact = NULL; - /* release any references held by the object here */ - if (G_OBJECT_CLASS (salut_im_channel_parent_class)->dispose) G_OBJECT_CLASS (salut_im_channel_parent_class)->dispose (object); } @@ -489,23 +288,19 @@ salut_im_channel_dispose (GObject *object) static void salut_im_channel_finalize (GObject *object) { - SalutImChannel *self = SALUT_IM_CHANNEL (object); - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); - - /* free any data held directly by the object here */ - g_free (priv->object_path); - tp_message_mixin_finalize (object); - G_OBJECT_CLASS (salut_im_channel_parent_class)->finalize (object); + if (G_OBJECT_CLASS (salut_im_channel_parent_class)->finalize) + G_OBJECT_CLASS (salut_im_channel_parent_class)->finalize (object); } void salut_im_channel_received_stanza (SalutImChannel *self, WockyStanza *stanza) { - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_conn = (TpBaseConnection *) priv->connection; + TpBaseChannel *base_chan = TP_BASE_CHANNEL (self); + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + base_chan); const gchar *from; TpChannelTextMessageType msgtype; const gchar *body; @@ -527,7 +322,8 @@ salut_im_channel_received_stanza (SalutImChannel *self, /* FIXME validate the from */ tp_message_mixin_take_received (G_OBJECT (self), - text_helper_create_received_message (base_conn, priv->handle, + text_helper_create_received_message (base_conn, + tp_base_channel_get_target_handle (base_chan), time (NULL), msgtype, body_offset)); } @@ -592,7 +388,9 @@ _send_message (SalutImChannel *self, const gchar *text, const gchar *token) { - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); + SalutConnection *conn = SALUT_CONNECTION (base_conn); SendMessageData *data; data = g_slice_new0 (SendMessageData); @@ -602,96 +400,22 @@ _send_message (SalutImChannel *self, data->text = g_strdup (text); data->token = g_strdup (token); - wocky_porter_send_async (priv->connection->porter, + wocky_porter_send_async (conn->porter, stanza, NULL, sent_message_cb, data); return TRUE; } -/** - * salut_im_channel_close - * - * Implements DBus method Close - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_im_channel_close (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - salut_im_channel_do_close (SALUT_IM_CHANNEL (iface)); - tp_svc_channel_return_from_close (context); -} - - -/** - * salut_im_channel_get_channel_type - * - * Implements DBus method GetChannelType - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_im_channel_get_channel_type (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_channel_type (context, - TP_IFACE_CHANNEL_TYPE_TEXT); -} - - -/** - * salut_im_channel_get_handle - * - * Implements DBus method GetHandle - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_im_channel_get_handle (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - SalutImChannel *self = SALUT_IM_CHANNEL (iface); - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); - - tp_svc_channel_return_from_get_handle (context, TP_HANDLE_TYPE_CONTACT, - priv->handle); -} - - -/** - * salut_im_channel_get_interfaces - * - * Implements DBus method GetInterfaces - * on interface org.freedesktop.Telepathy.Channel - */ -static void -salut_im_channel_get_interfaces (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_interfaces (context, - salut_im_channel_interfaces); -} - -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_im_channel_##x) - IMPLEMENT(close); - IMPLEMENT(get_channel_type); - IMPLEMENT(get_handle); - IMPLEMENT(get_interfaces); -#undef IMPLEMENT -} - static void _salut_im_channel_send (GObject *channel, - TpMessage *message, - TpMessageSendingFlags flags) + TpMessage *message, + TpMessageSendingFlags flags) { SalutImChannel *self = SALUT_IM_CHANNEL (channel); - SalutImChannelPrivate *priv = SALUT_IM_CHANNEL_GET_PRIVATE (self); + SalutImChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); + SalutConnection *conn = SALUT_CONNECTION (base_conn); GError *error = NULL; WockyStanza *stanza = NULL; guint type; @@ -701,8 +425,8 @@ _salut_im_channel_send (GObject *channel, if (!text_helper_validate_tp_message (message, &type, &token, &text, &error)) goto error; - stanza = text_helper_create_message (priv->connection->name, - priv->contact, type, text, &error); + stanza = text_helper_create_message (conn->name, + priv->contact, type, text, &error); if (stanza == NULL) goto error; diff --git a/src/im-channel.h b/src/im-channel.h index 35eb4216..a1a3dd01 100644 --- a/src/im-channel.h +++ b/src/im-channel.h @@ -23,22 +23,26 @@ #include <glib-object.h> #include <wocky/wocky.h> +#include <telepathy-glib/base-channel.h> #include <telepathy-glib/message-mixin.h> G_BEGIN_DECLS typedef struct _SalutImChannel SalutImChannel; typedef struct _SalutImChannelClass SalutImChannelClass; +typedef struct _SalutImChannelPrivate SalutImChannelPrivate; struct _SalutImChannelClass { - GObjectClass parent_class; + TpBaseChannelClass parent_class; TpDBusPropertiesMixinClass dbus_props_class; }; struct _SalutImChannel { - GObject parent; + TpBaseChannel parent; TpMessageMixin message_mixin; + + SalutImChannelPrivate *priv; }; GType salut_im_channel_get_type (void); diff --git a/src/im-manager.c b/src/im-manager.c index 01b1489c..e0f6bf18 100644 --- a/src/im-manager.c +++ b/src/im-manager.c @@ -35,6 +35,7 @@ #include <telepathy-glib/dbus.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> +#include <telepathy-glib/base-channel.h> #define DEBUG_FLAG DEBUG_IM #include "debug.h" @@ -554,10 +555,11 @@ salut_im_manager_new_channel (SalutImManager *mgr, chan = g_object_new (SALUT_TYPE_IM_CHANNEL, "connection", priv->connection, "contact", contact, - "object-path", path, "handle", handle, "initiator-handle", initiator, + "requested", (handle != initiator), NULL); + tp_base_channel_register ((TpBaseChannel *) chan); g_object_unref (contact); g_free (path); g_hash_table_insert (priv->channels, GUINT_TO_POINTER (handle), chan); diff --git a/src/muc-channel.c b/src/muc-channel.c index 40e60090..383b2812 100644 --- a/src/muc-channel.c +++ b/src/muc-channel.c @@ -37,9 +37,7 @@ #include <wocky/wocky.h> -#include <telepathy-glib/channel-iface.h> #include <telepathy-glib/interfaces.h> -#include <telepathy-glib/svc-generic.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/errors.h> #include <telepathy-glib/util.h> @@ -56,14 +54,7 @@ #include "text-helper.h" #include "tube-stream.h" -static void channel_iface_init (gpointer g_iface, gpointer iface_data); - -G_DEFINE_TYPE_WITH_CODE(SalutMucChannel, salut_muc_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_EXPORTABLE_CHANNEL, NULL); - G_IMPLEMENT_INTERFACE(TP_TYPE_CHANNEL_IFACE, NULL); +G_DEFINE_TYPE_WITH_CODE(SalutMucChannel, salut_muc_channel, TP_TYPE_BASE_CHANNEL, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_GROUP, tp_group_mixin_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TEXT, @@ -91,21 +82,8 @@ static guint signals[LAST_SIGNAL] = {0}; /* properties */ enum { - PROP_OBJECT_PATH = 1, - PROP_CHANNEL_TYPE, - PROP_HANDLE_TYPE, - PROP_HANDLE, - PROP_MUC_CONNECTION, - PROP_CONNECTION, + PROP_MUC_CONNECTION = 1, PROP_NAME, - PROP_CREATOR, - PROP_INTERFACES, - PROP_TARGET_ID, - PROP_REQUESTED, - PROP_INITIATOR_HANDLE, - PROP_INITIATOR_ID, - PROP_CHANNEL_PROPERTIES, - PROP_CHANNEL_DESTROYED, LAST_PROPERTY }; @@ -115,24 +93,16 @@ typedef struct _SalutMucChannelPrivate SalutMucChannelPrivate; struct _SalutMucChannelPrivate { gboolean dispose_has_run; - gchar *object_path; - TpHandle handle; SalutSelf *self; GibberMucConnection *muc_connection; gchar *muc_name; gboolean connected; - gboolean creator; guint timeout; /* (gchar *) -> (SalutContact *) */ GHashTable *senders; SalutMucManager *muc_manager; - TpHandle initiator; - gboolean requested; - gboolean closed; }; -#define SALUT_MUC_CHANNEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SALUT_TYPE_MUC_CHANNEL, SalutMucChannelPrivate)) - /* Callback functions */ static gboolean salut_muc_channel_send_stanza (SalutMucChannel *self, guint type, @@ -151,6 +121,8 @@ static void salut_muc_channel_disconnected (GibberTransport *transport, static void salut_muc_channel_send (GObject *channel, TpMessage *message, TpMessageSendingFlags flags); +static void salut_muc_channel_close (TpBaseChannel *base); + static void salut_muc_channel_get_property (GObject *object, @@ -159,82 +131,15 @@ salut_muc_channel_get_property (GObject *object, GParamSpec *pspec) { SalutMucChannel *chan = SALUT_MUC_CHANNEL (object); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (chan); - TpBaseConnection *base_conn = (TpBaseConnection *) chan->connection; + SalutMucChannelPrivate *priv = chan->priv; switch (property_id) { - case PROP_OBJECT_PATH: - g_value_set_string (value, priv->object_path); - break; case PROP_NAME: g_value_set_string (value, priv->muc_name); 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_ROOM); - break; - case PROP_HANDLE: - g_value_set_uint (value, priv->handle); - break; - case PROP_CONNECTION: - g_value_set_object (value, chan->connection); - break; case PROP_MUC_CONNECTION: g_value_set_object (value, priv->muc_connection); break; - case PROP_CREATOR: - g_value_set_boolean (value, priv->creator); - break; - case PROP_INTERFACES: - g_value_set_static_boxed (value, salut_muc_channel_interfaces); - break; - case PROP_TARGET_ID: - { - TpHandleRepoIface *repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_ROOM); - - g_value_set_string (value, tp_handle_inspect (repo, priv->handle)); - } - break; - case PROP_INITIATOR_HANDLE: - g_value_set_uint (value, priv->initiator); - break; - case PROP_INITIATOR_ID: - { - TpHandleRepoIface *repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); - - g_value_set_string (value, tp_handle_inspect (repo, priv->initiator)); - } - break; - case PROP_REQUESTED: - g_value_set_boolean (value, priv->requested); - 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", - TP_IFACE_CHANNEL, "TargetID", - TP_IFACE_CHANNEL, "InitiatorHandle", - TP_IFACE_CHANNEL, "InitiatorID", - TP_IFACE_CHANNEL, "Requested", - TP_IFACE_CHANNEL, "Interfaces", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessagePartSupportFlags", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "DeliveryReportingSupport", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "SupportedContentTypes", - TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessageTypes", - NULL)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -248,49 +153,16 @@ salut_muc_channel_set_property (GObject *object, GParamSpec *pspec) { SalutMucChannel *chan = SALUT_MUC_CHANNEL (object); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (chan); - const gchar *tmp; + SalutMucChannelPrivate *priv = chan->priv; switch (property_id) { - case PROP_OBJECT_PATH: - g_free (priv->object_path); - priv->object_path = g_value_dup_string (value); - break; case PROP_NAME: g_free (priv->muc_name); priv->muc_name = g_value_dup_string (value); break; - case PROP_HANDLE: - priv->handle = g_value_get_uint (value); - break; - case PROP_CONNECTION: - chan->connection = g_value_get_object (value); - break; case PROP_MUC_CONNECTION: priv->muc_connection = g_value_get_object (value); break; - case PROP_HANDLE_TYPE: - /* 0 is the old tp-glib value of unset, TP_UNKNOWN_HANDLE_TYPE is the - * new version */ - g_assert (g_value_get_uint (value) == 0 - || g_value_get_uint (value) == TP_HANDLE_TYPE_ROOM - || g_value_get_uint (value) == TP_UNKNOWN_HANDLE_TYPE); - break; - case PROP_CHANNEL_TYPE: - tmp = g_value_get_string (value); - g_assert (tmp == NULL - || !tp_strdiff (g_value_get_string (value), - TP_IFACE_CHANNEL_TYPE_TEXT)); - break; - case PROP_CREATOR: - priv->creator = g_value_get_boolean (value); - break; - case PROP_INITIATOR_HANDLE: - priv->initiator = g_value_get_uint (value); - break; - case PROP_REQUESTED: - priv->requested = g_value_get_boolean (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -300,8 +172,9 @@ salut_muc_channel_set_property (GObject *object, static void salut_muc_channel_add_self_to_members (SalutMucChannel *self) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_connection = TP_BASE_CONNECTION (self->connection); + SalutMucChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); TpIntSet *empty; TpIntSet *add; @@ -317,10 +190,10 @@ salut_muc_channel_add_self_to_members (SalutMucChannel *self) /* Now we are connected, move yourself to members */ empty = tp_intset_new (); add = tp_intset_new (); - tp_intset_add (add, base_connection->self_handle); + tp_intset_add (add, base_conn->self_handle); tp_group_mixin_change_members (G_OBJECT (self), - "", add, empty, empty, empty, base_connection->self_handle, + "", add, empty, empty, empty, base_conn->self_handle, TP_CHANNEL_GROUP_CHANGE_REASON_NONE); tp_intset_destroy (empty); @@ -331,7 +204,7 @@ static gboolean connected_timeout_cb (gpointer user_data) { SalutMucChannel *self = SALUT_MUC_CHANNEL (user_data); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; DEBUG ("Didn't receive muc senders. Timeout expired, " "adding myself as member anyway"); @@ -345,9 +218,9 @@ static void muc_connection_connected_cb (GibberMucConnection *connection, SalutMucChannel *self) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; - if (priv->creator) + if (tp_base_channel_is_requested (TP_BASE_CHANNEL (self))) { DEBUG ("I created this muc. Adding myself as member now"); salut_muc_channel_add_self_to_members (self); @@ -365,17 +238,15 @@ muc_connection_connected_cb (GibberMucConnection *connection, #define NUM_SUPPORTED_MESSAGE_TYPES 3 -static GObject * -salut_muc_channel_constructor (GType type, guint n_props, - GObjectConstructParam *props) +static void +salut_muc_channel_constructed (GObject *obj) { - GObject *obj; - TpDBusDaemon *bus; - SalutMucChannel *self; - SalutMucChannelPrivate *priv; - TpBaseConnection *base_conn; - TpHandleRepoIface *handle_repo; - TpHandleRepoIface *contact_repo; + SalutMucChannel *self = SALUT_MUC_CHANNEL (obj); + SalutMucChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( + base_conn, TP_HANDLE_TYPE_CONTACT); TpChannelTextMessageType types[NUM_SUPPORTED_MESSAGE_TYPES] = { TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION, @@ -386,20 +257,12 @@ salut_muc_channel_constructor (GType type, guint n_props, NULL }; - /* Parent constructor chain */ - obj = G_OBJECT_CLASS (salut_muc_channel_parent_class)-> - constructor (type, n_props, props); - - self = SALUT_MUC_CHANNEL (obj); - priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - - /* Ref our handle */ - base_conn = TP_BASE_CONNECTION (self->connection); - - handle_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_ROOM); + /* Parent constructed chain */ + void (*chain_up) (GObject *) = + ((GObjectClass *) salut_muc_channel_parent_class)->constructed; - tp_handle_ref (handle_repo, priv->handle); + if (chain_up != NULL) + chain_up (obj); /* Message mixin initialisation */ tp_message_mixin_init (obj, G_STRUCT_OFFSET (SalutMucChannel, message_mixin), @@ -410,7 +273,9 @@ salut_muc_channel_constructor (GType type, guint n_props, TP_DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_SUCCESSES, supported_content_types); - g_object_get (self->connection, "self", &(priv->self), NULL); + g_object_get (base_conn, + "self", &(priv->self), + NULL); g_object_unref (priv->self); g_assert (priv->self != NULL); @@ -420,7 +285,7 @@ salut_muc_channel_constructor (GType type, guint n_props, g_signal_connect (priv->muc_connection, "connected", G_CALLBACK (muc_connection_connected_cb), obj); - g_object_get (self->connection, + g_object_get (base_conn, "muc-manager", &(priv->muc_manager), NULL); g_assert (priv->muc_manager != NULL); @@ -428,12 +293,6 @@ salut_muc_channel_constructor (GType type, guint n_props, /* no need to keep a ref on the muc manager as it keeps a ref on us */ g_object_unref (priv->muc_manager); - /* Connect to the bus */ - bus = tp_base_connection_get_dbus_daemon (base_conn); - tp_dbus_daemon_register_object (bus, priv->object_path, obj); - - contact_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); tp_group_mixin_init (obj, G_STRUCT_OFFSET(SalutMucChannel, group), contact_repo, base_conn->self_handle); @@ -442,20 +301,18 @@ salut_muc_channel_constructor (GType type, guint n_props, TP_CHANNEL_GROUP_FLAG_CAN_ADD | TP_CHANNEL_GROUP_FLAG_MESSAGE_ADD, 0); - - return obj; } static void salut_muc_channel_init (SalutMucChannel *self) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, SALUT_TYPE_MUC_CHANNEL, + SalutMucChannelPrivate); + /* allocate any data required by the object here */ - priv->object_path = NULL; - self->connection = NULL; - priv->muc_name = NULL; - priv->timeout = 0; - priv->senders = g_hash_table_new_full (g_str_hash, g_str_equal, + self->priv->muc_name = NULL; + self->priv->timeout = 0; + self->priv->senders = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref); } @@ -471,19 +328,25 @@ invitation_append_parameter (gpointer key, gpointer value, gpointer data) } static WockyStanza * -create_invitation (SalutMucChannel *self, SalutContact *contact, +create_invitation (SalutMucChannel *self, + SalutContact *contact, const gchar *message) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_connection = TP_BASE_CONNECTION(self->connection); + SalutMucChannelPrivate *priv = self->priv; + TpBaseChannel *base_chan = TP_BASE_CHANNEL (self); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + base_chan); + SalutConnection *conn = SALUT_CONNECTION (base_connection); TpHandleRepoIface *room_repo = tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_ROOM); WockyStanza *msg; WockyNode *invite_node; + const gchar *target_id = tp_handle_inspect (room_repo, + tp_base_channel_get_target_handle (base_chan)); msg = wocky_stanza_build_to_contact (WOCKY_STANZA_TYPE_MESSAGE, WOCKY_STANZA_SUB_TYPE_NORMAL, - self->connection->name, WOCKY_CONTACT (contact), + conn->name, WOCKY_CONTACT (contact), '(', "body", '$', "You got a Clique chatroom invitation", ')', @@ -491,7 +354,7 @@ create_invitation (SalutMucChannel *self, SalutContact *contact, '*', &invite_node, ':', WOCKY_TELEPATHY_NS_CLIQUE, '(', "roomname", - '$', tp_handle_inspect (room_repo, priv->handle), + '$', target_id, ')', ')', NULL); @@ -507,7 +370,8 @@ create_invitation (SalutMucChannel *self, SalutContact *contact, invitation_append_parameter, invite_node); #ifdef ENABLE_OLPC - salut_self_olpc_augment_invitation (priv->self, priv->handle, contact->handle, + salut_self_olpc_augment_invitation (priv->self, + tp_base_channel_get_target_handle (base_chan), contact->handle, invite_node); #endif @@ -517,7 +381,7 @@ create_invitation (SalutMucChannel *self, SalutContact *contact, gboolean salut_muc_channel_publish_service (SalutMucChannel *self) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; return SALUT_MUC_CHANNEL_GET_CLASS (self)->publish_service (self, priv->muc_connection, priv->muc_name); @@ -536,8 +400,8 @@ send_invite_cb (GObject *source_object, { WockyPorter *porter = WOCKY_PORTER (source_object); SendInviteData *data = user_data; - TpBaseConnection *base_connection = TP_BASE_CONNECTION ( - data->self->connection); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (data->self)); GError *error = NULL; TpHandle handle; TpIntSet *empty, *removed; @@ -577,11 +441,15 @@ salut_muc_channel_send_invitation (SalutMucChannel *self, WockyStanza *stanza; SalutContactManager *contact_manager = NULL; SalutContact *contact; - WockyPorter *porter = self->connection->porter; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); + SalutConnection *conn = SALUT_CONNECTION (base_conn); + WockyPorter *porter = conn->porter; SendInviteData *data; - g_object_get (G_OBJECT (self->connection), "contact-manager", - &contact_manager, NULL); + g_object_get (G_OBJECT (conn), + "contact-manager", &contact_manager, + NULL); g_assert (contact_manager != NULL); contact = salut_contact_manager_get_contact (contact_manager, handle); @@ -616,9 +484,9 @@ salut_muc_channel_add_member (GObject *iface, const gchar *message, GError **error) { - SalutMucChannel *self = SALUT_MUC_CHANNEL(iface); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_connection = TP_BASE_CONNECTION (self->connection); + SalutMucChannel *self = SALUT_MUC_CHANNEL (iface); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); TpIntSet *empty, *remote_pending; if (handle == base_connection->self_handle) @@ -663,7 +531,8 @@ salut_muc_channel_add_member (GObject *iface, /* Adding a contact, let's invite him */ - DEBUG ("Trying to add handle %u to %s", handle, priv->object_path); + DEBUG ("Trying to add handle %u to %s", handle, + tp_base_channel_get_object_path (TP_BASE_CHANNEL (self))); if (!salut_muc_channel_send_invitation (self, handle, message, error)) return FALSE; @@ -686,9 +555,10 @@ salut_muc_channel_leave (SalutMucChannel *self, TpChannelGroupChangeReason reason, const gchar *message) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; + TpBaseChannel *base = TP_BASE_CHANNEL (self); - if (priv->closed) + if (tp_base_channel_is_destroyed (base)) return; if (priv->connected) @@ -701,8 +571,7 @@ salut_muc_channel_leave (SalutMucChannel *self, } else { - priv->closed = TRUE; - tp_svc_channel_emit_closed (self); + tp_base_channel_destroyed (base); } } @@ -714,7 +583,8 @@ salut_muc_channel_remove_member_with_reason (GObject *object, GError **error) { SalutMucChannel *self = SALUT_MUC_CHANNEL (object); - TpBaseConnection *base_connection = TP_BASE_CONNECTION (self->connection); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); if (handle != base_connection->self_handle) { @@ -728,78 +598,46 @@ salut_muc_channel_remove_member_with_reason (GObject *object, } static void -salut_muc_channel_class_init (SalutMucChannelClass *salut_muc_channel_class) { +salut_muc_channel_fill_immutable_properties (TpBaseChannel *chan, + GHashTable *properties) +{ + TpBaseChannelClass *cls = TP_BASE_CHANNEL_CLASS ( + salut_muc_channel_parent_class); + + cls->fill_immutable_properties (chan, properties); + + tp_dbus_properties_mixin_fill_properties_hash ( + G_OBJECT (chan), properties, + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessagePartSupportFlags", + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "DeliveryReportingSupport", + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "SupportedContentTypes", + TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "MessageTypes", + NULL); +} + +static void +salut_muc_channel_class_init (SalutMucChannelClass *salut_muc_channel_class) +{ GObjectClass *object_class = G_OBJECT_CLASS (salut_muc_channel_class); + TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS ( + salut_muc_channel_class); GParamSpec *param_spec; - static TpDBusPropertiesMixinPropImpl channel_props[] = { - { "TargetHandleType", "handle-type", NULL }, - { "TargetHandle", "handle", NULL }, - { "TargetID", "target-id", NULL }, - { "ChannelType", "channel-type", NULL }, - { "Interfaces", "interfaces", 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 } - }; g_type_class_add_private (salut_muc_channel_class, sizeof (SalutMucChannelPrivate)); object_class->dispose = salut_muc_channel_dispose; object_class->finalize = salut_muc_channel_finalize; - - object_class->constructor = salut_muc_channel_constructor; + object_class->constructed = salut_muc_channel_constructed; object_class->get_property = salut_muc_channel_get_property; object_class->set_property = salut_muc_channel_set_property; - 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_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_boolean ("requested", "Requested?", - "True if this channel was requested by the local user", - FALSE, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_REQUESTED, param_spec); - - param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle", - "The contact which invited us to the MUC, or ourselves if we joined of " - "our own accord", - 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 JID", - "The string obtained by inspecting this channel's initiator-handle", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INITIATOR_ID, - param_spec); + base_class->channel_type = TP_IFACE_CHANNEL_TYPE_TEXT; + base_class->interfaces = salut_muc_channel_interfaces; + base_class->target_handle_type = TP_HANDLE_TYPE_ROOM; + base_class->close = salut_muc_channel_close; + base_class->fill_immutable_properties = + salut_muc_channel_fill_immutable_properties; param_spec = g_param_spec_string ("name", "Name of the muc group", @@ -820,34 +658,6 @@ salut_muc_channel_class_init (SalutMucChannelClass *salut_muc_channel_class) { G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_MUC_CONNECTION, param_spec); - param_spec = g_param_spec_object ("connection", - "SalutConnection object", - "Salut Connection that owns the" - "connection for this IM channel", - 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); - - param_spec = g_param_spec_boolean ( - "creator", - "creator", - "Whether or not we created this muc", - FALSE, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, - PROP_CREATOR, 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); - signals[READY] = g_signal_new ( "ready", @@ -867,10 +677,6 @@ salut_muc_channel_class_init (SalutMucChannelClass *salut_muc_channel_class) { g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - salut_muc_channel_class->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (SalutMucChannelClass, dbus_props_class)); - tp_group_mixin_class_init (object_class, G_STRUCT_OFFSET(SalutMucChannelClass, group_class), salut_muc_channel_add_member, NULL); @@ -887,7 +693,7 @@ void salut_muc_channel_dispose (GObject *object) { SalutMucChannel *self = SALUT_MUC_CHANNEL (object); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; if (priv->dispose_has_run) return; @@ -915,12 +721,6 @@ salut_muc_channel_dispose (GObject *object) priv->senders = NULL; } - if (!priv->closed) - { - priv->closed = TRUE; - tp_svc_channel_emit_closed (self); - } - /* release any references held by the object here */ if (G_OBJECT_CLASS (salut_muc_channel_parent_class)->dispose) G_OBJECT_CLASS (salut_muc_channel_parent_class)->dispose (object); @@ -930,34 +730,33 @@ void salut_muc_channel_finalize (GObject *object) { SalutMucChannel *self = SALUT_MUC_CHANNEL (object); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; /* free any data held directly by the object here */ - g_free (priv->object_path); g_free (priv->muc_name); tp_group_mixin_finalize (object); tp_message_mixin_finalize (object); - G_OBJECT_CLASS (salut_muc_channel_parent_class)->finalize (object); + if (G_OBJECT_CLASS (salut_muc_channel_parent_class)->finalize) + G_OBJECT_CLASS (salut_muc_channel_parent_class)->finalize (object); } gboolean salut_muc_channel_invited (SalutMucChannel *self, TpHandle inviter, const gchar *stanza, GError **error) { - TpBaseConnection *base_connection = TP_BASE_CONNECTION (self->connection); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_CONTACT); - TpHandleRepoIface *room_repo = - tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_ROOM); gboolean ret = TRUE; /* Got invited to this muc channel */ DEBUG ("Got an invitation to %s from %s", - tp_handle_inspect (room_repo, priv->handle), - tp_handle_inspect (contact_repo, inviter)); + tp_handle_inspect (contact_repo, + tp_base_channel_get_target_handle (TP_BASE_CHANNEL (self))), + tp_handle_inspect (contact_repo, inviter)); /* If we are already a member, no further actions are needed */ if (tp_handle_set_is_member (self->group.members, @@ -1003,7 +802,7 @@ salut_muc_channel_send_stanza (SalutMucChannel *self, guint type, WockyStanza *stanza, GError **error) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; if (!gibber_muc_connection_send (priv->muc_connection, stanza, error)) { text_helper_report_delivery_error (TP_SVC_CHANNEL (self), @@ -1018,7 +817,9 @@ static void salut_muc_channel_add_members (SalutMucChannel *self, GArray *members) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); TpIntSet *empty, *changes; guint i; SalutContactManager *contact_mgr; @@ -1026,8 +827,9 @@ salut_muc_channel_add_members (SalutMucChannel *self, empty = tp_intset_new (); changes = tp_intset_new (); - g_object_get (G_OBJECT (self->connection), "contact-manager", - &contact_mgr, NULL); + g_object_get (G_OBJECT (base_conn), + "contact-manager", &contact_mgr, + NULL); g_assert (contact_mgr != NULL); for (i = 0; i < members->len; i++) @@ -1057,11 +859,12 @@ static void salut_muc_channel_remove_members (SalutMucChannel *self, GArray *members) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_connection = - (TpBaseConnection *) (self->connection); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles - (base_connection, TP_HANDLE_TYPE_CONTACT); + SalutMucChannelPrivate *priv = self->priv; + TpBaseChannel *base_chan = TP_BASE_CHANNEL (self); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + base_chan); + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( + base_connection, TP_HANDLE_TYPE_CONTACT); TpIntSet *empty, *changes; guint i; @@ -1103,8 +906,10 @@ salut_muc_channel_received_stanza (GibberMucConnection *conn, gpointer user_data) { SalutMucChannel *self = SALUT_MUC_CHANNEL (user_data); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - TpBaseConnection *base_connection = TP_BASE_CONNECTION (self->connection); + SalutMucChannelPrivate *priv = self->priv; + TpBaseChannel *base_chan = TP_BASE_CHANNEL (self); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + base_chan); TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base_connection, TP_HANDLE_TYPE_CONTACT); @@ -1115,6 +920,7 @@ salut_muc_channel_received_stanza (GibberMucConnection *conn, WockyNode *tubes_node; to = wocky_node_get_attribute (node, "to"); + if (strcmp (to, priv->muc_name)) { DEBUG("Stanza to another muc group, discarding"); return; @@ -1130,8 +936,9 @@ salut_muc_channel_received_stanza (GibberMucConnection *conn, } #ifdef ENABLE_OLPC - if (salut_connection_olpc_observe_muc_stanza (self->connection, priv->handle, - from_handle, stanza)) + if (salut_connection_olpc_observe_muc_stanza (self->connection, + tp_base_channel_get_target_handle (base_chan), + from_handle, stanza)) return; #endif @@ -1146,7 +953,7 @@ salut_muc_channel_received_stanza (GibberMucConnection *conn, gboolean created; tubes_chan = salut_muc_manager_ensure_tubes_channel (priv->muc_manager, - priv->handle, from_handle, &created); + tp_base_channel_get_target_handle (base_chan), from_handle, &created); g_assert (tubes_chan != NULL); channels = g_hash_table_new_full (g_direct_hash, g_direct_equal, @@ -1203,7 +1010,8 @@ salut_muc_channel_new_senders (GibberMucConnection *connection, gpointer user_data) { SalutMucChannel *self = SALUT_MUC_CHANNEL (user_data); - TpBaseConnection *base_connection = TP_BASE_CONNECTION (self->connection); + TpBaseConnection *base_connection = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); salut_muc_channel_add_members (self, senders); if (!tp_handle_set_is_member (self->group.members, @@ -1227,7 +1035,7 @@ static gboolean salut_muc_channel_connect (SalutMucChannel *channel, GError **error) { - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (channel); + SalutMucChannelPrivate *priv = channel->priv; g_signal_connect (priv->muc_connection, "received-stanza", G_CALLBACK (salut_muc_channel_received_stanza), channel); @@ -1248,7 +1056,7 @@ static void salut_muc_channel_disconnected (GibberTransport *transport, gpointer user_data) { SalutMucChannel *self = SALUT_MUC_CHANNEL (user_data); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); + SalutMucChannelPrivate *priv = self->priv; if (priv->timeout != 0) { @@ -1264,121 +1072,17 @@ salut_muc_channel_disconnected (GibberTransport *transport, gpointer user_data) g_signal_emit (self, signals[JOIN_ERROR], 0, &error); } - if (priv->closed) - return; - - priv->closed = TRUE; - tp_svc_channel_emit_closed (self); -} - -/* channel interfaces */ -/** - * salut_muc_channel_get_interfaces - * - * Implements D-Bus method GetInterfaces - * on interface org.freedesktop.Telepathy.Channel - * - * @error: Used to return a pointer to a GError detailing any error - * that occurred, D-Bus will throw the error only if this - * function returns FALSE. - * - * Returns: TRUE if successful, FALSE if an error was thrown. - */ -static void -salut_muc_channel_get_interfaces (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_interfaces (context, - salut_muc_channel_interfaces); -} - - -/** - * salut_muc_channel_get_handle - * - * Implements D-Bus method GetHandle - * on interface org.freedesktop.Telepathy.Channel - * - * @error: Used to return a pointer to a GError detailing any error - * that occurred, D-Bus will throw the error only if this - * function returns FALSE. - * - * Returns: TRUE if successful, FALSE if an error was thrown. - */ -static void -salut_muc_channel_get_handle (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - SalutMucChannel *self = SALUT_MUC_CHANNEL (iface); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - - tp_svc_channel_return_from_get_handle (context, TP_HANDLE_TYPE_ROOM, - priv->handle); -} -/** - * salut_muc_channel_get_channel_type - * - * Implements D-Bus method GetChannelType - * on interface org.freedesktop.Telepathy.Channel - * - * @error: Used to return a pointer to a GError detailing any error - * that occurred, D-Bus will throw the error only if this - * function returns FALSE. - * - * Returns: TRUE if successful, FALSE if an error was thrown. - */ -static void -salut_muc_channel_get_channel_type (TpSvcChannel *iface, - DBusGMethodInvocation *context) -{ - tp_svc_channel_return_from_get_channel_type (context, - TP_IFACE_CHANNEL_TYPE_TEXT); + tp_base_channel_destroyed (TP_BASE_CHANNEL (self)); } -/** - * salut_muc_channel_close - * - * Implements D-Bus method Close - * on interface org.freedesktop.Telepathy.Channel - * - * @error: Used to return a pointer to a GError detailing any error - * that occurred, D-Bus will throw the error only if this - * function returns FALSE. - * - * Returns: TRUE if successful, FALSE if an error was thrown. - */ static void -salut_muc_channel_close (TpSvcChannel *iface, DBusGMethodInvocation *context) +salut_muc_channel_close (TpBaseChannel *base) { - SalutMucChannel *self = SALUT_MUC_CHANNEL (iface); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE (self); - - if (priv->closed) - { - GError already = { TP_ERRORS, TP_ERROR_NOT_AVAILABLE, - "Channel already closed"}; - DEBUG ("channel already closed"); - - dbus_g_method_return_error (context, &already); - return; - } + SalutMucChannel *self = SALUT_MUC_CHANNEL (base); salut_muc_channel_leave (self, TP_CHANNEL_GROUP_CHANGE_REASON_NONE, ""); - tp_svc_channel_return_from_close (context); -} -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_muc_channel_##x) - IMPLEMENT (close); - IMPLEMENT (get_channel_type); - IMPLEMENT (get_handle); - IMPLEMENT (get_interfaces); -#undef IMPLEMENT + tp_base_channel_destroyed (base); } static void @@ -1386,8 +1090,11 @@ salut_muc_channel_send (GObject *channel, TpMessage *message, TpMessageSendingFlags flags) { - SalutMucChannel *self = SALUT_MUC_CHANNEL(channel); - SalutMucChannelPrivate *priv = SALUT_MUC_CHANNEL_GET_PRIVATE(self); + SalutMucChannel *self = SALUT_MUC_CHANNEL (channel); + SalutMucChannelPrivate *priv = self->priv; + TpBaseConnection *base_conn = tp_base_channel_get_connection ( + TP_BASE_CHANNEL (self)); + SalutConnection *conn = SALUT_CONNECTION (base_conn); GError *error = NULL; WockyStanza *stanza = NULL; guint type; @@ -1397,7 +1104,7 @@ salut_muc_channel_send (GObject *channel, if (!text_helper_validate_tp_message (message, &type, &token, &text, &error)) goto error; - stanza = text_helper_create_message_groupchat (self->connection->name, + stanza = text_helper_create_message_groupchat (conn->name, priv->muc_name, type, text, &error); if (stanza == NULL) diff --git a/src/muc-channel.h b/src/muc-channel.h index 902db5e5..3bb01f04 100644 --- a/src/muc-channel.h +++ b/src/muc-channel.h @@ -23,6 +23,7 @@ #include <glib-object.h> +#include <telepathy-glib/base-channel.h> #include <telepathy-glib/group-mixin.h> #include <telepathy-glib/message-mixin.h> @@ -34,9 +35,10 @@ G_BEGIN_DECLS typedef struct _SalutMucChannel SalutMucChannel; typedef struct _SalutMucChannelClass SalutMucChannelClass; +typedef struct _SalutMucChannelPrivate SalutMucChannelPrivate; struct _SalutMucChannelClass { - GObjectClass parent_class; + TpBaseChannelClass parent_class; TpGroupMixinClass group_class; TpDBusPropertiesMixinClass dbus_props_class; @@ -46,12 +48,12 @@ struct _SalutMucChannelClass { }; struct _SalutMucChannel { - GObject parent; + TpBaseChannel parent; TpGroupMixin group; TpMessageMixin message_mixin; /* private */ - SalutConnection *connection; + SalutMucChannelPrivate *priv; }; GType salut_muc_channel_get_type (void); diff --git a/src/muc-manager.c b/src/muc-manager.c index 46647fe7..8951da92 100644 --- a/src/muc-manager.c +++ b/src/muc-manager.c @@ -495,6 +495,8 @@ salut_muc_manager_new_muc_channel (SalutMucManager *mgr, new_connection, requested); g_free (path); + tp_base_channel_register ((TpBaseChannel *) chan); + g_signal_connect (chan, "closed", G_CALLBACK (muc_channel_closed_cb), mgr); g_hash_table_insert (priv->text_channels, GUINT_TO_POINTER (handle), chan); 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) { diff --git a/src/roomlist-channel.h b/src/roomlist-channel.h index 6bb64a95..09da6802 100644 --- a/src/roomlist-channel.h +++ b/src/roomlist-channel.h @@ -22,22 +22,25 @@ #include <glib-object.h> +#include <telepathy-glib/base-channel.h> + #include "connection.h" G_BEGIN_DECLS typedef struct _SalutRoomlistChannel SalutRoomlistChannel; typedef struct _SalutRoomlistChannelClass SalutRoomlistChannelClass; +typedef struct _SalutRoomlistChannelPrivate SalutRoomlistChannelPrivate; struct _SalutRoomlistChannelClass { - GObjectClass parent_class; + TpBaseChannelClass parent_class; TpDBusPropertiesMixinClass dbus_props_class; }; struct _SalutRoomlistChannel { - GObject parent; + TpBaseChannel parent; - gpointer priv; + SalutRoomlistChannelPrivate *priv; }; GType salut_roomlist_channel_get_type (void); diff --git a/src/roomlist-manager.c b/src/roomlist-manager.c index b1e57bb6..f95fbd31 100644 --- a/src/roomlist-manager.c +++ b/src/roomlist-manager.c @@ -44,6 +44,7 @@ #include <telepathy-glib/dbus.h> #include <telepathy-glib/interfaces.h> #include <telepathy-glib/util.h> +#include <telepathy-glib/base-channel.h> #define DEBUG_FLAG DEBUG_MUC #include "debug.h" @@ -358,6 +359,8 @@ make_roomlist_channel (SalutRoomlistManager *self) roomlist_channel = salut_roomlist_channel_new (priv->connection, object_path); + tp_base_channel_register (TP_BASE_CHANNEL (roomlist_channel)); + rooms = SALUT_ROOMLIST_MANAGER_GET_CLASS (self)->get_rooms (self); for (l = rooms; l != NULL; l = g_slist_next (l)) { |