From: David Woodhouse Date: Tue, 5 Dec 2017 23:52:04 +0000 (+0000) Subject: Add ref to ChimeConnection from each ChimeObject X-Git-Tag: v0.9~99 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=19c139b684faafedcd7d73d3d4987983c473eed8;p=pidgin-chime.git Add ref to ChimeConnection from each ChimeObject This makes life a lot easier. --- diff --git a/chime-call.c b/chime-call.c index c9eabb8..228b49b 100644 --- a/chime-call.c +++ b/chime-call.c @@ -441,7 +441,7 @@ void chime_init_calls(ChimeConnection *cxn) { ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn); - chime_object_collection_init(&priv->calls); + chime_object_collection_init(cxn, &priv->calls); } void chime_destroy_calls(ChimeConnection *cxn) diff --git a/chime-contact.c b/chime-contact.c index 7940e00..008a85c 100644 --- a/chime-contact.c +++ b/chime-contact.c @@ -598,7 +598,7 @@ void chime_init_contacts(ChimeConnection *cxn) g_return_if_fail(CHIME_IS_CONNECTION(cxn)); ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn); - chime_object_collection_init(&priv->contacts); + chime_object_collection_init(cxn, &priv->contacts); fetch_contacts(cxn, NULL); } diff --git a/chime-conversation.c b/chime-conversation.c index b931fa1..4e68acd 100644 --- a/chime-conversation.c +++ b/chime-conversation.c @@ -622,7 +622,7 @@ void chime_init_conversations(ChimeConnection *cxn) { ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn); - chime_object_collection_init(&priv->conversations); + chime_object_collection_init(cxn, &priv->conversations); chime_jugg_subscribe(cxn, priv->device_channel, "Conversation", conv_jugg_cb, NULL); diff --git a/chime-meeting.c b/chime-meeting.c index 5b91e16..524e408 100644 --- a/chime-meeting.c +++ b/chime-meeting.c @@ -489,7 +489,7 @@ void chime_init_meetings(ChimeConnection *cxn) { ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn); - chime_object_collection_init(&priv->meetings); + chime_object_collection_init(cxn, &priv->meetings); chime_jugg_subscribe(cxn, priv->device_channel, "JoinableMeetings", joinable_meetings_jugg_cb, NULL); diff --git a/chime-object.c b/chime-object.c index f64fbe2..6204bcd 100644 --- a/chime-object.c +++ b/chime-object.c @@ -37,6 +37,7 @@ typedef struct { * hash table in its ->dispose() */ gboolean is_dead; ChimeObjectCollection *collection; + ChimeConnection *cxn; } ChimeObjectPrivate; enum @@ -67,6 +68,9 @@ chime_object_dispose(GObject *object) chime_debug("Object disposed: %p\n", self); + if (priv->cxn) + g_clear_object(&priv->cxn); + G_OBJECT_CLASS(chime_object_parent_class)->dispose(object); } @@ -197,6 +201,17 @@ static void chime_object_init(ChimeObject *self) { } +ChimeConnection *chime_object_get_connection(ChimeObject *self) +{ + ChimeObjectPrivate *priv; + + g_return_val_if_fail(CHIME_IS_OBJECT(self), NULL); + + priv = chime_object_get_instance_private (self); + + return priv->cxn; + +} const gchar *chime_object_get_id(ChimeObject *self) { ChimeObjectPrivate *priv; @@ -239,6 +254,9 @@ void chime_object_collection_hash_object(ChimeObjectCollection *collection, Chim priv->generation = collection->generation; + if (!priv->cxn) + priv->cxn = g_object_ref(collection->cxn); + if (!priv->collection) { priv->collection = collection; g_hash_table_insert(collection->by_id, priv->id, object); @@ -290,12 +308,13 @@ static void unhash_object(gpointer _object) } } -void chime_object_collection_init(ChimeObjectCollection *coll) +void chime_object_collection_init(ChimeConnection *cxn, ChimeObjectCollection *coll) { coll->by_id = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, unhash_object); coll->by_name = g_hash_table_new(g_str_hash, g_str_equal); coll->generation = 0; + coll->cxn = cxn; } void chime_object_collection_destroy(ChimeObjectCollection *coll) diff --git a/chime-object.h b/chime-object.h index e206d46..99a0a62 100644 --- a/chime-object.h +++ b/chime-object.h @@ -33,19 +33,21 @@ typedef struct { GHashTable *by_id; GHashTable *by_name; gint64 generation; + ChimeConnection *cxn; } ChimeObjectCollection; struct _ChimeObjectClass { GObjectClass parent_class; }; +ChimeConnection *chime_object_get_connection(ChimeObject *self); const gchar *chime_object_get_id(ChimeObject *self); const gchar *chime_object_get_name(ChimeObject *self); gboolean chime_object_is_dead(ChimeObject *self); void chime_object_rename(ChimeObject *self, const gchar *name); -void chime_object_collection_init(ChimeObjectCollection *coll); +void chime_object_collection_init(ChimeConnection *cxn, ChimeObjectCollection *coll); void chime_object_collection_destroy(ChimeObjectCollection *coll); ChimeObject *chime_connection_object_by_name(ChimeObjectCollection *coll, diff --git a/chime-room.c b/chime-room.c index ced222f..1e67831 100644 --- a/chime-room.c +++ b/chime-room.c @@ -607,7 +607,7 @@ void chime_init_rooms(ChimeConnection *cxn) { ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn); - chime_object_collection_init(&priv->rooms); + chime_object_collection_init(cxn, &priv->rooms); chime_jugg_subscribe(cxn, priv->profile_channel, "VisibleRooms", visible_rooms_jugg_cb, NULL);