[PATCH 13/15] core: Add unref() functions to GrlMetadataSourceFooSpec



Add grl_metadata_source_foo_spec_unref() to decrement reference.

When references counter reaches 0, the spec is destroyed, and its contents are
released.
---
 src/grl-metadata-source.c |   40 ++++++++++++++++++++++++++++++++++++++++
 src/grl-metadata-source.h |    4 ++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c
index 1ed29a5..e9ea072 100644
--- a/src/grl-metadata-source.c
+++ b/src/grl-metadata-source.c
@@ -539,6 +539,46 @@ grl_metadata_source_set_metadata_spec_ref (GrlMetadataSourceSetMetadataSpec *sms
   return sms;
 }
 
+void
+grl_metadata_source_resolve_spec_unref (GrlMetadataSourceResolveSpec *rs)
+{
+  g_return_if_fail (rs);
+  g_return_if_fail (rs->ref_count > 0);
+
+  if (g_atomic_int_dec_and_test (&rs->ref_count)) {
+    if (rs->source) {
+      g_object_unref (rs->source);
+    }
+    if (rs->media) {
+      g_object_unref (rs->media);
+    }
+    if (rs->keys) {
+      g_list_free (rs->keys);
+    }
+    g_free (rs);
+  }
+}
+
+void
+grl_metadata_source_set_metadata_spec_unref (GrlMetadataSourceSetMetadataSpec *sms)
+{
+  g_return_if_fail (sms);
+  g_return_if_fail (sms->ref_count > 0);
+
+  if (g_atomic_int_dec_and_test (&sms->ref_count)) {
+    if (sms->source) {
+      g_object_unref (sms->source);
+    }
+    if (sms->media) {
+      g_object_unref (sms->media);
+    }
+    if (sms->keys) {
+      g_list_free (sms->keys);
+    }
+    g_free (sms);
+  }
+}
+
 /**
  * grl_metadata_source_supported_keys:
  * @source: a metadata source
diff --git a/src/grl-metadata-source.h b/src/grl-metadata-source.h
index ef6913c..bad1f6e 100644
--- a/src/grl-metadata-source.h
+++ b/src/grl-metadata-source.h
@@ -263,6 +263,10 @@ GrlMetadataSourceResolveSpec *grl_metadata_source_resolve_spec_ref (GrlMetadataS
 
 GrlMetadataSourceSetMetadataSpec *grl_metadata_source_set_metadata_spec_ref (GrlMetadataSourceSetMetadataSpec *sms);
 
+void grl_metadata_source_resolve_spec_unref (GrlMetadataSourceResolveSpec *rs);
+
+void grl_metadata_source_set_metadata_spec_unref (GrlMetadataSourceSetMetadataSpec *sms);
+
 GrlSupportedOps grl_metadata_source_supported_operations (GrlMetadataSource *source);
 
 const GList *grl_metadata_source_supported_keys (GrlMetadataSource *source);
-- 
1.7.0.4



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