]> www.infradead.org Git - pidgin-chime.git/commitdiff
Add ref to ChimeConnection from each ChimeObject
authorDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 5 Dec 2017 23:52:04 +0000 (23:52 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 5 Dec 2017 23:52:04 +0000 (23:52 +0000)
This makes life a lot easier.

chime-call.c
chime-contact.c
chime-conversation.c
chime-meeting.c
chime-object.c
chime-object.h
chime-room.c

index c9eabb8408fd5185377265ffd7f3e83a1541497a..228b49b337db487ebfdc30fca3891fdbb5613abe 100644 (file)
@@ -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)
index 7940e00588cb32703be32afa17e832d1ea0b779e..008a85ce6194812cb0356211688368856584649b 100644 (file)
@@ -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);
 }
index b931fa185c9ea9ad5e6f458e9c061c262708aae7..4e68acda6631f2b11e6cfa61fb8a80a3292ff042 100644 (file)
@@ -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);
index 5b91e165781214c1ecc0e66e1ace9c3e77e2a6fd..524e408064257f549059493104f4112496420c69 100644 (file)
@@ -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);
index f64fbe202836a8227b370f89fadfdb9de5cd1d83..6204bcd37494ef7ecb0338b1cf3b3d8cfbbd6f03 100644 (file)
@@ -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)
index e206d46ce5d3e5bc6a923383fe3d8a1d602ec136..99a0a62827ac82c4758805aad2efdb1adda73e9c 100644 (file)
@@ -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,
index ced222ff5626bb344d93f2450d853d989b7c112b..1e67831c13f56a8992b1282ee015031628497ac5 100644 (file)
@@ -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);