[PATCH 6/9] core: Do not directly destroy GrlMediaSourceFooSpec structures



Instead, use unref() to decrement its references counter, so it is destroyed
only if it reaches 0.
---
 src/grl-media-source.c |   68 ++++-------------------------------------------
 1 files changed, 6 insertions(+), 62 deletions(-)

diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index 960689c..8b66005 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -400,36 +400,6 @@ set_operation_data (GrlMediaSource *source, guint operation_id, gpointer data)
 }
 
 static void
-free_browse_operation_spec (GrlMediaSourceBrowseSpec *spec)
-{
-  g_debug ("free_browse_operation_spec");
-  g_object_unref (spec->source);
-  g_object_unref (spec->container);
-  g_list_free (spec->keys);
-  g_free (spec);
-}
-
-static void
-free_search_operation_spec (GrlMediaSourceSearchSpec *spec)
-{
-  g_debug ("free_search_operation_spec");
-  g_object_unref (spec->source);
-  g_free (spec->text);
-  g_list_free (spec->keys);
-  g_free (spec);
-}
-
-static void
-free_query_operation_spec (GrlMediaSourceQuerySpec *spec)
-{
-  g_debug ("free_query_operation_spec");
-  g_object_unref (spec->source);
-  g_free (spec->query);
-  g_list_free (spec->keys);
-  g_free (spec);
-}
-
-static void
 free_source_map_list (GList *source_map_list)
 {
   GList *iter;
@@ -496,17 +466,6 @@ metadata_idle (gpointer user_data)
   return FALSE;
 }
 
-static void
-store_idle_destroy (gpointer user_data)
-{
-  GrlMediaSourceStoreSpec *ss = (GrlMediaSourceStoreSpec *) user_data;
-  g_object_unref (ss->source);
-  if (ss->parent)
-    g_object_unref (ss->parent);
-  g_object_unref (ss->media);
-  g_free (ss);
-}
-
 static gboolean
 store_idle (gpointer user_data)
 {
@@ -516,15 +475,6 @@ store_idle (gpointer user_data)
   return FALSE;
 }
 
-static void
-remove_idle_destroy (gpointer user_data)
-{
-  GrlMediaSourceRemoveSpec *rs = (GrlMediaSourceRemoveSpec *) user_data;
-  g_object_unref (rs->source);
-  g_free (rs->media_id);
-  g_free (rs);
-}
-
 static gboolean
 remove_idle (gpointer user_data)
 {
@@ -748,11 +698,11 @@ browse_result_relay_cb (GrlMediaSource *source,
     g_debug ("Got remaining '0' for operation %d (%s)",
 	     browse_id,  grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
     if (brc->bspec) {
-      free_browse_operation_spec (brc->bspec);
+      grl_media_source_browse_spec_unref (brc->bspec);
     } else if (brc->sspec) {
-      free_search_operation_spec (brc->sspec);
+      grl_media_source_search_spec_unref (brc->sspec);
     } else if (brc->sspec) {
-      free_query_operation_spec (brc->qspec);
+      grl_media_source_query_spec_unref (brc->qspec);
     }
     g_free (brc->auto_split);
     g_free (brc);
@@ -777,13 +727,7 @@ metadata_result_relay_cb (GrlMediaSource *source,
 
   mrc->user_callback (source, media, mrc->user_data, error);
 
-  g_object_unref (mrc->spec->source);
-  if (mrc->spec->media) {
-    /* Can be NULL if getting metadata for root category */
-    g_object_unref (mrc->spec->media);
-  }
-  g_list_free (mrc->spec->keys);
-  g_free (mrc->spec);
+  grl_media_source_metadata_spec_unref (mrc->spec);
   g_free (mrc);
 }
 
@@ -2032,7 +1976,7 @@ grl_media_source_store (GrlMediaSource *source,
     g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
 		     store_idle,
 		     ss,
-		     store_idle_destroy);
+                     (GDestroyNotify) grl_media_source_store_spec_unref);
   } else {
     callback (source, parent, media, user_data, error);
     g_error_free (error);
@@ -2087,7 +2031,7 @@ grl_media_source_remove (GrlMediaSource *source,
     g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
 		     remove_idle,
 		     rs,
-		     remove_idle_destroy);
+                     (GDestroyNotify) grl_media_source_remove_spec_unref);
   } else {
     callback (source, media, user_data, error);
     g_error_free (error);
-- 
1.7.0.4



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