[gnome-photos/wip/rishi/collection: 7/25] base-manager, item-manager: Log additions and removals



commit 3fb0e00e004c6b14ee5915cc100f7403484852e2
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Sep 4 18:42:43 2017 +0200

    base-manager, item-manager: Log additions and removals

 src/photos-base-manager.c | 55 +++++++++++++++++++++++++++++++++++++++++++----
 src/photos-item-manager.c | 37 +++++++++++++++++++++++++++----
 2 files changed, 84 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 0527cab8..14752f4f 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -30,6 +30,7 @@
 #include <glib.h>
 
 #include "photos-base-manager.h"
+#include "photos-debug.h"
 #include "photos-filterable.h"
 
 
@@ -128,6 +129,7 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
   GSequenceIter *iter;
   PhotosBaseManagerObjectData *object_data;
   const gchar *id;
+  const gchar *type_name;
   guint position;
 
   priv = photos_base_manager_get_instance_private (self);
@@ -135,7 +137,7 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
   id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
   old_object = photos_base_manager_get_object_by_id (self, id);
   if (old_object != NULL)
-    return;
+    goto out;
 
   if (priv->sort_func == NULL)
     {
@@ -153,6 +155,29 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
 
   photos_base_manager_objects_changed (self, position, 0, 1);
   g_signal_emit (self, signals[OBJECT_ADDED], 0, object);
+
+ out:
+  type_name = G_OBJECT_TYPE_NAME (self);
+  if (old_object == NULL)
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) added for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    object,
+                    id);
+    }
+  else
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) already exists for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    old_object,
+                    id);
+    }
 }
 
 
@@ -256,15 +281,16 @@ static void
 photos_base_manager_default_remove_object_by_id (PhotosBaseManager *self, const gchar *id)
 {
   PhotosBaseManagerPrivate *priv;
-  GObject *object;
+  GObject *object = NULL;
   PhotosBaseManagerObjectData *object_data;
+  const gchar *type_name;
   guint position;
 
   priv = photos_base_manager_get_instance_private (self);
 
   object_data = g_hash_table_lookup (priv->objects, id);
   if (object_data == NULL)
-    return;
+    goto out;
 
   position = g_sequence_iter_get_position (object_data->iter);
   g_sequence_remove (object_data->iter);
@@ -275,7 +301,24 @@ photos_base_manager_default_remove_object_by_id (PhotosBaseManager *self, const
   photos_base_manager_objects_changed (self, position, 1, 0);
   g_signal_emit (self, signals[OBJECT_REMOVED], 0, object);
 
-  g_object_unref (object);
+ out:
+  type_name = G_OBJECT_TYPE_NAME (self);
+  if (object_data == NULL)
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: object not found for %s", type_name, self, 
G_STRFUNC, id);
+    }
+  else
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) removed for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    object,
+                    id);
+    }
+
+  g_clear_object (&object);
 }
 
 
@@ -557,6 +600,7 @@ photos_base_manager_clear (PhotosBaseManager *self)
   PhotosBaseManagerPrivate *priv;
   GSequenceIter *begin_iter;
   GSequenceIter *end_iter;
+  const gchar *type_name;
   guint count;
 
   g_return_if_fail (PHOTOS_IS_BASE_MANAGER (self));
@@ -574,6 +618,9 @@ photos_base_manager_clear (PhotosBaseManager *self)
 
   photos_base_manager_objects_changed (self, 0, count, 0);
   g_signal_emit (self, signals[CLEAR], 0);
+
+  type_name = G_OBJECT_TYPE_NAME (self);
+  photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: cleared", type_name, self, G_STRFUNC);
 }
 
 
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 25dd7cb9..9ed0e10a 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -32,6 +32,7 @@
 #include <tracker-sparql.h>
 
 #include "egg-counter.h"
+#include "photos-debug.h"
 #include "photos-enums.h"
 #include "photos-filterable.h"
 #include "photos-item-manager.h"
@@ -602,14 +603,15 @@ static void
 photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *id)
 {
   PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
-  PhotosBaseItem *item;
+  PhotosBaseItem *item = NULL;
+  const gchar *type_name;
   guint i;
 
   g_hash_table_remove (self->collections, id);
 
   item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id));
   if (item == NULL)
-    return;
+    goto out;
 
   g_signal_handlers_disconnect_by_func (item, photos_item_manager_info_updated, self);
   g_object_ref (item);
@@ -618,7 +620,25 @@ photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *i
     photos_base_manager_remove_object_by_id (self->item_mngr_chldrn[i], id);
 
   g_signal_emit_by_name (self, "object-removed", G_OBJECT (item));
-  g_object_unref (item);
+
+ out:
+  type_name = G_OBJECT_TYPE_NAME (self);
+  if (item == NULL)
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: object not found for %s", type_name, self, 
G_STRFUNC, id);
+    }
+  else
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) removed for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    item,
+                    id);
+    }
+
+  g_clear_object (&item);
 }
 
 
@@ -993,6 +1013,7 @@ void
 photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 {
   PhotosBaseManager *item_mngr_chld;
+  const gchar *type_name;
   guint i;
   guint n_items;
 
@@ -1001,6 +1022,9 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_EDIT);
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
 
+  type_name = G_OBJECT_TYPE_NAME (self);
+  photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: clearing mode %d", type_name, self, G_STRFUNC, mode);
+
   item_mngr_chld = self->item_mngr_chldrn[mode];
   n_items = g_list_model_get_n_items (G_LIST_MODEL (item_mngr_chld));
   for (i = 0; i < n_items; i++)
@@ -1020,7 +1044,10 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 
           item1 = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr_chldrn[j], id));
           if (item1 != NULL)
-            break;
+            {
+              photos_debug (PHOTOS_DEBUG_MANAGER, "Object (%p, %s) also exists in mode %d", item, id, j);
+              break;
+            }
         }
 
       if (item1 == NULL)
@@ -1029,12 +1056,14 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
           g_assert_true (item == item1);
 
           photos_base_manager_remove_object_by_id (self->item_mngr_chldrn[0], id);
+          photos_debug (PHOTOS_DEBUG_MANAGER, "Object (%p, %s) removed from mode 0", item, id);
         }
 
       g_object_unref (item);
     }
 
   photos_base_manager_clear (item_mngr_chld);
+  photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: clearing mode %d: done", type_name, self, G_STRFUNC, 
mode);
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]