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



commit a845c86e8cb95f94d30f5d3332c36ab3e3642e36
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 | 32 +++++++++++++++++++++++++--
 2 files changed, 81 insertions(+), 6 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 9dacc062..fb7b85b9 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -28,6 +28,7 @@
 #include <glib.h>
 
 #include "photos-base-manager.h"
+#include "photos-debug.h"
 #include "photos-filterable.h"
 
 
@@ -126,6 +127,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);
@@ -133,7 +135,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)
     {
@@ -151,6 +153,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);
+    }
 }
 
 
@@ -254,15 +279,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);
@@ -273,7 +299,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);
 }
 
 
@@ -550,6 +593,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));
@@ -567,6 +611,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 67a824ce..365d5450 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -30,6 +30,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"
@@ -644,13 +645,14 @@ photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *i
 {
   PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
   g_autoptr (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);
@@ -659,6 +661,23 @@ 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));
+
+ 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);
+    }
 }
 
 
@@ -1056,6 +1075,7 @@ void
 photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 {
   PhotosBaseManager *item_mngr_chld;
+  const gchar *type_name;
   guint i;
   guint n_items;
 
@@ -1064,6 +1084,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++)
@@ -1083,7 +1106,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)
@@ -1093,10 +1119,12 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 
           g_signal_handlers_disconnect_by_func (item, photos_item_manager_info_updated, self);
           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);
         }
     }
 
   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]