From feb9b9cebbbcc63e04fc19b06ed41a7cb4f232be Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 16 Apr 2014 20:29:30 +0100 Subject: Use TpPresenceMixin as the type for methods and vfuncs Otherwise, the vfuncs are not introspectable. --- .../telepathy-glib/telepathy-glib-sections.txt | 1 + examples/cm/call/conn.c | 20 +++++++++------- examples/cm/contactlist/conn.c | 23 ++++++++++-------- telepathy-glib/presence-mixin.c | 28 ++++++++++++---------- telepathy-glib/presence-mixin.h | 23 ++++++++++-------- tests/lib/contacts-conn.c | 19 ++++++++------- 6 files changed, 63 insertions(+), 51 deletions(-) diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt index 51e14fedf..50f650ccd 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt @@ -1688,6 +1688,7 @@ tp_presence_mixin_fill_contact_attributes tp_presence_mixin_emit_presence_update tp_presence_mixin_emit_one_presence_update +TP_PRESENCE_MIXIN TP_TYPE_PRESENCE_MIXIN TP_IS_PRESENCE_MIXIN TP_PRESENCE_MIXIN_GET_INTERFACE diff --git a/examples/cm/call/conn.c b/examples/cm/call/conn.c index eea43dd06..3dd0e0a40 100644 --- a/examples/cm/call/conn.c +++ b/examples/cm/call/conn.c @@ -127,7 +127,7 @@ constructed (GObject *object) if (chain_up != NULL) chain_up (object); - tp_presence_mixin_init (TP_BASE_CONNECTION (object)); + tp_presence_mixin_init (TP_PRESENCE_MIXIN (object)); } static void @@ -223,17 +223,18 @@ shut_down (TpBaseConnection *conn) } static gboolean -status_available (TpBaseConnection *base, +status_available (TpPresenceMixin *mixin, guint index_) { - return tp_base_connection_check_connected (base, NULL); + return tp_base_connection_check_connected (TP_BASE_CONNECTION (mixin), NULL); } static TpPresenceStatus * -get_contact_status (TpBaseConnection *base, +get_contact_status (TpPresenceMixin *mixin, TpHandle contact) { - ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (base); + ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (mixin); + TpBaseConnection *base = TP_BASE_CONNECTION (mixin); ExampleCallPresence presence; const gchar *message; @@ -255,11 +256,12 @@ get_contact_status (TpBaseConnection *base, } static gboolean -set_own_status (TpBaseConnection *base, +set_own_status (TpPresenceMixin *mixin, const TpPresenceStatus *status, GError **error) { - ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (base); + ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (mixin); + TpBaseConnection *base = TP_BASE_CONNECTION (mixin); GHashTable *presences; if (status->index == EXAMPLE_CALL_PRESENCE_AWAY) @@ -287,7 +289,7 @@ set_own_status (TpBaseConnection *base, g_hash_table_insert (presences, GUINT_TO_POINTER (tp_base_connection_get_self_handle (base)), (gpointer) status); - tp_presence_mixin_emit_presence_update (base, presences); + tp_presence_mixin_emit_presence_update (TP_PRESENCE_MIXIN (self), presences); g_hash_table_unref (presences); if (!self->priv->away) @@ -326,7 +328,7 @@ fill_contact_attributes (TpBaseConnection *conn, TpHandle contact, GVariantDict *attributes) { - if (tp_presence_mixin_fill_contact_attributes (conn, + if (tp_presence_mixin_fill_contact_attributes (TP_PRESENCE_MIXIN (conn), dbus_interface, contact, attributes)) return; diff --git a/examples/cm/contactlist/conn.c b/examples/cm/contactlist/conn.c index 9105a995b..20db31f90 100644 --- a/examples/cm/contactlist/conn.c +++ b/examples/cm/contactlist/conn.c @@ -177,7 +177,8 @@ presence_updated_cb (ExampleContactList *contact_list, status = tp_presence_status_new ( example_contact_list_get_presence (contact_list, contact), NULL); - tp_presence_mixin_emit_one_presence_update (base, contact, status); + tp_presence_mixin_emit_one_presence_update (TP_PRESENCE_MIXIN (self), + contact, status); tp_presence_status_free (status); } @@ -245,7 +246,7 @@ example_contact_list_connection_fill_contact_attributes (TpBaseConnection *conn, dbus_interface, contact, attributes)) return; - if (tp_presence_mixin_fill_contact_attributes (conn, + if (tp_presence_mixin_fill_contact_attributes (TP_PRESENCE_MIXIN (self), dbus_interface, contact, attributes)) return; @@ -276,7 +277,7 @@ constructed (GObject *object) g_signal_connect (self->priv->contact_list, "presence-updated", G_CALLBACK (presence_updated_cb), self); - tp_presence_mixin_init (TP_BASE_CONNECTION (object)); + tp_presence_mixin_init (TP_PRESENCE_MIXIN (object)); iface = tp_svc_interface_skeleton_new (skel, TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING1); @@ -285,17 +286,18 @@ constructed (GObject *object) } static gboolean -status_available (TpBaseConnection *base, +status_available (TpPresenceMixin *mixin, guint index_) { - return tp_base_connection_check_connected (base, NULL); + return tp_base_connection_check_connected (TP_BASE_CONNECTION (mixin), NULL); } static TpPresenceStatus * -get_contact_status (TpBaseConnection *base, +get_contact_status (TpPresenceMixin *mixin, TpHandle contact) { - ExampleContactListConnection *self = EXAMPLE_CONTACT_LIST_CONNECTION (base); + ExampleContactListConnection *self = EXAMPLE_CONTACT_LIST_CONNECTION (mixin); + TpBaseConnection *base = TP_BASE_CONNECTION (mixin); ExampleContactListPresence presence; /* we get our own status from the connection, and everyone else's status @@ -315,11 +317,12 @@ get_contact_status (TpBaseConnection *base, } static gboolean -set_own_status (TpBaseConnection *base, +set_own_status (TpPresenceMixin *mixin, const TpPresenceStatus *status, GError **error) { - ExampleContactListConnection *self = EXAMPLE_CONTACT_LIST_CONNECTION (base); + ExampleContactListConnection *self = EXAMPLE_CONTACT_LIST_CONNECTION (mixin); + TpBaseConnection *base = TP_BASE_CONNECTION (mixin); GHashTable *presences; if (status->index == EXAMPLE_CONTACT_LIST_PRESENCE_AWAY) @@ -342,7 +345,7 @@ set_own_status (TpBaseConnection *base, g_hash_table_insert (presences, GUINT_TO_POINTER (tp_base_connection_get_self_handle (base)), (gpointer) status); - tp_presence_mixin_emit_presence_update (base, presences); + tp_presence_mixin_emit_presence_update (TP_PRESENCE_MIXIN (self), presences); g_hash_table_unref (presences); return TRUE; } diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c index fd4ada225..8cfc6bb3b 100644 --- a/telepathy-glib/presence-mixin.c +++ b/telepathy-glib/presence-mixin.c @@ -226,14 +226,14 @@ tp_presence_status_free (TpPresenceStatus *status) G_DEFINE_INTERFACE (TpPresenceMixin, tp_presence_mixin, TP_TYPE_BASE_CONNECTION) -static void update_statuses_property (TpBaseConnection *self); -static void update_max_status_message_len_property (TpBaseConnection *self); +static void update_statuses_property (TpPresenceMixin *self); +static void update_max_status_message_len_property (TpPresenceMixin *self); static gboolean tp_presence_mixin_set_presence ( _TpGDBusConnectionInterfacePresence1 *skeleton, GDBusMethodInvocation *context, const gchar *status, const gchar *message, - TpBaseConnection *self); + TpPresenceMixin *self); static void tp_presence_mixin_default_init (TpPresenceMixinInterface *iface) @@ -241,11 +241,13 @@ tp_presence_mixin_default_init (TpPresenceMixinInterface *iface) } static void -connection_status_changed_cb (TpBaseConnection *self, +connection_status_changed_cb (TpBaseConnection *base, TpConnectionStatus status, TpConnectionStatusReason reason, gpointer user_data) { + TpPresenceMixin *self = TP_PRESENCE_MIXIN (base); + if (status == TP_CONNECTION_STATUS_CONNECTED) { update_statuses_property (self); @@ -262,7 +264,7 @@ connection_status_changed_cb (TpBaseConnection *self, * subclass that implements #TpPresenceMixin. */ void -tp_presence_mixin_init (TpBaseConnection *self) +tp_presence_mixin_init (TpPresenceMixin *self) { _TpGDBusConnectionInterfacePresence1 *presence_skeleton; TpPresenceMixinInterface *iface = TP_PRESENCE_MIXIN_GET_INTERFACE (self); @@ -322,7 +324,7 @@ tp_presence_mixin_init (TpBaseConnection *self) * #tp_presence_mixin_emit_one_presence_update. */ void -tp_presence_mixin_emit_presence_update (TpBaseConnection *self, +tp_presence_mixin_emit_presence_update (TpPresenceMixin *self, GHashTable *contact_statuses) { TpPresenceMixinInterface *iface = TP_PRESENCE_MIXIN_GET_INTERFACE (self); @@ -348,7 +350,7 @@ tp_presence_mixin_emit_presence_update (TpBaseConnection *self, * just a convenience wrapper around tp_presence_mixin_emit_presence_update(). */ void -tp_presence_mixin_emit_one_presence_update (TpBaseConnection *self, +tp_presence_mixin_emit_one_presence_update (TpPresenceMixin *self, TpHandle handle, const TpPresenceStatus *status) { @@ -365,7 +367,7 @@ tp_presence_mixin_emit_one_presence_update (TpBaseConnection *self, } static gboolean -check_status_available (TpBaseConnection *self, +check_status_available (TpPresenceMixin *self, TpPresenceMixinInterface *iface, guint i, GError **error, @@ -412,7 +414,7 @@ check_status_available (TpBaseConnection *self, } static int -check_for_status (TpBaseConnection *self, +check_for_status (TpPresenceMixin *self, const gchar *status, GError **error) { @@ -445,7 +447,7 @@ check_for_status (TpBaseConnection *self, } static void -update_statuses_property (TpBaseConnection *self) +update_statuses_property (TpPresenceMixin *self) { TpPresenceMixinInterface *iface = TP_PRESENCE_MIXIN_GET_INTERFACE (self); _TpGDBusConnectionInterfacePresence1 *presence_skeleton; @@ -481,7 +483,7 @@ update_statuses_property (TpBaseConnection *self) } static void -update_max_status_message_len_property (TpBaseConnection *self) +update_max_status_message_len_property (TpPresenceMixin *self) { TpPresenceMixinInterface *iface = TP_PRESENCE_MIXIN_GET_INTERFACE (self); _TpGDBusConnectionInterfacePresence1 *presence_skeleton; @@ -503,7 +505,7 @@ tp_presence_mixin_set_presence ( GDBusMethodInvocation *context, const gchar *status, const gchar *message, - TpBaseConnection *self) + TpPresenceMixin *self) { TpPresenceMixinInterface *iface = TP_PRESENCE_MIXIN_GET_INTERFACE (self); TpPresenceStatus status_to_set = { 0, }; @@ -620,7 +622,7 @@ construct_presence_map (const TpPresenceStatusSpec *supported_statuses, * Returns: %TRUE if @dbus_interface was handled */ gboolean -tp_presence_mixin_fill_contact_attributes (TpBaseConnection *self, +tp_presence_mixin_fill_contact_attributes (TpPresenceMixin *self, const gchar *dbus_interface, TpHandle contact, GVariantDict *attributes) diff --git a/telepathy-glib/presence-mixin.h b/telepathy-glib/presence-mixin.h index c9d97777e..4a7b54995 100644 --- a/telepathy-glib/presence-mixin.h +++ b/telepathy-glib/presence-mixin.h @@ -102,6 +102,10 @@ void tp_presence_status_free (TpPresenceStatus *status); #define TP_TYPE_PRESENCE_MIXIN \ (tp_presence_mixin_get_type ()) +#define TP_PRESENCE_MIXIN(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + TP_TYPE_PRESENCE_MIXIN, TpPresenceMixin)) + #define TP_IS_PRESENCE_MIXIN(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ TP_TYPE_PRESENCE_MIXIN)) @@ -111,22 +115,21 @@ void tp_presence_status_free (TpPresenceStatus *status); TP_TYPE_PRESENCE_MIXIN, TpPresenceMixinInterface)) typedef struct _TpPresenceMixinInterface TpPresenceMixinInterface; -/* For some reason g-i wants that name */ -typedef struct _TpPresenceMixinInterface TpPresenceMixin; +typedef struct _TpPresenceMixin TpPresenceMixin; -typedef gboolean (*TpPresenceMixinStatusAvailableFunc) (TpBaseConnection *self, +typedef gboolean (*TpPresenceMixinStatusAvailableFunc) (TpPresenceMixin *self, guint which); typedef TpPresenceStatus *(*TpPresenceMixinGetContactStatusFunc) ( - TpBaseConnection *self, + TpPresenceMixin *self, TpHandle contact); -typedef gboolean (*TpPresenceMixinSetOwnStatusFunc) (TpBaseConnection *self, +typedef gboolean (*TpPresenceMixinSetOwnStatusFunc) (TpPresenceMixin *self, const TpPresenceStatus *status, GError **error); typedef guint (*TpPresenceMixinGetMaximumStatusMessageLengthFunc) ( - TpBaseConnection *self); + TpPresenceMixin *self); struct _TpPresenceMixinInterface { GTypeInterface parent; @@ -142,14 +145,14 @@ struct _TpPresenceMixinInterface { GType tp_presence_mixin_get_type (void) G_GNUC_CONST; -void tp_presence_mixin_emit_presence_update (TpBaseConnection *self, +void tp_presence_mixin_emit_presence_update (TpPresenceMixin *self, GHashTable *contact_presences); -void tp_presence_mixin_emit_one_presence_update (TpBaseConnection *self, +void tp_presence_mixin_emit_one_presence_update (TpPresenceMixin *self, TpHandle handle, const TpPresenceStatus *status); -void tp_presence_mixin_init (TpBaseConnection *self); -gboolean tp_presence_mixin_fill_contact_attributes (TpBaseConnection *self, +void tp_presence_mixin_init (TpPresenceMixin *self); +gboolean tp_presence_mixin_fill_contact_attributes (TpPresenceMixin *self, const gchar *dbus_interface, TpHandle contact, GVariantDict *attributes); diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c index d4a3ebc13..a418cb7ce 100644 --- a/tests/lib/contacts-conn.c +++ b/tests/lib/contacts-conn.c @@ -298,7 +298,7 @@ tp_tests_contacts_connection_fill_contact_attributes (TpBaseConnection *base, dbus_interface, contact, attributes)) return; - if (tp_presence_mixin_fill_contact_attributes (base, + if (tp_presence_mixin_fill_contact_attributes (TP_PRESENCE_MIXIN (self), dbus_interface, contact, attributes)) return; @@ -417,7 +417,7 @@ constructed (GObject *object) self->priv->list_manager = g_object_new (TP_TESTS_TYPE_CONTACT_LIST_MANAGER, "connection", self, NULL); - tp_presence_mixin_init (TP_BASE_CONNECTION (self)); + tp_presence_mixin_init (TP_PRESENCE_MIXIN (self)); } /* Must match TpTestsContactsConnectionPresenceStatusIndex in the .h */ @@ -432,17 +432,17 @@ static const TpPresenceStatusSpec my_statuses[] = { }; static gboolean -my_status_available (TpBaseConnection *base, +my_status_available (TpPresenceMixin *mixin, guint index) { - return tp_base_connection_check_connected (base, NULL); + return tp_base_connection_check_connected (TP_BASE_CONNECTION (mixin), NULL); } static TpPresenceStatus * -my_get_contact_status (TpBaseConnection *base_conn, +my_get_contact_status (TpPresenceMixin *mixin, TpHandle contact) { - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (base_conn); + TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (mixin); gpointer key = GUINT_TO_POINTER (contact); TpTestsContactsConnectionPresenceStatusIndex index; const gchar *presence_message; @@ -456,10 +456,11 @@ my_get_contact_status (TpBaseConnection *base_conn, } static gboolean -my_set_own_status (TpBaseConnection *base_conn, +my_set_own_status (TpPresenceMixin *mixin, const TpPresenceStatus *status, GError **error) { + TpBaseConnection *base_conn = TP_BASE_CONNECTION (mixin); TpTestsContactsConnectionPresenceStatusIndex index = status->index; const gchar *message = status->message; TpHandle self_handle; @@ -473,7 +474,7 @@ my_set_own_status (TpBaseConnection *base_conn, } static guint -my_get_maximum_status_message_length_cb (TpBaseConnection *base_conn) +my_get_maximum_status_message_length_cb (TpPresenceMixin *mixin G_GNUC_UNUSED) { return 512; } @@ -632,7 +633,7 @@ tp_tests_contacts_connection_change_presences ( messages[i])); } - tp_presence_mixin_emit_presence_update ((TpBaseConnection *) self, + tp_presence_mixin_emit_presence_update (TP_PRESENCE_MIXIN (self), presences); g_hash_table_unref (presences); } -- cgit v1.2.3